X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fnetworkmodelcontroller.h;h=c3c075ba880690b320d35a70ac06163327c4e054;hp=f83e23f33df99414ec3dbf2b3cc780b6bbde9ab5;hb=45645a28bdc5b6c1052b3e4cebf8cc80832d205a;hpb=4988547cbb3c35016872a4ed8dbcc1376473ad80 diff --git a/src/uisupport/networkmodelcontroller.h b/src/uisupport/networkmodelcontroller.h index f83e23f3..c3c075ba 100644 --- a/src/uisupport/networkmodelcontroller.h +++ b/src/uisupport/networkmodelcontroller.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2019 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -18,8 +18,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef NETWORKMODELCONTROLLER_H_ -#define NETWORKMODELCONTROLLER_H_ +#pragma once + +#include "uisupport-export.h" + +#include +#include #include @@ -31,22 +35,24 @@ 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 { + enum ActionType + { // Network actions NetworkMask = 0x0f, NetworkConnect = 0x01, NetworkDisconnect = 0x02, - NetworkConnectAll = 0x03, - NetworkDisconnectAll = 0x04, + NetworkConnectAllWithDropdown = 0x03, + NetworkDisconnectAllWithDropdown = 0x04, + NetworkConnectAll = 0x05, + NetworkDisconnectAll = 0x06, // Buffer actions BufferMask = 0xf0, @@ -73,6 +79,7 @@ public: JoinChannel = 0x1000, ShowChannelList = 0x2000, ShowIgnoreList = 0x3000, + ShowNetworkConfig = 0x4000, // Nick actions NickMask = 0xff0000, @@ -111,10 +118,11 @@ public: HideBufferPermanently = 0x02000000 }; - inline Action *action(ActionType type) const; + inline Action* action(ActionType type) const; public: - enum ItemActiveState { + enum ItemActiveState + { InactiveState = 0x01, ActiveState = 0x02 }; @@ -125,89 +133,116 @@ public slots: virtual void disconnectedFromCore() {} protected: - inline ActionCollection *actionCollection() const; + inline ActionCollection* actionCollection() const; inline QList indexList() const; - inline MessageFilter *messageFilter() 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 &); - void setMessageFilter(MessageFilter *); - void setContextItem(const QString &); - void setSlot(QObject *receiver, const char *method); + void setIndexList(const QModelIndex&); + void setIndexList(const QList&); + void setMessageFilter(MessageFilter*); + void setContextItem(const QString&); + + using ActionSlot = std::function; - Action *registerAction(ActionType type, const QString &text, bool checkable = false); - Action *registerAction(NetworkModelController::ActionType type, const QIcon &icon, const QString &text, bool checkable = false); - bool checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags(ActiveState | InactiveState)); + template + ActionSlot buildActionSlot(Receiver* receiver, Slot slot) + { + static_assert(!std::is_same::value, "Old-style slots not supported"); + return [receiver, slot = std::move(slot)](QAction* action) { (receiver->*slot)(action); }; + } - QString nickName(const QModelIndex &index) const; - BufferId findQueryBuffer(const QModelIndex &index, const QString &predefinedNick = QString()) const; - BufferId findQueryBuffer(NetworkId, const QString &nickName) const; - void removeBuffers(const QModelIndexList &indexList); + 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); + bool checkRequirements(const QModelIndex& index, + ItemActiveStates requiredActiveState = QFlags(ActiveState | InactiveState)); + + QString nickName(const QModelIndex& index) const; + BufferId findQueryBuffer(const QModelIndex& index, const QString& predefinedNick = QString()) const; + BufferId findQueryBuffer(NetworkId, const QString& nickName) const; + void removeBuffers(const QModelIndexList& indexList); protected slots: - virtual void actionTriggered(QAction *); + virtual void actionTriggered(QAction*); signals: - void showChannelList(NetworkId); + /** + * Request to show the channel list dialog for the network, optionally searching by channel name + * + * @see MainWin::showChannelList() + * + * @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&, bool); + void showNetworkConfig(NetworkId); void showIgnoreList(QString); protected: - virtual void handleNetworkAction(ActionType, QAction *); - virtual void handleBufferAction(ActionType, QAction *); - virtual void handleHideAction(ActionType, QAction *); - virtual void handleNickAction(ActionType, QAction *action); - virtual void handleGeneralAction(ActionType, QAction *); - virtual void handleExternalAction(ActionType, QAction *); + virtual void handleNetworkAction(ActionType, QAction*); + virtual void handleBufferAction(ActionType, QAction*); + virtual void handleHideAction(ActionType, QAction*); + virtual void handleNickAction(ActionType, QAction* action); + virtual void handleGeneralAction(ActionType, QAction*); + virtual void handleExternalAction(ActionType, QAction*); class JoinDlg; private: - NetworkModel *_model; + NetworkModel* _model; - ActionCollection *_actionCollection; - QHash _actionByType; + ActionCollection* _actionCollection; + QHash _actionByType; QList _indexList; - MessageFilter *_messageFilter; - QString _contextItem; ///< Channel name or nick to provide context menu for - QObject *_receiver; - const char *_method; + MessageFilter* _messageFilter{nullptr}; + QString _contextItem; ///< Channel name or nick to provide context menu for + ActionSlot _actionSlot; }; - //! Input dialog for joining a channel 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; NetworkId networkId() const; private slots: - void on_channel_textChanged(const QString &); + void on_channel_textChanged(const QString&); private: - QComboBox *networks; - QLineEdit *channel; - QLineEdit *password; - QDialogButtonBox *buttonBox; + QComboBox* networks; + QLineEdit* channel; + QLineEdit* password; + QDialogButtonBox* buttonBox; }; - // inlines -ActionCollection *NetworkModelController::actionCollection() const { return _actionCollection; } -Action *NetworkModelController::action(ActionType type) const { return _actionByType.value(type, 0); } -QList 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 +ActionCollection* NetworkModelController::actionCollection() const +{ + return _actionCollection; +} +Action* NetworkModelController::action(ActionType type) const +{ + return _actionByType.value(type, 0); +} +QList NetworkModelController::indexList() const +{ + return _indexList; +} +MessageFilter* NetworkModelController::messageFilter() const +{ + return _messageFilter; +} +QString NetworkModelController::contextItem() const +{ + return _contextItem; +}