1 /***************************************************************************
2 * Copyright (C) 2005-08 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 NETWORKMODEL_H
22 #define NETWORKMODEL_H
26 #include "treemodel.h"
33 #include "selectionmodelsynchronizer.h"
34 #include "modelpropertymapper.h"
35 #include "clientsettings.h"
38 class MappedSelectionModel;
39 class QAbstractItemView;
43 /*****************************************
45 *****************************************/
46 class NetworkItem : public PropertyMapItem {
48 Q_PROPERTY(QString networkName READ networkName)
49 Q_PROPERTY(QString currentServer READ currentServer)
50 Q_PROPERTY(int nickCount READ nickCount)
53 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
55 virtual quint64 id() const;
56 virtual QVariant data(int column, int row) const;
58 bool isActive() const;
60 inline const NetworkId &networkId() const { return _networkId; }
61 QString networkName() const;
62 QString currentServer() const;
63 int nickCount() const;
65 virtual QString toolTip(int column) const;
68 void setNetworkName(const QString &networkName);
69 void setCurrentServer(const QString &serverName);
71 void attachNetwork(Network *network);
72 void attachIrcChannel(const QString &channelName);
77 QPointer<Network> _network;
80 /*****************************************
82 *****************************************/
83 class BufferItem : public PropertyMapItem {
85 Q_PROPERTY(QString bufferName READ bufferName WRITE setBufferName)
86 Q_PROPERTY(QString topic READ topic)
87 Q_PROPERTY(int nickCount READ nickCount)
90 BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0);
92 inline const BufferInfo &bufferInfo() const { return _bufferInfo; }
93 virtual quint64 id() const;
94 virtual QVariant data(int column, int role) const;
95 virtual bool setData(int column, const QVariant &value, int role);
97 void attachIrcChannel(IrcChannel *ircChannel);
99 QString bufferName() const;
100 inline BufferId bufferId() const { return _bufferInfo.bufferId(); }
101 inline BufferInfo::Type bufferType() const { return _bufferInfo.type(); }
103 void setBufferName(const QString &name);
104 QString topic() const;
105 int nickCount() const;
107 // bool isStatusBuffer() const;
109 bool isActive() const;
111 inline Buffer::ActivityLevel activityLevel() const { return _activity; }
112 void setActivityLevel(Buffer::ActivityLevel level);
113 void updateActivityLevel(Buffer::ActivityLevel level);
115 void setLastMsgInsert(QDateTime msgDate);
117 QDateTime lastSeen();
119 virtual QString toolTip(int column) const;
122 void setTopic(const QString &topic);
123 void join(const QList<IrcUser *> &ircUsers);
124 void part(IrcUser *ircUser);
126 void addUserToCategory(IrcUser *ircUser);
127 void addUsersToCategory(const QList<IrcUser *> &ircUser);
128 void removeUserFromCategory(IrcUser *ircUser);
129 void userModeChanged(IrcUser *ircUser);
132 void ircChannelDestroyed();
133 void ircUserDestroyed();
136 BufferInfo _bufferInfo;
138 Buffer::ActivityLevel _activity;
140 IrcChannel *_ircChannel;
143 /*****************************************
144 * User Category Items (like @vh etc.)
145 *****************************************/
146 class UserCategoryItem : public PropertyMapItem {
148 Q_PROPERTY(QString categoryName READ categoryName)
151 UserCategoryItem(int category, AbstractTreeItem *parent);
153 QString categoryName() const;
154 virtual quint64 id() const;
155 virtual QVariant data(int column, int role) const;
157 void addUsers(const QList<IrcUser *> &ircUser);
158 bool removeUser(IrcUser *ircUser);
160 static int categoryFromModes(const QString &modes);
165 static const QList<QChar> categories;
168 /*****************************************
170 *****************************************/
171 class IrcUserItem : public PropertyMapItem {
173 Q_PROPERTY(QString nickName READ nickName)
176 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
178 QString nickName() const;
179 bool isActive() const;
181 inline IrcUser *ircUser() { return _ircUser; }
182 inline virtual quint64 id() const { return _id; }
183 virtual QVariant data(int column, int role) const;
184 virtual QString toolTip(int column) const;
187 void setNick(QString newNick);
191 QPointer<IrcUser> _ircUser;
196 /*****************************************
198 *****************************************/
199 class NetworkModel : public TreeModel {
204 BufferTypeRole = TreeModel::UserRole,
214 NetworkItemType = 0x01,
215 BufferItemType = 0x02,
216 UserCategoryItemType = 0x04,
217 IrcUserItemType = 0x08
219 Q_DECLARE_FLAGS(itemTypes, itemType);
221 NetworkModel(QObject *parent = 0);
222 static QList<QVariant> defaultHeader();
224 static bool mimeContainsBufferList(const QMimeData *mimeData);
225 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
227 virtual QStringList mimeTypes() const;
228 virtual QMimeData *mimeData(const QModelIndexList &) const;
229 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
231 void attachNetwork(Network *network);
233 bool isBufferIndex(const QModelIndex &) const;
234 //Buffer *getBufferByIndex(const QModelIndex &) const;
235 QModelIndex networkIndex(NetworkId networkId);
236 QModelIndex bufferIndex(BufferId bufferId);
238 const Network *networkByIndex(const QModelIndex &index) const;
240 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
243 void bufferUpdated(BufferInfo bufferInfo);
244 void removeBuffer(BufferId bufferId);
245 void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
246 void networkRemoved(const NetworkId &networkId);
249 NetworkItem *networkItem(NetworkId networkId);
250 NetworkItem *existsNetworkItem(NetworkId networkId);
251 BufferItem *bufferItem(const BufferInfo &bufferInfo);
252 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
255 Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkModel::itemTypes);
257 #endif // NETWORKMODEL_H