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: [PATCH] GH-1433 with no default account, show profiles instead of accounts in selection dialog --- application/CMakeLists.txt | 10 ++-- application/InstanceWindow.h | 2 +- ...chInteraction.cpp => LaunchController.cpp} | 8 +-- ...LaunchInteraction.h => LaunchController.h} | 0 application/MainWindow.cpp | 5 +- ...lectDialog.cpp => ProfileSelectDialog.cpp} | 50 ++++++++++++++----- ...ntSelectDialog.h => ProfileSelectDialog.h} | 10 ++-- ...SelectDialog.ui => ProfileSelectDialog.ui} | 16 ++++-- application/main.cpp | 2 +- application/pages/global/AccountListPage.cpp | 1 - 10 files changed, 67 insertions(+), 37 deletions(-) rename application/{LaunchInteraction.cpp => LaunchController.cpp} (97%) rename application/{LaunchInteraction.h => LaunchController.h} (100%) rename application/dialogs/{AccountSelectDialog.cpp => ProfileSelectDialog.cpp} (56%) rename application/dialogs/{AccountSelectDialog.h => ProfileSelectDialog.h} (92%) rename application/dialogs/{AccountSelectDialog.ui => ProfileSelectDialog.ui} (78%) 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/LaunchInteraction.cpp b/application/LaunchController.cpp similarity index 97% rename from application/LaunchInteraction.cpp rename to application/LaunchController.cpp index 0b601d49..bc7f976a 100644 --- a/application/LaunchInteraction.cpp +++ b/application/LaunchController.cpp @@ -1,9 +1,9 @@ -#include "LaunchInteraction.h" +#include "LaunchController.h" #include "MainWindow.h" #include #include "MultiMC.h" #include "dialogs/CustomMessageBox.h" -#include "dialogs/AccountSelectDialog.h" +#include "dialogs/ProfileSelectDialog.h" #include "dialogs/ProgressDialog.h" #include "dialogs/EditAccountDialog.h" #include "InstanceWindow.h" @@ -59,8 +59,8 @@ void LaunchController::login() 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); + ProfileSelectDialog selectDialog(tr("Which profile would you like to use?"), + ProfileSelectDialog::GlobalDefaultCheckbox, m_parentWidget); selectDialog.exec(); diff --git a/application/LaunchInteraction.h b/application/LaunchController.h similarity index 100% rename from application/LaunchInteraction.h rename to application/LaunchController.h 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/ProfileSelectDialog.cpp similarity index 56% rename from application/dialogs/AccountSelectDialog.cpp rename to application/dialogs/ProfileSelectDialog.cpp index 3bf83d62..5c42bc7b 100644 --- a/application/dialogs/AccountSelectDialog.cpp +++ b/application/dialogs/ProfileSelectDialog.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "AccountSelectDialog.h" -#include "ui_AccountSelectDialog.h" +#include "ProfileSelectDialog.h" +#include +#include "ui_ProfileSelectDialog.h" #include @@ -24,14 +25,39 @@ #include -AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWidget *parent) - : QDialog(parent), ui(new Ui::AccountSelectDialog) +ProfileSelectDialog::ProfileSelectDialog(const QString &message, int flags, QWidget *parent) + : QDialog(parent), ui(new Ui::ProfileSelectDialog) { ui->setupUi(this); m_accounts = MMC->accounts(); - ui->listView->setModel(m_accounts.get()); - ui->listView->hideColumn(MojangAccountList::ActiveColumn); + 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()); @@ -48,27 +74,27 @@ AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWid connect(ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(on_buttonBox_accepted())); } -AccountSelectDialog::~AccountSelectDialog() +ProfileSelectDialog::~ProfileSelectDialog() { delete ui; } -MojangAccountPtr AccountSelectDialog::selectedAccount() const +MojangAccountPtr ProfileSelectDialog::selectedAccount() const { return m_selected; } -bool AccountSelectDialog::useAsGlobalDefault() const +bool ProfileSelectDialog::useAsGlobalDefault() const { return ui->globalDefaultCheck->isChecked(); } -bool AccountSelectDialog::useAsInstDefaullt() const +bool ProfileSelectDialog::useAsInstDefaullt() const { return ui->instDefaultCheck->isChecked(); } -void AccountSelectDialog::on_buttonBox_accepted() +void ProfileSelectDialog::on_buttonBox_accepted() { QModelIndexList selection = ui->listView->selectionModel()->selectedIndexes(); if (selection.size() > 0) @@ -79,7 +105,7 @@ void AccountSelectDialog::on_buttonBox_accepted() close(); } -void AccountSelectDialog::on_buttonBox_rejected() +void ProfileSelectDialog::on_buttonBox_rejected() { close(); } diff --git a/application/dialogs/AccountSelectDialog.h b/application/dialogs/ProfileSelectDialog.h similarity index 92% rename from application/dialogs/AccountSelectDialog.h rename to application/dialogs/ProfileSelectDialog.h index 7ae79314..5ac75b07 100644 --- a/application/dialogs/AccountSelectDialog.h +++ b/application/dialogs/ProfileSelectDialog.h @@ -23,10 +23,10 @@ namespace Ui { -class AccountSelectDialog; +class ProfileSelectDialog; } -class AccountSelectDialog : public QDialog +class ProfileSelectDialog : public QDialog { Q_OBJECT public: @@ -52,8 +52,8 @@ public: * 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(); + explicit ProfileSelectDialog(const QString& message="", int flags=0, QWidget *parent = 0); + ~ProfileSelectDialog(); /*! * Gets a pointer to the account that the user selected. @@ -86,5 +86,5 @@ protected: MojangAccountPtr m_selected; private: - Ui::AccountSelectDialog *ui; + Ui::ProfileSelectDialog *ui; }; diff --git a/application/dialogs/AccountSelectDialog.ui b/application/dialogs/ProfileSelectDialog.ui similarity index 78% rename from application/dialogs/AccountSelectDialog.ui rename to application/dialogs/ProfileSelectDialog.ui index 7af1512a..e779b51b 100644 --- a/application/dialogs/AccountSelectDialog.ui +++ b/application/dialogs/ProfileSelectDialog.ui @@ -1,12 +1,12 @@ - AccountSelectDialog - + ProfileSelectDialog + 0 0 - 413 + 465 300 @@ -17,12 +17,18 @@ - Select an account. + Select a profile. - + + + + 1 + + + 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"