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);
92 void ircChannelDestroyed();
95 BufferInfo _bufferInfo;
96 ActivityLevel _activity;
99 QPointer<IrcChannel> _ircChannel;
101 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
103 /*****************************************
105 *****************************************/
106 class NetworkItem : public PropertyMapItem {
108 Q_PROPERTY(QString networkName READ networkName)
109 Q_PROPERTY(QString currentServer READ currentServer)
110 Q_PROPERTY(int nickCount READ nickCount)
113 NetworkItem(const uint &netid, const QString &, AbstractTreeItem *parent = 0);
115 virtual QVariant data(int column, int row) const;
116 virtual quint64 id() const;
118 bool isActive() const;
120 QString networkName() const;
121 QString currentServer() const;
122 int nickCount() const;
125 void setNetworkName(const QString &networkName);
126 void setCurrentServer(const QString &serverName);
128 void attachNetwork(Network *network);
129 void attachIrcChannel(const QString &channelName);
133 QString _networkName;
135 QPointer<Network> _network;
138 /*****************************************
140 *****************************************/
141 class IrcUserItem : public PropertyMapItem {
143 Q_PROPERTY(QString nickName READ nickName)
146 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
151 void setNick(QString newNick);
152 void ircUserDestroyed();
159 /*****************************************
161 *****************************************/
162 class NetworkModel : public TreeModel {
167 BufferTypeRole = Qt::UserRole,
182 NetworkModel(QObject *parent = 0);
183 static QList<QVariant> defaultHeader();
185 static bool mimeContainsBufferList(const QMimeData *mimeData);
186 static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
188 virtual QStringList mimeTypes() const;
189 virtual QMimeData *mimeData(const QModelIndexList &) const;
190 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
192 void attachNetwork(Network *network);
194 bool isBufferIndex(const QModelIndex &) const;
195 Buffer *getBufferByIndex(const QModelIndex &) const;
196 QModelIndex bufferIndex(BufferId bufferId);
199 void bufferUpdated(BufferInfo bufferInfo);
200 void bufferActivity(BufferItem::ActivityLevel, BufferInfo bufferInfo);
203 QModelIndex networkIndex(uint networkId);
204 NetworkItem *network(uint networkId);
205 NetworkItem *newNetwork(uint networkId, const QString &networkName);
207 BufferItem *buffer(BufferInfo bufferInfo);
208 BufferItem *newBuffer(BufferInfo bufferInfo);
212 #endif // NETWORKMODEL_H