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;
56 virtual bool setData(int column, const QVariant &value, int role);
58 void attachIrcChannel(IrcChannel *ircChannel);
60 QString bufferName() const;
61 QString topic() const;
62 int nickCount() const;
70 bool isStatusBuffer() const;
71 Type bufferType() const;
73 bool isActive() const;
81 Q_DECLARE_FLAGS(ActivityLevel, Activity)
83 ActivityLevel activity() const;
84 void setActivity(const ActivityLevel &level);
85 void updateActivity(const ActivityLevel &level);
88 void setTopic(const QString &topic);
89 void join(IrcUser *ircUser);
90 void part(IrcUser *ircUser);
92 void addUserToCategory(IrcUser *ircUser);
93 void removeUserFromCategory(IrcUser *ircUser);
94 void userModeChanged(IrcUser *ircUser);
97 void ircChannelDestroyed();
100 BufferInfo _bufferInfo;
101 ActivityLevel _activity;
104 QPointer<IrcChannel> _ircChannel;
106 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
108 /*****************************************
110 *****************************************/
111 class NetworkItem : public PropertyMapItem {
113 Q_PROPERTY(QString networkName READ networkName)
114 Q_PROPERTY(QString currentServer READ currentServer)
115 Q_PROPERTY(int nickCount READ nickCount)
118 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
120 virtual quint64 id() const;
121 virtual QVariant data(int column, int row) const;
123 bool isActive() const;
125 QString networkName() const;
126 QString currentServer() const;
127 int nickCount() const;
130 void setNetworkName(const QString &networkName);
131 void setCurrentServer(const QString &serverName);
133 void attachNetwork(Network *network);
134 void attachIrcChannel(const QString &channelName);
137 NetworkId _networkId;
139 QPointer<Network> _network;
142 /*****************************************
143 * User Category Items (like @vh etc.)
144 *****************************************/
145 class UserCategoryItem : public PropertyMapItem {
147 Q_PROPERTY(QString categoryId READ categoryId)
150 UserCategoryItem(int category, AbstractTreeItem *parent);
152 QString categoryId();
153 virtual quint64 id() const;
154 virtual QVariant data(int column, int role) const;
156 void addUser(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;
184 virtual quint64 id() const;
185 virtual QVariant data(int column, int role) const;
186 virtual QString toolTip(int column) const;
189 void setNick(QString newNick);
196 /*****************************************
198 *****************************************/
199 class NetworkModel : public TreeModel {
204 BufferTypeRole = Qt::UserRole,
216 UserCategoryItemType,
220 NetworkModel(QObject *parent = 0);
221 static QList<QVariant> defaultHeader();
223 static bool mimeContainsBufferList(const QMimeData *mimeData);
224 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
226 virtual QStringList mimeTypes() const;
227 virtual QMimeData *mimeData(const QModelIndexList &) const;
228 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
230 void attachNetwork(Network *network);
232 bool isBufferIndex(const QModelIndex &) const;
233 //Buffer *getBufferByIndex(const QModelIndex &) const;
234 QModelIndex bufferIndex(BufferId bufferId);
237 void bufferUpdated(BufferInfo bufferInfo);
238 void updateBufferActivity(const Message &msg);
241 QModelIndex networkIndex(NetworkId networkId);
242 NetworkItem *networkItem(NetworkId networkId);
243 NetworkItem *existsNetworkItem(NetworkId networkId);
244 BufferItem *bufferItem(const BufferInfo &bufferInfo);
245 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
249 #endif // NETWORKMODEL_H