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,
65 HideUseDefaults = 0xe00,
66 HideApplyToAll = 0xf00,
71 ShowChannelList = 0x2000,
72 ShowIgnoreList = 0x3000,
78 NickSwitchTo = 0x030000,
79 NickCtcpVersion = 0x040000,
80 NickCtcpPing = 0x050000,
81 NickCtcpTime = 0x060000,
82 NickCtcpFinger = 0x070000,
86 NickDevoice = 0x0b0000,
89 NickKickBan = 0x0e0000,
91 // Actions that are handled externally
92 // These emit a signal to the action requester, rather than being handled here
93 ExternalMask = 0xff000000,
94 HideBufferTemporarily = 0x01000000,
95 HideBufferPermanently = 0x02000000
98 inline Action *action(ActionType type) const;
101 enum ItemActiveState {
102 InactiveState = 0x01,
105 Q_DECLARE_FLAGS(ItemActiveStates, ItemActiveState)
108 inline ActionCollection *actionCollection() const;
109 inline QList<QModelIndex> indexList() const;
110 inline MessageFilter *messageFilter() const;
111 inline QString contextItem() const ; ///< Channel name or nick to provide context menu for
112 inline QObject *receiver() const ;
113 inline const char *method() const;
115 void setIndexList(const QModelIndex &);
116 void setIndexList(const QList<QModelIndex> &);
117 void setMessageFilter(MessageFilter *);
118 void setContextItem(const QString &);
119 void setSlot(QObject *receiver, const char *method);
121 Action * registerAction(ActionType type, const QString &text, bool checkable = false);
122 Action * registerAction(ActionType type, const QPixmap &icon, const QString &text, bool checkable = false);
123 bool checkRequirements(const QModelIndex &index, ItemActiveStates requiredActiveState = QFlags<ItemActiveState>(ActiveState | InactiveState));
125 QString nickName(const QModelIndex &index) const;
126 BufferId findQueryBuffer(const QModelIndex &index, const QString &predefinedNick = QString()) const;
127 BufferId findQueryBuffer(NetworkId, const QString &nickName) const;
128 void removeBuffers(const QModelIndexList &indexList);
131 virtual void actionTriggered(QAction *);
134 void showChannelList(NetworkId);
135 void showIgnoreList(NetworkId);
138 virtual void handleNetworkAction(ActionType, QAction *);
139 virtual void handleBufferAction(ActionType, QAction *);
140 virtual void handleHideAction(ActionType, QAction *);
141 virtual void handleNickAction(ActionType, QAction *);
142 virtual void handleGeneralAction(ActionType, QAction *);
143 virtual void handleExternalAction(ActionType, QAction *);
148 NetworkModel *_model;
150 ActionCollection *_actionCollection;
151 QHash<ActionType, Action *> _actionByType;
153 QList<QModelIndex> _indexList;
154 MessageFilter *_messageFilter;
155 QString _contextItem; ///< Channel name or nick to provide context menu for
160 //! Input dialog for joining a channel
161 class NetworkModelController::JoinDlg : public QDialog {
165 JoinDlg(const QModelIndex &index, QWidget *parent = 0);
167 QString channelName() const;
168 NetworkId networkId() const;
171 void on_channel_textChanged(const QString &);
176 QDialogButtonBox *buttonBox;
181 ActionCollection *NetworkModelController::actionCollection() const { return _actionCollection; }
182 Action *NetworkModelController::action(ActionType type) const { return _actionByType.value(type, 0); }
183 QList<QModelIndex> NetworkModelController::indexList() const { return _indexList; }
184 MessageFilter *NetworkModelController::messageFilter() const { return _messageFilter; }
185 QString NetworkModelController::contextItem() const { return _contextItem; }
186 QObject *NetworkModelController::receiver() const { return _receiver; }
187 const char *NetworkModelController::method() const { return _method; }