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 ***************************************************************************/
26 #include <QStringList>
29 #include <QVariantMap>
34 #include "syncableobject.h"
40 // TODO: ConnectionInfo to propagate and sync the current state of NetworkConnection, encodings etcpp
42 class Network : public SyncableObject {
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)
54 Network(const NetworkId &networkid, QObject *parent = 0);
57 NetworkId networkId() const;
59 SignalProxy *proxy() const;
60 void setProxy(SignalProxy *proxy);
62 bool isMyNick(const QString &nick) const;
63 bool isMe(IrcUser *ircuser) const;
65 bool isChannelName(const QString &channelname) const;
67 bool isConnected() const;
69 QString prefixToMode(const QString &prefix);
70 QString prefixToMode(const QCharRef &prefix);
71 QString modeToPrefix(const QString &mode);
72 QString modeToPrefix(const QCharRef &mode);
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;
83 QString prefixModes();
85 bool supports(const QString ¶m) const;
86 QString support(const QString ¶m) const;
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;
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;
102 QByteArray codecForEncoding() const;
103 QByteArray codecForDecoding() const;
104 void setCodecForEncoding(QTextCodec *codec);
105 void setCodecForDecoding(QTextCodec *codec);
107 QString decodeString(const QByteArray &text) const;
108 QByteArray encodeString(const QString string) const;
111 void setNetworkName(const QString &networkName);
112 void setCurrentServer(const QString ¤tServer);
113 void setConnected(bool isConnected);
114 void setMyNick(const QString &mynick);
115 void setIdentity(IdentityId);
117 void setServerList(const QList<QVariantMap> &serverList);
119 void setCodecForEncoding(const QByteArray &codecName);
120 void setCodecForDecoding(const QByteArray &codecName);
122 void addSupport(const QString ¶m, const QString &value = QString());
123 void removeSupport(const QString ¶m);
125 inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
126 void removeIrcUser(QString nick);
129 QVariantMap initSupports() const;
130 QVariantList initServerList() const;
131 QStringList initIrcUsers() const;
132 QStringList initIrcChannels() const;
135 void initSetSupports(const QVariantMap &supports);
136 void initSetServerList(const QVariantList &serverList);
137 void initSetIrcUsers(const QStringList &hostmasks);
138 void initSetChannels(const QStringList &channels);
140 IrcUser *updateNickFromMask(const QString &mask);
142 // these slots are to keep the hashlists of all users and the
143 // channel lists up to date
144 void ircUserNickChanged(QString newnick);
146 void requestConnect();
149 void ircUserDestroyed();
150 void channelDestroyed();
151 void removeIrcUser(IrcUser *ircuser);
152 void ircUserInitDone();
153 void ircChannelInitDone();
156 void networkNameSet(const QString &networkName);
157 void currentServerSet(const QString ¤tServer);
158 void connectedSet(bool isConnected);
159 void myNickSet(const QString &mynick);
160 void identitySet(IdentityId);
162 void serverListSet(const QList<QVariantMap> &serverList);
164 void codecForEncodingSet(const QString &codecName);
165 void codecForDecodingSet(const QString &codecName);
167 void supportAdded(const QString ¶m, const QString &value);
168 void supportRemoved(const QString ¶m);
170 void ircUserAdded(const QString &hostmask);
171 void ircUserAdded(IrcUser *);
172 void ircChannelAdded(const QString &channelname);
173 void ircChannelAdded(IrcChannel *);
175 void ircUserRemoved(const QString &nick);
177 // needed for client sync progress
178 void ircUserRemoved(QObject *);
179 void ircChannelRemoved(QObject *);
181 void ircUserInitDone(IrcUser *);
182 void ircChannelInitDone(IrcChannel *);
184 void connectRequested(NetworkId = 0);
187 NetworkId _networkId;
188 IdentityId _identity;
191 QString _networkName;
192 QString _currentServer;
196 QString _prefixModes;
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
202 QList<QVariantMap> _serverList;
203 //QVariantMap networkSettings;
204 //QVariantMap identity;
206 QPointer<SignalProxy> _proxy;
207 void determinePrefixes();
209 QTextCodec *_codecForEncoding;
210 QTextCodec *_codecForDecoding;