enabled query in user context menu - now that the query command is working (thanks...
[quassel.git] / src / client / networkmodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef NETWORKMODEL_H
22 #define NETWORKMODEL_H
23
24 #include <QtCore>
25
26 #include "treemodel.h"
27 #include "buffer.h"
28
29 #include <QPointer>
30
31 class BufferInfo;
32
33 #include "selectionmodelsynchronizer.h"
34 #include "modelpropertymapper.h"
35 class MappedSelectionModel;
36 class QAbstractItemView;
37 class Network;
38 class IrcChannel;
39 class IrcUser;
40
41 /*****************************************
42  *  Fancy Buffer Items
43  *****************************************/
44 class BufferItem : public PropertyMapItem {
45   Q_OBJECT
46   Q_PROPERTY(QString bufferName READ bufferName)
47   Q_PROPERTY(QString topic READ topic)
48   Q_PROPERTY(int nickCount READ nickCount)
49
50 public:
51   BufferItem(BufferInfo bufferInfo, AbstractTreeItem *parent = 0);
52
53   const BufferInfo &bufferInfo() const;
54   virtual quint64 id() const;
55   virtual QVariant data(int column, int role) const;
56   virtual bool setData(int column, const QVariant &value, int role);
57
58   void attachIrcChannel(IrcChannel *ircChannel);
59
60   QString bufferName() const;
61   QString topic() const;
62   int nickCount() const;
63
64   enum Type {
65     StatusType,
66     ChannelType,
67     QueryType
68   };
69   
70   bool isStatusBuffer() const;
71   Type bufferType() const;
72
73   bool isActive() const;
74   
75   enum Activity {
76     NoActivity = 0x00,
77     OtherActivity = 0x01,
78     NewMessage = 0x02,
79     Highlight = 0x40
80   };
81   Q_DECLARE_FLAGS(ActivityLevel, Activity)
82
83   ActivityLevel activity() const;
84   void setActivity(const ActivityLevel &level);
85   void updateActivity(const ActivityLevel &level);
86
87 public slots:
88   void setTopic(const QString &topic);
89   void join(IrcUser *ircUser);
90   void part(IrcUser *ircUser);
91
92   void addUserToCategory(IrcUser *ircUser);
93   void removeUserFromCategory(IrcUser *ircUser);
94   void userModeChanged(IrcUser *ircUser);
95                                          
96 private slots:
97   void ircChannelDestroyed();
98   
99 private:
100   BufferInfo _bufferInfo;
101   ActivityLevel _activity;
102   Type _type;
103
104   QPointer<IrcChannel> _ircChannel;
105 };
106 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
107
108 /*****************************************
109  *  Network Items
110  *****************************************/
111 class NetworkItem : public PropertyMapItem {
112   Q_OBJECT
113   Q_PROPERTY(QString networkName READ networkName)
114   Q_PROPERTY(QString currentServer READ currentServer)
115   Q_PROPERTY(int nickCount READ nickCount)
116     
117 public:
118   NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
119
120   virtual quint64 id() const;
121   virtual QVariant data(int column, int row) const;
122
123   bool isActive() const;
124   
125   QString networkName() const;
126   QString currentServer() const;
127   int nickCount() const;
128   
129 public slots:
130   void setNetworkName(const QString &networkName);
131   void setCurrentServer(const QString &serverName);
132
133   void attachNetwork(Network *network);
134   void attachIrcChannel(const QString &channelName);
135
136   void setActive(bool connected);
137   
138 private:
139   NetworkId _networkId;
140
141   QPointer<Network> _network;
142 };
143
144 /*****************************************
145 *  User Category Items (like @vh etc.)
146 *****************************************/
147 class UserCategoryItem : public PropertyMapItem {
148   Q_OBJECT
149   Q_PROPERTY(QString categoryId READ categoryId)
150     
151 public:
152   UserCategoryItem(int category, AbstractTreeItem *parent);
153
154   QString categoryId();
155   virtual quint64 id() const;
156   virtual QVariant data(int column, int role) const;
157   
158   void addUser(IrcUser *ircUser);
159   bool removeUser(IrcUser *ircUser);
160
161   static int categoryFromModes(const QString &modes);
162
163 private:
164   int _category;
165
166   struct Category {
167     QChar mode;
168     QString displayString;
169     inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
170   };
171
172   static const QList<Category> categories;
173 };
174
175 /*****************************************
176 *  Irc User Items
177 *****************************************/
178 class IrcUserItem : public PropertyMapItem {
179   Q_OBJECT
180   Q_PROPERTY(QString nickName READ nickName)
181     
182 public:
183   IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
184
185   QString nickName() const;
186   IrcUser *ircUser();
187   virtual quint64 id() const;
188   virtual QVariant data(int column, int role) const;
189   virtual QString toolTip(int column) const;
190                                    
191 private slots:
192   void setNick(QString newNick);
193
194 private:
195   IrcUser *_ircUser;
196 };
197
198
199 /*****************************************
200  * NetworkModel
201  *****************************************/
202 class NetworkModel : public TreeModel {
203   Q_OBJECT
204
205 public:
206   enum myRoles {
207     BufferTypeRole = Qt::UserRole,
208     ItemActiveRole,
209     BufferActivityRole,
210     BufferIdRole,
211     NetworkIdRole,
212     BufferInfoRole,
213     ItemTypeRole
214   };
215
216   enum itemTypes {
217     NetworkItemType,
218     BufferItemType,
219     UserCategoryItemType,
220     IrcUserItemType
221   };
222     
223   NetworkModel(QObject *parent = 0);
224   static QList<QVariant> defaultHeader();
225
226   static bool mimeContainsBufferList(const QMimeData *mimeData);
227   static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
228
229   virtual QStringList mimeTypes() const;
230   virtual QMimeData *mimeData(const QModelIndexList &) const;
231   virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
232
233   void attachNetwork(Network *network);
234
235   bool isBufferIndex(const QModelIndex &) const;
236   //Buffer *getBufferByIndex(const QModelIndex &) const;
237   QModelIndex bufferIndex(BufferId bufferId);
238
239 public slots:
240   void bufferUpdated(BufferInfo bufferInfo);
241   void updateBufferActivity(const Message &msg);
242
243 private:
244   QModelIndex networkIndex(NetworkId networkId);
245   NetworkItem *networkItem(NetworkId networkId);
246   NetworkItem *existsNetworkItem(NetworkId networkId);
247   BufferItem *bufferItem(const BufferInfo &bufferInfo);
248   BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
249
250 };
251
252 #endif // NETWORKMODEL_H