Implement changes requested in review
[quassel.git] / src / common / signalproxy.h
index a985d0d..63d3438 100644 (file)
@@ -24,6 +24,8 @@
 #include <QEvent>
 #include <QSet>
 
+#include <functional>
+
 #include "protocol.h"
 
 struct QMetaObject;
@@ -78,14 +80,30 @@ public:
     void dumpProxyStats();
     void dumpSyncMap(SyncableObject *object);
 
+    /**@{*/
     /**
      * This method allows to send a signal only to a limited set of peers
-     * @param peerIds A list of peers that should receive it
+     * @param peers A list of peers that should receive it
      * @param closure Code you want to execute within of that restricted environment
      */
-    void restrictTargetPeers(std::initializer_list<Peer *> peerIds, std::function<void()> closure);
+    void restrictTargetPeers(QSet<Peer*> peers, std::function<void()> closure);
+    void restrictTargetPeers(Peer *peer, std::function<void()> closure) {
+        QSet<Peer*> set;
+        set.insert(peer);
+        restrictTargetPeers(set, std::move(closure));
+    }
+
+    //A better version, but only implemented on Qt5 if Initializer Lists exist
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+    void restrictTargetPeers(std::initializer_list<Peer*> peers, std::function<void()> closure) {
+        restrictTargetPeers(QSet<Peer*>(peers), std::move(closure));
+    }
+#endif
+#endif
+    /**}@*/
 
-    inline int peerCount() const { return _peers.size(); }
+    inline int peerCount() const { return _peerMap.size(); }
     QVariantList peerData();
 
     Peer *peerById(int peerId);
@@ -159,7 +177,6 @@ private:
 
     static void disconnectDevice(QIODevice *dev, const QString &reason = QString());
 
-    QSet<Peer *> _peers;
     QHash<int, Peer*> _peerMap;
 
     // containg a list of argtypes for fast access
@@ -188,7 +205,7 @@ private:
     QSet<Peer *> _restrictedTargets;
     bool _restrictMessageTarget = false;
 
-    Peer *_sourcePeer;
+    Peer *_sourcePeer = nullptr;
 
     friend class SignalRelay;
     friend class SyncableObject;