1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
21 #ifndef _NETWORKINFO_H_
22 #define _NETWORKINFO_H_
25 #include <QStringList>
28 #include <QVariantMap>
38 class NetworkInfo : public QObject {
41 Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
42 Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
43 Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
46 NetworkInfo(const uint &networkid, QObject *parent = 0);
47 //virtual ~NetworkInfo();
49 NetworkId networkId() const;
50 bool initialized() const;
52 SignalProxy *proxy() const;
53 void setProxy(SignalProxy *proxy);
55 bool isMyNick(const QString &nick) const;
56 bool isMyNick(IrcUser *ircuser) const;
58 bool isChannelName(const QString &channelname) const;
60 QString prefixToMode(const QString &prefix);
61 QString prefixToMode(const QCharRef &prefix);
62 QString modeToPrefix(const QString &mode);
63 QString modeToPrefix(const QCharRef &mode);
65 QString networkName() const;
66 QString currentServer() const;
67 QString myNick() const;
68 QStringList nicks() const;
69 QStringList channels() const;
72 QString prefixModes();
74 bool supports(const QString ¶m) const;
75 QString support(const QString ¶m) const;
77 IrcUser *newIrcUser(const QString &hostmask);
78 IrcUser *newIrcUser(const QByteArray &hostmask);
79 IrcUser *ircUser(QString nickname) const;
80 IrcUser *ircUser(const QByteArray &nickname) const;
81 QList<IrcUser *> ircUsers() const;
83 IrcChannel *newIrcChannel(const QString &channelname);
84 IrcChannel *newIrcChannel(const QByteArray &channelname);
85 IrcChannel *ircChannel(QString channelname);
86 IrcChannel *ircChannel(const QByteArray &channelname);
88 QList<IrcChannel *> ircChannels() const;
90 QTextCodec *codecForEncoding() const;
91 QTextCodec *codecForDecoding() const;
92 void setCodecForEncoding(const QString &codecName);
93 void setCodecForEncoding(QTextCodec *codec);
94 void setCodecForDecoding(const QString &codecName);
95 void setCodecForDecoding(QTextCodec *codec);
97 QString decodeString(const QByteArray &text) const;
98 QByteArray encodeString(const QString string) const;
101 void setNetworkName(const QString &networkName);
102 void setCurrentServer(const QString ¤tServer);
103 void setMyNick(const QString &mynick);
105 void addSupport(const QString ¶m, const QString &value = QString());
106 void removeSupport(const QString ¶m);
108 inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
109 void removeIrcUser(QString nick);
112 QVariantMap initSupports() const;
113 QStringList initIrcUsers() const;
114 QStringList initIrcChannels() const;
117 void initSetSupports(const QVariantMap &supports);
118 void initSetIrcUsers(const QStringList &hostmasks);
119 void initSetChannels(const QStringList &channels);
121 IrcUser *updateNickFromMask(const QString &mask);
123 // these slots are to keep the hashlists of all users and the
124 // channel lists up to date
125 void ircUserNickChanged(QString newnick);
126 void setInitialized();
129 void ircUserDestroyed();
130 void channelDestroyed();
131 void removeIrcUser(IrcUser *ircuser);
134 void networkNameSet(const QString &networkName);
135 void currentServerSet(const QString ¤tServer);
136 void myNickSet(const QString &mynick);
138 void supportAdded(const QString ¶m, const QString &value);
139 void supportRemoved(const QString ¶m);
141 void ircUserAdded(QString hostmask);
142 void ircChannelAdded(QString channelname);
144 void ircUserRemoved(QString nick);
147 void ircUserInitDone();
148 void ircChannelInitDone();
155 QString _networkName;
156 QString _currentServer;
159 QString _prefixModes;
161 QHash<QString, IrcUser *> _ircUsers; // stores all known nicks for the server
162 QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
163 QHash<QString, QString> _supports; // stores results from RPL_ISUPPORT
165 //QVariantMap networkSettings;
166 //QVariantMap identity;
168 QPointer<SignalProxy> _proxy;
169 void determinePrefixes();
171 QTextCodec *_codecForEncoding;
172 QTextCodec *_codecForDecoding;