modernize: Replace most remaining old-style connects by PMF ones
[quassel.git] / src / core / core.cpp
index e1ea083..556eec6 100644 (file)
@@ -70,6 +70,8 @@ public:
 Core::Core()
     : Singleton<Core>{this}
 {
+    Q_INIT_RESOURCE(sql);
+
     // Parent all QObject-derived attributes, so when the Core instance gets moved into another
     // thread, they get moved with it
     _server.setParent(this);
@@ -219,12 +221,12 @@ void Core::init()
             return false;
         });
 
-        connect(&_storageSyncTimer, SIGNAL(timeout()), this, SLOT(syncStorage()));
+        connect(&_storageSyncTimer, &QTimer::timeout, this, &Core::syncStorage);
         _storageSyncTimer.start(10 * 60 * 1000); // 10 minutes
     }
 
-    connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
-    connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
+    connect(&_server, &QTcpServer::newConnection, this, &Core::incomingConnection);
+    connect(&_v6server, &QTcpServer::newConnection, this, &Core::incomingConnection);
 
     if (!startListening()) {
         throw ExitException{EXIT_FAILURE, tr("Cannot open port for listening!")};
@@ -271,7 +273,7 @@ void Core::shutdown()
     }
 
     for (auto &&session : _sessions) {
-        connect(session, SIGNAL(shutdownComplete(SessionThread*)), this, SLOT(onSessionShutdown(SessionThread*)));
+        connect(session, &SessionThread::shutdownComplete, this, &Core::onSessionShutdown);
         session->shutdown();
     }
 }
@@ -441,7 +443,7 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings,
         return false;
     }
 
