+bool CoreConnection::connectToCore(AccountId accId)
+{
+ if (isConnected())
+ return false;
+
+ CoreAccountSettings s;
+
+ // FIXME: Don't force connection to internal core in mono client
+ if (Quassel::runMode() == Quassel::Monolithic) {
+ _account = accountModel()->account(accountModel()->internalAccount());
+ Q_ASSERT(_account.isValid());
+ }
+ else {
+ if (!accId.isValid()) {
+ // check our settings and figure out what to do
+ if (!s.autoConnectOnStartup())
+ return false;
+ if (s.autoConnectToFixedAccount())
+ accId = s.autoConnectAccount();
+ else
+ accId = s.lastAccount();
+ if (!accId.isValid())
+ return false;
+ }
+ _account = accountModel()->account(accId);
+ if (!_account.accountId().isValid()) {
+ return false;
+ }
+ if (Quassel::runMode() != Quassel::Monolithic) {
+ if (_account.isInternal())
+ return false;
+ }
+ }
+
+ s.setLastAccount(accId);
+ connectToCurrentAccount();
+ return true;
+}
+
+void CoreConnection::connectToCurrentAccount()
+{
+ if (_authHandler) {
+ qWarning() << Q_FUNC_INFO << "Already connected!";
+ return;
+ }
+
+ if (currentAccount().isInternal()) {
+ if (Quassel::runMode() != Quassel::Monolithic) {
+ qWarning() << "Cannot connect to internal core in client-only mode!";
+ return;
+ }
+
+ auto* peer = new InternalPeer();
+ _peer = peer;
+ Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership
+ emit connectionMsg(tr("Initializing..."));
+ emit connectToInternalCore(peer);
+ setState(Connected);
+ return;
+ }
+
+ _authHandler = new ClientAuthHandler(currentAccount(), this);
+
+ connect(_authHandler, &ClientAuthHandler::disconnected, this, &CoreConnection::coreSocketDisconnected);
+ connect(_authHandler, &ClientAuthHandler::connectionReady, this, &CoreConnection::onConnectionReady);
+ connect(_authHandler, &ClientAuthHandler::socketError, this, &CoreConnection::coreSocketError);
+ connect(_authHandler, &ClientAuthHandler::transferProgress, this, &CoreConnection::updateProgress);
+ connect(_authHandler,
+ &ClientAuthHandler::requestDisconnect,
+ this,
+ selectOverload<const QString&, bool>(&CoreConnection::disconnectFromCore));
+
+ connect(_authHandler, &ClientAuthHandler::errorMessage, this, &CoreConnection::connectionError);
+ connect(_authHandler, &ClientAuthHandler::errorPopup, this, &CoreConnection::connectionErrorPopup, Qt::QueuedConnection);
+ connect(_authHandler, &ClientAuthHandler::statusMessage, this, &CoreConnection::connectionMsg);
+ connect(_authHandler, &ClientAuthHandler::encrypted, this, &CoreConnection::encrypted);
+ connect(_authHandler, &ClientAuthHandler::startCoreSetup, this, &CoreConnection::startCoreSetup);
+ connect(_authHandler, &ClientAuthHandler::coreSetupFailed, this, &CoreConnection::coreSetupFailed);
+ connect(_authHandler, &ClientAuthHandler::coreSetupSuccessful, this, &CoreConnection::coreSetupSuccess);
+ connect(_authHandler, &ClientAuthHandler::userAuthenticationRequired, this, &CoreConnection::userAuthenticationRequired);
+ connect(_authHandler, &ClientAuthHandler::handleNoSslInClient, this, &CoreConnection::handleNoSslInClient);
+ connect(_authHandler, &ClientAuthHandler::handleNoSslInCore, this, &CoreConnection::handleNoSslInCore);