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(); accountMenu->clear();
std::shared_ptr<MojangAccountList> accounts = MMC->accounts(); std::shared_ptr<MojangAccountList> accounts = MMC->accounts();
MojangAccountPtr active_account = accounts->activeAccount();
QString active_username; QString active_username = "";
if(accounts->activeAccount() != nullptr) if(active_account != nullptr)
{ {
active_username = accounts->activeAccount()->username(); 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); accountMenu->addAction(manageAccountsAction);
} }
@ -310,18 +323,19 @@ void MainWindow::repopulateAccountsMenu()
void MainWindow::changeActiveAccount() void MainWindow::changeActiveAccount()
{ {
QAction* sAction = (QAction*) sender(); QAction* sAction = (QAction*) sender();
// Profile's associated Mojang username // Profile's associated Mojang username
// Will need to change when profiles are properly implemented // Will need to change when profiles are properly implemented
if(sAction->data().type() != QVariant::Type::String) return; if(sAction->data().type() != QVariant::Type::String) return;
QString id = sAction->data().toString(); QVariant data = sAction->data();
QString id = "";
if(id != nullptr && !id.isEmpty()) if(!data.isNull())
{ {
MMC->accounts()->setActiveAccount(id); id = data.toString();
} }
MMC->accounts()->setActiveAccount(id);
activeAccountChanged(); activeAccountChanged();
} }
@ -331,7 +345,7 @@ void MainWindow::activeAccountChanged()
MojangAccountPtr account = MMC->accounts()->activeAccount(); MojangAccountPtr account = MMC->accounts()->activeAccount();
if(account != nullptr) if(account != nullptr && account->username() != "")
{ {
const AccountProfile *profile = account->currentProfile(); const AccountProfile *profile = account->currentProfile();
if(profile != nullptr) if(profile != nullptr)

View File

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

View File

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