Make monolithic client work again
[quassel.git] / src / qtui / settingspages / coreaccountsettingspage.cpp
index 72ac209..be08cb5 100644 (file)
@@ -28,7 +28,8 @@
 CoreAccountSettingsPage::CoreAccountSettingsPage(QWidget *parent)
 : SettingsPage(tr("Misc"), tr("Core Accounts"), parent),
 _lastAccountId(0),
-_lastAutoConnectId(0)
+_lastAutoConnectId(0),
+_standalone(false)
 {
   ui.setupUi(this);
   initAutoWidgets();
@@ -47,12 +48,30 @@ _lastAutoConnectId(0)
   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();
 }
 
@@ -69,7 +88,6 @@ QVariant CoreAccountSettingsPage::loadAutoWidgetValue(const QString &widgetName)
     AccountId id = s.autoConnectAccount();
     if(!id.isValid())
       return QVariant();
-    ui.autoConnectAccount->setCurrentIndex(model()->accountIndex(id).row());
     return id.toInt();
   }
   return SettingsPage::loadAutoWidgetValue(widgetName);
@@ -112,6 +130,19 @@ void CoreAccountSettingsPage::rowsInserted(const QModelIndex &index, int start,
   _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) {
@@ -126,7 +157,14 @@ void CoreAccountSettingsPage::on_editAccountButton_clicked() {
   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));
@@ -144,11 +182,22 @@ void CoreAccountSettingsPage::on_deleteAccountButton_clicked() {
   }
 }
 
+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() {