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(Buffer *, AbstractTreeItem *parent = 0);
53 virtual quint64 id() const;
54 virtual QVariant data(int column, int role) const;
56 void attachIrcChannel(IrcChannel *ircChannel);
58 QString bufferName() const;
59 QString topic() const;
60 int nickCount() const;
63 Buffer *buffer() const { return buf; }
64 void setActivity(const Buffer::ActivityLevel &);
67 void setTopic(const QString &topic);
68 void join(IrcUser *ircUser);
69 void part(IrcUser *ircUser);
72 QColor foreground(int column) const;
75 Buffer::ActivityLevel activity;
77 QPointer<IrcChannel> _ircChannel;
80 /*****************************************
82 *****************************************/
83 class NetworkItem : public PropertyMapItem {
85 Q_PROPERTY(QString networkName READ networkName)
86 Q_PROPERTY(QString currentServer READ currentServer)
87 Q_PROPERTY(int nickCount READ nickCount)
90 NetworkItem(const uint &netid, const QString &, AbstractTreeItem *parent = 0);
92 virtual QVariant data(int column, int row) const;
93 virtual quint64 id() const;
95 QString networkName() const;
96 QString currentServer() const;
97 int nickCount() const;
100 void setNetworkName(const QString &networkName);
101 void setCurrentServer(const QString &serverName);
103 void attachNetworkInfo(NetworkInfo *networkInfo);
104 void attachIrcChannel(const QString &channelName);
108 QString _networkName;
110 QPointer<NetworkInfo> _networkInfo;
113 /*****************************************
115 *****************************************/
116 class IrcUserItem : public PropertyMapItem {
118 Q_PROPERTY(QString nickName READ nickName)
121 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
126 void setNick(QString newNick);
127 void ircUserDestroyed();
134 /*****************************************
136 *****************************************/
137 class NetworkModel : public TreeModel {
142 BufferTypeRole = Qt::UserRole,
157 NetworkModel(QObject *parent = 0);
158 static QList<QVariant> defaultHeader();
160 static bool mimeContainsBufferList(const QMimeData *mimeData);
161 static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
163 virtual QStringList mimeTypes() const;
164 virtual QMimeData *mimeData(const QModelIndexList &) const;
165 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
167 void attachNetworkInfo(NetworkInfo *networkInfo);
169 bool isBufferIndex(const QModelIndex &) const;
170 Buffer *getBufferByIndex(const QModelIndex &) const;
171 QModelIndex bufferIndex(BufferInfo bufferInfo);
174 void bufferUpdated(Buffer *);
175 void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
178 QModelIndex networkIndex(uint networkId);
179 NetworkItem *network(uint networkId);
180 NetworkItem *newNetwork(uint networkId, const QString &networkName);
182 BufferItem *buffer(BufferInfo bufferInfo);
183 BufferItem *newBuffer(BufferInfo bufferInfo);
187 #endif // NETWORKMODEL_H