X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fnetworkmodel.h;h=7412d135187d768179d4857653318536415aba84;hp=014cab143c1e8c0a35ba0327181ad1d2c84bf555;hb=3c2914faeb01f3bc32e29f40179ae88040fbcf59;hpb=5a9559260e3b80c8578fc1102a40454c92807463 diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 014cab14..7412d135 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -21,24 +21,12 @@ #ifndef NETWORKMODEL_H #define NETWORKMODEL_H -#include - -#include "treemodel.h" -#include "buffer.h" - -#include - -class BufferInfo; - -#include "selectionmodelsynchronizer.h" -#include "modelpropertymapper.h" +#include "bufferinfo.h" #include "clientsettings.h" -#include "ircchannel.h" -#include "ircuser.h" +#include "message.h" #include "network.h" +#include "treemodel.h" -class MappedSelectionModel; -class QAbstractItemView; class BufferItem; /***************************************** @@ -49,11 +37,10 @@ class NetworkItem : public PropertyMapItem { Q_PROPERTY(QString networkName READ networkName) Q_PROPERTY(QString currentServer READ currentServer) Q_PROPERTY(int nickCount READ nickCount) - + public: NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0); - virtual quint64 id() const { return qHash(_networkId); } virtual QVariant data(int column, int row) const; inline bool isActive() const { return (bool)_network ? _network->isConnected() : false; } @@ -65,6 +52,8 @@ public: virtual QString toolTip(int column) const; + BufferItem *findBufferItem(BufferId bufferId); + inline BufferItem *findBufferItem(const BufferInfo &bufferInfo) { return findBufferItem(bufferInfo.bufferId()); } BufferItem *bufferItem(const BufferInfo &bufferInfo); public slots: @@ -73,6 +62,7 @@ public slots: void attachNetwork(Network *network); void attachIrcChannel(IrcChannel *channel); + void attachIrcUser(IrcUser *ircUser); private: NetworkId _networkId; @@ -93,7 +83,6 @@ public: BufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent = 0); inline const BufferInfo &bufferInfo() const { return _bufferInfo; } - virtual inline quint64 id() const { return qHash(_bufferInfo.bufferId()); } virtual QVariant data(int column, int role) const; virtual bool setData(int column, const QVariant &value, int role); @@ -107,14 +96,15 @@ public: virtual inline bool isActive() const { return qobject_cast(parent())->isActive(); } - inline Buffer::ActivityLevel activityLevel() const { return _activity; } - void setActivityLevel(Buffer::ActivityLevel level); - void updateActivityLevel(Buffer::ActivityLevel level); - - void setLastMsgInsert(QDateTime msgDate); - bool setLastSeen(); - QDateTime lastSeen(); + inline const MsgId &lastSeenMsgId() const { return _lastSeenMsgId; } + inline const MsgId &lastSeenMarkerMsgId() const { return _lastSeenMarkerMsgId; } + void setLastSeenMsgId(const MsgId &msgId); + inline BufferInfo::ActivityLevel activityLevel() const { return _activity; } + void setActivityLevel(BufferInfo::ActivityLevel level); + void clearActivityLevel(); + void updateActivityLevel(const Message &msg); + bool isCurrentBuffer() const; virtual QString toolTip(int column) const; public slots: @@ -122,7 +112,9 @@ public slots: private: BufferInfo _bufferInfo; - Buffer::ActivityLevel _activity; + BufferInfo::ActivityLevel _activity; + MsgId _lastSeenMsgId; + MsgId _lastSeenMarkerMsgId; }; /***************************************** @@ -147,38 +139,51 @@ class QueryBufferItem : public BufferItem { public: QueryBufferItem(const BufferInfo &bufferInfo, NetworkItem *parent); + virtual QVariant data(int column, int role) const; + virtual bool setData(int column, const QVariant &value, int role); + virtual inline bool isActive() const { return (bool)_ircUser; } virtual QString toolTip(int column) const; + +public slots: + void attachIrcUser(IrcUser *ircUser); + void ircUserQuited(); + +private: + IrcUser *_ircUser; }; /***************************************** * ChannelBufferItem *****************************************/ +class UserCategoryItem; + class ChannelBufferItem : public BufferItem { Q_OBJECT public: ChannelBufferItem(const BufferInfo &bufferInfo, AbstractTreeItem *parent); + virtual QVariant data(int column, int role) const; virtual inline bool isActive() const { return (bool)_ircChannel; } virtual QString toolTip(int column) const; virtual inline QString topic() const { return (bool)_ircChannel ? _ircChannel->topic() : QString(); } virtual inline int nickCount() const { return (bool)_ircChannel ? _ircChannel->ircUsers().count() : 0; } - + void attachIrcChannel(IrcChannel *ircChannel); public slots: void join(const QList &ircUsers); void part(IrcUser *ircUser); + UserCategoryItem *findCategoryItem(int categoryId); void addUserToCategory(IrcUser *ircUser); void addUsersToCategory(const QList &ircUser); void removeUserFromCategory(IrcUser *ircUser); void userModeChanged(IrcUser *ircUser); private slots: - void ircChannelDestroyed(); - void ircUserDestroyed(); + void ircChannelParted(); private: IrcChannel *_ircChannel; @@ -187,17 +192,19 @@ private: /***************************************** * User Category Items (like @vh etc.) *****************************************/ +class IrcUserItem; class UserCategoryItem : public PropertyMapItem { Q_OBJECT Q_PROPERTY(QString categoryName READ categoryName) - + public: UserCategoryItem(int category, AbstractTreeItem *parent); QString categoryName() const; - virtual quint64 id() const; + inline int categoryId() const { return _category; } virtual QVariant data(int column, int role) const; - + + IrcUserItem *findIrcUser(IrcUser *ircUser); void addUsers(const QList &ircUser); bool removeUser(IrcUser *ircUser); @@ -215,25 +222,22 @@ private: class IrcUserItem : public PropertyMapItem { Q_OBJECT Q_PROPERTY(QString nickName READ nickName) - + public: IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent); - QString nickName() const; - bool isActive() const; + inline QString nickName() const { return _ircUser ? _ircUser->nick() : QString(); } + inline bool isActive() const { return _ircUser ? !_ircUser->isAway() : false; } inline IrcUser *ircUser() { return _ircUser; } - inline virtual quint64 id() const { return _id; } virtual QVariant data(int column, int role) const; virtual QString toolTip(int column) const; private slots: - void setNick(QString newNick); - void setAway(bool); + inline void ircUserQuited() { parent()->removeChild(this); } private: QPointer _ircUser; - quint64 _id; }; @@ -244,23 +248,26 @@ class NetworkModel : public TreeModel { Q_OBJECT public: - enum myRoles { + enum Role { BufferTypeRole = TreeModel::UserRole, ItemActiveRole, BufferActivityRole, BufferIdRole, NetworkIdRole, BufferInfoRole, - ItemTypeRole + ItemTypeRole, + UserAwayRole, + IrcUserRole, + IrcChannelRole }; - enum itemType { + enum ItemType { NetworkItemType = 0x01, BufferItemType = 0x02, UserCategoryItemType = 0x04, IrcUserItemType = 0x08 }; - Q_DECLARE_FLAGS(itemTypes, itemType); + Q_DECLARE_FLAGS(ItemTypes, ItemType) NetworkModel(QObject *parent = 0); static QList defaultHeader(); @@ -270,7 +277,6 @@ public: virtual QStringList mimeTypes() const; virtual QMimeData *mimeData(const QModelIndexList &) const; - virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &); void attachNetwork(Network *network); @@ -281,21 +287,52 @@ public: const Network *networkByIndex(const QModelIndex &index) const; - Buffer::ActivityLevel bufferActivity(const BufferInfo &buffer) const; + BufferInfo::ActivityLevel bufferActivity(const BufferInfo &buffer) const; + + //! Finds a buffer with a given name in a given network + /** This performs a linear search through all BufferItems, hence it is expensive. + * @param networkId The network which we search in + * @param bufferName The bufferName we look for + * @return The id of the buffer if found, an invalid one else + */ + BufferId bufferId(NetworkId networkId, const QString &bufferName, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const; + + QString bufferName(BufferId bufferId) const; + BufferInfo::Type bufferType(BufferId bufferId) const; + BufferInfo bufferInfo(BufferId bufferId) const; + MsgId lastSeenMsgId(BufferId bufferId) const; + MsgId lastSeenMarkerMsgId(BufferId bufferId) const; + NetworkId networkId(BufferId bufferId) const; + QString networkName(BufferId bufferId) const; + + inline QList allBufferIds() const { return _bufferItemCache.keys(); } public slots: void bufferUpdated(BufferInfo bufferInfo); void removeBuffer(BufferId bufferId); - void setBufferActivity(const BufferInfo &buffer, Buffer::ActivityLevel activity); + void setLastSeenMsgId(const BufferId &bufferId, const MsgId &msgId); + void setBufferActivity(const BufferId &bufferId, BufferInfo::ActivityLevel activity); + void clearBufferActivity(const BufferId &bufferId); + void updateBufferActivity(const Message &msg); void networkRemoved(const NetworkId &networkId); - + +signals: + void setLastSeenMsg(BufferId bufferId, MsgId msgId); + +private slots: + void checkForRemovedBuffers(const QModelIndex &parent, int start, int end); + void checkForNewBuffers(const QModelIndex &parent, int start, int end); + private: + int networkRow(NetworkId networkId) const; + NetworkItem *findNetworkItem(NetworkId networkId) const; NetworkItem *networkItem(NetworkId networkId); - NetworkItem *existsNetworkItem(NetworkId networkId); + inline BufferItem *findBufferItem(const BufferInfo &bufferInfo) const { return findBufferItem(bufferInfo.bufferId()); } + BufferItem *findBufferItem(BufferId bufferId) const; BufferItem *bufferItem(const BufferInfo &bufferInfo); - BufferItem *existsBufferItem(const BufferInfo &bufferInfo); + QHash _bufferItemCache; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkModel::itemTypes); +Q_DECLARE_OPERATORS_FOR_FLAGS(NetworkModel::ItemTypes) #endif // NETWORKMODEL_H