made the signalproxy compile with MSVC
[quassel.git] / src / common / network.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 _NETWORK_H_
22 #define _NETWORK_H_
23
24 #include <QDebug>
25 #include <QString>
26 #include <QStringList>
27 #include <QList>
28 #include <QHash>
29 #include <QVariantMap>
30 #include <QPointer>
31 #include <QMutex>
32
33 #include "types.h"
34 #include "syncableobject.h"
35
36 class SignalProxy;
37 class IrcUser;
38 class IrcChannel;
39
40 // TODO: ConnectionInfo to propagate and sync the current state of NetworkConnection, encodings etcpp
41
42 class Network : public SyncableObject {
43   Q_OBJECT
44
45   Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
46   Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
47   Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
48   Q_PROPERTY(QByteArray codecForEncoding READ codecForEncoding WRITE setCodecForEncoding STORED false)
49   Q_PROPERTY(QByteArray codecForDecoding READ codecForDecoding WRITE setCodecForDecoding STORED false)
50   Q_PROPERTY(IdentityId identityId READ identity WRITE setIdentity STORED false)
51   Q_PROPERTY(bool isConnected READ isConnected WRITE setConnected STORED false)
52
53 public:
54   Network(const NetworkId &networkid, QObject *parent = 0);
55   //virtual ~Network();
56
57   NetworkId networkId() const;
58
59   SignalProxy *proxy() const;
60   void setProxy(SignalProxy *proxy);
61
62   bool isMyNick(const QString &nick) const;
63   bool isMe(IrcUser *ircuser) const;
64
65   bool isChannelName(const QString &channelname) const;
66
67   bool isConnected() const;
68
69   QString prefixToMode(const QString &prefix);
70   QString prefixToMode(const QCharRef &prefix);
71   QString modeToPrefix(const QString &mode);
72   QString modeToPrefix(const QCharRef &mode);
73
74   QString networkName() const;
75   QString currentServer() const;
76   QString myNick() const;
77   IdentityId identity() const;
78   QStringList nicks() const;
79   QStringList channels() const;
80   QList<QVariantMap> serverList() const;
81
82   QString prefixes();
83   QString prefixModes();
84
85   bool supports(const QString &param) const;
86   QString support(const QString &param) const;
87
88   IrcUser *newIrcUser(const QString &hostmask);
89   IrcUser *newIrcUser(const QByteArray &hostmask);
90   IrcUser *ircUser(QString nickname) const;
91   IrcUser *ircUser(const QByteArray &nickname) const;
92   QList<IrcUser *> ircUsers() const;
93   quint32 ircUserCount() const;
94
95   IrcChannel *newIrcChannel(const QString &channelname);
96   IrcChannel *newIrcChannel(const QByteArray &channelname);
97   IrcChannel *ircChannel(QString channelname);
98   IrcChannel *ircChannel(const QByteArray &channelname);
99   QList<IrcChannel *> ircChannels() const;
100   quint32 ircChannelCount() const;
101
102   QByteArray codecForEncoding() const;
103   QByteArray codecForDecoding() const;
104   void setCodecForEncoding(QTextCodec *codec);
105   void setCodecForDecoding(QTextCodec *codec);
106
107   QString decodeString(const QByteArray &text) const;
108   QByteArray encodeString(const QString string) const;
109
110 public slots:
111   void setNetworkName(const QString &networkName);
112   void setCurrentServer(const QString &currentServer);
113   void setConnected(bool isConnected);
114   void setMyNick(const QString &mynick);
115   void setIdentity(IdentityId);
116
117   void setServerList(const QList<QVariantMap> &serverList);
118
119   void setCodecForEncoding(const QByteArray &codecName);
120   void setCodecForDecoding(const QByteArray &codecName);
121
122   void addSupport(const QString &param, const QString &value = QString());
123   void removeSupport(const QString &param);
124
125   inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
126   void removeIrcUser(QString nick);
127   
128   //init geters
129   QVariantMap initSupports() const;
130   QVariantList initServerList() const;
131   QStringList initIrcUsers() const;
132   QStringList initIrcChannels() const;
133   
134   //init seters
135   void initSetSupports(const QVariantMap &supports);
136   void initSetServerList(const QVariantList &serverList);
137   void initSetIrcUsers(const QStringList &hostmasks);
138   void initSetChannels(const QStringList &channels);
139   
140   IrcUser *updateNickFromMask(const QString &mask);
141
142   // these slots are to keep the hashlists of all users and the
143   // channel lists up to date
144   void ircUserNickChanged(QString newnick);
145
146   void requestConnect();
147
148 private slots:
149   void ircUserDestroyed();
150   void channelDestroyed();
151   void removeIrcUser(IrcUser *ircuser);
152   void ircUserInitDone();
153   void ircChannelInitDone();
154
155 signals:
156   void networkNameSet(const QString &networkName);
157   void currentServerSet(const QString &currentServer);
158   void connectedSet(bool isConnected);
159   void myNickSet(const QString &mynick);
160   void identitySet(IdentityId);
161
162   void serverListSet(const QList<QVariantMap> &serverList);
163
164   void codecForEncodingSet(const QString &codecName);
165   void codecForDecodingSet(const QString &codecName);
166
167   void supportAdded(const QString &param, const QString &value);
168   void supportRemoved(const QString &param);
169
170   void ircUserAdded(const QString &hostmask);
171   void ircUserAdded(IrcUser *);
172   void ircChannelAdded(const QString &channelname);
173   void ircChannelAdded(IrcChannel *);
174
175   void ircUserRemoved(const QString &nick);
176
177   // needed for client sync progress
178   void ircUserRemoved(QObject *);
179   void ircChannelRemoved(QObject *);
180
181   void ircUserInitDone(IrcUser *);
182   void ircChannelInitDone(IrcChannel *);
183
184   void connectRequested(NetworkId = 0);
185
186 private:
187   NetworkId _networkId;
188   IdentityId _identity;
189
190   QString _myNick;
191   QString _networkName;
192   QString _currentServer;
193   bool _connected;
194
195   QString _prefixes;
196   QString _prefixModes;
197
198   QHash<QString, IrcUser *> _ircUsers;  // stores all known nicks for the server
199   QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
200   QHash<QString, QString> _supports;  // stores results from RPL_ISUPPORT
201
202   QList<QVariantMap> _serverList;
203   //QVariantMap networkSettings;
204   //QVariantMap identity;
205   
206   QPointer<SignalProxy> _proxy;
207   void determinePrefixes();
208
209   QTextCodec *_codecForEncoding;
210   QTextCodec *_codecForDecoding;
211
212 };
213
214 #endif