modernize: Replace most remaining old-style connects by PMF ones
[quassel.git] / src / common / remotepeer.cpp
index 7c80406..c3ad24f 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2016 by the Quassel Project                        *
+ *   Copyright (C) 2005-2018 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -30,6 +30,7 @@
 #endif
 
 #include "remotepeer.h"
+#include "util.h"
 
 using namespace Protocol;
 
@@ -39,27 +40,28 @@ RemotePeer::RemotePeer(::AuthHandler *authHandler, QTcpSocket *socket, Compresso
     : Peer(authHandler, parent),
     _socket(socket),
     _compressor(new Compressor(socket, level, this)),
-    _signalProxy(0),
+    _signalProxy(nullptr),
     _heartBeatTimer(new QTimer(this)),
     _heartBeatCount(0),
     _lag(0),
     _msgSize(0)
 {
     socket->setParent(this);
-    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(onSocketStateChanged(QAbstractSocket::SocketState)));
-    connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError)));
-    connect(socket, SIGNAL(disconnected()), SIGNAL(disconnected()));
+    connect(socket, &QAbstractSocket::stateChanged, this, &RemotePeer::onSocketStateChanged);
+    connect(socket, selectOverload<QAbstractSocket::SocketError>(&QAbstractSocket::error), this, &RemotePeer::onSocketError);
+    connect(socket, &QAbstractSocket::disconnected, this, &Peer::disconnected);
 
 #ifdef HAVE_SSL
-    QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket);
-    if (sslSocket)
-        connect(sslSocket, SIGNAL(encrypted()), SIGNAL(secureStateChanged()));
+    auto *sslSocket = qobject_cast<QSslSocket *>(socket);
+    if (sslSocket) {
+        connect(sslSocket, &QSslSocket::encrypted, this, [this]() { emit secureStateChanged(true); });
+    }
 #endif
 
-    connect(_compressor, SIGNAL(readyRead()), SLOT(onReadyRead()));
-    connect(_compressor, SIGNAL(error(Compressor::Error)), SLOT(onCompressionError(Compressor::Error)));
+    connect(_compressor, &Compressor::readyRead, this, &RemotePeer::onReadyRead);
+    connect(_compressor, &Compressor::error, this, &RemotePeer::onCompressionError);
 
-    connect(_heartBeatTimer, SIGNAL(timeout()), SLOT(sendHeartBeat()));
+    connect(_heartBeatTimer, &QTimer::timeout, this, &RemotePeer::sendHeartBeat);
 }
 
 
@@ -121,8 +123,8 @@ void RemotePeer::setSignalProxy(::SignalProxy *proxy)
 
     if (!proxy) {
         _heartBeatTimer->stop();
-        disconnect(signalProxy(), 0, this, 0);
-        _signalProxy = 0;
+        disconnect(signalProxy(), nullptr, this, nullptr);
+        _signalProxy = nullptr;
         if (isOpen())
             close();
     }
@@ -132,7 +134,7 @@ void RemotePeer::setSignalProxy(::SignalProxy *proxy)
             return;
         }
         _signalProxy = proxy;
-        connect(proxy, SIGNAL(heartBeatIntervalChanged(int)), SLOT(changeHeartBeatInterval(int)));
+        connect(proxy, &SignalProxy::heartBeatIntervalChanged, this, &RemotePeer::changeHeartBeatInterval);
         _heartBeatTimer->setInterval(proxy->heartBeatInterval() * 1000);
         _heartBeatTimer->start();
     }
@@ -168,7 +170,7 @@ bool RemotePeer::isSecure() const
         if (isLocal())
             return true;
 #ifdef HAVE_SSL
-        QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket());
+        auto *sslSocket = qobject_cast<QSslSocket *>(socket());
         if (sslSocket && sslSocket->isEncrypted())
             return true;
 #endif
@@ -260,7 +262,7 @@ bool RemotePeer::readMessage(QByteArray &msg)
 
 void RemotePeer::writeMessage(const QByteArray &msg)
 {
-    quint32 size = qToBigEndian<quint32>(msg.size());
+    auto size = qToBigEndian<quint32>(msg.size());
     _compressor->write((const char*)&size, 4, Compressor::NoFlush);
     _compressor->write(msg.constData(), msg.size());
 }