+}
+
+
+void CoreConnection::disconnectFromCore()
+{
+ if (_socket) {
+ _requestedDisconnect = true;
+ disconnectFromCore(QString(), false); // requested disconnect, so don't try to reconnect
+ }
+}
+
+
+void CoreConnection::disconnectFromCore(const QString &errorString, bool wantReconnect)
+{
+ if (!wantReconnect)
+ _reconnectTimer.stop();
+
+ _wasReconnect = wantReconnect; // store if disconnect was requested
+
+ resetConnection(wantReconnect);
+
+ if (errorString.isEmpty())
+ emit connectionError(tr("Disconnected"));
+ else
+ emit connectionError(errorString);
+}
+
+
+void CoreConnection::resetConnection(bool wantReconnect)
+{
+ if (_resetting)
+ return;
+ _resetting = true;
+
+ _wantReconnect = wantReconnect;
+
+ if (_peer) {
+ disconnect(_socket, 0, this, 0);
+ disconnect(_peer, 0, this, 0);
+ _peer->close();
+
+ if (_peer->parent() == this)
+ _peer->deleteLater(); // if it's not us, it belongs to the sigproxy which will delete it
+ _socket = 0; // socket is owned and will be deleted by RemoteConnection
+ _peer = 0;
+ }
+ else if (_socket) {
+ disconnect(_socket, 0, this, 0);
+ _socket->deleteLater();
+ _socket = 0;
+ }
+
+ _requestedDisconnect = false;
+
+ _coreMsgBuffer.clear();
+ _netsToSync.clear();
+ _numNetsToSync = 0;
+
+ setProgressMaximum(-1); // disable
+ setState(Disconnected);
+ emit lagUpdated(-1);
+
+ emit connectionMsg(tr("Disconnected from core."));
+ emit encrypted(false);
+
+ // initiate if a reconnect if appropriate
+ CoreConnectionSettings s;
+ if (wantReconnect && s.autoReconnect()) {
+ _reconnectTimer.start();
+ }
+
+ _resetting = false;
+}
+
+
+void CoreConnection::reconnectToCore()
+{
+ if (currentAccount().isValid())
+ connectToCore(currentAccount().accountId());
+}
+
+
+bool CoreConnection::connectToCore(AccountId accId)
+{
+ if (isConnected())