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 virtual QVariant data(int column, int row) const;
115 bool isActive() const;
117 QString networkName() const;
118 QString currentServer() const;
119 int nickCount() const;
122 void setNetworkName(const QString &networkName);
123 void setCurrentServer(const QString &serverName);
125 void attachNetwork(Network *network);
126 void attachIrcChannel(const QString &channelName);
128 void setActive(bool connected);
131 NetworkId _networkId;
133 QPointer<Network> _network;
136 /*****************************************
137 * User Category Items (like @vh etc.)
138 *****************************************/
139 class UserCategoryItem : public PropertyMapItem {
141 Q_PROPERTY(QString categoryId READ categoryId)
144 UserCategoryItem(int category, AbstractTreeItem *parent);
146 QString categoryId();
147 virtual quint64 id() const;
148 virtual QVariant data(int column, int role) const;
150 void addUser(IrcUser *ircUser);
151 bool removeUser(IrcUser *ircUser);
153 static int categoryFromModes(const QString &modes);
160 QString displayString;
161 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
164 static const QList<Category> categories;
167 /*****************************************
169 *****************************************/
170 class IrcUserItem : public PropertyMapItem {
172 Q_PROPERTY(QString nickName READ nickName)
175 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
177 QString nickName() const;
178 bool isActive() const;
181 virtual quint64 id() const;
182 virtual QVariant data(int column, int role) const;
183 virtual QString toolTip(int column) const;
186 void setNick(QString newNick);
189 QPointer<IrcUser> _ircUser;
194 /*****************************************
196 *****************************************/
197 class NetworkModel : public TreeModel {
202 BufferTypeRole = Qt::UserRole,
214 UserCategoryItemType,
218 NetworkModel(QObject *parent = 0);
219 static QList<QVariant> defaultHeader();
221 static bool mimeContainsBufferList(const QMimeData *mimeData);
222 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
224 virtual QStringList mimeTypes() const;
225 virtual QMimeData *mimeData(const QModelIndexList &) const;
226 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
228 void attachNetwork(Network *network);
230 bool isBufferIndex(const QModelIndex &) const;
231 //Buffer *getBufferByIndex(const QModelIndex &) const;
232 QModelIndex bufferIndex(BufferId bufferId);
234 const Network *networkByIndex(const QModelIndex &index) const;
236 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
239 void bufferUpdated(BufferInfo bufferInfo);
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