CoreAccountSettingsPage::CoreAccountSettingsPage(QWidget *parent)
: SettingsPage(tr("Misc"), tr("Core Accounts"), parent),
_lastAccountId(0),
-_lastAutoConnectId(0)
+_lastAutoConnectId(0),
+_standalone(false)
{
ui.setupUi(this);
initAutoWidgets();
setWidgetStates();
}
+void CoreAccountSettingsPage::setStandAlone(bool standalone) {
+ _standalone = standalone;
+}
+
void CoreAccountSettingsPage::load() {
_model->update(Client::coreAccountModel());
-
SettingsPage::load();
+
+ CoreAccountSettings s;
+
+ if(Quassel::runMode() != Quassel::Monolithic) {
+ // make sure we don't have selected the internal account as autoconnect account
+
+ if(s.autoConnectOnStartup() && s.autoConnectToFixedAccount()) {
+ CoreAccount acc = _model->account(s.autoConnectAccount());
+ if(acc.isInternal())
+ ui.autoConnectOnStartup->setChecked(false);
+ }
+ }
ui.accountView->setCurrentIndex(model()->index(0, 0));
ui.accountView->selectionModel()->select(model()->index(0, 0), QItemSelectionModel::Select);
+
+ QModelIndex idx = model()->accountIndex(s.autoConnectAccount());
+ ui.autoConnectAccount->setCurrentIndex(idx.isValid() ? idx.row() : 0);
setWidgetStates();
}
if(widgetName == "autoConnectAccount") {
CoreAccountSettings s;
AccountId id = s.autoConnectAccount();
- if(id <= 0)
+ if(!id.isValid())
return QVariant();
- ui.autoConnectAccount->setCurrentIndex(model()->accountIndex(id).row());
return id.toInt();
}
return SettingsPage::loadAutoWidgetValue(widgetName);
_lastAccountId = _lastAutoConnectId = 0;
}
+AccountId CoreAccountSettingsPage::selectedAccount() const {
+ QModelIndex index = ui.accountView->currentIndex();
+ if(!index.isValid())
+ return 0;
+ return index.data(CoreAccountModel::AccountIdRole).value<AccountId>();
+}
+
+void CoreAccountSettingsPage::setSelectedAccount(AccountId accId) {
+ QModelIndex index = model()->accountIndex(accId);
+ if(index.isValid())
+ ui.accountView->setCurrentIndex(index);
+}
+
void CoreAccountSettingsPage::on_addAccountButton_clicked() {
CoreAccountEditDlg dlg(CoreAccount(), this);
if(dlg.exec() == QDialog::Accepted) {
if(!idx.isValid())
return;
- CoreAccountEditDlg dlg(_model->account(idx), this);
+ editAccount(idx);
+}
+
+void CoreAccountSettingsPage::editAccount(const QModelIndex &index) {
+ if(!index.isValid())
+ return;
+
+ CoreAccountEditDlg dlg(_model->account(index), this);
if(dlg.exec() == QDialog::Accepted) {
AccountId id = _model->createOrUpdateAccount(dlg.account());
ui.accountView->setCurrentIndex(model()->accountIndex(id));
}
}
+void CoreAccountSettingsPage::on_accountView_doubleClicked(const QModelIndex &index) {
+ if(!index.isValid())
+ return;
+
+ if(isStandAlone())
+ emit connectToCore(index.data(CoreAccountModel::AccountIdRole).value<AccountId>());
+ else
+ editAccount(index);
+}
+
void CoreAccountSettingsPage::setWidgetStates() {
- bool selected = ui.accountView->selectionModel()->selectedIndexes().count();
+ AccountId accId = selectedAccount();
+ bool editable = accId.isValid() && accId != model()->internalAccount();
- ui.editAccountButton->setEnabled(selected);
- ui.deleteAccountButton->setEnabled(selected);
+ ui.editAccountButton->setEnabled(editable);
+ ui.deleteAccountButton->setEnabled(editable);
}
void CoreAccountSettingsPage::widgetHasChanged() {