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"
31 #include <QItemSelectionModel>
35 #include "selectionmodelsynchronizer.h"
36 #include "modelpropertymapper.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(Buffer *, AbstractTreeItem *parent = 0);
55 virtual quint64 id() const;
56 virtual QVariant data(int column, int role) const;
58 void attachIrcChannel(IrcChannel *ircChannel);
60 QString bufferName() const;
61 QString topic() const;
62 int nickCount() const;
65 Buffer *buffer() const { return buf; }
66 void setActivity(const Buffer::ActivityLevel &);
69 void setTopic(const QString &topic);
70 void join(IrcUser *ircUser);
71 void part(IrcUser *ircUser);
74 QColor foreground(int column) const;
77 Buffer::ActivityLevel activity;
79 QPointer<IrcChannel> _ircChannel;
82 /*****************************************
84 *****************************************/
85 class NetworkItem : public PropertyMapItem {
87 Q_PROPERTY(QString networkName READ networkName)
88 Q_PROPERTY(QString currentServer READ currentServer)
89 Q_PROPERTY(int nickCount READ nickCount)
92 NetworkItem(const uint &netid, const QString &, AbstractTreeItem *parent = 0);
94 virtual QVariant data(int column, int row) const;
95 virtual quint64 id() const;
97 QString networkName() const;
98 QString currentServer() const;
99 int nickCount() const;
102 void setNetworkName(const QString &networkName);
103 void setCurrentServer(const QString &serverName);
105 void attachNetworkInfo(NetworkInfo *networkInfo);
106 void attachIrcChannel(const QString &channelName);
110 QString _networkName;
112 QPointer<NetworkInfo> _networkInfo;
115 /*****************************************
117 *****************************************/
118 class IrcUserItem : public PropertyMapItem {
120 Q_PROPERTY(QString nickName READ nickName)
123 IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
128 void setNick(QString newNick);
129 void ircUserDestroyed();
136 /*****************************************
138 *****************************************/
139 class NetworkModel : public TreeModel {
144 BufferTypeRole = Qt::UserRole,
159 NetworkModel(QObject *parent = 0);
160 static QList<QVariant> defaultHeader();
162 inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
163 inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
165 void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
166 void synchronizeView(QAbstractItemView *view);
167 void mapProperty(int column, int role, QObject *target, const QByteArray &property);
169 static bool mimeContainsBufferList(const QMimeData *mimeData);
170 static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
172 virtual QStringList mimeTypes() const;
173 virtual QMimeData *mimeData(const QModelIndexList &) const;
174 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
176 void attachNetworkInfo(NetworkInfo *networkInfo);
179 void bufferUpdated(Buffer *);
180 void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
181 void selectBuffer(Buffer *buffer);
182 void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
185 void bufferSelected(Buffer *);
186 void selectionChanged(const QModelIndex &);
189 bool isBufferIndex(const QModelIndex &) const;
190 Buffer *getBufferByIndex(const QModelIndex &) const;
192 QModelIndex networkIndex(uint networkId);
193 NetworkItem *network(uint networkId);
194 NetworkItem *newNetwork(uint networkId, const QString &networkName);
196 QModelIndex bufferIndex(BufferInfo bufferInfo);
197 BufferItem *buffer(BufferInfo bufferInfo);
198 BufferItem *newBuffer(BufferInfo bufferInfo);
200 QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
201 QPointer<ModelPropertyMapper> _propertyMapper;
202 Buffer *currentBuffer;
205 #endif // NETWORKMODEL_H