X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fbuffertreemodel.h;h=f2e118e194fc5ca864f239c51ac93ccaa733d979;hp=23471ad8d46fbaed7ac35f642083ff317aec057e;hb=c9ef00c67a47448e92398a5dce6ce5b74e77783a;hpb=0ac9ce4d7cf768d13993d6aa1d6b791c4149a843 diff --git a/src/client/buffertreemodel.h b/src/client/buffertreemodel.h index 23471ad8..f2e118e1 100644 --- a/src/client/buffertreemodel.h +++ b/src/client/buffertreemodel.h @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by The Quassel Team * + * Copyright (C) 2005-07 by the Quassel IRC Team * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -26,73 +26,158 @@ #include "treemodel.h" #include "buffer.h" +#include + +#include + +class BufferInfo; + +#include "selectionmodelsynchronizer.h" +#include "modelpropertymapper.h" +class MappedSelectionModel; +class QAbstractItemView; +class NetworkInfo; +class IrcChannel; +class IrcUser; + /***************************************** * Fancy Buffer Items *****************************************/ -class BufferTreeItem : public TreeItem { +class BufferTreeItem : public PropertyMapItem { Q_OBJECT - + Q_PROPERTY(QString bufferName READ bufferName) + Q_PROPERTY(QString topic READ topic) + Q_PROPERTY(int nickCount READ nickCount) + public: - BufferTreeItem(Buffer *, TreeItem *parent = 0); - QVariant data(int column, int role) const; + BufferTreeItem(Buffer *, AbstractTreeItem *parent = 0); + + virtual quint64 id() const; + virtual QVariant data(int column, int role) const; + + void attachIrcChannel(IrcChannel *ircChannel); + + QString bufferName() const; + QString topic() const; + int nickCount() const; + + Buffer *buffer() const { return buf; } void setActivity(const Buffer::ActivityLevel &); + +public slots: + void setTopic(const QString &topic); + void join(IrcUser *ircUser); + void part(IrcUser *ircUser); -protected: - QString text(int column) const; +private: QColor foreground(int column) const; - + Buffer *buf; Buffer::ActivityLevel activity; + + QPointer _ircChannel; }; +/***************************************** + * Network Items + *****************************************/ +class NetworkTreeItem : public PropertyMapItem { + Q_OBJECT + Q_PROPERTY(QString networkName READ networkName) + Q_PROPERTY(QString currentServer READ currentServer) + Q_PROPERTY(int nickCount READ nickCount) + +public: + NetworkTreeItem(const uint &netid, const QString &, AbstractTreeItem *parent = 0); + + virtual QVariant data(int column, int row) const; + virtual quint64 id() const; + + QString networkName() const; + QString currentServer() const; + int nickCount() const; + +public slots: + void setNetworkName(const QString &networkName); + void setCurrentServer(const QString &serverName); + + void attachNetworkInfo(NetworkInfo *networkInfo); + void attachIrcChannel(const QString &channelName); + +private: + uint _networkId; + QString _networkName; + + QPointer _networkInfo; +}; /***************************************** * BufferTreeModel *****************************************/ class BufferTreeModel : public TreeModel { Q_OBJECT - + public: - enum myRoles { + enum myRoles { BufferTypeRole = Qt::UserRole, BufferActiveRole, - BufferNameRole, - BufferIdRole + BufferUidRole, + NetworkIdRole, + ItemTypeRole }; - + + enum itemTypes { + AbstractItem, + SimpleItem, + NetworkItem, + BufferItem, + NickItem + }; + BufferTreeModel(QObject *parent = 0); static QList defaultHeader(); - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - -// void clearActivity(Buffer *buffer); - + inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; } + inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; } + + void synchronizeSelectionModel(MappedSelectionModel *selectionModel); + void synchronizeView(QAbstractItemView *view); + void mapProperty(int column, int role, QObject *target, const QByteArray &property); + + static bool mimeContainsBufferList(const QMimeData *mimeData); + static QList< QPair > mimeDataToBufferList(const QMimeData *mimeData); + + virtual QStringList mimeTypes() const; + virtual QMimeData *mimeData(const QModelIndexList &) const; + virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &); + + void attachNetworkInfo(NetworkInfo *networkInfo); + public slots: - void bufferUpdated(Buffer *); - void changeCurrent(const QModelIndex &, const QModelIndex &); + void bufferUpdated(Buffer *); + void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); void selectBuffer(Buffer *buffer); - void doubleClickReceived(const QModelIndex &); void bufferActivity(Buffer::ActivityLevel, Buffer *buffer); - + signals: void bufferSelected(Buffer *); - void invalidateFilter(); - void fakeUserInput(BufferId, QString); void selectionChanged(const QModelIndex &); - + private: bool isBufferIndex(const QModelIndex &) const; Buffer *getBufferByIndex(const QModelIndex &) const; - QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer); - QModelIndex getOrCreateBufferItemIndex(Buffer *buffer); - QStringList mimeTypes() const; - QMimeData *mimeData(const QModelIndexList &) const; - bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &); + QModelIndex networkIndex(uint networkId); + NetworkTreeItem *network(uint networkId); + NetworkTreeItem *newNetwork(uint networkId, const QString &networkName); - QHash networkItem; - QHash bufferItem; + QModelIndex bufferIndex(BufferInfo bufferInfo); + BufferTreeItem *buffer(BufferInfo bufferInfo); + BufferTreeItem *newBuffer(BufferInfo bufferInfo); + + QPointer _selectionModelSynchronizer; + QPointer _propertyMapper; Buffer *currentBuffer; };