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 class MappedSelectionModel;
36 class QAbstractItemView;
41 /*****************************************
43 *****************************************/
44 class BufferItem : public PropertyMapItem {
46 Q_PROPERTY(QString bufferName READ bufferName)
47 Q_PROPERTY(QString topic READ topic)
48 Q_PROPERTY(int nickCount READ nickCount)
51 BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0);
53 const BufferInfo &bufferInfo() const;
54 virtual quint64 id() const;
55 virtual QVariant data(int column, int role) const;
57 void attachIrcChannel(IrcChannel *ircChannel);
59 QString bufferName() const;
60 QString topic() const;
61 int nickCount() const;
69 bool isStatusBuffer() const;
70 Type bufferType() const;
72 bool isActive() const;
80 Q_DECLARE_FLAGS(ActivityLevel, Activity)
82 ActivityLevel activity() const;
83 void setActivity(const ActivityLevel &level);
84 void addActivity(const ActivityLevel &level);
87 void setTopic(const QString &topic);
88 void join(IrcUser *ircUser);
89 void part(IrcUser *ircUser);
91 void addUserToCategory(IrcUser *ircUser);
92 void removeUserFromCategory(IrcUser *ircUser);
93 void userModeChanged(IrcUser *ircUser);
96 void ircChannelDestroyed();
99 BufferInfo _bufferInfo;
100 ActivityLevel _activity;
103 QPointer<IrcChannel> _ircChannel;
105 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
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 QVariant data(int column, int row) const;
120 virtual quint64 id() const;
122 bool isActive() const;
124 QString networkName() const;
125 QString currentServer() const;
126 int nickCount() 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;
154 void addUser(IrcUser *ircUser);
156 static int categoryFromModes(const QString &modes);
159 void checkNoChilds();
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);
185 virtual quint64 id() const;
188 void setNick(QString newNick);
189 void ircUserDestroyed();
196 /*****************************************
198 *****************************************/
199 class NetworkModel : public TreeModel {
204 BufferTypeRole = Qt::UserRole,
219 NetworkModel(QObject *parent = 0);
220 static QList<QVariant> defaultHeader();
222 static bool mimeContainsBufferList(const QMimeData *mimeData);
223 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
225 virtual QStringList mimeTypes() const;
226 virtual QMimeData *mimeData(const QModelIndexList &) const;
227 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
229 void attachNetwork(Network *network);
231 bool isBufferIndex(const QModelIndex &) const;
232 //Buffer *getBufferByIndex(const QModelIndex &) const;
233 QModelIndex bufferIndex(BufferId bufferId);
236 void bufferUpdated(BufferInfo bufferInfo);
237 void bufferActivity(BufferItem::ActivityLevel, BufferInfo bufferInfo);
240 QModelIndex networkIndex(NetworkId networkId);
241 NetworkItem *networkItem(NetworkId networkId);
242 NetworkItem *existsNetworkItem(NetworkId networkId);
243 BufferItem *bufferItem(const BufferInfo &bufferInfo);
244 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
248 #endif // NETWORKMODEL_H