1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
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 _BUFFERTREEMODEL_H_
22 #define _BUFFERTREEMODEL_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 BufferTreeItem : public PropertyMapItem {
48 Q_PROPERTY(QString bufferName READ bufferName)
49 Q_PROPERTY(QString topic READ topic)
50 Q_PROPERTY(int nickCount READ nickCount)
53 BufferTreeItem(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 NetworkTreeItem : public PropertyMapItem {
87 Q_PROPERTY(QString networkName READ networkName)
88 Q_PROPERTY(QString currentServer READ currentServer)
89 Q_PROPERTY(int nickCount READ nickCount)
92 NetworkTreeItem(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 BufferTreeModel : public TreeModel {
123 BufferTypeRole = Qt::UserRole,
138 BufferTreeModel(QObject *parent = 0);
139 static QList<QVariant> defaultHeader();
141 inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
142 inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
144 void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
145 void synchronizeView(QAbstractItemView *view);
146 void mapProperty(int column, int role, QObject *target, const QByteArray &property);
148 static bool mimeContainsBufferList(const QMimeData *mimeData);
149 static QList< QPair<uint, uint> > mimeDataToBufferList(const QMimeData *mimeData);
151 virtual QStringList mimeTypes() const;
152 virtual QMimeData *mimeData(const QModelIndexList &) const;
153 virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
155 void attachNetworkInfo(NetworkInfo *networkInfo);
158 void bufferUpdated(Buffer *);
159 void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
160 void selectBuffer(Buffer *buffer);
161 void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
164 void bufferSelected(Buffer *);
165 void selectionChanged(const QModelIndex &);
168 bool isBufferIndex(const QModelIndex &) const;
169 Buffer *getBufferByIndex(const QModelIndex &) const;
171 QModelIndex networkIndex(uint networkId);
172 NetworkTreeItem *network(uint networkId);
173 NetworkTreeItem *newNetwork(uint networkId, const QString &networkName);
175 QModelIndex bufferIndex(BufferInfo bufferInfo);
176 BufferTreeItem *buffer(BufferInfo bufferInfo);
177 BufferTreeItem *newBuffer(BufferInfo bufferInfo);
179 QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
180 QPointer<ModelPropertyMapper> _propertyMapper;
181 Buffer *currentBuffer;