1 /***************************************************************************
2 * Copyright (C) 2005-2015 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
25 QTextCodec *Network::_defaultCodecForServer = 0;
26 QTextCodec *Network::_defaultCodecForEncoding = 0;
27 QTextCodec *Network::_defaultCodecForDecoding = 0;
29 // ====================
31 // ====================
32 INIT_SYNCABLE_OBJECT(Network)
33 Network::Network(const NetworkId &networkid, QObject *parent)
34 : SyncableObject(parent),
36 _networkId(networkid),
40 _networkName(QString("<not initialized>")),
41 _currentServer(QString()),
43 _connectionState(Disconnected),
45 _prefixModes(QString()),
46 _useRandomServer(false),
47 _useAutoIdentify(false),
49 _useAutoReconnect(false),
50 _autoReconnectInterval(60),
51 _autoReconnectRetries(10),
52 _unlimitedReconnectRetries(false),
56 _autoAwayActive(false)
58 setObjectName(QString::number(networkid.toInt()));
64 emit aboutToBeDestroyed();
68 bool Network::isChannelName(const QString &channelname) const
70 if (channelname.isEmpty())
73 if (supports("CHANTYPES"))
74 return support("CHANTYPES").contains(channelname[0]);
76 return QString("#&!+").contains(channelname[0]);
80 NetworkInfo Network::networkInfo() const
83 info.networkName = networkName();
84 info.networkId = networkId();
85 info.identity = identity();
86 info.codecForServer = codecForServer();
87 info.codecForEncoding = codecForEncoding();
88 info.codecForDecoding = codecForDecoding();
89 info.serverList = serverList();
90 info.useRandomServer = useRandomServer();
91 info.perform = perform();
92 info.useAutoIdentify = useAutoIdentify();
93 info.autoIdentifyService = autoIdentifyService();
94 info.autoIdentifyPassword = autoIdentifyPassword();
95 info.useSasl = useSasl();
96 info.saslAccount = saslAccount();
97 info.saslPassword = saslPassword();
98 info.useAutoReconnect = useAutoReconnect();
99 info.autoReconnectInterval = autoReconnectInterval();
100 info.autoReconnectRetries = autoReconnectRetries();
101 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
102 info.rejoinChannels = rejoinChannels();
107 void Network::setNetworkInfo(const NetworkInfo &info)
109 // we don't set our ID!
110 if (!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
111 if (info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
112 if (info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
113 if (info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
114 if (info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
115 if (info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
116 if (info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
117 if (info.perform != perform()) setPerform(info.perform);
118 if (info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
119 if (info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
120 if (info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
121 if (info.useSasl != useSasl()) setUseSasl(info.useSasl);
122 if (info.saslAccount != saslAccount()) setSaslAccount(info.saslAccount);
123 if (info.saslPassword != saslPassword()) setSaslPassword(info.saslPassword);
124 if (info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
125 if (info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
126 if (info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
127 if (info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
128 if (info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
132 QString Network::prefixToMode(const QString &prefix) const
134 if (prefixes().contains(prefix))
135 return QString(prefixModes()[prefixes().indexOf(prefix)]);
141 QString Network::modeToPrefix(const QString &mode) const
143 if (prefixModes().contains(mode))
144 return QString(prefixes()[prefixModes().indexOf(mode)]);
150 QStringList Network::nicks() const
152 // we don't use _ircUsers.keys() since the keys may be
153 // not up to date after a nick change
155 foreach(IrcUser *ircuser, _ircUsers.values()) {
156 nicks << ircuser->nick();
162 QString Network::prefixes() const
164 if (_prefixes.isNull())
171 QString Network::prefixModes() const
173 if (_prefixModes.isNull())
180 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
181 Network::ChannelModeType Network::channelModeType(const QString &mode)
184 return NOT_A_CHANMODE;
186 QString chanmodes = support("CHANMODES");
187 if (chanmodes.isEmpty())
188 return NOT_A_CHANMODE;
190 ChannelModeType modeType = A_CHANMODE;
191 for (int i = 0; i < chanmodes.count(); i++) {
192 if (chanmodes[i] == mode[0])
194 else if (chanmodes[i] == ',')
195 modeType = (ChannelModeType)(modeType << 1);
197 if (modeType > D_CHANMODE) {
198 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
199 modeType = NOT_A_CHANMODE;
205 QString Network::support(const QString ¶m) const
207 QString support_ = param.toUpper();
208 if (_supports.contains(support_))
209 return _supports[support_];
215 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData)
217 QString nick(nickFromMask(hostmask).toLower());
218 if (!_ircUsers.contains(nick)) {
219 IrcUser *ircuser = ircUserFactory(hostmask);
220 if (!initData.isEmpty()) {
221 ircuser->fromVariantMap(initData);
222 ircuser->setInitialized();
226 proxy()->synchronize(ircuser);
228 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
230 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
232 _ircUsers[nick] = ircuser;
234 // This method will be called with a nick instead of hostmask by setInitIrcUsersAndChannels().
235 // Not a problem because initData contains all we need; however, making sure here to get the real
236 // hostmask out of the IrcUser afterwards.
237 QString mask = ircuser->hostmask();
238 SYNC_OTHER(addIrcUser, ARG(mask));
239 // emit ircUserAdded(mask);
240 emit ircUserAdded(ircuser);
243 return _ircUsers[nick];
247 IrcUser *Network::ircUser(QString nickname) const
249 nickname = nickname.toLower();
250 if (_ircUsers.contains(nickname))
251 return _ircUsers[nickname];
257 void Network::removeIrcUser(IrcUser *ircuser)
259 QString nick = _ircUsers.key(ircuser);
263 _ircUsers.remove(nick);
264 disconnect(ircuser, 0, this, 0);
265 ircuser->deleteLater();
269 void Network::removeIrcChannel(IrcChannel *channel)
271 QString chanName = _ircChannels.key(channel);
272 if (chanName.isNull())
275 _ircChannels.remove(chanName);
276 disconnect(channel, 0, this, 0);
277 channel->deleteLater();
281 void Network::removeChansAndUsers()
283 QList<IrcUser *> users = ircUsers();
285 QList<IrcChannel *> channels = ircChannels();
286 _ircChannels.clear();
289 qDeleteAll(channels);
293 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData)
295 if (!_ircChannels.contains(channelname.toLower())) {
296 IrcChannel *channel = ircChannelFactory(channelname);
297 if (!initData.isEmpty()) {
298 channel->fromVariantMap(initData);
299 channel->setInitialized();
303 proxy()->synchronize(channel);
305 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
307 _ircChannels[channelname.toLower()] = channel;
309 SYNC_OTHER(addIrcChannel, ARG(channelname))
310 // emit ircChannelAdded(channelname);
311 emit ircChannelAdded(channel);
313 return _ircChannels[channelname.toLower()];
317 IrcChannel *Network::ircChannel(QString channelname) const
319 channelname = channelname.toLower();
320 if (_ircChannels.contains(channelname))
321 return _ircChannels[channelname];
327 QByteArray Network::defaultCodecForServer()
329 if (_defaultCodecForServer)
330 return _defaultCodecForServer->name();
335 void Network::setDefaultCodecForServer(const QByteArray &name)
337 _defaultCodecForServer = QTextCodec::codecForName(name);
341 QByteArray Network::defaultCodecForEncoding()
343 if (_defaultCodecForEncoding)
344 return _defaultCodecForEncoding->name();
349 void Network::setDefaultCodecForEncoding(const QByteArray &name)
351 _defaultCodecForEncoding = QTextCodec::codecForName(name);
355 QByteArray Network::defaultCodecForDecoding()
357 if (_defaultCodecForDecoding)
358 return _defaultCodecForDecoding->name();
363 void Network::setDefaultCodecForDecoding(const QByteArray &name)
365 _defaultCodecForDecoding = QTextCodec::codecForName(name);
369 QByteArray Network::codecForServer() const
372 return _codecForServer->name();
377 void Network::setCodecForServer(const QByteArray &name)
379 setCodecForServer(QTextCodec::codecForName(name));
383 void Network::setCodecForServer(QTextCodec *codec)
385 _codecForServer = codec;
386 QByteArray codecName = codecForServer();
387 SYNC_OTHER(setCodecForServer, ARG(codecName))
388 emit configChanged();
392 QByteArray Network::codecForEncoding() const
394 if (_codecForEncoding)
395 return _codecForEncoding->name();
400 void Network::setCodecForEncoding(const QByteArray &name)
402 setCodecForEncoding(QTextCodec::codecForName(name));
406 void Network::setCodecForEncoding(QTextCodec *codec)
408 _codecForEncoding = codec;
409 QByteArray codecName = codecForEncoding();
410 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
411 emit configChanged();
415 QByteArray Network::codecForDecoding() const
417 if (_codecForDecoding)
418 return _codecForDecoding->name();
419 else return QByteArray();
423 void Network::setCodecForDecoding(const QByteArray &name)
425 setCodecForDecoding(QTextCodec::codecForName(name));
429 void Network::setCodecForDecoding(QTextCodec *codec)
431 _codecForDecoding = codec;
432 QByteArray codecName = codecForDecoding();
433 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
434 emit configChanged();
438 // FIXME use server encoding if appropriate
439 QString Network::decodeString(const QByteArray &text) const
441 if (_codecForDecoding)
442 return ::decodeString(text, _codecForDecoding);
443 else return ::decodeString(text, _defaultCodecForDecoding);
447 QByteArray Network::encodeString(const QString &string) const
449 if (_codecForEncoding) {
450 return _codecForEncoding->fromUnicode(string);
452 if (_defaultCodecForEncoding) {
453 return _defaultCodecForEncoding->fromUnicode(string);
455 return string.toLatin1();
459 QString Network::decodeServerString(const QByteArray &text) const
462 return ::decodeString(text, _codecForServer);
464 return ::decodeString(text, _defaultCodecForServer);
468 QByteArray Network::encodeServerString(const QString &string) const
470 if (_codecForServer) {
471 return _codecForServer->fromUnicode(string);
473 if (_defaultCodecForServer) {
474 return _defaultCodecForServer->fromUnicode(string);
476 return string.toLatin1();
480 // ====================
482 // ====================
483 void Network::setNetworkName(const QString &networkName)
485 _networkName = networkName;
486 SYNC(ARG(networkName))
487 emit networkNameSet(networkName);
488 emit configChanged();
492 void Network::setCurrentServer(const QString ¤tServer)
494 _currentServer = currentServer;
495 SYNC(ARG(currentServer))
496 emit currentServerSet(currentServer);
500 void Network::setConnected(bool connected)
502 if (_connected == connected)
505 _connected = connected;
507 setMyNick(QString());
508 setCurrentServer(QString());
509 removeChansAndUsers();
512 emit connectedSet(connected);
516 //void Network::setConnectionState(ConnectionState state) {
517 void Network::setConnectionState(int state)
519 _connectionState = (ConnectionState)state;
520 //qDebug() << "netstate" << networkId() << networkName() << state;
522 emit connectionStateSet(_connectionState);
526 void Network::setMyNick(const QString &nickname)
529 if (!_myNick.isEmpty() && !ircUser(myNick())) {
530 newIrcUser(myNick());
533 emit myNickSet(nickname);
537 void Network::setLatency(int latency)
539 if (_latency == latency)
546 void Network::setIdentity(IdentityId id)
550 emit identitySet(id);
551 emit configChanged();
555 void Network::setServerList(const QVariantList &serverList)
557 _serverList = fromVariantList<Server>(serverList);
558 SYNC(ARG(serverList))
559 emit configChanged();
563 void Network::setUseRandomServer(bool use)
565 _useRandomServer = use;
567 emit configChanged();
571 void Network::setPerform(const QStringList &perform)
575 emit configChanged();
579 void Network::setUseAutoIdentify(bool use)
581 _useAutoIdentify = use;
583 emit configChanged();
587 void Network::setAutoIdentifyService(const QString &service)
589 _autoIdentifyService = service;
591 emit configChanged();
595 void Network::setAutoIdentifyPassword(const QString &password)
597 _autoIdentifyPassword = password;
599 emit configChanged();
603 void Network::setUseSasl(bool use)
607 emit configChanged();
611 void Network::setSaslAccount(const QString &account)
613 _saslAccount = account;
615 emit configChanged();
619 void Network::setSaslPassword(const QString &password)
621 _saslPassword = password;
623 emit configChanged();
627 void Network::setUseAutoReconnect(bool use)
629 _useAutoReconnect = use;
631 emit configChanged();
635 void Network::setAutoReconnectInterval(quint32 interval)
637 _autoReconnectInterval = interval;
639 emit configChanged();
643 void Network::setAutoReconnectRetries(quint16 retries)
645 _autoReconnectRetries = retries;
647 emit configChanged();
651 void Network::setUnlimitedReconnectRetries(bool unlimited)
653 _unlimitedReconnectRetries = unlimited;
655 emit configChanged();
659 void Network::setRejoinChannels(bool rejoin)
661 _rejoinChannels = rejoin;
663 emit configChanged();
667 void Network::addSupport(const QString ¶m, const QString &value)
669 if (!_supports.contains(param)) {
670 _supports[param] = value;
671 SYNC(ARG(param), ARG(value))
676 void Network::removeSupport(const QString ¶m)
678 if (_supports.contains(param)) {
679 _supports.remove(param);
685 QVariantMap Network::initSupports() const
687 QVariantMap supports;
688 QHashIterator<QString, QString> iter(_supports);
689 while (iter.hasNext()) {
691 supports[iter.key()] = iter.value();
697 // There's potentially a lot of users and channels, so it makes sense to optimize the format of this.
698 // Rather than sending a thousand maps with identical keys, we convert this into one map containing lists
699 // where each list index corresponds to a particular IrcUser. This saves sending the key names a thousand times.
700 // Benchmarks have shown space savings of around 56%, resulting in saving several MBs worth of data on sync
701 // (without compression) with a decent amount of IrcUsers.
702 QVariantMap Network::initIrcUsersAndChannels() const
704 QVariantMap usersAndChannels;
706 if (_ircUsers.count()) {
707 QHash<QString, QVariantList> users;
708 QHash<QString, IrcUser *>::const_iterator it = _ircUsers.begin();
709 QHash<QString, IrcUser *>::const_iterator end = _ircUsers.end();
711 const QVariantMap &map = it.value()->toVariantMap();
712 QVariantMap::const_iterator mapiter = map.begin();
713 while (mapiter != map.end()) {
714 users[mapiter.key()] << mapiter.value();
719 // Can't have a container with a value type != QVariant in a QVariant :(
720 // However, working directly on a QVariantMap is awkward for appending, thus the detour via the hash above.
722 foreach(const QString &key, users.keys())
723 userMap[key] = users[key];
724 usersAndChannels["Users"] = userMap;
727 if (_ircChannels.count()) {
728 QHash<QString, QVariantList> channels;
729 QHash<QString, IrcChannel *>::const_iterator it = _ircChannels.begin();
730 QHash<QString, IrcChannel *>::const_iterator end = _ircChannels.end();
732 const QVariantMap &map = it.value()->toVariantMap();
733 QVariantMap::const_iterator mapiter = map.begin();
734 while (mapiter != map.end()) {
735 channels[mapiter.key()] << mapiter.value();
740 QVariantMap channelMap;
741 foreach(const QString &key, channels.keys())
742 channelMap[key] = channels[key];
743 usersAndChannels["Channels"] = channelMap;
746 return usersAndChannels;
750 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels)
753 if (isInitialized()) {
754 qWarning() << "Network" << networkId() << "received init data for users and channels although there already are known users or channels!";
758 // toMap() and toList() are cheap, so we can avoid copying to lists...
759 // However, we really have to make sure to never accidentally detach from the shared data!
761 const QVariantMap &users = usersAndChannels["Users"].toMap();
764 int count = users["nick"].toList().count();
765 foreach(const QString &key, users.keys()) {
766 if (users[key].toList().count() != count) {
767 qWarning() << "Received invalid usersAndChannels init data, sizes of attribute lists don't match!";
772 // now create the individual IrcUsers
773 for(int i = 0; i < count; i++) {
775 foreach(const QString &key, users.keys())
776 map[key] = users[key].toList().at(i);
777 newIrcUser(map["nick"].toString(), map); // newIrcUser() properly handles the hostmask being just the nick
780 // same thing for IrcChannels
781 const QVariantMap &channels = usersAndChannels["Channels"].toMap();
784 count = channels["name"].toList().count();
785 foreach(const QString &key, channels.keys()) {
786 if (channels[key].toList().count() != count) {
787 qWarning() << "Received invalid usersAndChannels init data, sizes of attribute lists don't match!";
791 // now create the individual IrcChannels
792 for(int i = 0; i < count; i++) {
794 foreach(const QString &key, channels.keys())
795 map[key] = channels[key].toList().at(i);
796 newIrcChannel(map["name"].toString(), map);
801 void Network::initSetSupports(const QVariantMap &supports)
803 QMapIterator<QString, QVariant> iter(supports);
804 while (iter.hasNext()) {
806 addSupport(iter.key(), iter.value().toString());
811 IrcUser *Network::updateNickFromMask(const QString &mask)
813 QString nick(nickFromMask(mask).toLower());
816 if (_ircUsers.contains(nick)) {
817 ircuser = _ircUsers[nick];
818 ircuser->updateHostmask(mask);
821 ircuser = newIrcUser(mask);
827 void Network::ircUserNickChanged(QString newnick)
829 QString oldnick = _ircUsers.key(qobject_cast<IrcUser *>(sender()));
831 if (oldnick.isNull())
834 if (newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
836 if (myNick().toLower() == oldnick)
841 void Network::emitConnectionError(const QString &errorMsg)
843 emit connectionError(errorMsg);
847 // ====================
849 // ====================
850 void Network::determinePrefixes() const
852 // seems like we have to construct them first
853 QString prefix = support("PREFIX");
855 if (prefix.startsWith("(") && prefix.contains(")")) {
856 _prefixes = prefix.section(")", 1);
857 _prefixModes = prefix.mid(1).section(")", 0, 0);
860 QString defaultPrefixes("~&@%+");
861 QString defaultPrefixModes("qaohv");
863 if (prefix.isEmpty()) {
864 _prefixes = defaultPrefixes;
865 _prefixModes = defaultPrefixModes;
868 // clear the existing modes, just in case we're run multiple times
869 _prefixes = QString();
870 _prefixModes = QString();
872 // we just assume that in PREFIX are only prefix chars stored
873 for (int i = 0; i < defaultPrefixes.size(); i++) {
874 if (prefix.contains(defaultPrefixes[i])) {
875 _prefixes += defaultPrefixes[i];
876 _prefixModes += defaultPrefixModes[i];
880 if (!_prefixes.isNull())
883 // well... our assumption was obviously wrong...
884 // check if it's only prefix modes
885 for (int i = 0; i < defaultPrefixes.size(); i++) {
886 if (prefix.contains(defaultPrefixModes[i])) {
887 _prefixes += defaultPrefixes[i];
888 _prefixModes += defaultPrefixModes[i];
891 // now we've done all we've could...
896 /************************************************************************
898 ************************************************************************/
900 NetworkInfo::NetworkInfo()
903 useRandomServer(false),
904 useAutoIdentify(false),
905 autoIdentifyService("NickServ"),
907 useAutoReconnect(true),
908 autoReconnectInterval(60),
909 autoReconnectRetries(20),
910 unlimitedReconnectRetries(false),
916 bool NetworkInfo::operator==(const NetworkInfo &other) const
918 if (networkId != other.networkId) return false;
919 if (networkName != other.networkName) return false;
920 if (identity != other.identity) return false;
921 if (codecForServer != other.codecForServer) return false;
922 if (codecForEncoding != other.codecForEncoding) return false;
923 if (codecForDecoding != other.codecForDecoding) return false;
924 if (serverList != other.serverList) return false;
925 if (useRandomServer != other.useRandomServer) return false;
926 if (perform != other.perform) return false;
927 if (useAutoIdentify != other.useAutoIdentify) return false;
928 if (autoIdentifyService != other.autoIdentifyService) return false;
929 if (autoIdentifyPassword != other.autoIdentifyPassword) return false;
930 if (useSasl != other.useSasl) return false;
931 if (saslAccount != other.saslAccount) return false;
932 if (saslPassword != other.saslPassword) return false;
933 if (useAutoReconnect != other.useAutoReconnect) return false;
934 if (autoReconnectInterval != other.autoReconnectInterval) return false;
935 if (autoReconnectRetries != other.autoReconnectRetries) return false;
936 if (unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
937 if (rejoinChannels != other.rejoinChannels) return false;
942 bool NetworkInfo::operator!=(const NetworkInfo &other) const
944 return !(*this == other);
948 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info)
951 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
952 i["NetworkName"] = info.networkName;
953 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
954 i["CodecForServer"] = info.codecForServer;
955 i["CodecForEncoding"] = info.codecForEncoding;
956 i["CodecForDecoding"] = info.codecForDecoding;
957 i["ServerList"] = toVariantList(info.serverList);
958 i["UseRandomServer"] = info.useRandomServer;
959 i["Perform"] = info.perform;
960 i["UseAutoIdentify"] = info.useAutoIdentify;
961 i["AutoIdentifyService"] = info.autoIdentifyService;
962 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
963 i["UseSasl"] = info.useSasl;
964 i["SaslAccount"] = info.saslAccount;
965 i["SaslPassword"] = info.saslPassword;
966 i["UseAutoReconnect"] = info.useAutoReconnect;
967 i["AutoReconnectInterval"] = info.autoReconnectInterval;
968 i["AutoReconnectRetries"] = info.autoReconnectRetries;
969 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
970 i["RejoinChannels"] = info.rejoinChannels;
976 QDataStream &operator>>(QDataStream &in, NetworkInfo &info)
980 info.networkId = i["NetworkId"].value<NetworkId>();
981 info.networkName = i["NetworkName"].toString();
982 info.identity = i["Identity"].value<IdentityId>();
983 info.codecForServer = i["CodecForServer"].toByteArray();
984 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
985 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
986 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
987 info.useRandomServer = i["UseRandomServer"].toBool();
988 info.perform = i["Perform"].toStringList();
989 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
990 info.autoIdentifyService = i["AutoIdentifyService"].toString();
991 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
992 info.useSasl = i["UseSasl"].toBool();
993 info.saslAccount = i["SaslAccount"].toString();
994 info.saslPassword = i["SaslPassword"].toString();
995 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
996 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
997 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
998 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
999 info.rejoinChannels = i["RejoinChannels"].toBool();
1004 QDebug operator<<(QDebug dbg, const NetworkInfo &i)
1006 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
1007 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
1008 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
1009 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
1010 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
1011 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
1012 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
1013 << " rejoinChannels = " << i.rejoinChannels << ")";
1018 QDataStream &operator<<(QDataStream &out, const Network::Server &server)
1020 QVariantMap serverMap;
1021 serverMap["Host"] = server.host;
1022 serverMap["Port"] = server.port;
1023 serverMap["Password"] = server.password;
1024 serverMap["UseSSL"] = server.useSsl;
1025 serverMap["sslVersion"] = server.sslVersion;
1026 serverMap["UseProxy"] = server.useProxy;
1027 serverMap["ProxyType"] = server.proxyType;
1028 serverMap["ProxyHost"] = server.proxyHost;
1029 serverMap["ProxyPort"] = server.proxyPort;
1030 serverMap["ProxyUser"] = server.proxyUser;
1031 serverMap["ProxyPass"] = server.proxyPass;
1037 QDataStream &operator>>(QDataStream &in, Network::Server &server)
1039 QVariantMap serverMap;
1041 server.host = serverMap["Host"].toString();
1042 server.port = serverMap["Port"].toUInt();
1043 server.password = serverMap["Password"].toString();
1044 server.useSsl = serverMap["UseSSL"].toBool();
1045 server.sslVersion = serverMap["sslVersion"].toInt();
1046 server.useProxy = serverMap["UseProxy"].toBool();
1047 server.proxyType = serverMap["ProxyType"].toInt();
1048 server.proxyHost = serverMap["ProxyHost"].toString();
1049 server.proxyPort = serverMap["ProxyPort"].toUInt();
1050 server.proxyUser = serverMap["ProxyUser"].toString();
1051 server.proxyPass = serverMap["ProxyPass"].toString();
1056 bool Network::Server::operator==(const Server &other) const
1058 if (host != other.host) return false;
1059 if (port != other.port) return false;
1060 if (password != other.password) return false;
1061 if (useSsl != other.useSsl) return false;
1062 if (sslVersion != other.sslVersion) return false;
1063 if (useProxy != other.useProxy) return false;
1064 if (proxyType != other.proxyType) return false;
1065 if (proxyHost != other.proxyHost) return false;
1066 if (proxyPort != other.proxyPort) return false;
1067 if (proxyUser != other.proxyUser) return false;
1068 if (proxyPass != other.proxyPass) return false;
1073 bool Network::Server::operator!=(const Server &other) const
1075 return !(*this == other);
1079 QDebug operator<<(QDebug dbg, const Network::Server &server)
1081 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";