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 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 void setBufferName(const QString &name);
64 QString topic() const;
65 int nickCount() const;
67 bool isStatusBuffer() const;
68 BufferInfo::Type bufferType() const;
70 bool isActive() const;
72 inline Buffer::ActivityLevel activityLevel() const { return _activity; }
73 bool setActivityLevel(Buffer::ActivityLevel level);
74 void updateActivityLevel(Buffer::ActivityLevel level);
76 void setLastMsgInsert(QDateTime msgDate);
80 virtual QString toolTip(int column) const;
83 void setTopic(const QString &topic);
84 void join(const QList<IrcUser *> &ircUsers);
85 void part(IrcUser *ircUser);
87 void addUserToCategory(IrcUser *ircUser);
88 void addUsersToCategory(const QList<IrcUser *> &ircUser);
89 void removeUserFromCategory(IrcUser *ircUser);
90 void userModeChanged(IrcUser *ircUser);
93 void ircChannelDestroyed();
94 void ircUserDestroyed();
97 BufferInfo _bufferInfo;
99 Buffer::ActivityLevel _activity;
101 QPointer<IrcChannel> _ircChannel;
105 /*****************************************
107 *****************************************/
108 class NetworkItem : public PropertyMapItem {
110 Q_PROPERTY(QString networkName READ networkName)
111 Q_PROPERTY(QString currentServer READ currentServer)
112 Q_PROPERTY(int nickCount READ nickCount)
115 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
117 virtual quint64 id() const;
118 inline const NetworkId &networkId() const { return _networkId; }
119 virtual QVariant data(int column, int row) const;
121 bool isActive() const;
123 QString networkName() const;
124 QString currentServer() const;
125 int nickCount() const;
127 virtual QString toolTip(int column) const;
130 void setNetworkName(const QString &networkName);
131 void setCurrentServer(const QString &serverName);
133 void attachNetwork(Network *network);
134 void attachIrcChannel(const QString &channelName);
137 NetworkId _networkId;
139 QPointer<Network> _network;
142 /*****************************************
143 * User Category Items (like @vh etc.)
144 *****************************************/
145 class UserCategoryItem : public PropertyMapItem {
147 Q_PROPERTY(QString categoryId READ categoryId)
150 UserCategoryItem(int category, AbstractTreeItem *parent);
152 QString categoryId();
153 virtual quint64 id() const;
154 virtual QVariant data(int column, int role) const;
156 void addUsers(const QList<IrcUser *> &ircUser);
157 bool removeUser(IrcUser *ircUser);
159 static int categoryFromModes(const QString &modes);
166 QString displayString;
167 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
170 static const QList<Category> categories;
173 /*****************************************
175 *****************************************/
176 class IrcUserItem : public PropertyMapItem {
178 Q_PROPERTY(QString nickName READ nickName)
181 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
183 QString nickName() const;
184 bool isActive() const;
187 virtual quint64 id() const;
188 virtual QVariant data(int column, int role) const;
189 virtual QString toolTip(int column) const;
192 void setNick(QString newNick);
196 QPointer<IrcUser> _ircUser;
201 /*****************************************
203 *****************************************/
204 class NetworkModel : public TreeModel {
209 BufferTypeRole = Qt::UserRole,
221 UserCategoryItemType,
225 NetworkModel(QObject *parent = 0);
226 static QList<QVariant> defaultHeader();
228 static bool mimeContainsBufferList(const QMimeData *mimeData);
229 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
231 virtual QStringList mimeTypes() const;
232 virtual QMimeData *mimeData(const QModelIndexList &) const;
233 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
235 void attachNetwork(Network *network);
237 bool isBufferIndex(const QModelIndex &) const;
238 //Buffer *getBufferByIndex(const QModelIndex &) const;
239 QModelIndex bufferIndex(BufferId bufferId);
241 const Network *networkByIndex(const QModelIndex &index) const;
243 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
246 void bufferUpdated(BufferInfo bufferInfo);
247 void removeBuffer(BufferId bufferId);
248 void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
249 void networkRemoved(const NetworkId &networkId);
252 QModelIndex networkIndex(NetworkId networkId);
253 NetworkItem *networkItem(NetworkId networkId);
254 NetworkItem *existsNetworkItem(NetworkId networkId);
255 BufferItem *bufferItem(const BufferInfo &bufferInfo);
256 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
260 #endif // NETWORKMODEL_H