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"
37 class MappedSelectionModel;
38 class QAbstractItemView;
43 /*****************************************
45 *****************************************/
46 class BufferItem : public PropertyMapItem {
48 Q_PROPERTY(QString bufferName READ bufferName WRITE setBufferName)
49 Q_PROPERTY(QString topic READ topic)
50 Q_PROPERTY(int nickCount READ nickCount)
53 BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0);
55 inline const BufferInfo &bufferInfo() const { return _bufferInfo; }
56 virtual quint64 id() const;
57 virtual QVariant data(int column, int role) const;
58 virtual bool setData(int column, const QVariant &value, int role);
60 void attachIrcChannel(IrcChannel *ircChannel);
62 QString bufferName() const;
63 inline BufferId bufferId() const { return _bufferInfo.bufferId(); }
64 inline BufferInfo::Type bufferType() const { return _bufferInfo.type(); }
66 void setBufferName(const QString &name);
67 QString topic() const;
68 int nickCount() const;
70 // bool isStatusBuffer() const;
72 bool isActive() const;
74 inline Buffer::ActivityLevel activityLevel() const { return _activity; }
75 void setActivityLevel(Buffer::ActivityLevel level);
76 void updateActivityLevel(Buffer::ActivityLevel level);
78 void setLastMsgInsert(QDateTime msgDate);
82 virtual QString toolTip(int column) const;
85 void setTopic(const QString &topic);
86 void join(const QList<IrcUser *> &ircUsers);
87 void part(IrcUser *ircUser);
89 void addUserToCategory(IrcUser *ircUser);
90 void addUsersToCategory(const QList<IrcUser *> &ircUser);
91 void removeUserFromCategory(IrcUser *ircUser);
92 void userModeChanged(IrcUser *ircUser);
95 void ircChannelDestroyed();
96 void ircUserDestroyed();
99 BufferInfo _bufferInfo;
101 Buffer::ActivityLevel _activity;
103 IrcChannel *_ircChannel;
107 /*****************************************
109 *****************************************/
110 class NetworkItem : public PropertyMapItem {
112 Q_PROPERTY(QString networkName READ networkName)
113 Q_PROPERTY(QString currentServer READ currentServer)
114 Q_PROPERTY(int nickCount READ nickCount)
117 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
119 virtual quint64 id() const;
120 virtual QVariant data(int column, int row) const;
122 bool isActive() const;
124 inline const NetworkId &networkId() const { return _networkId; }
125 QString networkName() const;
126 QString currentServer() const;
127 int nickCount() const;
129 virtual QString toolTip(int column) const;
132 void setNetworkName(const QString &networkName);
133 void setCurrentServer(const QString &serverName);
135 void attachNetwork(Network *network);
136 void attachIrcChannel(const QString &channelName);
139 NetworkId _networkId;
141 QPointer<Network> _network;
144 /*****************************************
145 * User Category Items (like @vh etc.)
146 *****************************************/
147 class UserCategoryItem : public PropertyMapItem {
149 Q_PROPERTY(QString categoryName READ categoryName)
152 UserCategoryItem(int category, AbstractTreeItem *parent);
154 QString categoryName() const;
155 virtual quint64 id() const;
156 virtual QVariant data(int column, int role) const;
158 void addUsers(const QList<IrcUser *> &ircUser);
159 bool removeUser(IrcUser *ircUser);
161 static int categoryFromModes(const QString &modes);
166 static const QList<QChar> categories;
169 /*****************************************
171 *****************************************/
172 class IrcUserItem : public PropertyMapItem {
174 Q_PROPERTY(QString nickName READ nickName)
177 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
179 QString nickName() const;
180 bool isActive() const;
183 virtual quint64 id() const;
184 virtual QVariant data(int column, int role) const;
185 virtual QString toolTip(int column) const;
188 void setNick(QString newNick);
192 QPointer<IrcUser> _ircUser;
197 /*****************************************
199 *****************************************/
200 class NetworkModel : public TreeModel {
205 BufferTypeRole = TreeModel::UserRole,
215 NetworkItemType = 0x01,
216 BufferItemType = 0x02,
217 UserCategoryItemType = 0x04,
218 IrcUserItemType = 0x08
220 Q_DECLARE_FLAGS(itemTypes, itemType);
222 NetworkModel(QObject *parent = 0);
223 static QList<QVariant> defaultHeader();
225 static bool mimeContainsBufferList(const QMimeData *mimeData);
226 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
228 virtual QStringList mimeTypes() const;
229 virtual QMimeData *mimeData(const QModelIndexList &) const;
230 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
232 void attachNetwork(Network *network);
234 bool isBufferIndex(const QModelIndex &) const;
235 //Buffer *getBufferByIndex(const QModelIndex &) const;
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 QModelIndex networkIndex(NetworkId networkId);
250 NetworkItem *networkItem(NetworkId networkId);
251 NetworkItem *existsNetworkItem(NetworkId networkId);
252 BufferItem *bufferItem(const BufferInfo &bufferInfo);
253 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
256 Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkModel::itemTypes);
258 #endif // NETWORKMODEL_H