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(IrcUser *ircUser);
85 void part(IrcUser *ircUser);
87 void addUserToCategory(IrcUser *ircUser);
88 void removeUserFromCategory(IrcUser *ircUser);
89 void userModeChanged(IrcUser *ircUser);
92 void ircChannelDestroyed();
93 void ircUserDestroyed();
96 BufferInfo _bufferInfo;
98 Buffer::ActivityLevel _activity;
100 QPointer<IrcChannel> _ircChannel;
104 /*****************************************
106 *****************************************/
107 class NetworkItem : public PropertyMapItem {
109 Q_PROPERTY(QString networkName READ networkName)
110 Q_PROPERTY(QString currentServer READ currentServer)
111 Q_PROPERTY(int nickCount READ nickCount)
114 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
116 virtual quint64 id() const;
117 inline const NetworkId &networkId() const { return _networkId; }
118 virtual QVariant data(int column, int row) const;
120 bool isActive() const;
122 QString networkName() const;
123 QString currentServer() const;
124 int nickCount() const;
126 virtual QString toolTip(int column) const;
129 void setNetworkName(const QString &networkName);
130 void setCurrentServer(const QString &serverName);
132 void attachNetwork(Network *network);
133 void attachIrcChannel(const QString &channelName);
136 NetworkId _networkId;
138 QPointer<Network> _network;
141 /*****************************************
142 * User Category Items (like @vh etc.)
143 *****************************************/
144 class UserCategoryItem : public PropertyMapItem {
146 Q_PROPERTY(QString categoryId READ categoryId)
149 UserCategoryItem(int category, AbstractTreeItem *parent);
151 QString categoryId();
152 virtual quint64 id() const;
153 virtual QVariant data(int column, int role) const;
155 void addUser(IrcUser *ircUser);
156 bool removeUser(IrcUser *ircUser);
158 static int categoryFromModes(const QString &modes);
165 QString displayString;
166 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
169 static const QList<Category> categories;
172 /*****************************************
174 *****************************************/
175 class IrcUserItem : public PropertyMapItem {
177 Q_PROPERTY(QString nickName READ nickName)
180 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
182 QString nickName() const;
183 bool isActive() const;
186 virtual quint64 id() const;
187 virtual QVariant data(int column, int role) const;
188 virtual QString toolTip(int column) const;
191 void setNick(QString newNick);
195 QPointer<IrcUser> _ircUser;
200 /*****************************************
202 *****************************************/
203 class NetworkModel : public TreeModel {
208 BufferTypeRole = Qt::UserRole,
220 UserCategoryItemType,
224 NetworkModel(QObject *parent = 0);
225 static QList<QVariant> defaultHeader();
227 static bool mimeContainsBufferList(const QMimeData *mimeData);
228 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
230 virtual QStringList mimeTypes() const;
231 virtual QMimeData *mimeData(const QModelIndexList &) const;
232 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
234 void attachNetwork(Network *network);
236 bool isBufferIndex(const QModelIndex &) const;
237 //Buffer *getBufferByIndex(const QModelIndex &) const;
238 QModelIndex bufferIndex(BufferId bufferId);
240 const Network *networkByIndex(const QModelIndex &index) const;
242 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
245 void bufferUpdated(BufferInfo bufferInfo);
246 void removeBuffer(BufferId bufferId);
247 void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
248 void networkRemoved(const NetworkId &networkId);
251 QModelIndex networkIndex(NetworkId networkId);
252 NetworkItem *networkItem(NetworkId networkId);
253 NetworkItem *existsNetworkItem(NetworkId networkId);
254 BufferItem *bufferItem(const BufferInfo &bufferInfo);
255 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
259 #endif // NETWORKMODEL_H