+ _lastPingTime(0),
+ _pingCount(0),
+ _sendPings(false),
+ _requestedUserModes('-')
+{
+ _autoReconnectTimer.setSingleShot(true);
+ connect(&_socketCloseTimer, SIGNAL(timeout()), this, SLOT(socketCloseTimeout()));
+
+ setPingInterval(networkConfig()->pingInterval());
+ connect(&_pingTimer, SIGNAL(timeout()), this, SLOT(sendPing()));
+
+ setAutoWhoDelay(networkConfig()->autoWhoDelay());
+ setAutoWhoInterval(networkConfig()->autoWhoInterval());
+
+ QHash<QString, QString> channels = coreSession()->persistentChannels(networkId());
+ foreach(QString chan, channels.keys()) {
+ _channelKeys[chan.toLower()] = channels[chan];
+ }
+
+ connect(networkConfig(), SIGNAL(pingTimeoutEnabledSet(bool)), SLOT(enablePingTimeout(bool)));
+ connect(networkConfig(), SIGNAL(pingIntervalSet(int)), SLOT(setPingInterval(int)));
+ connect(networkConfig(), SIGNAL(autoWhoEnabledSet(bool)), SLOT(setAutoWhoEnabled(bool)));
+ connect(networkConfig(), SIGNAL(autoWhoIntervalSet(int)), SLOT(setAutoWhoInterval(int)));
+ connect(networkConfig(), SIGNAL(autoWhoDelaySet(int)), SLOT(setAutoWhoDelay(int)));
+
+ connect(&_autoReconnectTimer, SIGNAL(timeout()), this, SLOT(doAutoReconnect()));
+ connect(&_autoWhoTimer, SIGNAL(timeout()), this, SLOT(sendAutoWho()));
+ connect(&_autoWhoCycleTimer, SIGNAL(timeout()), this, SLOT(startAutoWhoCycle()));
+ connect(&_tokenBucketTimer, SIGNAL(timeout()), this, SLOT(fillBucketAndProcessQueue()));
+
+ connect(&socket, SIGNAL(connected()), this, SLOT(socketInitialized()));
+ connect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));
+ connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
+ connect(&socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
+ connect(&socket, SIGNAL(readyRead()), this, SLOT(socketHasData()));
+#ifdef HAVE_SSL
+ connect(&socket, SIGNAL(encrypted()), this, SLOT(socketInitialized()));
+ connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
+#endif
+ connect(this, SIGNAL(newEvent(Event *)), coreSession()->eventManager(), SLOT(postEvent(Event *)));
+
+ if (Quassel::isOptionSet("oidentd")) {
+ connect(this, SIGNAL(socketInitialized(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(addSocket(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Qt::BlockingQueuedConnection);
+ connect(this, SIGNAL(socketDisconnected(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)), Core::instance()->oidentdConfigGenerator(), SLOT(removeSocket(const CoreIdentity*, QHostAddress, quint16, QHostAddress, quint16)));
+ }
+}
+
+
+CoreNetwork::~CoreNetwork()
+{
+ if (connectionState() != Disconnected && connectionState() != Network::Reconnecting)
+ disconnectFromIrc(false); // clean up, but this does not count as requested disconnect!
+ disconnect(&socket, 0, this, 0); // this keeps the socket from triggering events during clean up
+ delete _userInputHandler;
+}
+
+
+QString CoreNetwork::channelDecode(const QString &bufferName, const QByteArray &string) const
+{
+ if (!bufferName.isEmpty()) {
+ IrcChannel *channel = ircChannel(bufferName);
+ if (channel)
+ return channel->decodeString(string);
+ }
+ return decodeString(string);
+}
+
+
+QString CoreNetwork::userDecode(const QString &userNick, const QByteArray &string) const
+{
+ IrcUser *user = ircUser(userNick);
+ if (user)
+ return user->decodeString(string);
+ return decodeString(string);
+}
+
+
+QByteArray CoreNetwork::channelEncode(const QString &bufferName, const QString &string) const
+{
+ if (!bufferName.isEmpty()) {
+ IrcChannel *channel = ircChannel(bufferName);
+ if (channel)
+ return channel->encodeString(string);
+ }
+ return encodeString(string);
+}
+
+
+QByteArray CoreNetwork::userEncode(const QString &userNick, const QString &string) const
+{
+ IrcUser *user = ircUser(userNick);
+ if (user)
+ return user->encodeString(string);
+ return encodeString(string);
+}
+
+
+void CoreNetwork::connectToIrc(bool reconnecting)