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"
43 // TODO: ConnectionInfo to propagate and sync the current state of NetworkConnection, encodings etcpp
45 class Network : public SyncableObject {
48 Q_PROPERTY(QString networkName READ networkName WRITE setNetworkName STORED false)
49 Q_PROPERTY(QString currentServer READ currentServer WRITE setCurrentServer STORED false)
50 Q_PROPERTY(QString myNick READ myNick WRITE setMyNick STORED false)
51 Q_PROPERTY(QByteArray codecForEncoding READ codecForEncoding WRITE setCodecForEncoding STORED false)
52 Q_PROPERTY(QByteArray codecForDecoding READ codecForDecoding WRITE setCodecForDecoding STORED false)
53 Q_PROPERTY(IdentityId identityId READ identity WRITE setIdentity STORED false)
54 Q_PROPERTY(bool isConnected READ isConnected WRITE setConnected STORED false)
57 Network(const NetworkId &networkid, QObject *parent = 0);
60 NetworkId networkId() const;
62 SignalProxy *proxy() const;
63 void setProxy(SignalProxy *proxy);
65 bool isMyNick(const QString &nick) const;
66 bool isMe(IrcUser *ircuser) const;
68 bool isChannelName(const QString &channelname) const;
70 bool isConnected() const;
72 QString prefixToMode(const QString &prefix);
73 QString prefixToMode(const QCharRef &prefix);
74 QString modeToPrefix(const QString &mode);
75 QString modeToPrefix(const QCharRef &mode);
77 QString networkName() const;
78 QString currentServer() const;
79 QString myNick() const;
80 IdentityId identity() const;
81 QStringList nicks() const;
82 QStringList channels() const;
83 QList<QVariantMap> serverList() const;
85 NetworkInfo networkInfo() const;
86 void setNetworkInfo(const NetworkInfo &);
89 QString prefixModes();
91 bool supports(const QString ¶m) const;
92 QString support(const QString ¶m) const;
94 IrcUser *newIrcUser(const QString &hostmask);
95 IrcUser *newIrcUser(const QByteArray &hostmask);
96 IrcUser *ircUser(QString nickname) const;
97 IrcUser *ircUser(const QByteArray &nickname) const;
98 QList<IrcUser *> ircUsers() const;
99 quint32 ircUserCount() const;
101 IrcChannel *newIrcChannel(const QString &channelname);
102 IrcChannel *newIrcChannel(const QByteArray &channelname);
103 IrcChannel *ircChannel(QString channelname) const;
104 IrcChannel *ircChannel(const QByteArray &channelname) const;
105 QList<IrcChannel *> ircChannels() const;
106 quint32 ircChannelCount() const;
108 QByteArray codecForEncoding() const;
109 QByteArray codecForDecoding() const;
110 void setCodecForEncoding(QTextCodec *codec);
111 void setCodecForDecoding(QTextCodec *codec);
113 QString decodeString(const QByteArray &text) const;
114 QByteArray encodeString(const QString string) const;
117 void setNetworkName(const QString &networkName);
118 void setCurrentServer(const QString ¤tServer);
119 void setConnected(bool isConnected);
120 void setMyNick(const QString &mynick);
121 void setIdentity(IdentityId);
123 void setServerList(const QList<QVariantMap> &serverList);
125 void setCodecForEncoding(const QByteArray &codecName);
126 void setCodecForDecoding(const QByteArray &codecName);
128 void addSupport(const QString ¶m, const QString &value = QString());
129 void removeSupport(const QString ¶m);
131 inline void addIrcUser(const QString &hostmask) { newIrcUser(hostmask); }
132 void removeIrcUser(QString nick);
135 QVariantMap initSupports() const;
136 QVariantList initServerList() const;
137 QStringList initIrcUsers() const;
138 QStringList initIrcChannels() const;
141 void initSetSupports(const QVariantMap &supports);
142 void initSetServerList(const QVariantList &serverList);
143 void initSetIrcUsers(const QStringList &hostmasks);
144 void initSetChannels(const QStringList &channels);
146 IrcUser *updateNickFromMask(const QString &mask);
148 // these slots are to keep the hashlists of all users and the
149 // channel lists up to date
150 void ircUserNickChanged(QString newnick);
152 void requestConnect();
153 void requestDisconnect();
156 void ircUserDestroyed();
157 void channelDestroyed();
158 void removeIrcUser(IrcUser *ircuser);
159 void ircUserInitDone();
160 void ircChannelInitDone();
163 void networkNameSet(const QString &networkName);
164 void currentServerSet(const QString ¤tServer);
165 void connectedSet(bool isConnected);
166 void myNickSet(const QString &mynick);
167 void identitySet(IdentityId);
169 void serverListSet(const QList<QVariantMap> &serverList);
171 void codecForEncodingSet(const QString &codecName);
172 void codecForDecodingSet(const QString &codecName);
174 void supportAdded(const QString ¶m, const QString &value);
175 void supportRemoved(const QString ¶m);
177 void ircUserAdded(const QString &hostmask);
178 void ircUserAdded(IrcUser *);
179 void ircChannelAdded(const QString &channelname);
180 void ircChannelAdded(IrcChannel *);
182 void ircUserRemoved(const QString &nick);
184 // needed for client sync progress
185 void ircUserRemoved(QObject *);
186 void ircChannelRemoved(QObject *);
188 void ircUserInitDone(IrcUser *);
189 void ircChannelInitDone(IrcChannel *);
191 void connectRequested(NetworkId = 0);
192 void disconnectRequested(NetworkId = 0);
195 NetworkId _networkId;
196 IdentityId _identity;
199 QString _networkName;
200 QString _currentServer;
204 QString _prefixModes;
206 QHash<QString, IrcUser *> _ircUsers; // stores all known nicks for the server
207 QHash<QString, IrcChannel *> _ircChannels; // stores all known channels
208 QHash<QString, QString> _supports; // stores results from RPL_ISUPPORT
210 QList<QVariantMap> _serverList;
211 QStringList _perform;
212 //QVariantMap networkSettings;
214 QPointer<SignalProxy> _proxy;
215 void determinePrefixes();
217 QTextCodec *_codecForEncoding;
218 QTextCodec *_codecForDecoding;
222 //! Stores all editable information about a network (as opposed to runtime state).
227 QByteArray codecForEncoding;
228 QByteArray codecForDecoding;
229 QList<QVariantMap> serverList;
231 bool operator==(const NetworkInfo &other) const;
232 bool operator!=(const NetworkInfo &other) const;