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;
72 bool isStatusBuffer() const;
73 Type bufferType() const;
75 bool isActive() const;
83 Q_DECLARE_FLAGS(ActivityLevel, Activity)
85 ActivityLevel activity() const;
86 bool setActivity(const ActivityLevel &level);
87 void updateActivity(const ActivityLevel &level);
89 void setLastMsgInsert(QDateTime msgDate);
94 void setTopic(const QString &topic);
95 void join(IrcUser *ircUser);
96 void part(IrcUser *ircUser);
98 void addUserToCategory(IrcUser *ircUser);
99 void removeUserFromCategory(IrcUser *ircUser);
100 void userModeChanged(IrcUser *ircUser);
103 void ircChannelDestroyed();
106 BufferInfo _bufferInfo;
107 ActivityLevel _activity;
109 QDateTime _lastMsgInsert;
112 QPointer<IrcChannel> _ircChannel;
114 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
116 /*****************************************
118 *****************************************/
119 class NetworkItem : public PropertyMapItem {
121 Q_PROPERTY(QString networkName READ networkName)
122 Q_PROPERTY(QString currentServer READ currentServer)
123 Q_PROPERTY(int nickCount READ nickCount)
126 NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
128 virtual quint64 id() const;
129 virtual QVariant data(int column, int row) const;
131 bool isActive() const;
133 QString networkName() const;
134 QString currentServer() const;
135 int nickCount() const;
138 void setNetworkName(const QString &networkName);
139 void setCurrentServer(const QString &serverName);
141 void attachNetwork(Network *network);
142 void attachIrcChannel(const QString &channelName);
144 void setActive(bool connected);
147 NetworkId _networkId;
149 QPointer<Network> _network;
152 /*****************************************
153 * User Category Items (like @vh etc.)
154 *****************************************/
155 class UserCategoryItem : public PropertyMapItem {
157 Q_PROPERTY(QString categoryId READ categoryId)
160 UserCategoryItem(int category, AbstractTreeItem *parent);
162 QString categoryId();
163 virtual quint64 id() const;
164 virtual QVariant data(int column, int role) const;
166 void addUser(IrcUser *ircUser);
167 bool removeUser(IrcUser *ircUser);
169 static int categoryFromModes(const QString &modes);
176 QString displayString;
177 inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
180 static const QList<Category> categories;
183 /*****************************************
185 *****************************************/
186 class IrcUserItem : public PropertyMapItem {
188 Q_PROPERTY(QString nickName READ nickName)
191 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
193 QString nickName() const;
195 virtual quint64 id() const;
196 virtual QVariant data(int column, int role) const;
197 virtual QString toolTip(int column) const;
200 void setNick(QString newNick);
207 /*****************************************
209 *****************************************/
210 class NetworkModel : public TreeModel {
215 BufferTypeRole = Qt::UserRole,
228 UserCategoryItemType,
232 NetworkModel(QObject *parent = 0);
233 static QList<QVariant> defaultHeader();
235 static bool mimeContainsBufferList(const QMimeData *mimeData);
236 static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
238 virtual QStringList mimeTypes() const;
239 virtual QMimeData *mimeData(const QModelIndexList &) const;
240 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
242 void attachNetwork(Network *network);
244 bool isBufferIndex(const QModelIndex &) const;
245 //Buffer *getBufferByIndex(const QModelIndex &) const;
246 QModelIndex bufferIndex(BufferId bufferId);
248 const Network *networkByIndex(const QModelIndex &index) const;
251 void bufferUpdated(BufferInfo bufferInfo);
252 void updateBufferActivity(const Message &msg);
255 QModelIndex networkIndex(NetworkId networkId);
256 NetworkItem *networkItem(NetworkId networkId);
257 NetworkItem *existsNetworkItem(NetworkId networkId);
258 BufferItem *bufferItem(const BufferInfo &bufferInfo);
259 BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
263 #endif // NETWORKMODEL_H