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)
49 Q_PROPERTY(QString topic READ topic)
50 Q_PROPERTY(int nickCount READ nickCount)
53 BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0);
55 const BufferInfo &bufferInfo() const;
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 QString topic() const;
64 int nickCount() const;
72 bool isStatusBuffer() const;
73 Type bufferType() const;
75 bool isActive() const;
83 Q_DECLARE_FLAGS(ActivityLevel, Activity)
85 ActivityLevel activity() const;
86 bool setActivity(const ActivityLevel &level);
87 void updateActivity(const ActivityLevel &level);
89 void setLastMsgInsert(QDateTime msgDate);
94 void setTopic(const QString &topic);
95 void join(IrcUser *ircUser);
96 void part(IrcUser *ircUser);
98 void addUserToCategory(IrcUser *ircUser);
99 void removeUserFromCategory(IrcUser *ircUser);
100 void userModeChanged(IrcUser *ircUser);
103 void ircChannelDestroyed();
104 void ircUserDestroyed();
107 BufferInfo _bufferInfo;
108 ActivityLevel _activity;
110 QDateTime _lastMsgInsert;
113 QPointer<IrcChannel> _ircChannel;
115 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
117 /*****************************************
119 *****************************************/
120 class NetworkItem : public PropertyMapItem {
122 Q_PROPERTY(QString networkName READ networkName)
123 Q_PROPERTY(QString currentServer READ currentServer)
124 Q_PROPERTY(int nickCount READ nickCount)
127 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
129 virtual quint64 id() const;
130 virtual QVariant data(int column, int row) const;
132 bool isActive() const;
134 QString networkName() const;
135 QString currentServer() const;
136 int nickCount() const;
139 void setNetworkName(const QString &networkName);
140 void setCurrentServer(const QString &serverName);
142 void attachNetwork(Network *network);
143 void attachIrcChannel(const QString &channelName);
145 void setActive(bool connected);
148 NetworkId _networkId;
150 QPointer<Network> _network;
153 /*****************************************
154 * User Category Items (like @vh etc.)
155 *****************************************/
156 class UserCategoryItem : public PropertyMapItem {
158 Q_PROPERTY(QString categoryId READ categoryId)
161 UserCategoryItem(int category, AbstractTreeItem *parent);
163 QString categoryId();
164 virtual quint64 id() const;
165 virtual QVariant data(int column, int role) const;
167 void addUser(IrcUser *ircUser);
168 bool removeUser(IrcUser *ircUser);
170 static int categoryFromModes(const QString &modes);
177 QString displayString;
178 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
181 static const QList<Category> categories;
184 /*****************************************
186 *****************************************/
187 class IrcUserItem : public PropertyMapItem {
189 Q_PROPERTY(QString nickName READ nickName)
192 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
194 QString nickName() const;
195 bool isActive() const;
198 virtual quint64 id() const;
199 virtual QVariant data(int column, int role) const;
200 virtual QString toolTip(int column) const;
203 void setNick(QString newNick);
206 QPointer<IrcUser> _ircUser;
211 /*****************************************
213 *****************************************/
214 class NetworkModel : public TreeModel {
219 BufferTypeRole = Qt::UserRole,
232 UserCategoryItemType,
236 NetworkModel(QObject *parent = 0);
237 static QList<QVariant> defaultHeader();
239 static bool mimeContainsBufferList(const QMimeData *mimeData);
240 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
242 virtual QStringList mimeTypes() const;
243 virtual QMimeData *mimeData(const QModelIndexList &) const;
244 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
246 void attachNetwork(Network *network);
248 bool isBufferIndex(const QModelIndex &) const;
249 //Buffer *getBufferByIndex(const QModelIndex &) const;
250 QModelIndex bufferIndex(BufferId bufferId);
252 const Network *networkByIndex(const QModelIndex &index) const;
255 void bufferUpdated(BufferInfo bufferInfo);
256 void updateBufferActivity(const Message &msg);
259 QModelIndex networkIndex(NetworkId networkId);
260 NetworkItem *networkItem(NetworkId networkId);
261 NetworkItem *existsNetworkItem(NetworkId networkId);
262 BufferItem *bufferItem(const BufferInfo &bufferInfo);
263 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
267 #endif // NETWORKMODEL_H