+void CoreConnection::reconnectToCore()
+{
+ if (currentAccount().isValid()) {
+ _wasReconnect = true;
+ connectToCore(currentAccount().accountId());
+ }
+}
+
+
+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;
+ }
+ emit startInternalCore();
+
+ InternalPeer *peer = new InternalPeer();
+ _peer = peer;
+ Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership
+ emit connectToInternalCore(peer);
+ setState(Connected);
+
+ return;
+ }
+
+ _authHandler = new ClientAuthHandler(currentAccount(), this);
+
+ connect(_authHandler, SIGNAL(disconnected()), SLOT(coreSocketDisconnected()));
+ connect(_authHandler, SIGNAL(connectionReady()), SLOT(onConnectionReady()));
+ connect(_authHandler, SIGNAL(socketError(QAbstractSocket::SocketError,QString)), SLOT(coreSocketError(QAbstractSocket::SocketError,QString)));
+ connect(_authHandler, SIGNAL(transferProgress(int,int)), SLOT(updateProgress(int,int)));
+ connect(_authHandler, SIGNAL(requestDisconnect(QString,bool)), SLOT(disconnectFromCore(QString,bool)));
+
+ connect(_authHandler, SIGNAL(errorMessage(QString)), SIGNAL(connectionError(QString)));
+ connect(_authHandler, SIGNAL(errorPopup(QString)), SIGNAL(connectionErrorPopup(QString)), Qt::QueuedConnection);
+ connect(_authHandler, SIGNAL(statusMessage(QString)), SIGNAL(connectionMsg(QString)));
+ connect(_authHandler, SIGNAL(encrypted(bool)), SIGNAL(encrypted(bool)));
+ connect(_authHandler, SIGNAL(startCoreSetup(QVariantList, QVariantList)), SIGNAL(startCoreSetup(QVariantList, QVariantList)));
+ connect(_authHandler, SIGNAL(coreSetupFailed(QString)), SIGNAL(coreSetupFailed(QString)));
+ connect(_authHandler, SIGNAL(coreSetupSuccessful()), SIGNAL(coreSetupSuccess()));
+ connect(_authHandler, SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)), SIGNAL(userAuthenticationRequired(CoreAccount*,bool*,QString)));
+ connect(_authHandler, SIGNAL(handleNoSslInClient(bool*)), SIGNAL(handleNoSslInClient(bool*)));
+ connect(_authHandler, SIGNAL(handleNoSslInCore(bool*)), SIGNAL(handleNoSslInCore(bool*)));