test: Add build system support and a main function for unit tests
[quassel.git] / src / uisupport / networkmodelcontroller.h
index 5ffe127..1d691f7 100644 (file)
  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
  ***************************************************************************/
 
-#ifndef NETWORKMODELCONTROLLER_H_
-#define NETWORKMODELCONTROLLER_H_
+#pragma once
+
+#include "uisupport-export.h"
+
+#include <functional>
+#include <type_traits>
 
 #include <QDialog>
 
@@ -31,13 +35,12 @@ class QComboBox;
 class QDialogButtonBox;
 class QLineEdit;
 
-class NetworkModelController : public QObject
+class UISUPPORT_EXPORT NetworkModelController : public QObject
 {
     Q_OBJECT
 
 public:
-    NetworkModelController(QObject *parent = 0);
-    virtual ~NetworkModelController();
+    NetworkModelController(QObject *parent = nullptr);
 
     // don't change enums without doublechecking masks etc. in code
     enum ActionType {
@@ -132,14 +135,24 @@ protected:
     inline QList<QModelIndex> indexList() const;
     inline MessageFilter *messageFilter() const;
     inline QString contextItem() const;  ///< Channel name or nick to provide context menu for
-    inline QObject *receiver() const;
-    inline const char *method() const;
 
     void setIndexList(const QModelIndex &);
     void setIndexList(const QList<QModelIndex> &);
     void setMessageFilter(MessageFilter *);
     void setContextItem(const QString &);
-    void setSlot(QObject *receiver, const char *method);
+
+    using ActionSlot = std::function<void(QAction*)>;
+
+    template<typename Receiver, typename Slot>
+    ActionSlot buildActionSlot(Receiver *receiver, Slot slot)
+    {
+        static_assert(!std::is_same<Slot, const char*>::value, "Old-style slots not supported");
+        return [receiver, slot = std::move(slot)](QAction *action) {
+            (receiver->*slot)(action);
+        };
+    }
+
+    void setSlot(ActionSlot slot);
 
     Action *registerAction(ActionType type, const QString &text, bool checkable = false);
     Action *registerAction(NetworkModelController::ActionType type, const QIcon &icon, const QString &text, bool checkable = false);
@@ -159,10 +172,11 @@ signals:
      *
      * @see MainWin::showChannelList()
      *
-     * @param networkId       Network ID for associated network
-     * @param channelFilters  Partial channel name to search for, or empty to show all
+     * @param networkId        Network ID for associated network
+     * @param channelFilters   Partial channel name to search for, or empty to show all
+     * @param listImmediately  If true, immediately list channels, otherwise just show dialog
      */
-    void showChannelList(NetworkId, const QString &);
+    void showChannelList(NetworkId, const QString &, bool);
     void showNetworkConfig(NetworkId);
     void showIgnoreList(QString);
 
@@ -183,10 +197,9 @@ private:
     QHash<ActionType, Action *> _actionByType;
 
     QList<QModelIndex> _indexList;
-    MessageFilter *_messageFilter;
+    MessageFilter *_messageFilter{nullptr};
     QString _contextItem; ///< Channel name or nick to provide context menu for
-    QObject *_receiver;
-    const char *_method;
+    ActionSlot _actionSlot;
 };
 
 
@@ -196,7 +209,7 @@ class NetworkModelController::JoinDlg : public QDialog
     Q_OBJECT
 
 public:
-    JoinDlg(const QModelIndex &index, QWidget *parent = 0);
+    JoinDlg(const QModelIndex &index, QWidget *parent = nullptr);
 
     QString channelName() const;
     QString channelPassword() const;
@@ -219,7 +232,3 @@ Action *NetworkModelController::action(ActionType type) const { return _actionBy
 QList<QModelIndex> NetworkModelController::indexList() const { return _indexList; }
 MessageFilter *NetworkModelController::messageFilter() const { return _messageFilter; }
 QString NetworkModelController::contextItem() const { return _contextItem; }
-QObject *NetworkModelController::receiver() const { return _receiver; }
-const char *NetworkModelController::method() const { return _method; }
-
-#endif