-void CoreNetwork::connectToIrc(bool reconnecting) {
- if(!reconnecting && useAutoReconnect() && _autoReconnectCount == 0) {
- _autoReconnectTimer.setInterval(autoReconnectInterval() * 1000);
- if(unlimitedReconnectRetries())
- _autoReconnectCount = -1;
- else
- _autoReconnectCount = autoReconnectRetries();
- }
- if(serverList().isEmpty()) {
- qWarning() << "Server list empty, ignoring connect request!";
- return;
- }
- CoreIdentity *identity = identityPtr();
- if(!identity) {
- qWarning() << "Invalid identity configures, ignoring connect request!";
- return;
- }
-
- // cleaning up old quit reason
- _quitReason.clear();
-
- // use a random server?
- if(useRandomServer()) {
- _lastUsedServerIndex = qrand() % serverList().size();
- } else if(_previousConnectionAttemptFailed) {
- // cycle to next server if previous connection attempt failed
- displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Connection failed. Cycling to next Server"));
- if(++_lastUsedServerIndex >= serverList().size()) {
- _lastUsedServerIndex = 0;
- }
- }
- _previousConnectionAttemptFailed = false;
-
- Server server = usedServer();
- displayStatusMsg(tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
- displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Connecting to %1:%2...").arg(server.host).arg(server.port));
-
- if(server.useProxy) {
- QNetworkProxy proxy((QNetworkProxy::ProxyType)server.proxyType, server.proxyHost, server.proxyPort, server.proxyUser, server.proxyPass);
- socket.setProxy(proxy);
- } else {
- socket.setProxy(QNetworkProxy::NoProxy);
- }