qt4-b-gone: Remove all code supporting Qt < 5.5 and KDE4
[quassel.git] / src / common / signalproxy.cpp
index bf07f28..19b9af8 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  *
@@ -96,11 +96,7 @@ void SignalProxy::SignalRelay::attachSignal(QObject *sender, int signalId, const
     }
     else {
         fn = SIGNAL(fakeMethodSignature());
-#if QT_VERSION >= 0x050000
         fn = fn.replace("fakeMethodSignature()", sender->metaObject()->method(signalId).methodSignature());
-#else
-        fn = fn.replace("fakeMethodSignature()", sender->metaObject()->method(signalId).signature());
-#endif
     }
 
     _slots[slotId] = Signal(sender, signalId, fn);
@@ -145,11 +141,7 @@ int SignalProxy::SignalRelay::qt_metacall(QMetaObject::Call _c, int _id, void **
             const QList<int> &argTypes = eMeta->argTypes(signal.signalId);
             for (int i = 0; i < argTypes.size(); i++) {
                 if (argTypes[i] == 0) {
-#if QT_VERSION >= 0x050000
                     qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(signal.signalId).methodSignature().constData());
-#else
-                    qWarning() << "SignalRelay::qt_metacall(): received invalid data for argument number" << i << "of signal" << QString("%1::%2").arg(caller->metaObject()->className()).arg(caller->metaObject()->method(signal.signalId).signature());
-#endif
                     qWarning() << "                            - make sure all your data types are known by the Qt MetaSystem";
                     return _id;
                 }
@@ -475,8 +467,11 @@ void SignalProxy::synchronize(SyncableObject *obj)
 
 void SignalProxy::detachObject(QObject *obj)
 {
-    detachSignals(obj);
-    detachSlots(obj);
+    // Don't try to connect SignalProxy from itself on shutdown
+    if (obj != this) {
+        detachSignals(obj);
+        detachSlots(obj);
+    }
 }
 
 
@@ -666,11 +661,7 @@ bool SignalProxy::invokeSlot(QObject *receiver, int methodId, const QVariantList
     // check for argument compatibility and build params array
     for (int i = 0; i < numArgs; i++) {
         if (!params[i].isValid()) {
-#if QT_VERSION >= 0x050000
             qWarning() << "SignalProxy::invokeSlot(): received invalid data for argument number" << i << "of method" << QString("%1::%2()").arg(receiver->metaObject()->className()).arg(receiver->metaObject()->method(methodId).methodSignature().constData());
-#else
-            qWarning() << "SignalProxy::invokeSlot(): received invalid data for argument number" << i << "of method" << QString("%1::%2()").arg(receiver->metaObject()->className()).arg(receiver->metaObject()->method(methodId).signature());
-#endif
             qWarning() << "                            - make sure all your data types are known by the Qt MetaSystem";
             return false;
         }
@@ -829,7 +820,7 @@ void SignalProxy::updateSecureState()
 
 QVariantList SignalProxy::peerData() {
     QVariantList result;
-    for (auto peer : _peerMap.values()) {
+    for (auto &&peer : _peerMap.values()) {
         QVariantMap data;
         data["id"] = peer->id();
         data["clientVersion"] = peer->clientVersion();
@@ -839,13 +830,18 @@ QVariantList SignalProxy::peerData() {
         data["remoteAddress"] = peer->address();
         data["connectedSince"] = peer->connectedSince();
         data["secure"] = peer->isSecure();
+        data["features"] = static_cast<quint32>(peer->features().toLegacyFeatures());
+        data["featureList"] = peer->features().toStringList();
         result << data;
     }
     return result;
 }
 
 Peer *SignalProxy::peerById(int peerId) {
-    return _peerMap[peerId];
+    // We use ::value() here instead of the [] operator because the latter has the side-effect
+    // of automatically inserting a null value with the passed key into the map.  See
+    // https://doc.qt.io/qt-5/qhash.html#operator-5b-5d and https://doc.qt.io/qt-5/qhash.html#value.
+    return _peerMap.value(peerId);
 }
 
 void SignalProxy::restrictTargetPeers(QSet<Peer*> peers, std::function<void()> closure)
@@ -888,11 +884,7 @@ SignalProxy::ExtendedMetaObject::ExtendedMetaObject(const QMetaObject *meta, boo
         if (_meta->method(i).methodType() != QMetaMethod::Slot)
             continue;
 
-#if QT_VERSION >= 0x050000
         if (_meta->method(i).methodSignature().contains('*'))
-#else
-        if (QByteArray(_meta->method(i).signature()).contains('*'))
-#endif
             continue;  // skip methods with ptr params
 
         QByteArray method = methodName(_meta->method(i));
@@ -921,11 +913,7 @@ SignalProxy::ExtendedMetaObject::ExtendedMetaObject(const QMetaObject *meta, boo
             }
             if (checkConflicts) {
                 qWarning() << "class" << meta->className() << "contains overloaded methods which is currently not supported!";
-#if QT_VERSION >= 0x050000
                 qWarning() << " - " << _meta->method(i).methodSignature() << "conflicts with" << _meta->method(_methodIds[method]).methodSignature();
-#else
-                qWarning() << " - " << _meta->method(i).signature() << "conflicts with" << _meta->method(_methodIds[method]).signature();
-#endif
             }
             continue;
         }
@@ -965,11 +953,7 @@ const QHash<int, int> &SignalProxy::ExtendedMetaObject::receiveMap()
             if (QMetaType::Void == (QMetaType::Type)returnType(i))
                 continue;
 
-#if QT_VERSION >= 0x050000
             signature = requestSlot.methodSignature();
-#else
-            signature = QByteArray(requestSlot.signature());
-#endif
             if (!signature.startsWith("request"))
                 continue;
 
@@ -1003,22 +987,14 @@ const QHash<int, int> &SignalProxy::ExtendedMetaObject::receiveMap()
 
 QByteArray SignalProxy::ExtendedMetaObject::methodName(const QMetaMethod &method)
 {
-#if QT_VERSION >= 0x050000
     QByteArray sig(method.methodSignature());
-#else
-    QByteArray sig(method.signature());
-#endif
     return sig.left(sig.indexOf("("));
 }
 
 
 QString SignalProxy::ExtendedMetaObject::methodBaseName(const QMetaMethod &method)
 {
-#if QT_VERSION >= 0x050000
     QString methodname = QString(method.methodSignature()).section("(", 0, 0);
-#else
-    QString methodname = QString(method.signature()).section("(", 0, 0);
-#endif
 
     // determine where we have to chop:
     int upperCharPos;
@@ -1056,11 +1032,7 @@ SignalProxy::ExtendedMetaObject::MethodDescriptor::MethodDescriptor(const QMetaM
     _argTypes = argTypes;
 
     // determine minArgCount
-#if QT_VERSION >= 0x050000
     QString signature(method.methodSignature());
-#else
-    QString signature(method.signature());
-#endif
     _minArgCount = method.parameterTypes().count() - signature.count("=");
 
     _receiverMode = (_methodName.startsWith("request"))