GH-1433 with no default account, show profiles instead of accounts in selection dialog

This commit is contained in:
Petr Mrázek
2016-08-11 00:44:01 +02:00
parent 55544893a3
commit 2f0441b3c1
10 changed files with 67 additions and 37 deletions

View File

@ -13,8 +13,9 @@
* limitations under the License.
*/
#include "AccountSelectDialog.h"
#include "ui_AccountSelectDialog.h"
#include "ProfileSelectDialog.h"
#include <SkinUtils.h>
#include "ui_ProfileSelectDialog.h"
#include <QItemSelectionModel>
@ -24,14 +25,39 @@
#include <MultiMC.h>
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 <QTreeWidgetItem *> 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();
}

View File

@ -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;
};

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AccountSelectDialog</class>
<widget class="QDialog" name="AccountSelectDialog">
<class>ProfileSelectDialog</class>
<widget class="QDialog" name="ProfileSelectDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>413</width>
<width>465</width>
<height>300</height>
</rect>
</property>
@ -17,12 +17,18 @@
<item>
<widget class="QLabel" name="msgLabel">
<property name="text">
<string>Select an account.</string>
<string>Select a profile.</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="listView"/>
<widget class="QTreeWidget" name="listView">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">