+CoreConnectDlg::~CoreConnectDlg() {
+ //qDebug() << "destroy";
+}
+
+void CoreConnectDlg::setAccountEditEnabled(bool en) {
+ ui.accountList->setEnabled(en);
+ ui.hostEdit->setEnabled(en && !ui.internalCore->isChecked());
+ ui.userEdit->setEnabled(en);
+ ui.passwdEdit->setEnabled(en);
+ ui.port->setEnabled(en && !ui.internalCore->isChecked());
+ ui.editAccount->setEnabled(en);
+ ui.delAccount->setEnabled(en);
+ ui.internalCore->setEnabled(en);
+ ui.rememberPasswd->setEnabled(en);
+ ui.autoConnect->setEnabled(en);
+ ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(en && checkInputValid());
+}
+
+void CoreConnectDlg::accountChanged(const QString &text) {
+ AccountSettings s;
+ if(!curacc.isEmpty()) {
+ QVariantMap oldAcc;
+ oldAcc["User"] = ui.userEdit->text();
+ oldAcc["Host"] = ui.hostEdit->text();
+ oldAcc["Port"] = ui.port->value();
+ oldAcc["InternalCore"] = ui.internalCore->isChecked();
+ if(ui.rememberPasswd->isChecked()) oldAcc["Password"] = ui.passwdEdit->text();
+ s.setValue(curacc, "AccountData", oldAcc);
+ }
+ ui.autoConnect->setChecked(false);
+ if(!text.isEmpty()) { // empty text: just save stuff
+ curacc = text;
+ s.setLastAccount(curacc);
+ QVariantMap newAcc = s.value(curacc, "AccountData").toMap();
+ ui.userEdit->setText(newAcc["User"].toString());
+ ui.hostEdit->setText(newAcc["Host"].toString());
+ ui.port->setValue(newAcc["Port"].toInt());
+ ui.internalCore->setChecked(newAcc["InternalCore"].toBool());
+ if(newAcc.contains("Password")) {
+ ui.passwdEdit->setText(newAcc["Password"].toString());
+ ui.rememberPasswd->setChecked(true);
+ } else ui.rememberPasswd->setChecked(false);
+ if(s.autoConnectAccount() == curacc) ui.autoConnect->setChecked(true);
+ }
+}
+
+void CoreConnectDlg::autoConnectToggled(bool autoConnect) {
+ AccountSettings s;
+ if(autoConnect) s.setAutoConnectAccount(curacc);
+ else s.setAutoConnectAccount("");
+}
+
+bool CoreConnectDlg::checkInputValid() {
+ bool res = (ui.internalCore->isChecked() || ui.hostEdit->text().count()) && ui.userEdit->text().count();
+ ui.buttonBox1->button(QDialogButtonBox::Ok)->setEnabled(res);
+ return res;
+}
+
+void CoreConnectDlg::createAccount() {
+ QString accname = QInputDialog::getText(this, tr("Create Account"), tr("Please enter a name for the new account:"));
+ if(accname.isEmpty()) return;
+ if(ui.accountList->findText(accname) >= 0) {
+ QMessageBox::warning(this, tr("Account name already exists!"), tr("An account named '%1' already exists, and account names must be unique!").arg(accname));
+ return;
+ }
+ QVariantMap defdata;
+ ui.accountList->addItem(accname);
+ ui.accountList->setCurrentIndex(ui.accountList->findText(accname));
+ setAccountEditEnabled(true);
+}
+
+void CoreConnectDlg::removeAccount() {
+ QString acc = ui.accountList->currentText();
+ int res = QMessageBox::warning(this, tr("Delete account?"), tr("Do you really want to delete the data for the account '%1'?<br>"
+ "Note that this only affects your local account settings and will not remove "
+ "any data from the core.").arg(acc),
+ QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
+ if(res == QMessageBox::Yes) {
+ AccountSettings s;
+ s.removeAccount(acc);
+ curacc = "";
+ ui.accountList->removeItem(ui.accountList->findText(acc));
+ if(!ui.accountList->count()) setAccountEditEnabled(false);
+ }
+}
+
+bool CoreConnectDlg::willDoInternalAutoConnect() {
+ AccountSettings s;
+ if(Global::runMode != Global::Monolithic) return false;
+ if(ui.autoConnect->isChecked() && s.autoConnectAccount() == curacc && ui.internalCore->isChecked()) {
+ return true;
+ }
+ return false;
+}
+
+void CoreConnectDlg::doAutoConnect() {
+ AccountSettings s;
+ if(s.autoConnectAccount() == curacc) {
+ doConnect();
+ }
+}
+
+void CoreConnectDlg::doConnect() {
+ accountChanged(); // save current account info
+
+ QVariantMap conninfo;
+ ui.stackedWidget->setCurrentIndex(1);
+ if(ui.internalCore->isChecked()) {
+ // FIXME
+ coreConnectionError(tr("Can't connect to internal core at the moment [serious breakage due to switch to dynamic signals]. Please check back later."));
+ return;
+ if(Global::runMode != Global::Monolithic) {
+ coreConnectionError(tr("Can't connect to internal core, since we are running as a standalone GUI!"));
+ return;
+ }
+ ui.connectionGroupBox->setTitle(tr("Connecting to internal core"));
+ ui.connectionProgress->hide();
+ } else {
+ ui.connectionGroupBox->setTitle(tr("Connecting to %1").arg(ui.hostEdit->text()));
+ conninfo["Host"] = ui.hostEdit->text();
+ conninfo["Port"] = ui.port->value();
+ }
+ conninfo["User"] = ui.userEdit->text();
+ conninfo["Password"] = ui.passwdEdit->text();
+ ui.profileLabel->hide(); ui.guiProfile->hide();
+ ui.newGuiProfile->hide(); ui.alwaysUseProfile->hide();
+ ui.connectionProgress->show();
+ try {
+ Client::instance()->connectToCore(conninfo);
+ } catch(Exception e) {
+ QString msg;
+ //if(!e.msg().isEmpty()) msg = tr("<br>%1").arg(e.msg()); // FIXME throw more detailed (vulgo: any) error msg
+ coreConnectionError(tr("Invalid user or password. Pleasy try again.%1").arg(msg));
+ //QMessageBox::warning(this, tr("Unknown account"), tr("Invalid user or password. Pleasy try again.%1").arg(msg));
+ //cancelConnect();
+ return;
+ }
+}
+
+void CoreConnectDlg::cancelConnect() {
+ ui.stackedWidget->setCurrentIndex(0);
+}
+
+void CoreConnectDlg::setStartState() { /*