1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #ifndef NETWORKMODELCONTROLLER_H_
22 #define NETWORKMODELCONTROLLER_H_
25 #include "actioncollection.h"
26 #include "messagefilter.h"
28 class NetworkModelController : public QObject {
32 NetworkModelController(QObject *parent = 0);
33 virtual ~NetworkModelController();
35 // don't change enums without doublechecking masks etc. in code
39 NetworkConnect = 0x01,
40 NetworkDisconnect = 0x02,
46 BufferSwitchTo = 0x30,
56 HideDayChange = 0x0600,
57 HideUseDefaults = 0xe00,
58 HideApplyToAll = 0xf00,
63 ShowChannelList = 0x2000,
64 ShowIgnoreList = 0x3000,
70 NickSwitchTo = 0x030000,
71 NickCtcpVersion = 0x040000,
72 NickCtcpPing = 0x050000,
73 NickCtcpTime = 0x060000,
74 NickCtcpFinger = 0x070000,
78 NickDevoice = 0x0b0000,
81 NickKickBan = 0x0e0000,
83 // Actions that are handled externally
84 // These emit a signal to the action requester, rather than being handled here
85 ExternalMask = 0xff000000,
86 HideBufferTemporarily = 0x01000000,
87 HideBufferPermanently = 0x02000000
90 inline Action *action(ActionType type) const;
93 enum ItemActiveState {
97 Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState)
100 inline ActionCollection *actionCollection() const;
101 inline QList<QModelIndex> indexList() const;
102 inline MessageFilter *messageFilter() const;
103 inline QString contextItem() const ; ///< Channel name or nick to provide context menu for
104 inline QObject *receiver() const ;
105 inline const char *method() const;
107 void setIndexList(const QModelIndex &);
108 void setIndexList(const QList<QModelIndex> &);
109 void setMessageFilter(MessageFilter *);
110 void setContextItem(const QString &);
111 void setSlot(QObject *receiver, const char *method);
113 void registerAction(ActionType type, const QString &text, bool checkable = false);
114 void registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable = false);
115 bool checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
117 QString nickName(const QModelIndex &index) const;
118 BufferId findQueryBuffer(const QModelIndex &index, const QString &predefinedNick = QString()) const;
119 BufferId findQueryBuffer(NetworkId, const QString &nickName) const;
120 void removeBuffers(const QModelIndexList &indexList);
123 virtual void actionTriggered(QAction *);
126 void showChannelList(NetworkId);
127 void showIgnoreList(NetworkId);
130 void handleNetworkAction(ActionType, QAction *);
131 void handleBufferAction(ActionType, QAction *);
132 void handleHideAction(ActionType, QAction *);
133 void handleNickAction(ActionType, QAction *);
134 void handleGeneralAction(ActionType, QAction *);
135 void handleExternalAction(ActionType, QAction *);
137 NetworkModel *_model;
139 ActionCollection *_actionCollection;
140 QHash<ActionType, Action *> _actionByType;
142 QList<QModelIndex> _indexList;
143 MessageFilter *_messageFilter;
144 QString _contextItem; ///< Channel name or nick to provide context menu for
150 ActionCollection *NetworkModelController::actionCollection() const { return _actionCollection; }
151 Action *NetworkModelController::action(ActionType type) const { return _actionByType.value(type, 0); }
152 QList<QModelIndex> NetworkModelController::indexList() const { return _indexList; }
153 MessageFilter *NetworkModelController::messageFilter() const { return _messageFilter; }
154 QString NetworkModelController::contextItem() const { return _contextItem; }
155 QObject *NetworkModelController::receiver() const { return _receiver; }
156 const char *NetworkModelController::method() const { return _method; }