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;
77 Q_DECLARE_FLAGS(ActivityLevel, Activity)
79 ActivityLevel activity() const;
80 bool setActivity(const ActivityLevel &level);
81 void updateActivity(const ActivityLevel &level);
83 void setLastMsgInsert(QDateTime msgDate);
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();
98 void ircUserDestroyed();
101 BufferInfo _bufferInfo;
102 ActivityLevel _activity;
103 QDateTime _lastMsgInsert;
106 QPointer<IrcChannel> _ircChannel;
108 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
110 /*****************************************
112 *****************************************/
113 class NetworkItem : public PropertyMapItem {
115 Q_PROPERTY(QString networkName READ networkName)
116 Q_PROPERTY(QString currentServer READ currentServer)
117 Q_PROPERTY(int nickCount READ nickCount)
120 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
122 virtual quint64 id() const;
123 virtual QVariant data(int column, int row) const;
125 bool isActive() const;
127 QString networkName() const;
128 QString currentServer() const;
129 int nickCount() const;
132 void setNetworkName(const QString &networkName);
133 void setCurrentServer(const QString &serverName);
135 void attachNetwork(Network *network);
136 void attachIrcChannel(const QString &channelName);
138 void setActive(bool connected);
141 NetworkId _networkId;
143 QPointer<Network> _network;
146 /*****************************************
147 * User Category Items (like @vh etc.)
148 *****************************************/
149 class UserCategoryItem : public PropertyMapItem {
151 Q_PROPERTY(QString categoryId READ categoryId)
154 UserCategoryItem(int category, AbstractTreeItem *parent);
156 QString categoryId();
157 virtual quint64 id() const;
158 virtual QVariant data(int column, int role) const;
160 void addUser(IrcUser *ircUser);
161 bool removeUser(IrcUser *ircUser);
163 static int categoryFromModes(const QString &modes);
170 QString displayString;
171 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
174 static const QList<Category> categories;
177 /*****************************************
179 *****************************************/
180 class IrcUserItem : public PropertyMapItem {
182 Q_PROPERTY(QString nickName READ nickName)
185 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
187 QString nickName() const;
188 bool isActive() const;
191 virtual quint64 id() const;
192 virtual QVariant data(int column, int role) const;
193 virtual QString toolTip(int column) const;
196 void setNick(QString newNick);
199 QPointer<IrcUser> _ircUser;
204 /*****************************************
206 *****************************************/
207 class NetworkModel : public TreeModel {
212 BufferTypeRole = Qt::UserRole,
225 UserCategoryItemType,
229 NetworkModel(QObject *parent = 0);
230 static QList<QVariant> defaultHeader();
232 static bool mimeContainsBufferList(const QMimeData *mimeData);
233 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
235 virtual QStringList mimeTypes() const;
236 virtual QMimeData *mimeData(const QModelIndexList &) const;
237 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
239 void attachNetwork(Network *network);
241 bool isBufferIndex(const QModelIndex &) const;
242 //Buffer *getBufferByIndex(const QModelIndex &) const;
243 QModelIndex bufferIndex(BufferId bufferId);
245 const Network *networkByIndex(const QModelIndex &index) const;
248 void bufferUpdated(BufferInfo bufferInfo);
249 void updateBufferActivity(const Message &msg);
250 void networkRemoved(const NetworkId &networkId);
253 QModelIndex networkIndex(NetworkId networkId);
254 NetworkItem *networkItem(NetworkId networkId);
255 NetworkItem *existsNetworkItem(NetworkId networkId);
256 BufferItem *bufferItem(const BufferInfo &bufferInfo);
257 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
261 #endif // NETWORKMODEL_H