1 /***************************************************************************
2 * Copyright (C) 2005-09 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 QTextCodec *Network::_defaultCodecForServer = 0;
27 QTextCodec *Network::_defaultCodecForEncoding = 0;
28 QTextCodec *Network::_defaultCodecForDecoding = 0;
29 QString Network::_networksIniPath = QString();
31 // ====================
33 // ====================
34 INIT_SYNCABLE_OBJECT(Network)
35 Network::Network(const NetworkId &networkid, QObject *parent)
36 : SyncableObject(parent),
38 _networkId(networkid),
42 _networkName(QString("<not initialized>")),
43 _currentServer(QString()),
45 _connectionState(Disconnected),
47 _prefixModes(QString()),
48 _useRandomServer(false),
49 _useAutoIdentify(false),
51 _useAutoReconnect(false),
52 _autoReconnectInterval(60),
53 _autoReconnectRetries(10),
54 _unlimitedReconnectRetries(false),
58 _autoAwayActive(false)
60 setObjectName(QString::number(networkid.toInt()));
64 emit aboutToBeDestroyed();
67 bool Network::isChannelName(const QString &channelname) const {
68 if(channelname.isEmpty())
71 if(supports("CHANTYPES"))
72 return support("CHANTYPES").contains(channelname[0]);
74 return QString("#&!+").contains(channelname[0]);
77 NetworkInfo Network::networkInfo() const {
79 info.networkName = networkName();
80 info.networkId = networkId();
81 info.identity = identity();
82 info.codecForServer = codecForServer();
83 info.codecForEncoding = codecForEncoding();
84 info.codecForDecoding = codecForDecoding();
85 info.serverList = serverList();
86 info.useRandomServer = useRandomServer();
87 info.perform = perform();
88 info.useAutoIdentify = useAutoIdentify();
89 info.autoIdentifyService = autoIdentifyService();
90 info.autoIdentifyPassword = autoIdentifyPassword();
91 info.useSasl = useSasl();
92 info.saslAccount = saslAccount();
93 info.saslPassword = saslPassword();
94 info.useAutoReconnect = useAutoReconnect();
95 info.autoReconnectInterval = autoReconnectInterval();
96 info.autoReconnectRetries = autoReconnectRetries();
97 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
98 info.rejoinChannels = rejoinChannels();
102 void Network::setNetworkInfo(const NetworkInfo &info) {
103 // we don't set our ID!
104 if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
105 if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
106 if(info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
107 if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
108 if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
109 if(info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
110 if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
111 if(info.perform != perform()) setPerform(info.perform);
112 if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
113 if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
114 if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
115 if(info.useSasl != useSasl()) setUseSasl(info.useSasl);
116 if(info.saslAccount != saslAccount()) setSaslAccount(info.saslAccount);
117 if(info.saslPassword != saslPassword()) setSaslPassword(info.saslPassword);
118 if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
119 if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
120 if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
121 if(info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
122 if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
125 QString Network::prefixToMode(const QString &prefix) {
126 if(prefixes().contains(prefix))
127 return QString(prefixModes()[prefixes().indexOf(prefix)]);
132 QString Network::modeToPrefix(const QString &mode) {
133 if(prefixModes().contains(mode))
134 return QString(prefixes()[prefixModes().indexOf(mode)]);
139 QStringList Network::nicks() const {
140 // we don't use _ircUsers.keys() since the keys may be
141 // not up to date after a nick change
143 foreach(IrcUser *ircuser, _ircUsers.values()) {
144 nicks << ircuser->nick();
149 QString Network::prefixes() {
150 if(_prefixes.isNull())
156 QString Network::prefixModes() {
157 if(_prefixModes.isNull())
163 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
164 Network::ChannelModeType Network::channelModeType(const QString &mode) {
166 return NOT_A_CHANMODE;
168 QString chanmodes = support("CHANMODES");
169 if(chanmodes.isEmpty())
170 return NOT_A_CHANMODE;
172 ChannelModeType modeType = A_CHANMODE;
173 for(int i = 0; i < chanmodes.count(); i++) {
174 if(chanmodes[i] == mode[0])
176 else if(chanmodes[i] == ',')
177 modeType = (ChannelModeType)(modeType << 1);
179 if(modeType > D_CHANMODE) {
180 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
181 modeType = NOT_A_CHANMODE;
186 QString Network::support(const QString ¶m) const {
187 QString support_ = param.toUpper();
188 if(_supports.contains(support_))
189 return _supports[support_];
194 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) {
195 QString nick(nickFromMask(hostmask).toLower());
196 if(!_ircUsers.contains(nick)) {
197 IrcUser *ircuser = new IrcUser(hostmask, this);
198 if(!initData.isEmpty()) {
199 ircuser->fromVariantMap(initData);
200 ircuser->setInitialized();
204 proxy()->synchronize(ircuser);
206 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
208 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
210 _ircUsers[nick] = ircuser;
212 SYNC_OTHER(addIrcUser, ARG(hostmask))
213 // emit ircUserAdded(hostmask);
214 emit ircUserAdded(ircuser);
217 return _ircUsers[nick];
220 IrcUser *Network::ircUser(QString nickname) const {
221 nickname = nickname.toLower();
222 if(_ircUsers.contains(nickname))
223 return _ircUsers[nickname];
228 void Network::removeIrcUser(IrcUser *ircuser) {
229 QString nick = _ircUsers.key(ircuser);
233 _ircUsers.remove(nick);
234 disconnect(ircuser, 0, this, 0);
235 ircuser->deleteLater();
238 void Network::removeIrcChannel(IrcChannel *channel) {
239 QString chanName = _ircChannels.key(channel);
240 if(chanName.isNull())
243 _ircChannels.remove(chanName);
244 disconnect(channel, 0, this, 0);
245 channel->deleteLater();
248 void Network::removeChansAndUsers() {
249 QList<IrcUser *> users = ircUsers();
251 QList<IrcChannel *> channels = ircChannels();
252 _ircChannels.clear();
254 foreach(IrcChannel *channel, channels) {
255 proxy()->detachObject(channel);
256 disconnect(channel, 0, this, 0);
258 foreach(IrcUser *user, users) {
259 proxy()->detachObject(user);
260 disconnect(user, 0, this, 0);
263 // the second loop is needed because quit can have sideffects
264 foreach(IrcUser *user, users) {
269 qDeleteAll(channels);
272 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) {
273 if(!_ircChannels.contains(channelname.toLower())) {
274 IrcChannel *channel = ircChannelFactory(channelname);
275 if(!initData.isEmpty()) {
276 channel->fromVariantMap(initData);
277 channel->setInitialized();
281 proxy()->synchronize(channel);
283 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
285 _ircChannels[channelname.toLower()] = channel;
287 SYNC_OTHER(addIrcChannel, ARG(channelname))
288 // emit ircChannelAdded(channelname);
289 emit ircChannelAdded(channel);
291 return _ircChannels[channelname.toLower()];
294 IrcChannel *Network::ircChannel(QString channelname) const {
295 channelname = channelname.toLower();
296 if(_ircChannels.contains(channelname))
297 return _ircChannels[channelname];
302 QByteArray Network::defaultCodecForServer() {
303 if(_defaultCodecForServer)
304 return _defaultCodecForServer->name();
308 void Network::setDefaultCodecForServer(const QByteArray &name) {
309 _defaultCodecForServer = QTextCodec::codecForName(name);
312 QByteArray Network::defaultCodecForEncoding() {
313 if(_defaultCodecForEncoding)
314 return _defaultCodecForEncoding->name();
318 void Network::setDefaultCodecForEncoding(const QByteArray &name) {
319 _defaultCodecForEncoding = QTextCodec::codecForName(name);
322 QByteArray Network::defaultCodecForDecoding() {
323 if(_defaultCodecForDecoding)
324 return _defaultCodecForDecoding->name();
328 void Network::setDefaultCodecForDecoding(const QByteArray &name) {
329 _defaultCodecForDecoding = QTextCodec::codecForName(name);
332 QByteArray Network::codecForServer() const {
334 return _codecForServer->name();
338 void Network::setCodecForServer(const QByteArray &name) {
339 setCodecForServer(QTextCodec::codecForName(name));
342 void Network::setCodecForServer(QTextCodec *codec) {
343 _codecForServer = codec;
344 QByteArray codecName = codecForServer();
345 SYNC_OTHER(setCodecForServer, ARG(codecName))
346 emit configChanged();
349 QByteArray Network::codecForEncoding() const {
350 if(_codecForEncoding)
351 return _codecForEncoding->name();
355 void Network::setCodecForEncoding(const QByteArray &name) {
356 setCodecForEncoding(QTextCodec::codecForName(name));
359 void Network::setCodecForEncoding(QTextCodec *codec) {
360 _codecForEncoding = codec;
361 QByteArray codecName = codecForEncoding();
362 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
363 emit configChanged();
366 QByteArray Network::codecForDecoding() const {
367 if(_codecForDecoding)
368 return _codecForDecoding->name();
369 else return QByteArray();
372 void Network::setCodecForDecoding(const QByteArray &name) {
373 setCodecForDecoding(QTextCodec::codecForName(name));
376 void Network::setCodecForDecoding(QTextCodec *codec) {
377 _codecForDecoding = codec;
378 QByteArray codecName = codecForDecoding();
379 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
380 emit configChanged();
383 // FIXME use server encoding if appropriate
384 QString Network::decodeString(const QByteArray &text) const {
385 if(_codecForDecoding)
386 return ::decodeString(text, _codecForDecoding);
387 else return ::decodeString(text, _defaultCodecForDecoding);
390 QByteArray Network::encodeString(const QString &string) const {
391 if(_codecForEncoding) {
392 return _codecForEncoding->fromUnicode(string);
394 if(_defaultCodecForEncoding) {
395 return _defaultCodecForEncoding->fromUnicode(string);
397 return string.toAscii();
400 QString Network::decodeServerString(const QByteArray &text) const {
402 return ::decodeString(text, _codecForServer);
404 return ::decodeString(text, _defaultCodecForServer);
407 QByteArray Network::encodeServerString(const QString &string) const {
408 if(_codecForServer) {
409 return _codecForServer->fromUnicode(string);
411 if(_defaultCodecForServer) {
412 return _defaultCodecForServer->fromUnicode(string);
414 return string.toAscii();
417 /*** Handle networks.ini ***/
419 QStringList Network::presetNetworks(bool onlyDefault) {
420 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
421 if(_networksIniPath.isNull()) {
422 _networksIniPath = Quassel::findDataFilePath("networks.ini");
423 if(_networksIniPath.isNull()) {
424 _networksIniPath = ""; // now we won't check again, as it's not null anymore
425 return QStringList();
428 if(!_networksIniPath.isEmpty()) {
429 QSettings s(_networksIniPath, QSettings::IniFormat);
430 QStringList networks = s.childGroups();
431 if(!networks.isEmpty()) {
432 // we sort the list case-insensitive
433 QMap<QString, QString> sorted;
434 foreach(QString net, networks) {
435 if(onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
437 sorted[net.toLower()] = net;
439 return sorted.values();
442 return QStringList();
445 QStringList Network::presetDefaultChannels(const QString &networkName) {
446 if(_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
447 return QStringList();
448 QSettings s(_networksIniPath, QSettings::IniFormat);
449 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
452 NetworkInfo Network::networkInfoFromPreset(const QString &networkName) {
454 if(!_networksIniPath.isEmpty()) {
455 info.networkName = networkName;
456 QSettings s(_networksIniPath, QSettings::IniFormat);
457 s.beginGroup(info.networkName);
458 foreach(QString server, s.value("Servers").toStringList()) {
460 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
461 if(splitserver.count() != 2) {
462 qWarning() << "Invalid server entry in networks.conf:" << server;
465 if(splitserver[1].at(0) == '+')
467 uint port = splitserver[1].toUInt();
469 qWarning() << "Invalid port entry in networks.conf:" << server;
472 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
478 QByteArray Network::bufferKey(const QString &recipient) const {
479 return _keyHash[recipient.toLower()];
482 void Network::setBufferKey(const QString &recipient, const QByteArray &key) {
483 _keyHash[recipient.toLower()] = key;
486 // ====================
488 // ====================
489 void Network::setNetworkName(const QString &networkName) {
490 _networkName = networkName;
491 SYNC(ARG(networkName))
492 emit networkNameSet(networkName);
493 emit configChanged();
496 void Network::setCurrentServer(const QString ¤tServer) {
497 _currentServer = currentServer;
498 SYNC(ARG(currentServer))
499 emit currentServerSet(currentServer);
502 void Network::setConnected(bool connected) {
503 if(_connected == connected)
506 _connected = connected;
508 setMyNick(QString());
509 setCurrentServer(QString());
510 removeChansAndUsers();
513 emit connectedSet(connected);
516 //void Network::setConnectionState(ConnectionState state) {
517 void Network::setConnectionState(int state) {
518 _connectionState = (ConnectionState)state;
519 //qDebug() << "netstate" << networkId() << networkName() << state;
521 emit connectionStateSet(_connectionState);
524 void Network::setMyNick(const QString &nickname) {
526 if(!_myNick.isEmpty() && !ircUser(myNick())) {
527 newIrcUser(myNick());
530 emit myNickSet(nickname);
533 void Network::setLatency(int latency) {
534 if(_latency == latency)
540 void Network::setIdentity(IdentityId id) {
543 emit identitySet(id);
544 emit configChanged();
547 void Network::setServerList(const QVariantList &serverList) {
548 _serverList = fromVariantList<Server>(serverList);
549 SYNC(ARG(serverList))
550 emit configChanged();
553 void Network::setUseRandomServer(bool use) {
554 _useRandomServer = use;
556 emit configChanged();
559 void Network::setPerform(const QStringList &perform) {
562 emit configChanged();
565 void Network::setUseAutoIdentify(bool use) {
566 _useAutoIdentify = use;
568 emit configChanged();
571 void Network::setAutoIdentifyService(const QString &service) {
572 _autoIdentifyService = service;
574 emit configChanged();
577 void Network::setAutoIdentifyPassword(const QString &password) {
578 _autoIdentifyPassword = password;
580 emit configChanged();
583 void Network::setUseSasl(bool use) {
586 emit configChanged();
589 void Network::setSaslAccount(const QString &account) {
590 _saslAccount = account;
592 emit configChanged();
595 void Network::setSaslPassword(const QString &password) {
596 _saslPassword = password;
598 emit configChanged();
601 void Network::setUseAutoReconnect(bool use) {
602 _useAutoReconnect = use;
604 emit configChanged();
607 void Network::setAutoReconnectInterval(quint32 interval) {
608 _autoReconnectInterval = interval;
610 emit configChanged();
613 void Network::setAutoReconnectRetries(quint16 retries) {
614 _autoReconnectRetries = retries;
616 emit configChanged();
619 void Network::setUnlimitedReconnectRetries(bool unlimited) {
620 _unlimitedReconnectRetries = unlimited;
622 emit configChanged();
625 void Network::setRejoinChannels(bool rejoin) {
626 _rejoinChannels = rejoin;
628 emit configChanged();
631 void Network::addSupport(const QString ¶m, const QString &value) {
632 if(!_supports.contains(param)) {
633 _supports[param] = value;
634 SYNC(ARG(param), ARG(value))
638 void Network::removeSupport(const QString ¶m) {
639 if(_supports.contains(param)) {
640 _supports.remove(param);
645 QVariantMap Network::initSupports() const {
646 QVariantMap supports;
647 QHashIterator<QString, QString> iter(_supports);
648 while(iter.hasNext()) {
650 supports[iter.key()] = iter.value();
655 QVariantMap Network::initIrcUsersAndChannels() const {
656 QVariantMap usersAndChannels;
658 QVariantMap channels;
660 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
661 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
662 while(userIter != userIterEnd) {
663 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
666 usersAndChannels["users"] = users;
668 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
669 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
670 while(channelIter != channelIterEnd) {
671 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
674 usersAndChannels["channels"] = channels;
676 return usersAndChannels;
679 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
681 if(isInitialized()) {
682 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
686 QVariantMap users = usersAndChannels.value("users").toMap();
687 QVariantMap::const_iterator userIter = users.constBegin();
688 QVariantMap::const_iterator userIterEnd = users.constEnd();
689 while(userIter != userIterEnd) {
690 newIrcUser(userIter.key(), userIter.value().toMap());
694 QVariantMap channels = usersAndChannels.value("channels").toMap();
695 QVariantMap::const_iterator channelIter = channels.constBegin();
696 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
697 while(channelIter != channelIterEnd) {
698 newIrcChannel(channelIter.key(), channelIter.value().toMap());
703 void Network::initSetSupports(const QVariantMap &supports) {
704 QMapIterator<QString, QVariant> iter(supports);
705 while(iter.hasNext()) {
707 addSupport(iter.key(), iter.value().toString());
711 IrcUser *Network::updateNickFromMask(const QString &mask) {
712 QString nick(nickFromMask(mask).toLower());
715 if(_ircUsers.contains(nick)) {
716 ircuser = _ircUsers[nick];
717 ircuser->updateHostmask(mask);
719 ircuser = newIrcUser(mask);
724 void Network::ircUserNickChanged(QString newnick) {
725 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
730 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
732 if(myNick().toLower() == oldnick)
736 void Network::emitConnectionError(const QString &errorMsg) {
737 emit connectionError(errorMsg);
740 // ====================
742 // ====================
743 void Network::determinePrefixes() {
744 // seems like we have to construct them first
745 QString prefix = support("PREFIX");
747 if(prefix.startsWith("(") && prefix.contains(")")) {
748 _prefixes = prefix.section(")", 1);
749 _prefixModes = prefix.mid(1).section(")", 0, 0);
751 QString defaultPrefixes("~&@%+");
752 QString defaultPrefixModes("qaohv");
754 if(prefix.isEmpty()) {
755 _prefixes = defaultPrefixes;
756 _prefixModes = defaultPrefixModes;
760 // we just assume that in PREFIX are only prefix chars stored
761 for(int i = 0; i < defaultPrefixes.size(); i++) {
762 if(prefix.contains(defaultPrefixes[i])) {
763 _prefixes += defaultPrefixes[i];
764 _prefixModes += defaultPrefixModes[i];
768 if(!_prefixes.isNull())
771 // well... our assumption was obviously wrong...
772 // check if it's only prefix modes
773 for(int i = 0; i < defaultPrefixes.size(); i++) {
774 if(prefix.contains(defaultPrefixModes[i])) {
775 _prefixes += defaultPrefixes[i];
776 _prefixModes += defaultPrefixModes[i];
779 // now we've done all we've could...
783 /************************************************************************
785 ************************************************************************/
787 NetworkInfo::NetworkInfo()
790 useRandomServer(false),
791 useAutoIdentify(false),
792 autoIdentifyService("NickServ"),
794 useAutoReconnect(true),
795 autoReconnectInterval(60),
796 autoReconnectRetries(20),
797 unlimitedReconnectRetries(false),
803 bool NetworkInfo::operator==(const NetworkInfo &other) const {
804 if(networkId != other.networkId) return false;
805 if(networkName != other.networkName) return false;
806 if(identity != other.identity) return false;
807 if(codecForServer != other.codecForServer) return false;
808 if(codecForEncoding != other.codecForEncoding) return false;
809 if(codecForDecoding != other.codecForDecoding) return false;
810 if(serverList != other.serverList) return false;
811 if(useRandomServer != other.useRandomServer) return false;
812 if(perform != other.perform) return false;
813 if(useAutoIdentify != other.useAutoIdentify) return false;
814 if(autoIdentifyService != other.autoIdentifyService) return false;
815 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
816 if(useSasl != other.useSasl) return false;
817 if(saslAccount != other.saslAccount) return false;
818 if(saslPassword != other.saslPassword) return false;
819 if(useAutoReconnect != other.useAutoReconnect) return false;
820 if(autoReconnectInterval != other.autoReconnectInterval) return false;
821 if(autoReconnectRetries != other.autoReconnectRetries) return false;
822 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
823 if(rejoinChannels != other.rejoinChannels) return false;
827 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
828 return !(*this == other);
831 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
833 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
834 i["NetworkName"] = info.networkName;
835 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
836 i["CodecForServer"] = info.codecForServer;
837 i["CodecForEncoding"] = info.codecForEncoding;
838 i["CodecForDecoding"] = info.codecForDecoding;
839 i["ServerList"] = toVariantList(info.serverList);
840 i["UseRandomServer"] = info.useRandomServer;
841 i["Perform"] = info.perform;
842 i["UseAutoIdentify"] = info.useAutoIdentify;
843 i["AutoIdentifyService"] = info.autoIdentifyService;
844 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
845 i["UseSasl"] = info.useSasl;
846 i["SaslAccount"] = info.saslAccount;
847 i["SaslPassword"] = info.saslPassword;
848 i["UseAutoReconnect"] = info.useAutoReconnect;
849 i["AutoReconnectInterval"] = info.autoReconnectInterval;
850 i["AutoReconnectRetries"] = info.autoReconnectRetries;
851 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
852 i["RejoinChannels"] = info.rejoinChannels;
857 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
860 info.networkId = i["NetworkId"].value<NetworkId>();
861 info.networkName = i["NetworkName"].toString();
862 info.identity = i["Identity"].value<IdentityId>();
863 info.codecForServer = i["CodecForServer"].toByteArray();
864 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
865 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
866 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
867 info.useRandomServer = i["UseRandomServer"].toBool();
868 info.perform = i["Perform"].toStringList();
869 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
870 info.autoIdentifyService = i["AutoIdentifyService"].toString();
871 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
872 info.useSasl = i["UseSasl"].toBool();
873 info.saslAccount = i["SaslAccount"].toString();
874 info.saslPassword = i["SaslPassword"].toString();
875 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
876 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
877 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
878 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
879 info.rejoinChannels = i["RejoinChannels"].toBool();
883 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
884 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
885 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
886 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
887 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
888 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
889 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
890 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
891 << " rejoinChannels = " << i.rejoinChannels << ")";
895 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
896 QVariantMap serverMap;
897 serverMap["Host"] = server.host;
898 serverMap["Port"] = server.port;
899 serverMap["Password"] = server.password;
900 serverMap["UseSSL"] = server.useSsl;
901 serverMap["sslVersion"] = server.sslVersion;
902 serverMap["UseProxy"] = server.useProxy;
903 serverMap["ProxyType"] = server.proxyType;
904 serverMap["ProxyHost"] = server.proxyHost;
905 serverMap["ProxyPort"] = server.proxyPort;
906 serverMap["ProxyUser"] = server.proxyUser;
907 serverMap["ProxyPass"] = server.proxyPass;
912 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
913 QVariantMap serverMap;
915 server.host = serverMap["Host"].toString();
916 server.port = serverMap["Port"].toUInt();
917 server.password = serverMap["Password"].toString();
918 server.useSsl = serverMap["UseSSL"].toBool();
919 server.sslVersion = serverMap["sslVersion"].toInt();
920 server.useProxy = serverMap["UseProxy"].toBool();
921 server.proxyType = serverMap["ProxyType"].toInt();
922 server.proxyHost = serverMap["ProxyHost"].toString();
923 server.proxyPort = serverMap["ProxyPort"].toUInt();
924 server.proxyUser = serverMap["ProxyUser"].toString();
925 server.proxyPass = serverMap["ProxyPass"].toString();
930 bool Network::Server::operator==(const Server &other) const {
931 if(host != other.host) return false;
932 if(port != other.port) return false;
933 if(password != other.password) return false;
934 if(useSsl != other.useSsl) return false;
935 if(sslVersion != other.sslVersion) return false;
936 if(useProxy != other.useProxy) return false;
937 if(proxyType != other.proxyType) return false;
938 if(proxyHost != other.proxyHost) return false;
939 if(proxyPort != other.proxyPort) return false;
940 if(proxyUser != other.proxyUser) return false;
941 if(proxyPass != other.proxyPass) return false;
945 bool Network::Server::operator!=(const Server &other) const {
946 return !(*this == other);
949 QDebug operator<<(QDebug dbg, const Network::Server &server) {
950 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";