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_
27 #include "actioncollection.h"
28 #include "messagefilter.h"
31 class QDialogButtonBox;
34 class NetworkModelController : public QObject {
38 NetworkModelController(QObject *parent = 0);
39 virtual ~NetworkModelController();
41 // don't change enums without doublechecking masks etc. in code
45 NetworkConnect = 0x01,
46 NetworkDisconnect = 0x02,
47 NetworkConnectAll = 0x03,
48 NetworkDisconnectAll = 0x04,
54 BufferSwitchTo = 0x30,
64 HideDayChange = 0x0600,
66 HideUseDefaults = 0xe00,
67 HideApplyToAll = 0xf00,
72 ShowChannelList = 0x2000,
73 ShowIgnoreList = 0x3000,
79 NickSwitchTo = 0x030000,
80 NickCtcpVersion = 0x040000,
81 NickCtcpPing = 0x050000,
82 NickCtcpTime = 0x060000,
83 NickCtcpFinger = 0x070000,
87 NickDevoice = 0x0b0000,
90 NickKickBan = 0x0e0000,
91 NickIgnoreUser = 0x0f0000,
92 NickIgnoreHost = 0x100000,
93 NickIgnoreDomain = 0x200000,
94 NickIgnoreCustom = 0x300000,
95 // The next 5 types have stay together
96 // Don't change without reading ContextMenuActionProvider::addIgnoreMenu!
97 NickIgnoreToggleEnabled0 = 0x400000,
98 NickIgnoreToggleEnabled1 = 0x500000,
99 NickIgnoreToggleEnabled2 = 0x600000,
100 NickIgnoreToggleEnabled3 = 0x700000,
101 NickIgnoreToggleEnabled4 = 0x800000,
103 // Actions that are handled externally
104 // These emit a signal to the action requester, rather than being handled here
105 ExternalMask = 0xff000000,
106 HideBufferTemporarily = 0x01000000,
107 HideBufferPermanently = 0x02000000
110 inline Action *action(ActionType type) const;
113 enum ItemActiveState {
114 InactiveState = 0x01,
117 Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState)
120 inline ActionCollection *actionCollection() const;
121 inline QList<QModelIndex> indexList() const;
122 inline MessageFilter *messageFilter() const;
123 inline QString contextItem() const ; ///< Channel name or nick to provide context menu for
124 inline QObject *receiver() const ;
125 inline const char *method() const;
127 void setIndexList(const QModelIndex &);
128 void setIndexList(const QList<QModelIndex> &);
129 void setMessageFilter(MessageFilter *);
130 void setContextItem(const QString &);
131 void setSlot(QObject *receiver, const char *method);
133 Action * registerAction(ActionType type, const QString &text, bool checkable = false);
134 Action * registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable = false);
135 bool checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
137 QString nickName(const QModelIndex &index) const;
138 BufferId findQueryBuffer(const QModelIndex &index, const QString &predefinedNick = QString()) const;
139 BufferId findQueryBuffer(NetworkId, const QString &nickName) const;
140 void removeBuffers(const QModelIndexList &indexList);
143 virtual void actionTriggered(QAction *);
146 void showChannelList(NetworkId);
147 void showIgnoreList(QString);
150 virtual void handleNetworkAction(ActionType, QAction *);
151 virtual void handleBufferAction(ActionType, QAction *);
152 virtual void handleHideAction(ActionType, QAction *);
153 virtual void handleNickAction(ActionType, QAction *action);
154 virtual void handleGeneralAction(ActionType, QAction *);
155 virtual void handleExternalAction(ActionType, QAction *);
160 NetworkModel *_model;
162 ActionCollection *_actionCollection;
163 QHash<ActionType, Action *> _actionByType;
165 QList<QModelIndex> _indexList;
166 MessageFilter *_messageFilter;
167 QString _contextItem; ///< Channel name or nick to provide context menu for
172 //! Input dialog for joining a channel
173 class NetworkModelController::JoinDlg : public QDialog {
177 JoinDlg(const QModelIndex &index, QWidget *parent = 0);
179 QString channelName() const;
180 NetworkId networkId() const;
183 void on_channel_textChanged(const QString &);
188 QDialogButtonBox *buttonBox;
193 ActionCollection *NetworkModelController::actionCollection() const { return _actionCollection; }
194 Action *NetworkModelController::action(ActionType type) const { return _actionByType.value(type, 0); }
195 QList<QModelIndex> NetworkModelController::indexList() const { return _indexList; }
196 MessageFilter *NetworkModelController::messageFilter() const { return _messageFilter; }
197 QString NetworkModelController::contextItem() const { return _contextItem; }
198 QObject *NetworkModelController::receiver() const { return _receiver; }
199 const char *NetworkModelController::method() const { return _method; }