Add igungor to aboutdlg.cpp
[quassel.git] / src / core / networkconnection.cpp
index 617433f..d177d4c 100644 (file)
@@ -35,6 +35,8 @@
 #include "userinputhandler.h"
 #include "ctcphandler.h"
 
+#include "logger.h"
+
 NetworkConnection::NetworkConnection(Network *network, CoreSession *session)
   : QObject(network),
     _connectionState(Network::Disconnected),
@@ -87,7 +89,7 @@ NetworkConnection::NetworkConnection(Network *network, CoreSession *session)
   connect(network, SIGNAL(autoReconnectIntervalSet(quint32)), this, SLOT(autoReconnectSettingsChanged()));
   connect(network, SIGNAL(autoReconnectRetriesSet(quint16)), this, SLOT(autoReconnectSettingsChanged()));
 
-#ifndef QT_NO_OPENSSL
+#ifdef HAVE_SSL
   connect(&socket, SIGNAL(encrypted()), this, SLOT(socketEncrypted()));
   connect(&socket, SIGNAL(sslErrors(const QList<QSslError> &)), this, SLOT(sslErrors(const QList<QSslError> &)));
 #endif
@@ -251,19 +253,24 @@ void NetworkConnection::sendPerform() {
   if(!joinString.isEmpty()) userInputHandler()->handleJoin(statusBuf, joinString);
 }
 
-void NetworkConnection::disconnectFromIrc(bool requested) {
+void NetworkConnection::disconnectFromIrc(bool requested, const QString &reason) {
   _quitRequested = requested; // see socketDisconnected();
   _autoReconnectTimer.stop();
   _autoReconnectCount = 0; // prohibiting auto reconnect
   displayMsg(Message::Server, BufferInfo::StatusBuffer, "", tr("Disconnecting."));
   if(socket.state() == QAbstractSocket::UnconnectedState) {
     socketDisconnected();
-  } else if(socket.state() < QAbstractSocket::ConnectedState) {
+  } else if(socket.state() < QAbstractSocket::ConnectedState || !requested) {
+    // we might be in a state waiting for a timeout...
+    // or (!requested) this is a core shutdown...
+    // in both cases we don't really care... set a disconnected state
     socket.close();
-    // we might be in a state waiting for a timeout... we don't care... set a disconnected state
     socketDisconnected();
   } else {
-    _socketCloseTimer.start(10000); // the irc server has 10 seconds to close the socket
+    // quit gracefully if it's user requested quit
+    userInputHandler()->issueQuit(reason);
+    // the irc server has 10 seconds to close the socket
+    _socketCloseTimer.start(10000);
   }
 }
 
@@ -276,7 +283,7 @@ void NetworkConnection::socketHasData() {
 
 void NetworkConnection::socketError(QAbstractSocket::SocketError) {
   _previousConnectionAttemptFailed = true;
-  qDebug() << qPrintable(tr("Could not connect to %1 (%2)").arg(network()->networkName(), socket.errorString()));
+  qWarning() << qPrintable(tr("Could not connect to %1 (%2)").arg(network()->networkName(), socket.errorString()));
   emit connectionError(socket.errorString());
   emit displayMsg(Message::Error, BufferInfo::StatusBuffer, "", tr("Connection failure: %1").arg(socket.errorString()));
   network()->emitConnectionError(socket.errorString());
@@ -289,7 +296,7 @@ void NetworkConnection::socketError(QAbstractSocket::SocketError) {
   //exit(1);
 }
 
-#ifndef QT_NO_OPENSSL
+#ifdef HAVE_SSL
 
 void NetworkConnection::sslErrors(const QList<QSslError> &sslErrors) {
   Q_UNUSED(sslErrors)
@@ -313,10 +320,10 @@ void NetworkConnection::socketEncrypted() {
   socketInitialized();
 }
 
-#endif  // QT_NO_OPENSSL
+#endif  // HAVE_SSL
 
 void NetworkConnection::socketConnected() {
-#ifdef QT_NO_OPENSSL
+#ifndef HAVE_SSL
   socketInitialized();
   return;
 #else
@@ -333,7 +340,7 @@ void NetworkConnection::socketInitialized() {
   //emit connected(networkId());  initialize first!
   Identity *identity = coreSession()->identity(network()->identity());
   if(!identity) {
-    qWarning() << "Identity invalid!";
+    qCritical() << "Identity invalid!";
     disconnectFromIrc();
     return;
   }
@@ -379,7 +386,13 @@ void NetworkConnection::socketDisconnected() {
   _autoWhoInProgress.clear();
 
   _socketCloseTimer.stop();
-  
+
+  IrcUser *me = network()->me();
+  if(me) {
+    foreach(QString channel, me->channels())
+      emit displayMsg(Message::Quit, BufferInfo::ChannelBuffer, channel, "", me->hostmask());
+  }
+
   network()->setConnected(false);
   emit disconnected(networkId());
   if(_quitRequested) {
@@ -468,12 +481,9 @@ void NetworkConnection::putCmd(const QString &cmd, const QList<QByteArray> &para
   if(cmd == "PRIVMSG" && params.count() > 1) {
     int overrun = lastParamOverrun(cmd, params);
     if(overrun) {
-      QList<QByteArray> paramCopy1;
-      QList<QByteArray> paramCopy2;
-      for(int i = 0; i < params.count() - 1; i++) {
-       paramCopy1 << params[i];
-       paramCopy2 << params[i];
-      }
+      QList<QByteArray> paramCopy1 = params;
+      paramCopy1.removeLast();
+      QList<QByteArray> paramCopy2 = paramCopy1;
 
       QByteArray lastPart = params.last();
       QByteArray splitter(" .,-");
@@ -482,8 +492,7 @@ void NetworkConnection::putCmd(const QString &cmd, const QList<QByteArray> &para
       for(int i = 0; i < splitter.size(); i++) {
        splitPos = qMax(splitPos, lastPart.lastIndexOf(splitter[i], maxSplitPos));
       }
-
-      if(splitPos == -1) {
+      if(splitPos <= 0) {
        splitPos = maxSplitPos;
       }