2caa4dc9960153452facfb70acc4b7b246debc68
[quassel.git] / src / common / networkinfo.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 _NETWORKINFO_H_
22 #define _NETWORKINFO_H_
23
24 #include <QString>
25 #include <QStringList>
26 #include <QList>
27 #include <QHash>
28 #include <QVariantMap>
29 #include <QPointer>
30
31 #include "types.h"
32 #include "syncableobject.h"
33
34 class SignalProxy;
35 class IrcUser;
36 class IrcChannel;
37
38
39 class NetworkInfo : public SyncableObject {
40   Q_OBJECT
41
42   Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
43   Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
44   Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
45
46 public:
47   NetworkInfo(const uint &networkid, QObject *parent = 0);
48   //virtual ~NetworkInfo();
49
50   NetworkId networkId() const;
51   bool initialized() const;
52
53   SignalProxy *proxy() const;
54   void setProxy(SignalProxy *proxy);
55
56   bool isMyNick(const QString &nick) const;
57   bool isMyNick(IrcUser *ircuser) const;
58
59   bool isChannelName(const QString &channelname) const;
60
61   QString prefixToMode(const QString &prefix);
62   QString prefixToMode(const QCharRef &prefix);
63   QString modeToPrefix(const QString &mode);
64   QString modeToPrefix(const QCharRef &mode);
65
66   QString networkName() const;
67   QString currentServer() const;
68   QString myNick() const;
69   QStringList nicks() const;
70   QStringList channels() const;
71
72   QString prefixes();
73   QString prefixModes();
74
75   bool supports(const QString &param) const;
76   QString support(const QString &param) const;
77
78   IrcUser *newIrcUser(const QString &hostmask);
79   IrcUser *newIrcUser(const QByteArray &hostmask);
80   IrcUser *ircUser(QString nickname) const;
81   IrcUser *ircUser(const QByteArray &nickname) const;
82   QList<IrcUser *> ircUsers() const;
83
84   IrcChannel *newIrcChannel(const QString &channelname);
85   IrcChannel *newIrcChannel(const QByteArray &channelname);
86   IrcChannel *ircChannel(QString channelname);
87   IrcChannel *ircChannel(const QByteArray &channelname);
88   
89   QList<IrcChannel *> ircChannels() const;
90
91   QTextCodec *codecForEncoding() const;
92   QTextCodec *codecForDecoding() const;
93   void setCodecForEncoding(const QString &codecName);
94   void setCodecForEncoding(QTextCodec *codec);
95   void setCodecForDecoding(const QString &codecName);
96   void setCodecForDecoding(QTextCodec *codec);
97
98   QString decodeString(const QByteArray &text) const;
99   QByteArray encodeString(const QString string) const;
100
101 public slots:
102   void setNetworkName(const QString &networkName);
103   void setCurrentServer(const QString &currentServer);
104   void setMyNick(const QString &mynick);
105
106   void addSupport(const QString &param, const QString &value = QString());
107   void removeSupport(const QString &param);
108
109   inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
110   void removeIrcUser(QString nick);
111   
112   //init geters
113   QVariantMap initSupports() const;
114   QStringList initIrcUsers() const;
115   QStringList initIrcChannels() const;
116   
117   //init seters
118   void initSetSupports(const QVariantMap &supports);
119   void initSetIrcUsers(const QStringList &hostmasks);
120   void initSetChannels(const QStringList &channels);
121   
122   IrcUser *updateNickFromMask(const QString &mask);
123
124   // these slots are to keep the hashlists of all users and the
125   // channel lists up to date
126   void ircUserNickChanged(QString newnick);
127   void setInitialized();
128
129 private slots:
130   void ircUserDestroyed();
131   void channelDestroyed();
132   void removeIrcUser(IrcUser *ircuser);
133   
134 signals:
135   void networkNameSet(const QString &networkName);
136   void currentServerSet(const QString &currentServer);
137   void myNickSet(const QString &mynick);
138
139   void supportAdded(const QString &param, const QString &value);
140   void supportRemoved(const QString &param);
141   
142   void ircUserAdded(QString hostmask);
143   void ircChannelAdded(QString channelname);
144
145   void ircUserRemoved(QString nick);
146   
147   void initDone();
148   void ircUserInitDone();
149   void ircChannelInitDone();
150   
151 private:
152   uint _networkId;
153   bool _initialized;
154   
155   QString _myNick;
156   QString _networkName;
157   QString _currentServer;
158
159   QString _prefixes;
160   QString _prefixModes;
161
162   QHash<QString, IrcUser *> _ircUsers;  // stores all known nicks for the server
163   QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
164   QHash<QString, QString> _supports;  // stores results from RPL_ISUPPORT
165
166   //QVariantMap networkSettings;
167   //QVariantMap identity;
168   
169   QPointer<SignalProxy> _proxy;
170   void determinePrefixes();
171
172   QTextCodec *_codecForEncoding;
173   QTextCodec *_codecForDecoding;
174
175 };
176
177 #endif