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 inline const BufferInfo &bufferInfo() const { return _bufferInfo; }
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 inline BufferId bufferId() const { return _bufferInfo.bufferId(); }
64 inline BufferInfo::Type bufferType() const { return _bufferInfo.type(); }
66 void setBufferName(const QString &name);
67 QString topic() const;
68 int nickCount() const;
70 // bool isStatusBuffer() const;
72 bool isActive() const;
74 inline Buffer::ActivityLevel activityLevel() const { return _activity; }
75 bool setActivityLevel(Buffer::ActivityLevel level);
76 void updateActivityLevel(Buffer::ActivityLevel level);
78 void setLastMsgInsert(QDateTime msgDate);
82 virtual QString toolTip(int column) const;
85 void setTopic(const QString &topic);
86 void join(const QList<IrcUser *> &ircUsers);
87 void part(IrcUser *ircUser);
89 void addUserToCategory(IrcUser *ircUser);
90 void addUsersToCategory(const QList<IrcUser *> &ircUser);
91 void removeUserFromCategory(IrcUser *ircUser);
92 void userModeChanged(IrcUser *ircUser);
95 void ircChannelDestroyed();
96 void ircUserDestroyed();
99 BufferInfo _bufferInfo;
101 Buffer::ActivityLevel _activity;
103 QPointer<IrcChannel> _ircChannel;
107 /*****************************************
109 *****************************************/
110 class NetworkItem : public PropertyMapItem {
112 Q_PROPERTY(QString networkName READ networkName)
113 Q_PROPERTY(QString currentServer READ currentServer)
114 Q_PROPERTY(int nickCount READ nickCount)
117 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
119 virtual quint64 id() const;
120 virtual QVariant data(int column, int row) const;
122 bool isActive() const;
124 inline const NetworkId &networkId() const { return _networkId; }
125 QString networkName() const;
126 QString currentServer() const;
127 int nickCount() const;
129 virtual QString toolTip(int column) const;
132 void setNetworkName(const QString &networkName);
133 void setCurrentServer(const QString &serverName);
135 void attachNetwork(Network *network);
136 void attachIrcChannel(const QString &channelName);
139 NetworkId _networkId;
141 QPointer<Network> _network;
144 /*****************************************
145 * User Category Items (like @vh etc.)
146 *****************************************/
147 class UserCategoryItem : public PropertyMapItem {
149 Q_PROPERTY(QString categoryId READ categoryId)
152 UserCategoryItem(int category, AbstractTreeItem *parent);
154 QString categoryId();
155 virtual quint64 id() const;
156 virtual QVariant data(int column, int role) const;
158 void addUsers(const QList<IrcUser *> &ircUser);
159 bool removeUser(IrcUser *ircUser);
161 static int categoryFromModes(const QString &modes);
168 QString displayString;
169 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
172 static const QList<Category> categories;
175 /*****************************************
177 *****************************************/
178 class IrcUserItem : public PropertyMapItem {
180 Q_PROPERTY(QString nickName READ nickName)
183 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
185 QString nickName() const;
186 bool isActive() const;
189 virtual quint64 id() const;
190 virtual QVariant data(int column, int role) const;
191 virtual QString toolTip(int column) const;
194 void setNick(QString newNick);
198 QPointer<IrcUser> _ircUser;
203 /*****************************************
205 *****************************************/
206 class NetworkModel : public TreeModel {
211 BufferTypeRole = Qt::UserRole,
223 UserCategoryItemType,
227 NetworkModel(QObject *parent = 0);
228 static QList<QVariant> defaultHeader();
230 static bool mimeContainsBufferList(const QMimeData *mimeData);
231 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
233 virtual QStringList mimeTypes() const;
234 virtual QMimeData *mimeData(const QModelIndexList &) const;
235 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
237 void attachNetwork(Network *network);
239 bool isBufferIndex(const QModelIndex &) const;
240 //Buffer *getBufferByIndex(const QModelIndex &) const;
241 QModelIndex bufferIndex(BufferId bufferId);
243 const Network *networkByIndex(const QModelIndex &index) const;
245 Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const;
248 void bufferUpdated(BufferInfo bufferInfo);
249 void removeBuffer(BufferId bufferId);
250 void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity);
251 void networkRemoved(const NetworkId &networkId);
254 QModelIndex networkIndex(NetworkId networkId);
255 NetworkItem *networkItem(NetworkId networkId);
256 NetworkItem *existsNetworkItem(NetworkId networkId);
257 BufferItem *bufferItem(const BufferInfo &bufferInfo);
258 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
262 #endif // NETWORKMODEL_H