Add support for "no default account"

This commit is contained in:
Sky 2013-11-27 23:39:36 +00:00
parent d32cb1c95d
commit 191e850cf1
3 changed files with 29 additions and 9 deletions

View File

@ -255,9 +255,10 @@ void MainWindow::repopulateAccountsMenu()
accountMenu->clear();
std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
MojangAccountPtr active_account = accounts->activeAccount();
QString active_username;
if(accounts->activeAccount() != nullptr)
QString active_username = "";
if(active_account != nullptr)
{
active_username = accounts->activeAccount()->username();
}
@ -301,6 +302,18 @@ void MainWindow::repopulateAccountsMenu()
}
}
QAction *action = new QAction(tr("No default"), this);
action->setCheckable(true);
action->setData("");
if(active_username.isEmpty())
{
action->setChecked(true);
}
accountMenu->addAction(action);
connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount()));
accountMenu->addSeparator();
accountMenu->addAction(manageAccountsAction);
}
@ -310,18 +323,19 @@ void MainWindow::repopulateAccountsMenu()
void MainWindow::changeActiveAccount()
{
QAction* sAction = (QAction*) sender();
// Profile's associated Mojang username
// Will need to change when profiles are properly implemented
if(sAction->data().type() != QVariant::Type::String) return;
QString id = sAction->data().toString();
if(id != nullptr && !id.isEmpty())
QVariant data = sAction->data();
QString id = "";
if(!data.isNull())
{
MMC->accounts()->setActiveAccount(id);
id = data.toString();
}
MMC->accounts()->setActiveAccount(id);
activeAccountChanged();
}
@ -331,7 +345,7 @@ void MainWindow::activeAccountChanged()
MojangAccountPtr account = MMC->accounts()->activeAccount();
if(account != nullptr)
if(account != nullptr && account->username() != "")
{
const AccountProfile *profile = account->currentProfile();
if(profile != nullptr)

View File

@ -92,6 +92,8 @@ void AccountListDialog::on_setDefaultBtn_clicked()
void AccountListDialog::on_noDefaultBtn_clicked()
{
m_accounts->setActiveAccount("");
emit activeAccountChanged();
}
void AccountListDialog::on_closeBtnBox_rejected()

View File

@ -100,9 +100,11 @@ void MojangAccountList::setActiveAccount(const QString& username)
else
{
for (MojangAccountPtr account : m_accounts)
{
if (account->username() == username)
m_activeAccount = username;
}
}
endResetModel();
onListChanged();
}
@ -113,7 +115,9 @@ void MojangAccountList::onListChanged()
if (m_autosave)
// TODO: Alert the user if this fails.
saveList();
emit listChanged();
// TODO: stop this getting called from setActiveAccount
//emit listChanged();
}