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;
66 bool isStatusBuffer() const;
67 BufferInfo::Type bufferType() const;
69 bool isActive() const;
71 inline Buffer::ActivityLevel activityLevel() const { return _activity; }
72 bool setActivityLevel(Buffer::ActivityLevel level);
73 void updateActivityLevel(Buffer::ActivityLevel level);
75 void setLastMsgInsert(QDateTime msgDate);
80 void setTopic(const QString &topic);
81 void join(IrcUser *ircUser);
82 void part(IrcUser *ircUser);
84 void addUserToCategory(IrcUser *ircUser);
85 void removeUserFromCategory(IrcUser *ircUser);
86 void userModeChanged(IrcUser *ircUser);
89 void ircChannelDestroyed();
90 void ircUserDestroyed();
93 BufferInfo _bufferInfo;
94 Buffer::ActivityLevel _activity;
96 QPointer<IrcChannel> _ircChannel;
100 /*****************************************
102 *****************************************/
103 class NetworkItem : public PropertyMapItem {
105 Q_PROPERTY(QString networkName READ networkName)
106 Q_PROPERTY(QString currentServer READ currentServer)
107 Q_PROPERTY(int nickCount READ nickCount)
110 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
112 virtual quint64 id() const;
113 inline const NetworkId &networkId() const { return _networkId; }
114 virtual QVariant data(int column, int row) const;
116 bool isActive() const;
118 QString networkName() const;
119 QString currentServer() const;
120 int nickCount() const;
123 void setNetworkName(const QString &networkName);
124 void setCurrentServer(const QString &serverName);
126 void attachNetwork(Network *network);
127 void attachIrcChannel(const QString &channelName);
130 NetworkId _networkId;
132 QPointer<Network> _network;
135 /*****************************************
136 * User Category Items (like @vh etc.)
137 *****************************************/
138 class UserCategoryItem : public PropertyMapItem {
140 Q_PROPERTY(QString categoryId READ categoryId)
143 UserCategoryItem(int category, AbstractTreeItem *parent);
145 QString categoryId();
146 virtual quint64 id() const;
147 virtual QVariant data(int column, int role) const;
149 void addUser(IrcUser *ircUser);
150 bool removeUser(IrcUser *ircUser);
152 static int categoryFromModes(const QString &modes);
159 QString displayString;
160 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
163 static const QList<Category> categories;
166 /*****************************************
168 *****************************************/
169 class IrcUserItem : public PropertyMapItem {
171 Q_PROPERTY(QString nickName READ nickName)
174 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
176 QString nickName() const;
177 bool isActive() const;
180 virtual quint64 id() const;
181 virtual QVariant data(int column, int role) const;
182 virtual QString toolTip(int column) const;
185 void setNick(QString newNick);
188 QPointer<IrcUser> _ircUser;
193 /*****************************************
195 *****************************************/
196 class NetworkModel : public TreeModel {
201 BufferTypeRole = Qt::UserRole,
213 UserCategoryItemType,
217 NetworkModel(QObject *parent = 0);
218 static QList<QVariant> defaultHeader();
220 static bool mimeContainsBufferList(const QMimeData *mimeData);
221 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
223 virtual QStringList mimeTypes() const;
224 virtual QMimeData *mimeData(const QModelIndexList &) const;
225 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
227 void attachNetwork(Network *network);
229 bool isBufferIndex(const QModelIndex &) const;
230 //Buffer *getBufferByIndex(const QModelIndex &) const;
231 QModelIndex bufferIndex(BufferId bufferId);
233 const Network *networkByIndex(const QModelIndex &index) const;
235 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
238 void bufferUpdated(BufferInfo bufferInfo);
239 void removeBuffer(BufferId bufferId);
240 void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
241 void networkRemoved(const NetworkId &networkId);
244 QModelIndex networkIndex(NetworkId networkId);
245 NetworkItem *networkItem(NetworkId networkId);
246 NetworkItem *existsNetworkItem(NetworkId networkId);
247 BufferItem *bufferItem(const BufferInfo &bufferInfo);
248 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
252 #endif // NETWORKMODEL_H