made the signalproxy compile with MSVC
[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
57   void attachIrcChannel(IrcChannel *ircChannel);
58
59   QString bufferName() const;
60   QString topic() const;
61   int nickCount() const;
62
63   enum Type {
64     StatusType,
65     ChannelType,
66     QueryType
67   };
68   
69   bool isStatusBuffer() const;
70   Type bufferType() const;
71
72   bool isActive() const;
73   
74   enum Activity {
75     NoActivity = 0x00,
76     OtherActivity = 0x01,
77     NewMessage = 0x02,
78     Highlight = 0x40
79   };
80   Q_DECLARE_FLAGS(ActivityLevel, Activity)
81
82   ActivityLevel activity() const;
83   void setActivity(const ActivityLevel &level);
84   void addActivity(const ActivityLevel &level);
85
86 public slots:
87   void setTopic(const QString &topic);
88   void join(IrcUser *ircUser);
89   void part(IrcUser *ircUser);
90
91   void addUserToCategory(IrcUser *ircUser);
92   void removeUserFromCategory(IrcUser *ircUser);
93   void userModeChanged(IrcUser *ircUser);
94                                          
95 private slots:
96   void ircChannelDestroyed();
97   
98 private:
99   BufferInfo _bufferInfo;
100   ActivityLevel _activity;
101   Type _type;
102
103   QPointer<IrcChannel> _ircChannel;
104 };
105 Q_DECLARE_OPERATORS_FOR_FLAGS(BufferItem::ActivityLevel)
106
107 /*****************************************
108  *  Network Items
109  *****************************************/
110 class NetworkItem : public PropertyMapItem {
111   Q_OBJECT
112   Q_PROPERTY(QString networkName READ networkName)
113   Q_PROPERTY(QString currentServer READ currentServer)
114   Q_PROPERTY(int nickCount READ nickCount)
115     
116 public:
117   NetworkItem(const NetworkId &netid, AbstractTreeItem *parent = 0);
118
119   virtual QVariant data(int column, int row) const;
120   virtual quint64 id() const;
121
122   bool isActive() const;
123   
124   QString networkName() const;
125   QString currentServer() const;
126   int nickCount() const;
127   
128 public slots:
129   void setNetworkName(const QString &networkName);
130   void setCurrentServer(const QString &serverName);
131
132   void attachNetwork(Network *network);
133   void attachIrcChannel(const QString &channelName);
134   
135 private:
136   NetworkId _networkId;
137
138   QPointer<Network> _network;
139 };
140
141 /*****************************************
142 *  User Category Items (like @vh etc.)
143 *****************************************/
144 class UserCategoryItem : public PropertyMapItem {
145   Q_OBJECT
146   Q_PROPERTY(QString categoryId READ categoryId)
147     
148 public:
149   UserCategoryItem(int category, AbstractTreeItem *parent);
150
151   QString categoryId();
152   virtual quint64 id() const;
153
154   void addUser(IrcUser *ircUser);
155
156   static int categoryFromModes(const QString &modes);
157
158 private:
159   int _category;
160
161   struct Category {
162     QChar mode;
163     QString displayString;
164     inline Category(QChar mode_, QString displayString_) : mode(mode_), displayString(displayString_) {};
165   };
166
167   static const QList<Category> categories;
168 };
169
170 /*****************************************
171 *  Irc User Items
172 *****************************************/
173 class IrcUserItem : public PropertyMapItem {
174   Q_OBJECT
175   Q_PROPERTY(QString nickName READ nickName)
176     
177 public:
178   IrcUserItem(IrcUser *ircUser, AbstractTreeItem *parent);
179
180   QString nickName();
181   IrcUser *ircUser();
182   virtual quint64 id() const;
183
184 private slots:
185   void setNick(QString newNick);
186   void ircUserDestroyed();
187
188 private:
189   IrcUser *_ircUser;
190 };
191
192
193 /*****************************************
194  * NetworkModel
195  *****************************************/
196 class NetworkModel : public TreeModel {
197   Q_OBJECT
198
199 public:
200   enum myRoles {
201     BufferTypeRole = Qt::UserRole,
202     ItemActiveRole,
203     BufferIdRole,
204     NetworkIdRole,
205     ItemTypeRole
206   };
207
208   enum itemTypes {
209     AbstractItemType,
210     SimpleItemType,
211     NetworkItemType,
212     BufferItemType,
213     NickItemType
214   };
215     
216   NetworkModel(QObject *parent = 0);
217   static QList<QVariant> defaultHeader();
218
219   static bool mimeContainsBufferList(const QMimeData *mimeData);
220   static QList< QPair<NetworkId, BufferId> > mimeDataToBufferList(const QMimeData *mimeData);
221
222   virtual QStringList mimeTypes() const;
223   virtual QMimeData *mimeData(const QModelIndexList &) const;
224   virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
225
226   void attachNetwork(Network *network);
227
228   bool isBufferIndex(const QModelIndex &) const;
229   //Buffer *getBufferByIndex(const QModelIndex &) const;
230   QModelIndex bufferIndex(BufferId bufferId);
231
232 public slots:
233   void bufferUpdated(BufferInfo bufferInfo);
234   void bufferActivity(BufferItem::ActivityLevel, BufferInfo bufferInfo);
235
236 private:
237   QModelIndex networkIndex(NetworkId networkId);
238   NetworkItem *networkItem(NetworkId networkId);
239   NetworkItem *existsNetworkItem(NetworkId networkId);
240   BufferItem *bufferItem(const BufferInfo &bufferInfo);
241   BufferItem *existsBufferItem(const BufferInfo &bufferInfo);
242
243 };
244
245 #endif // NETWORKMODEL_H