X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fcoreconnectdlg.cpp;h=c30005b76fe910fc5c7b00b3655848b6000ea2ee;hp=d61a021108e8e4faf2df65574956f0dae6a4d5a3;hb=98b90b37d2fbdeed81808ce1401146bf7993e409;hpb=299541db5d6586c0b09e036816dfd28477ebc249 diff --git a/src/qtui/coreconnectdlg.cpp b/src/qtui/coreconnectdlg.cpp index d61a0211..c30005b7 100644 --- a/src/qtui/coreconnectdlg.cpp +++ b/src/qtui/coreconnectdlg.cpp @@ -29,9 +29,11 @@ #include "clientsyncer.h" #include "coreconfigwizard.h" #include "iconloader.h" +#include "quassel.h" CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent) - : QDialog(parent) + : QDialog(parent), + _internalAccountId(0) { ui.setupUi(this); ui.editAccount->setIcon(SmallIcon("document-properties")); @@ -40,6 +42,10 @@ CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent) ui.connectIcon->setPixmap(BarIcon("network-disconnect")); ui.secureConnection->setPixmap(SmallIcon("document-encrypt")); + if(Quassel::runMode() != Quassel::Monolithic) { + ui.useInternalCore->hide(); + } + // make it look more native under Mac OS X: setWindowFlags(Qt::Sheet); @@ -60,6 +66,10 @@ CoreConnectDlg::CoreConnectDlg(bool autoconnect, QWidget *parent) foreach(AccountId id, s.knownAccounts()) { if(!id.isValid()) continue; QVariantMap data = s.retrieveAccountData(id); + if(data.contains("InternalAccount") && data["InternalAccount"].toBool()) { + _internalAccountId = id; + continue; + } data["AccountId"] = QVariant::fromValue(id); accounts[id] = data; QListWidgetItem *item = new QListWidgetItem(data["AccountName"].toString(), ui.accountList); @@ -145,14 +155,7 @@ void CoreConnectDlg::on_addAccount_clicked() { for(int i = 0; i < ui.accountList->count(); i++) existing << ui.accountList->item(i)->text(); CoreAccountEditDlg dlg(0, QVariantMap(), existing, this); if(dlg.exec() == QDialog::Accepted) { - // find free ID - AccountId id = accounts.count() + 1; - for(AccountId i = 1; i <= accounts.count(); i++) { - if(!accounts.keys().contains(i)) { - id = i; - break; - } - } + AccountId id = findFreeAccountId(); QVariantMap data = dlg.accountData(); data["AccountId"] = QVariant::fromValue(id); accounts[id] = data; @@ -216,15 +219,15 @@ void CoreConnectDlg::on_accountButtonBox_accepted() { } void CoreConnectDlg::on_useInternalCore_clicked() { -// // FIXME: this needs to be a qobject_cast - therefore MonolithicApplication needs to be a proper QObject... :/ -// MonolithicApplication *monoApp = qobject_cast(QApplication::instance()); -// if(monoApp) { -// qDebug() << "starting core..."; -// monoApp->startInternalCore(); -// monoApp->connectClientSyncer(clientSyncer); -// } - clientSyncer->useInternalCore(); - startSync(); + if(!_internalAccountId.isValid()) { + _internalAccountId = findFreeAccountId(); + QVariantMap data; + data["InternalAccount"] = true; + CoreAccountSettings accountSettings; + accountSettings.storeAccountData(_internalAccountId, data); + } + clientSyncer->useInternalCore(_internalAccountId); + ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Cancel); } /***************************************************** @@ -422,7 +425,8 @@ void CoreConnectDlg::startSync() { ui.user->setEnabled(true); ui.password->setEnabled(true); ui.rememberPasswd->setEnabled(true); - ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + if(ui.loginButtonBox->standardButtons() & QDialogButtonBox::Ok) // in mono mode we don't show an Ok Button + ui.loginButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } void CoreConnectDlg::coreSessionProgress(quint32 val, quint32 max) { @@ -452,6 +456,13 @@ void CoreConnectDlg::syncFinished() { } } +AccountId CoreConnectDlg::findFreeAccountId() { + for(AccountId i = 1;; i++) { + if(!accounts.contains(i) && i != _internalAccountId) + return i; + } +} + /***************************************************************************************** * CoreAccountEditDlg *****************************************************************************************/ @@ -463,10 +474,11 @@ CoreAccountEditDlg::CoreAccountEditDlg(AccountId id, const QVariantMap &acct, co existing = _existing; if(id.isValid()) { + account = acct; + existing.removeAll(acct["AccountName"].toString()); ui.host->setText(acct["Host"].toString()); ui.port->setValue(acct["Port"].toUInt()); - ui.useInternal->setChecked(acct["UseInternal"].toBool()); ui.accountName->setText(acct["AccountName"].toString()); #ifdef HAVE_SSL ui.useSsl->setChecked(acct["useSsl"].toBool()); @@ -487,21 +499,12 @@ CoreAccountEditDlg::CoreAccountEditDlg(AccountId id, const QVariantMap &acct, co ui.useSsl->setEnabled(false); #endif } - -#ifndef BUILD_MONO - // if we don't have a mono build we hide the option to use the internal connection and force the setting to use remote host - ui.useInternal->setChecked(false); - ui.useInternal->hide(); - ui.useRemote->hide(); - ui.labelUseBuiltinCore->hide(); -#endif } QVariantMap CoreAccountEditDlg::accountData() { account["AccountName"] = ui.accountName->text().trimmed(); account["Host"] = ui.host->text().trimmed(); account["Port"] = ui.port->value(); - account["UseInternal"] = ui.useInternal->isChecked(); account["useSsl"] = ui.useSsl->isChecked(); account["useProxy"] = ui.useProxy->isChecked(); account["proxyHost"] = ui.proxyHost->text().trimmed(); @@ -513,7 +516,7 @@ QVariantMap CoreAccountEditDlg::accountData() { } void CoreAccountEditDlg::setWidgetStates() { - bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && (ui.useInternal->isChecked() || !ui.host->text().isEmpty()); + bool ok = !ui.accountName->text().trimmed().isEmpty() && !existing.contains(ui.accountName->text()) && !ui.host->text().isEmpty(); ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); } @@ -526,8 +529,3 @@ void CoreAccountEditDlg::on_accountName_textChanged(const QString &text) { Q_UNUSED(text); setWidgetStates(); } - -void CoreAccountEditDlg::on_useRemote_toggled(bool state) { - Q_UNUSED(state); - setWidgetStates(); -}