-    connect(storage.get(), SIGNAL(dbUpgradeInProgress(bool)), this, SIGNAL(dbUpgradeInProgress(bool)));
+    connect(storage.get(), &Storage::dbUpgradeInProgress, this, &Core::dbUpgradeInProgress);
 
     Storage::State storageState = storage->init(settings, environment, loadFromEnvironment);
     switch (storageState) {
@@ -463,8 +465,8 @@ bool Core::initStorage(const QString &backend, const QVariantMap &settings,
     case Storage::IsReady:
         // delete all other backends
         _registeredStorageBackends.clear();
-        connect(storage.get(), SIGNAL(bufferInfoUpdated(UserId, const BufferInfo &)),
-                this, SIGNAL(bufferInfoUpdated(UserId, const BufferInfo &)));
+        connect(storage.get(), &Storage::bufferInfoUpdated,
+                this, &Core::bufferInfoUpdated);
         break;
     }
     _storage = std::move(storage);
@@ -575,7 +577,7 @@ bool Core::initAuthenticator(const QString &backend, const QVariantMap &settings
 bool Core::sslSupported()
 {
 #ifdef HAVE_SSL
-    SslServer *sslServer = qobject_cast<SslServer *>(&instance()->_server);
+    auto *sslServer = qobject_cast<SslServer *>(&instance()->_server);
     return sslServer && sslServer->isCertValid();
 #else
     return false;
@@ -586,10 +588,10 @@ bool Core::sslSupported()
 bool Core::reloadCerts()
 {
 #ifdef HAVE_SSL
-    SslServer *sslServerv4 = qobject_cast<SslServer *>(&_server);
+    auto *sslServerv4 = qobject_cast<SslServer *>(&_server);
     bool retv4 = sslServerv4->reloadCerts();
 
-    SslServer *sslServerv6 = qobject_cast<SslServer *>(&_v6server);
+    auto *sslServerv6 = qobject_cast<SslServer *>(&_v6server);
     bool retv6 = sslServerv6->reloadCerts();
 
     return retv4 && retv6;
@@ -734,17 +736,17 @@ void Core::stopListening(const QString &reason)
 
 void Core::incomingConnection()
 {
-    QTcpServer *server = qobject_cast<QTcpServer *>(sender());
+    auto *server = qobject_cast<QTcpServer *>(sender());
     Q_ASSERT(server);
     while (server->hasPendingConnections()) {
         QTcpSocket *socket = server->nextPendingConnection();
 
-        CoreAuthHandler *handler = new CoreAuthHandler(socket, this);
+        auto *handler = new CoreAuthHandler(socket, this);
         _connectingClients.insert(handler);
 
-        connect(handler, SIGNAL(disconnected()), SLOT(clientDisconnected()));
-        connect(handler, SIGNAL(socketError(QAbstractSocket::SocketError,QString)), SLOT(socketError(QAbstractSocket::SocketError,QString)));
-        connect(handler, SIGNAL(handshakeComplete(RemotePeer*,UserId)), SLOT(setupClientSession(RemotePeer*,UserId)));
+        connect(handler, &AuthHandler::disconnected, this, &Core::clientDisconnected);
+        connect(handler, &AuthHandler::socketError, this, &Core::socketError);
+        connect(handler, &CoreAuthHandler::handshakeComplete, this, &Core::setupClientSession);
 
         quInfo() << qPrintable(tr("Client connected from"))  << qPrintable(socket->peerAddress().toString());
 
@@ -758,7 +760,7 @@ void Core::incomingConnection()
 // Potentially called during the initialization phase (before handing the connection off to the session)
 void Core::clientDisconnected()
 {
-    CoreAuthHandler *handler = qobject_cast<CoreAuthHandler *>(sender());
+    auto *handler = qobject_cast<CoreAuthHandler *>(sender());
     Q_ASSERT(handler);
 
     quInfo() << qPrintable(tr("Non-authed client disconnected:")) << qPrintable(handler->socket()->peerAddress().toString());
@@ -777,11 +779,11 @@ void Core::clientDisconnected()
 
 void Core::setupClientSession(RemotePeer *peer, UserId uid)
 {
-    CoreAuthHandler *handler = qobject_cast<CoreAuthHandler *>(sender());
+    auto *handler = qobject_cast<CoreAuthHandler *>(sender());
     Q_ASSERT(handler);
 
     // From now on everything is handled by the client session
-    disconnect(handler, 0, this, 0);
+    disconnect(handler, nullptr, this, nullptr);
     _connectingClients.remove(handler);
     handler->deleteLater();
 
@@ -797,7 +799,7 @@ void Core::setupClientSession(RemotePeer *peer, UserId uid)
 void Core::customEvent(QEvent *event)
 {
     if (event->type() == AddClientEventId) {
-        AddClientEvent *addClientEvent = static_cast<AddClientEvent *>(event);
+        auto *addClientEvent = static_cast<AddClientEvent *>(event);
         addClientHelper(addClientEvent->peer, addClientEvent->userId);
         return;
     }
@@ -849,7 +851,7 @@ void Core::setupInternalClientSession(QPointer<InternalPeer> clientPeer)
         return;
     }
 
-    InternalPeer *corePeer = new InternalPeer(this);
+    auto *corePeer = new InternalPeer(this);
     corePeer->setPeer(clientPeer);
     clientPeer->setPeer(corePeer);
 
@@ -1179,7 +1181,7 @@ std::unique_ptr<AbstractSqlMigrationReader> Core::getMigrationReader(Storage *st
     if (!storage)
         return nullptr;
 
-    AbstractSqlStorage *sqlStorage = qobject_cast<AbstractSqlStorage *>(storage);
+    auto *sqlStorage = qobject_cast<AbstractSqlStorage *>(storage);
     if (!sqlStorage) {
         qDebug() << "Core::migrateDb(): only SQL based backends can be migrated!";
         return nullptr;
@@ -1194,7 +1196,7 @@ std::unique_ptr<AbstractSqlMigrationWriter> Core::getMigrationWriter(Storage *st
     if (!storage)
         return nullptr;
 
-    AbstractSqlStorage *sqlStorage = qobject_cast<AbstractSqlStorage *>(storage);
+    auto *sqlStorage = qobject_cast<AbstractSqlStorage *>(storage);
     if (!sqlStorage) {
         qDebug() << "Core::migrateDb(): only SQL based backends can be migrated!";
         return nullptr;