From 2f0441b3c1cd9fc3bcb176d2852da8f92a6e6777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 11 Aug 2016 00:44:01 +0200 Subject: GH-1433 with no default account, show profiles instead of accounts in selection dialog --- application/CMakeLists.txt | 10 +- application/InstanceWindow.h | 2 +- application/LaunchController.cpp | 276 +++++++++++++++++++++++++++ application/LaunchController.h | 48 +++++ application/LaunchInteraction.cpp | 276 --------------------------- application/LaunchInteraction.h | 48 ----- application/MainWindow.cpp | 5 +- application/dialogs/AccountSelectDialog.cpp | 85 --------- application/dialogs/AccountSelectDialog.h | 90 --------- application/dialogs/AccountSelectDialog.ui | 56 ------ application/dialogs/ProfileSelectDialog.cpp | 111 +++++++++++ application/dialogs/ProfileSelectDialog.h | 90 +++++++++ application/dialogs/ProfileSelectDialog.ui | 62 ++++++ application/main.cpp | 2 +- application/pages/global/AccountListPage.cpp | 1 - 15 files changed, 596 insertions(+), 566 deletions(-) create mode 100644 application/LaunchController.cpp create mode 100644 application/LaunchController.h delete mode 100644 application/LaunchInteraction.cpp delete mode 100644 application/LaunchInteraction.h delete mode 100644 application/dialogs/AccountSelectDialog.cpp delete mode 100644 application/dialogs/AccountSelectDialog.h delete mode 100644 application/dialogs/AccountSelectDialog.ui create mode 100644 application/dialogs/ProfileSelectDialog.cpp create mode 100644 application/dialogs/ProfileSelectDialog.h create mode 100644 application/dialogs/ProfileSelectDialog.ui diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index 46c496e2..0bc103bf 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -110,8 +110,8 @@ SET(MULTIMC_SOURCES SettingsUI.h # Processes - LaunchInteraction.h - LaunchInteraction.cpp + LaunchController.h + LaunchController.cpp # page provider for instances InstancePageProvider.h @@ -168,8 +168,8 @@ SET(MULTIMC_SOURCES # GUI - dialogs dialogs/AboutDialog.cpp dialogs/AboutDialog.h - dialogs/AccountSelectDialog.cpp - dialogs/AccountSelectDialog.h + dialogs/ProfileSelectDialog.cpp + dialogs/ProfileSelectDialog.h dialogs/CopyInstanceDialog.cpp dialogs/CopyInstanceDialog.h dialogs/CustomMessageBox.cpp @@ -267,7 +267,7 @@ SET(MULTIMC_UIS dialogs/VersionSelectDialog.ui dialogs/ProgressDialog.ui dialogs/IconPickerDialog.ui - dialogs/AccountSelectDialog.ui + dialogs/ProfileSelectDialog.ui dialogs/EditAccountDialog.ui dialogs/ExportInstanceDialog.ui dialogs/LoginDialog.ui diff --git a/application/InstanceWindow.h b/application/InstanceWindow.h index db84b9be..1da2231f 100644 --- a/application/InstanceWindow.h +++ b/application/InstanceWindow.h @@ -16,7 +16,7 @@ #pragma once #include -#include "LaunchInteraction.h" +#include "LaunchController.h" #include #include #include "launch/LaunchTask.h" diff --git a/application/LaunchController.cpp b/application/LaunchController.cpp new file mode 100644 index 00000000..bc7f976a --- /dev/null +++ b/application/LaunchController.cpp @@ -0,0 +1,276 @@ +#include "LaunchController.h" +#include "MainWindow.h" +#include +#include "MultiMC.h" +#include "dialogs/CustomMessageBox.h" +#include "dialogs/ProfileSelectDialog.h" +#include "dialogs/ProgressDialog.h" +#include "dialogs/EditAccountDialog.h" +#include "InstanceWindow.h" +#include "BuildConfig.h" +#include "JavaCommon.h" +#include "SettingsUI.h" +#include +#include +#include +#include +#include +#include + +LaunchController::LaunchController(QObject *parent) : Task(parent) +{ +} + +void LaunchController::executeTask() +{ + login(); +} + +// FIXME: minecraft specific +void LaunchController::login() +{ + if (!m_instance) + { + emitFailed(tr("No instance specified")); + return; + } + + JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget); + + // Find an account to use. + std::shared_ptr accounts = MMC->accounts(); + MojangAccountPtr account = accounts->activeAccount(); + if (accounts->count() <= 0) + { + // Tell the user they need to log in at least one account in order to play. + auto reply = CustomMessageBox::selectable( + m_parentWidget, tr("No Accounts"), + tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " + "account logged in to MultiMC." + "Would you like to open the account manager to add an account now?"), + QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); + + if (reply == QMessageBox::Yes) + { + // Open the account manager. + SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts"); + } + } + else if (account.get() == nullptr) + { + // If no default account is set, ask the user which one to use. + ProfileSelectDialog selectDialog(tr("Which profile would you like to use?"), + ProfileSelectDialog::GlobalDefaultCheckbox, m_parentWidget); + + selectDialog.exec(); + + // Launch the instance with the selected account. + account = selectDialog.selectedAccount(); + + // If the user said to use the account as default, do that. + if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) + accounts->setActiveAccount(account->username()); + } + + // if no account is selected, we bail + if (!account.get()) + { + emitFailed(tr("No account selected for launch")); + return; + } + + // we try empty password first :) + QString password; + // we loop until the user succeeds in logging in or gives up + bool tryagain = true; + // the failure. the default failure. + const QString needLoginAgain = tr("Your account is currently not logged in. Please enter " + "your password to log in again."); + QString failReason = needLoginAgain; + + while (tryagain) + { + m_session = std::make_shared(); + m_session->wants_online = m_online; + auto task = account->login(m_session, password); + if (task) + { + // We'll need to validate the access token to make sure the account + // is still logged in. + ProgressDialog progDialog(m_parentWidget); + if (m_online) + { + progDialog.setSkipButton(true, tr("Play Offline")); + } + progDialog.execWithTask(task.get()); + if (!task->successful()) + { + auto failReasonNew = task->failReason(); + if(failReasonNew == "Invalid token.") + { + failReason = needLoginAgain; + } + else failReason = failReasonNew; + } + } + switch (m_session->status) + { + case AuthSession::Undetermined: + { + qCritical() << "Received undetermined session status during login. Bye."; + tryagain = false; + emitFailed(tr("Received undetermined session status during login.")); + break; + } + case AuthSession::RequiresPassword: + { + EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField); + auto username = m_session->username; + auto chopN = [](QString toChop, int N) -> QString + { + if(toChop.size() > N) + { + auto left = toChop.left(N); + left += QString("\u25CF").repeated(toChop.size() - N); + return left; + } + return toChop; + }; + + if(username.contains('@')) + { + auto parts = username.split('@'); + auto mailbox = chopN(parts[0],3); + QString domain = chopN(parts[1], 3); + username = mailbox + '@' + domain; + } + passDialog.setUsername(username); + if (passDialog.exec() == QDialog::Accepted) + { + password = passDialog.password(); + } + else + { + tryagain = false; + } + break; + } + case AuthSession::PlayableOffline: + { + // we ask the user for a player name + bool ok = false; + QString usedname = m_session->player_name; + QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), + tr("Choose your offline mode player name."), + QLineEdit::Normal, m_session->player_name, &ok); + if (!ok) + { + tryagain = false; + break; + } + if (name.length()) + { + usedname = name; + } + m_session->MakeOffline(usedname); + // offline flavored game from here :3 + } + case AuthSession::PlayableOnline: + { + launchInstance(); + tryagain = false; + return; + } + } + } + emitFailed(tr("Failed to launch.")); +} + +void LaunchController::launchInstance() +{ + Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); + Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL"); + + if(!m_instance->reload()) + { + QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't load the instance profile.")); + emitFailed(tr("Couldn't load the instance profile.")); + return; + } + + m_launcher = m_instance->createLaunchTask(m_session); + if (!m_launcher) + { + emitFailed(tr("Couldn't instantiate a launcher.")); + return; + } + + auto mainWindow = qobject_cast(m_parentWidget); + auto instanceWindow = qobject_cast(m_parentWidget); + if(mainWindow) + { + m_console = mainWindow->showInstanceWindow(m_instance); + } + else if(instanceWindow) + { + // NOOP + } + else + { + // this is used when launching directly from command line + m_console = new InstanceWindow(m_instance); + m_console->setQuitOnClose(true); + } + connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch); + + m_launcher->prependStep(std::make_shared(m_launcher.get(), "MultiMC version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::MultiMC)); + m_launcher->start(); +} + +void LaunchController::readyForLaunch() +{ + if (!m_profiler) + { + m_launcher->proceed(); + emitSucceeded(); + return; + } + + QString error; + if (!m_profiler->check(&error)) + { + m_launcher->abort(); + QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); + emitFailed("Profiler startup failed"); + return; + } + BaseProfiler *profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this); + + connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString & message) + { + QMessageBox msg; + msg.setText(tr("The game launch is delayed until you press the " + "button. This is the right time to setup the profiler, as the " + "profiler server is running now.\n\n%1").arg(message)); + msg.setWindowTitle(tr("Waiting")); + msg.setIcon(QMessageBox::Information); + msg.addButton(tr("Launch"), QMessageBox::AcceptRole); + msg.setModal(true); + msg.exec(); + m_launcher->proceed(); + emitSucceeded(); + }); + connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message) + { + QMessageBox msg; + msg.setText(tr("Couldn't start the profiler: %1").arg(message)); + msg.setWindowTitle(tr("Error")); + msg.setIcon(QMessageBox::Critical); + msg.addButton(QMessageBox::Ok); + msg.setModal(true); + msg.exec(); + m_launcher->abort(); + emitFailed("Profiler startup failed"); + }); + profilerInstance->beginProfiling(m_launcher); +} diff --git a/application/LaunchController.h b/application/LaunchController.h new file mode 100644 index 00000000..55cb1e58 --- /dev/null +++ b/application/LaunchController.h @@ -0,0 +1,48 @@ +#pragma once +#include +#include +#include + +class InstanceWindow; +class LaunchController: public Task +{ + Q_OBJECT +public: + virtual void executeTask(); + + LaunchController(QObject * parent = nullptr); + virtual ~LaunchController(){}; + + void setInstance(InstancePtr instance) + { + m_instance = instance; + } + void setOnline(bool online) + { + m_online = online; + } + void setProfiler(BaseProfilerFactory *profiler) + { + m_profiler = profiler; + } + void setParentWidget(QWidget * widget) + { + m_parentWidget = widget; + } + +private: + void login(); + void launchInstance(); + +private slots: + void readyForLaunch(); + +private: + BaseProfilerFactory *m_profiler = nullptr; + bool m_online = true; + InstancePtr m_instance; + QWidget * m_parentWidget = nullptr; + InstanceWindow *m_console = nullptr; + AuthSessionPtr m_session; + std::shared_ptr m_launcher; +}; diff --git a/application/LaunchInteraction.cpp b/application/LaunchInteraction.cpp deleted file mode 100644 index 0b601d49..00000000 --- a/application/LaunchInteraction.cpp +++ /dev/null @@ -1,276 +0,0 @@ -#include "LaunchInteraction.h" -#include "MainWindow.h" -#include -#include "MultiMC.h" -#include "dialogs/CustomMessageBox.h" -#include "dialogs/AccountSelectDialog.h" -#include "dialogs/ProgressDialog.h" -#include "dialogs/EditAccountDialog.h" -#include "InstanceWindow.h" -#include "BuildConfig.h" -#include "JavaCommon.h" -#include "SettingsUI.h" -#include -#include -#include -#include -#include -#include - -LaunchController::LaunchController(QObject *parent) : Task(parent) -{ -} - -void LaunchController::executeTask() -{ - login(); -} - -// FIXME: minecraft specific -void LaunchController::login() -{ - if (!m_instance) - { - emitFailed(tr("No instance specified")); - return; - } - - JavaCommon::checkJVMArgs(m_instance->settings()->get("JvmArgs").toString(), m_parentWidget); - - // Find an account to use. - std::shared_ptr accounts = MMC->accounts(); - MojangAccountPtr account = accounts->activeAccount(); - if (accounts->count() <= 0) - { - // Tell the user they need to log in at least one account in order to play. - auto reply = CustomMessageBox::selectable( - m_parentWidget, tr("No Accounts"), - tr("In order to play Minecraft, you must have at least one Mojang or Minecraft " - "account logged in to MultiMC." - "Would you like to open the account manager to add an account now?"), - QMessageBox::Information, QMessageBox::Yes | QMessageBox::No)->exec(); - - if (reply == QMessageBox::Yes) - { - // Open the account manager. - SettingsUI::ShowPageDialog(MMC->globalSettingsPages(), m_parentWidget, "accounts"); - } - } - else if (account.get() == nullptr) - { - // If no default account is set, ask the user which one to use. - AccountSelectDialog selectDialog(tr("Which account would you like to use?"), - AccountSelectDialog::GlobalDefaultCheckbox, m_parentWidget); - - selectDialog.exec(); - - // Launch the instance with the selected account. - account = selectDialog.selectedAccount(); - - // If the user said to use the account as default, do that. - if (selectDialog.useAsGlobalDefault() && account.get() != nullptr) - accounts->setActiveAccount(account->username()); - } - - // if no account is selected, we bail - if (!account.get()) - { - emitFailed(tr("No account selected for launch")); - return; - } - - // we try empty password first :) - QString password; - // we loop until the user succeeds in logging in or gives up - bool tryagain = true; - // the failure. the default failure. - const QString needLoginAgain = tr("Your account is currently not logged in. Please enter " - "your password to log in again."); - QString failReason = needLoginAgain; - - while (tryagain) - { - m_session = std::make_shared(); - m_session->wants_online = m_online; - auto task = account->login(m_session, password); - if (task) - { - // We'll need to validate the access token to make sure the account - // is still logged in. - ProgressDialog progDialog(m_parentWidget); - if (m_online) - { - progDialog.setSkipButton(true, tr("Play Offline")); - } - progDialog.execWithTask(task.get()); - if (!task->successful()) - { - auto failReasonNew = task->failReason(); - if(failReasonNew == "Invalid token.") - { - failReason = needLoginAgain; - } - else failReason = failReasonNew; - } - } - switch (m_session->status) - { - case AuthSession::Undetermined: - { - qCritical() << "Received undetermined session status during login. Bye."; - tryagain = false; - emitFailed(tr("Received undetermined session status during login.")); - break; - } - case AuthSession::RequiresPassword: - { - EditAccountDialog passDialog(failReason, m_parentWidget, EditAccountDialog::PasswordField); - auto username = m_session->username; - auto chopN = [](QString toChop, int N) -> QString - { - if(toChop.size() > N) - { - auto left = toChop.left(N); - left += QString("\u25CF").repeated(toChop.size() - N); - return left; - } - return toChop; - }; - - if(username.contains('@')) - { - auto parts = username.split('@'); - auto mailbox = chopN(parts[0],3); - QString domain = chopN(parts[1], 3); - username = mailbox + '@' + domain; - } - passDialog.setUsername(username); - if (passDialog.exec() == QDialog::Accepted) - { - password = passDialog.password(); - } - else - { - tryagain = false; - } - break; - } - case AuthSession::PlayableOffline: - { - // we ask the user for a player name - bool ok = false; - QString usedname = m_session->player_name; - QString name = QInputDialog::getText(m_parentWidget, tr("Player name"), - tr("Choose your offline mode player name."), - QLineEdit::Normal, m_session->player_name, &ok); - if (!ok) - { - tryagain = false; - break; - } - if (name.length()) - { - usedname = name; - } - m_session->MakeOffline(usedname); - // offline flavored game from here :3 - } - case AuthSession::PlayableOnline: - { - launchInstance(); - tryagain = false; - return; - } - } - } - emitFailed(tr("Failed to launch.")); -} - -void LaunchController::launchInstance() -{ - Q_ASSERT_X(m_instance != NULL, "launchInstance", "instance is NULL"); - Q_ASSERT_X(m_session.get() != nullptr, "launchInstance", "session is NULL"); - - if(!m_instance->reload()) - { - QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't load the instance profile.")); - emitFailed(tr("Couldn't load the instance profile.")); - return; - } - - m_launcher = m_instance->createLaunchTask(m_session); - if (!m_launcher) - { - emitFailed(tr("Couldn't instantiate a launcher.")); - return; - } - - auto mainWindow = qobject_cast(m_parentWidget); - auto instanceWindow = qobject_cast(m_parentWidget); - if(mainWindow) - { - m_console = mainWindow->showInstanceWindow(m_instance); - } - else if(instanceWindow) - { - // NOOP - } - else - { - // this is used when launching directly from command line - m_console = new InstanceWindow(m_instance); - m_console->setQuitOnClose(true); - } - connect(m_launcher.get(), &LaunchTask::readyForLaunch, this, &LaunchController::readyForLaunch); - - m_launcher->prependStep(std::make_shared(m_launcher.get(), "MultiMC version: " + BuildConfig.printableVersionString() + "\n\n", MessageLevel::MultiMC)); - m_launcher->start(); -} - -void LaunchController::readyForLaunch() -{ - if (!m_profiler) - { - m_launcher->proceed(); - emitSucceeded(); - return; - } - - QString error; - if (!m_profiler->check(&error)) - { - m_launcher->abort(); - QMessageBox::critical(m_parentWidget, tr("Error"), tr("Couldn't start profiler: %1").arg(error)); - emitFailed("Profiler startup failed"); - return; - } - BaseProfiler *profilerInstance = m_profiler->createProfiler(m_launcher->instance(), this); - - connect(profilerInstance, &BaseProfiler::readyToLaunch, [this](const QString & message) - { - QMessageBox msg; - msg.setText(tr("The game launch is delayed until you press the " - "button. This is the right time to setup the profiler, as the " - "profiler server is running now.\n\n%1").arg(message)); - msg.setWindowTitle(tr("Waiting")); - msg.setIcon(QMessageBox::Information); - msg.addButton(tr("Launch"), QMessageBox::AcceptRole); - msg.setModal(true); - msg.exec(); - m_launcher->proceed(); - emitSucceeded(); - }); - connect(profilerInstance, &BaseProfiler::abortLaunch, [this](const QString & message) - { - QMessageBox msg; - msg.setText(tr("Couldn't start the profiler: %1").arg(message)); - msg.setWindowTitle(tr("Error")); - msg.setIcon(QMessageBox::Critical); - msg.addButton(QMessageBox::Ok); - msg.setModal(true); - msg.exec(); - m_launcher->abort(); - emitFailed("Profiler startup failed"); - }); - profilerInstance->beginProfiling(m_launcher); -} diff --git a/application/LaunchInteraction.h b/application/LaunchInteraction.h deleted file mode 100644 index 55cb1e58..00000000 --- a/application/LaunchInteraction.h +++ /dev/null @@ -1,48 +0,0 @@ -#pragma once -#include -#include -#include - -class InstanceWindow; -class LaunchController: public Task -{ - Q_OBJECT -public: - virtual void executeTask(); - - LaunchController(QObject * parent = nullptr); - virtual ~LaunchController(){}; - - void setInstance(InstancePtr instance) - { - m_instance = instance; - } - void setOnline(bool online) - { - m_online = online; - } - void setProfiler(BaseProfilerFactory *profiler) - { - m_profiler = profiler; - } - void setParentWidget(QWidget * widget) - { - m_parentWidget = widget; - } - -private: - void login(); - void launchInstance(); - -private slots: - void readyForLaunch(); - -private: - BaseProfilerFactory *m_profiler = nullptr; - bool m_online = true; - InstancePtr m_instance; - QWidget * m_parentWidget = nullptr; - InstanceWindow *m_console = nullptr; - AuthSessionPtr m_session; - std::shared_ptr m_launcher; -}; diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 88c0fc09..ce6f7181 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -66,12 +67,11 @@ #include #include #include - #include "InstanceWindow.h" #include "InstancePageProvider.h" #include "InstanceProxyModel.h" #include "JavaCommon.h" -#include "LaunchInteraction.h" +#include "LaunchController.h" #include "SettingsUI.h" #include "groupview/GroupView.h" #include "groupview/InstanceDelegate.h" @@ -84,7 +84,6 @@ #include "dialogs/CustomMessageBox.h" #include "dialogs/IconPickerDialog.h" #include "dialogs/CopyInstanceDialog.h" -#include "dialogs/AccountSelectDialog.h" #include "dialogs/UpdateDialog.h" #include "dialogs/EditAccountDialog.h" #include "dialogs/NotificationDialog.h" diff --git a/application/dialogs/AccountSelectDialog.cpp b/application/dialogs/AccountSelectDialog.cpp deleted file mode 100644 index 3bf83d62..00000000 --- a/application/dialogs/AccountSelectDialog.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "AccountSelectDialog.h" -#include "ui_AccountSelectDialog.h" - -#include - -#include - -#include - -#include - -AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWidget *parent) - : QDialog(parent), ui(new Ui::AccountSelectDialog) -{ - ui->setupUi(this); - - m_accounts = MMC->accounts(); - ui->listView->setModel(m_accounts.get()); - ui->listView->hideColumn(MojangAccountList::ActiveColumn); - - // Set the message label. - ui->msgLabel->setVisible(!message.isEmpty()); - ui->msgLabel->setText(message); - - // Flags... - ui->globalDefaultCheck->setVisible(flags & GlobalDefaultCheckbox); - ui->instDefaultCheck->setVisible(flags & InstanceDefaultCheckbox); - qDebug() << flags; - - // Select the first entry in the list. - ui->listView->setCurrentIndex(ui->listView->model()->index(0, 0)); - - connect(ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(on_buttonBox_accepted())); -} - -AccountSelectDialog::~AccountSelectDialog() -{ - delete ui; -} - -MojangAccountPtr AccountSelectDialog::selectedAccount() const -{ - return m_selected; -} - -bool AccountSelectDialog::useAsGlobalDefault() const -{ - return ui->globalDefaultCheck->isChecked(); -} - -bool AccountSelectDialog::useAsInstDefaullt() const -{ - return ui->instDefaultCheck->isChecked(); -} - -void AccountSelectDialog::on_buttonBox_accepted() -{ - QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); - if (selection.size() > 0) - { - QModelIndex selected = selection.first(); - m_selected = selected.data(MojangAccountList::PointerRole).value(); - } - close(); -} - -void AccountSelectDialog::on_buttonBox_rejected() -{ - close(); -} diff --git a/application/dialogs/AccountSelectDialog.h b/application/dialogs/AccountSelectDialog.h deleted file mode 100644 index 7ae79314..00000000 --- a/application/dialogs/AccountSelectDialog.h +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include - -#include "minecraft/auth/MojangAccountList.h" - -namespace Ui -{ -class AccountSelectDialog; -} - -class AccountSelectDialog : public QDialog -{ - Q_OBJECT -public: - enum Flags - { - NoFlags = 0, - - /*! - * Shows a check box on the dialog that allows the user to specify that the account - * they've selected should be used as the global default for all instances. - */ - GlobalDefaultCheckbox, - - /*! - * Shows a check box on the dialog that allows the user to specify that the account - * they've selected should be used as the default for the instance they are currently launching. - * This is not currently implemented. - */ - InstanceDefaultCheckbox, - }; - - /*! - * Constructs a new account select dialog with the given parent and message. - * The message will be shown at the top of the dialog. It is an empty string by default. - */ - explicit AccountSelectDialog(const QString& message="", int flags=0, QWidget *parent = 0); - ~AccountSelectDialog(); - - /*! - * Gets a pointer to the account that the user selected. - * This is null if the user clicked cancel or hasn't clicked OK yet. - */ - MojangAccountPtr selectedAccount() const; - - /*! - * Returns true if the user checked the "use as global default" checkbox. - * If the checkbox wasn't shown, this function returns false. - */ - bool useAsGlobalDefault() const; - - /*! - * Returns true if the user checked the "use as instance default" checkbox. - * If the checkbox wasn't shown, this function returns false. - */ - bool useAsInstDefaullt() const; - -public -slots: - void on_buttonBox_accepted(); - - void on_buttonBox_rejected(); - -protected: - std::shared_ptr m_accounts; - - //! The account that was selected when the user clicked OK. - MojangAccountPtr m_selected; - -private: - Ui::AccountSelectDialog *ui; -}; diff --git a/application/dialogs/AccountSelectDialog.ui b/application/dialogs/AccountSelectDialog.ui deleted file mode 100644 index 7af1512a..00000000 --- a/application/dialogs/AccountSelectDialog.ui +++ /dev/null @@ -1,56 +0,0 @@ - - - AccountSelectDialog - - - - 0 - 0 - 413 - 300 - - - - Select an Account - - - - - - Select an account. - - - - - - - - - - - - Use as default? - - - - - - - Use as default for this instance only? - - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - diff --git a/application/dialogs/ProfileSelectDialog.cpp b/application/dialogs/ProfileSelectDialog.cpp new file mode 100644 index 00000000..5c42bc7b --- /dev/null +++ b/application/dialogs/ProfileSelectDialog.cpp @@ -0,0 +1,111 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ProfileSelectDialog.h" +#include +#include "ui_ProfileSelectDialog.h" + +#include + +#include + +#include + +#include + +ProfileSelectDialog::ProfileSelectDialog(const QString &message, int flags, QWidget *parent) + : QDialog(parent), ui(new Ui::ProfileSelectDialog) +{ + ui->setupUi(this); + + m_accounts = MMC->accounts(); + auto view = ui->listView; + //view->setModel(m_accounts.get()); + //view->hideColumn(MojangAccountList::ActiveColumn); + view->setColumnCount(1); + view->setRootIsDecorated(false); + if(QTreeWidgetItem* header = view->headerItem()) + { + header->setText(0, tr("Name")); + } + else + { + view->setHeaderLabel(tr("Name")); + } + QList items; + for (int i = 0; i < m_accounts->count(); i++) + { + MojangAccountPtr account = m_accounts->at(i); + for (auto profile : account->profiles()) + { + auto item = new QTreeWidgetItem(view); + item->setText(0, profile.name); + item->setIcon(0, SkinUtils::getFaceFromCache(profile.id)); + item->setData(0, MojangAccountList::PointerRole, QVariant::fromValue(account)); + items.append(item); + } + } + view->addTopLevelItems(items); + + // Set the message label. + ui->msgLabel->setVisible(!message.isEmpty()); + ui->msgLabel->setText(message); + + // Flags... + ui->globalDefaultCheck->setVisible(flags & GlobalDefaultCheckbox); + ui->instDefaultCheck->setVisible(flags & InstanceDefaultCheckbox); + qDebug() << flags; + + // Select the first entry in the list. + ui->listView->setCurrentIndex(ui->listView->model()->index(0, 0)); + + connect(ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(on_buttonBox_accepted())); +} + +ProfileSelectDialog::~ProfileSelectDialog() +{ + delete ui; +} + +MojangAccountPtr ProfileSelectDialog::selectedAccount() const +{ + return m_selected; +} + +bool ProfileSelectDialog::useAsGlobalDefault() const +{ + return ui->globalDefaultCheck->isChecked(); +} + +bool ProfileSelectDialog::useAsInstDefaullt() const +{ + return ui->instDefaultCheck->isChecked(); +} + +void ProfileSelectDialog::on_buttonBox_accepted() +{ + QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); + if (selection.size() > 0) + { + QModelIndex selected = selection.first(); + m_selected = selected.data(MojangAccountList::PointerRole).value(); + } + close(); +} + +void ProfileSelectDialog::on_buttonBox_rejected() +{ + close(); +} diff --git a/application/dialogs/ProfileSelectDialog.h b/application/dialogs/ProfileSelectDialog.h new file mode 100644 index 00000000..5ac75b07 --- /dev/null +++ b/application/dialogs/ProfileSelectDialog.h @@ -0,0 +1,90 @@ +/* Copyright 2013-2015 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#include + +#include "minecraft/auth/MojangAccountList.h" + +namespace Ui +{ +class ProfileSelectDialog; +} + +class ProfileSelectDialog : public QDialog +{ + Q_OBJECT +public: + enum Flags + { + NoFlags = 0, + + /*! + * Shows a check box on the dialog that allows the user to specify that the account + * they've selected should be used as the global default for all instances. + */ + GlobalDefaultCheckbox, + + /*! + * Shows a check box on the dialog that allows the user to specify that the account + * they've selected should be used as the default for the instance they are currently launching. + * This is not currently implemented. + */ + InstanceDefaultCheckbox, + }; + + /*! + * Constructs a new account select dialog with the given parent and message. + * The message will be shown at the top of the dialog. It is an empty string by default. + */ + explicit ProfileSelectDialog(const QString& message="", int flags=0, QWidget *parent = 0); + ~ProfileSelectDialog(); + + /*! + * Gets a pointer to the account that the user selected. + * This is null if the user clicked cancel or hasn't clicked OK yet. + */ + MojangAccountPtr selectedAccount() const; + + /*! + * Returns true if the user checked the "use as global default" checkbox. + * If the checkbox wasn't shown, this function returns false. + */ + bool useAsGlobalDefault() const; + + /*! + * Returns true if the user checked the "use as instance default" checkbox. + * If the checkbox wasn't shown, this function returns false. + */ + bool useAsInstDefaullt() const; + +public +slots: + void on_buttonBox_accepted(); + + void on_buttonBox_rejected(); + +protected: + std::shared_ptr m_accounts; + + //! The account that was selected when the user clicked OK. + MojangAccountPtr m_selected; + +private: + Ui::ProfileSelectDialog *ui; +}; diff --git a/application/dialogs/ProfileSelectDialog.ui b/application/dialogs/ProfileSelectDialog.ui new file mode 100644 index 00000000..e779b51b --- /dev/null +++ b/application/dialogs/ProfileSelectDialog.ui @@ -0,0 +1,62 @@ + + + ProfileSelectDialog + + + + 0 + 0 + 465 + 300 + + + + Select an Account + + + + + + Select a profile. + + + + + + + + 1 + + + + + + + + + + Use as default? + + + + + + + Use as default for this instance only? + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/application/main.cpp b/application/main.cpp index 6b0c361b..a996ef3b 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -1,6 +1,6 @@ #include "MultiMC.h" #include "MainWindow.h" -#include "LaunchInteraction.h" +#include "LaunchController.h" #include #include diff --git a/application/pages/global/AccountListPage.cpp b/application/pages/global/AccountListPage.cpp index f4aa58b0..b0391689 100644 --- a/application/pages/global/AccountListPage.cpp +++ b/application/pages/global/AccountListPage.cpp @@ -25,7 +25,6 @@ #include "Env.h" #include "dialogs/ProgressDialog.h" -#include "dialogs/AccountSelectDialog.h" #include "dialogs/LoginDialog.h" #include "dialogs/CustomMessageBox.h" #include "dialogs/SkinUploadDialog.h" -- cgit v1.2.3