1 /***************************************************************************
2 * Copyright (C) 2005-2014 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 ***************************************************************************/
27 QTextCodec *Network::_defaultCodecForServer = 0;
28 QTextCodec *Network::_defaultCodecForEncoding = 0;
29 QTextCodec *Network::_defaultCodecForDecoding = 0;
30 QString Network::_networksIniPath = QString();
32 // ====================
34 // ====================
35 INIT_SYNCABLE_OBJECT(Network)
36 Network::Network(const NetworkId &networkid, QObject *parent)
37 : SyncableObject(parent),
39 _networkId(networkid),
43 _networkName(QString("<not initialized>")),
44 _currentServer(QString()),
46 _connectionState(Disconnected),
48 _prefixModes(QString()),
49 _useRandomServer(false),
50 _useAutoIdentify(false),
52 _useAutoReconnect(false),
53 _autoReconnectInterval(60),
54 _autoReconnectRetries(10),
55 _unlimitedReconnectRetries(false),
59 _autoAwayActive(false)
61 setObjectName(QString::number(networkid.toInt()));
67 emit aboutToBeDestroyed();
71 bool Network::isChannelName(const QString &channelname) const
73 if (channelname.isEmpty())
76 if (supports("CHANTYPES"))
77 return support("CHANTYPES").contains(channelname[0]);
79 return QString("#&!+").contains(channelname[0]);
83 NetworkInfo Network::networkInfo() const
86 info.networkName = networkName();
87 info.networkId = networkId();
88 info.identity = identity();
89 info.codecForServer = codecForServer();
90 info.codecForEncoding = codecForEncoding();
91 info.codecForDecoding = codecForDecoding();
92 info.serverList = serverList();
93 info.useRandomServer = useRandomServer();
94 info.perform = perform();
95 info.useAutoIdentify = useAutoIdentify();
96 info.autoIdentifyService = autoIdentifyService();
97 info.autoIdentifyPassword = autoIdentifyPassword();
98 info.useSasl = useSasl();
99 info.saslAccount = saslAccount();
100 info.saslPassword = saslPassword();
101 info.useAutoReconnect = useAutoReconnect();
102 info.autoReconnectInterval = autoReconnectInterval();
103 info.autoReconnectRetries = autoReconnectRetries();
104 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
105 info.rejoinChannels = rejoinChannels();
110 void Network::setNetworkInfo(const NetworkInfo &info)
112 // we don't set our ID!
113 if (!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
114 if (info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
115 if (info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
116 if (info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
117 if (info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
118 if (info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
119 if (info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
120 if (info.perform != perform()) setPerform(info.perform);
121 if (info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
122 if (info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
123 if (info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
124 if (info.useSasl != useSasl()) setUseSasl(info.useSasl);
125 if (info.saslAccount != saslAccount()) setSaslAccount(info.saslAccount);
126 if (info.saslPassword != saslPassword()) setSaslPassword(info.saslPassword);
127 if (info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
128 if (info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
129 if (info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
130 if (info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
131 if (info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
135 QString Network::prefixToMode(const QString &prefix) const
137 if (prefixes().contains(prefix))
138 return QString(prefixModes()[prefixes().indexOf(prefix)]);
144 QString Network::modeToPrefix(const QString &mode) const
146 if (prefixModes().contains(mode))
147 return QString(prefixes()[prefixModes().indexOf(mode)]);
153 QStringList Network::nicks() const
155 // we don't use _ircUsers.keys() since the keys may be
156 // not up to date after a nick change
158 foreach(IrcUser *ircuser, _ircUsers.values()) {
159 nicks << ircuser->nick();
165 QString Network::prefixes() const
167 if (_prefixes.isNull())
174 QString Network::prefixModes() const
176 if (_prefixModes.isNull())
183 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
184 Network::ChannelModeType Network::channelModeType(const QString &mode)
187 return NOT_A_CHANMODE;
189 QString chanmodes = support("CHANMODES");
190 if (chanmodes.isEmpty())
191 return NOT_A_CHANMODE;
193 ChannelModeType modeType = A_CHANMODE;
194 for (int i = 0; i < chanmodes.count(); i++) {
195 if (chanmodes[i] == mode[0])
197 else if (chanmodes[i] == ',')
198 modeType = (ChannelModeType)(modeType << 1);
200 if (modeType > D_CHANMODE) {
201 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
202 modeType = NOT_A_CHANMODE;
208 QString Network::support(const QString ¶m) const
210 QString support_ = param.toUpper();
211 if (_supports.contains(support_))
212 return _supports[support_];
218 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData)
220 QString nick(nickFromMask(hostmask).toLower());
221 if (!_ircUsers.contains(nick)) {
222 IrcUser *ircuser = ircUserFactory(hostmask);
223 if (!initData.isEmpty()) {
224 ircuser->fromVariantMap(initData);
225 ircuser->setInitialized();
229 proxy()->synchronize(ircuser);
231 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
233 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
235 _ircUsers[nick] = ircuser;
237 // This method will be called with a nick instead of hostmask by setInitIrcUsersAndChannels().
238 // Not a problem because initData contains all we need; however, making sure here to get the real
239 // hostmask out of the IrcUser afterwards.
240 QString mask = ircuser->hostmask();
241 SYNC_OTHER(addIrcUser, ARG(mask));
242 // emit ircUserAdded(mask);
243 emit ircUserAdded(ircuser);
246 return _ircUsers[nick];
250 IrcUser *Network::ircUser(QString nickname) const
252 nickname = nickname.toLower();
253 if (_ircUsers.contains(nickname))
254 return _ircUsers[nickname];
260 void Network::removeIrcUser(IrcUser *ircuser)
262 QString nick = _ircUsers.key(ircuser);
266 _ircUsers.remove(nick);
267 disconnect(ircuser, 0, this, 0);
268 ircuser->deleteLater();
272 void Network::removeIrcChannel(IrcChannel *channel)
274 QString chanName = _ircChannels.key(channel);
275 if (chanName.isNull())
278 _ircChannels.remove(chanName);
279 disconnect(channel, 0, this, 0);
280 channel->deleteLater();
284 void Network::removeChansAndUsers()
286 QList<IrcUser *> users = ircUsers();
288 QList<IrcChannel *> channels = ircChannels();
289 _ircChannels.clear();
292 qDeleteAll(channels);
296 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData)
298 if (!_ircChannels.contains(channelname.toLower())) {
299 IrcChannel *channel = ircChannelFactory(channelname);
300 if (!initData.isEmpty()) {
301 channel->fromVariantMap(initData);
302 channel->setInitialized();
306 proxy()->synchronize(channel);
308 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
310 _ircChannels[channelname.toLower()] = channel;
312 SYNC_OTHER(addIrcChannel, ARG(channelname))
313 // emit ircChannelAdded(channelname);
314 emit ircChannelAdded(channel);
316 return _ircChannels[channelname.toLower()];
320 IrcChannel *Network::ircChannel(QString channelname) const
322 channelname = channelname.toLower();
323 if (_ircChannels.contains(channelname))
324 return _ircChannels[channelname];
330 QByteArray Network::defaultCodecForServer()
332 if (_defaultCodecForServer)
333 return _defaultCodecForServer->name();
338 void Network::setDefaultCodecForServer(const QByteArray &name)
340 _defaultCodecForServer = QTextCodec::codecForName(name);
344 QByteArray Network::defaultCodecForEncoding()
346 if (_defaultCodecForEncoding)
347 return _defaultCodecForEncoding->name();
352 void Network::setDefaultCodecForEncoding(const QByteArray &name)
354 _defaultCodecForEncoding = QTextCodec::codecForName(name);
358 QByteArray Network::defaultCodecForDecoding()
360 if (_defaultCodecForDecoding)
361 return _defaultCodecForDecoding->name();
366 void Network::setDefaultCodecForDecoding(const QByteArray &name)
368 _defaultCodecForDecoding = QTextCodec::codecForName(name);
372 QByteArray Network::codecForServer() const
375 return _codecForServer->name();
380 void Network::setCodecForServer(const QByteArray &name)
382 setCodecForServer(QTextCodec::codecForName(name));
386 void Network::setCodecForServer(QTextCodec *codec)
388 _codecForServer = codec;
389 QByteArray codecName = codecForServer();
390 SYNC_OTHER(setCodecForServer, ARG(codecName))
391 emit configChanged();
395 QByteArray Network::codecForEncoding() const
397 if (_codecForEncoding)
398 return _codecForEncoding->name();
403 void Network::setCodecForEncoding(const QByteArray &name)
405 setCodecForEncoding(QTextCodec::codecForName(name));
409 void Network::setCodecForEncoding(QTextCodec *codec)
411 _codecForEncoding = codec;
412 QByteArray codecName = codecForEncoding();
413 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
414 emit configChanged();
418 QByteArray Network::codecForDecoding() const
420 if (_codecForDecoding)
421 return _codecForDecoding->name();
422 else return QByteArray();
426 void Network::setCodecForDecoding(const QByteArray &name)
428 setCodecForDecoding(QTextCodec::codecForName(name));
432 void Network::setCodecForDecoding(QTextCodec *codec)
434 _codecForDecoding = codec;
435 QByteArray codecName = codecForDecoding();
436 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
437 emit configChanged();
441 // FIXME use server encoding if appropriate
442 QString Network::decodeString(const QByteArray &text) const
444 if (_codecForDecoding)
445 return ::decodeString(text, _codecForDecoding);
446 else return ::decodeString(text, _defaultCodecForDecoding);
450 QByteArray Network::encodeString(const QString &string) const
452 if (_codecForEncoding) {
453 return _codecForEncoding->fromUnicode(string);
455 if (_defaultCodecForEncoding) {
456 return _defaultCodecForEncoding->fromUnicode(string);
458 return string.toAscii();
462 QString Network::decodeServerString(const QByteArray &text) const
465 return ::decodeString(text, _codecForServer);
467 return ::decodeString(text, _defaultCodecForServer);
471 QByteArray Network::encodeServerString(const QString &string) const
473 if (_codecForServer) {
474 return _codecForServer->fromUnicode(string);
476 if (_defaultCodecForServer) {
477 return _defaultCodecForServer->fromUnicode(string);
479 return string.toAscii();
483 /*** Handle networks.ini ***/
485 QStringList Network::presetNetworks(bool onlyDefault)
487 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
488 if (_networksIniPath.isNull()) {
489 _networksIniPath = Quassel::findDataFilePath("networks.ini");
490 if (_networksIniPath.isNull()) {
491 _networksIniPath = ""; // now we won't check again, as it's not null anymore
492 return QStringList();
495 if (!_networksIniPath.isEmpty()) {
496 QSettings s(_networksIniPath, QSettings::IniFormat);
497 QStringList networks = s.childGroups();
498 if (!networks.isEmpty()) {
499 // we sort the list case-insensitive
500 QMap<QString, QString> sorted;
501 foreach(QString net, networks) {
502 if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
504 sorted[net.toLower()] = net;
506 return sorted.values();
509 return QStringList();
513 QStringList Network::presetDefaultChannels(const QString &networkName)
515 if (_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
516 return QStringList();
517 QSettings s(_networksIniPath, QSettings::IniFormat);
518 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
522 NetworkInfo Network::networkInfoFromPreset(const QString &networkName)
525 if (!_networksIniPath.isEmpty()) {
526 info.networkName = networkName;
527 QSettings s(_networksIniPath, QSettings::IniFormat);
528 s.beginGroup(info.networkName);
529 foreach(QString server, s.value("Servers").toStringList()) {
531 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
532 if (splitserver.count() != 2) {
533 qWarning() << "Invalid server entry in networks.conf:" << server;
536 if (splitserver[1].at(0) == '+')
538 uint port = splitserver[1].toUInt();
540 qWarning() << "Invalid port entry in networks.conf:" << server;
543 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
550 // ====================
552 // ====================
553 void Network::setNetworkName(const QString &networkName)
555 _networkName = networkName;
556 SYNC(ARG(networkName))
557 emit networkNameSet(networkName);
558 emit configChanged();
562 void Network::setCurrentServer(const QString ¤tServer)
564 _currentServer = currentServer;
565 SYNC(ARG(currentServer))
566 emit currentServerSet(currentServer);
570 void Network::setConnected(bool connected)
572 if (_connected == connected)
575 _connected = connected;
577 setMyNick(QString());
578 setCurrentServer(QString());
579 removeChansAndUsers();
582 emit connectedSet(connected);
586 //void Network::setConnectionState(ConnectionState state) {
587 void Network::setConnectionState(int state)
589 _connectionState = (ConnectionState)state;
590 //qDebug() << "netstate" << networkId() << networkName() << state;
592 emit connectionStateSet(_connectionState);
596 void Network::setMyNick(const QString &nickname)
599 if (!_myNick.isEmpty() && !ircUser(myNick())) {
600 newIrcUser(myNick());
603 emit myNickSet(nickname);
607 void Network::setLatency(int latency)
609 if (_latency == latency)
616 void Network::setIdentity(IdentityId id)
620 emit identitySet(id);
621 emit configChanged();
625 void Network::setServerList(const QVariantList &serverList)
627 _serverList = fromVariantList<Server>(serverList);
628 SYNC(ARG(serverList))
629 emit configChanged();
633 void Network::setUseRandomServer(bool use)
635 _useRandomServer = use;
637 emit configChanged();
641 void Network::setPerform(const QStringList &perform)
645 emit configChanged();
649 void Network::setUseAutoIdentify(bool use)
651 _useAutoIdentify = use;
653 emit configChanged();
657 void Network::setAutoIdentifyService(const QString &service)
659 _autoIdentifyService = service;
661 emit configChanged();
665 void Network::setAutoIdentifyPassword(const QString &password)
667 _autoIdentifyPassword = password;
669 emit configChanged();
673 void Network::setUseSasl(bool use)
677 emit configChanged();
681 void Network::setSaslAccount(const QString &account)
683 _saslAccount = account;
685 emit configChanged();
689 void Network::setSaslPassword(const QString &password)
691 _saslPassword = password;
693 emit configChanged();
697 void Network::setUseAutoReconnect(bool use)
699 _useAutoReconnect = use;
701 emit configChanged();
705 void Network::setAutoReconnectInterval(quint32 interval)
707 _autoReconnectInterval = interval;
709 emit configChanged();
713 void Network::setAutoReconnectRetries(quint16 retries)
715 _autoReconnectRetries = retries;
717 emit configChanged();
721 void Network::setUnlimitedReconnectRetries(bool unlimited)
723 _unlimitedReconnectRetries = unlimited;
725 emit configChanged();
729 void Network::setRejoinChannels(bool rejoin)
731 _rejoinChannels = rejoin;
733 emit configChanged();
737 void Network::addSupport(const QString ¶m, const QString &value)
739 if (!_supports.contains(param)) {
740 _supports[param] = value;
741 SYNC(ARG(param), ARG(value))
746 void Network::removeSupport(const QString ¶m)
748 if (_supports.contains(param)) {
749 _supports.remove(param);
755 QVariantMap Network::initSupports() const
757 QVariantMap supports;
758 QHashIterator<QString, QString> iter(_supports);
759 while (iter.hasNext()) {
761 supports[iter.key()] = iter.value();
767 // There's potentially a lot of users and channels, so it makes sense to optimize the format of this.
768 // Rather than sending a thousand maps with identical keys, we convert this into one map containing lists
769 // where each list index corresponds to a particular IrcUser. This saves sending the key names a thousand times.
770 // Benchmarks have shown space savings of around 56%, resulting in saving several MBs worth of data on sync
771 // (without compression) with a decent amount of IrcUsers.
772 QVariantMap Network::initIrcUsersAndChannels() const
774 QVariantMap usersAndChannels;
776 if (_ircUsers.count()) {
777 QHash<QString, QVariantList> users;
778 QHash<QString, IrcUser *>::const_iterator it = _ircUsers.begin();
779 QHash<QString, IrcUser *>::const_iterator end = _ircUsers.end();
781 const QVariantMap &map = it.value()->toVariantMap();
782 QVariantMap::const_iterator mapiter = map.begin();
783 while (mapiter != map.end()) {
784 users[mapiter.key()] << mapiter.value();
789 // Can't have a container with a value type != QVariant in a QVariant :(
790 // However, working directly on a QVariantMap is awkward for appending, thus the detour via the hash above.
792 foreach(const QString &key, users.keys())
793 userMap[key] = users[key];
794 usersAndChannels["Users"] = userMap;
797 if (_ircChannels.count()) {
798 QHash<QString, QVariantList> channels;
799 QHash<QString, IrcChannel *>::const_iterator it = _ircChannels.begin();
800 QHash<QString, IrcChannel *>::const_iterator end = _ircChannels.end();
802 const QVariantMap &map = it.value()->toVariantMap();
803 QVariantMap::const_iterator mapiter = map.begin();
804 while (mapiter != map.end()) {
805 channels[mapiter.key()] << mapiter.value();
810 QVariantMap channelMap;
811 foreach(const QString &key, channels.keys())
812 channelMap[key] = channels[key];
813 usersAndChannels["Channels"] = channelMap;
816 return usersAndChannels;
820 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels)
823 if (isInitialized()) {
824 qWarning() << "Network" << networkId() << "received init data for users and channels although there already are known users or channels!";
828 // toMap() and toList() are cheap, so we can avoid copying to lists...
829 // However, we really have to make sure to never accidentally detach from the shared data!
831 const QVariantMap &users = usersAndChannels["Users"].toMap();
834 int count = users["nick"].toList().count();
835 foreach(const QString &key, users.keys()) {
836 if (users[key].toList().count() != count) {
837 qWarning() << "Received invalid usersAndChannels init data, sizes of attribute lists don't match!";
842 // now create the individual IrcUsers
843 for(int i = 0; i < count; i++) {
845 foreach(const QString &key, users.keys())
846 map[key] = users[key].toList().at(i);
847 newIrcUser(map["nick"].toString(), map); // newIrcUser() properly handles the hostmask being just the nick
850 // same thing for IrcChannels
851 const QVariantMap &channels = usersAndChannels["Channels"].toMap();
854 count = channels["name"].toList().count();
855 foreach(const QString &key, channels.keys()) {
856 if (channels[key].toList().count() != count) {
857 qWarning() << "Received invalid usersAndChannels init data, sizes of attribute lists don't match!";
861 // now create the individual IrcChannels
862 for(int i = 0; i < count; i++) {
864 foreach(const QString &key, channels.keys())
865 map[key] = channels[key].toList().at(i);
866 newIrcChannel(map["name"].toString(), map);
871 void Network::initSetSupports(const QVariantMap &supports)
873 QMapIterator<QString, QVariant> iter(supports);
874 while (iter.hasNext()) {
876 addSupport(iter.key(), iter.value().toString());
881 IrcUser *Network::updateNickFromMask(const QString &mask)
883 QString nick(nickFromMask(mask).toLower());
886 if (_ircUsers.contains(nick)) {
887 ircuser = _ircUsers[nick];
888 ircuser->updateHostmask(mask);
891 ircuser = newIrcUser(mask);
897 void Network::ircUserNickChanged(QString newnick)
899 QString oldnick = _ircUsers.key(qobject_cast<IrcUser *>(sender()));
901 if (oldnick.isNull())
904 if (newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
906 if (myNick().toLower() == oldnick)
911 void Network::emitConnectionError(const QString &errorMsg)
913 emit connectionError(errorMsg);
917 // ====================
919 // ====================
920 void Network::determinePrefixes() const
922 // seems like we have to construct them first
923 QString prefix = support("PREFIX");
925 if (prefix.startsWith("(") && prefix.contains(")")) {
926 _prefixes = prefix.section(")", 1);
927 _prefixModes = prefix.mid(1).section(")", 0, 0);
930 QString defaultPrefixes("~&@%+");
931 QString defaultPrefixModes("qaohv");
933 if (prefix.isEmpty()) {
934 _prefixes = defaultPrefixes;
935 _prefixModes = defaultPrefixModes;
938 // clear the existing modes, just in case we're run multiple times
939 _prefixes = QString();
940 _prefixModes = QString();
942 // we just assume that in PREFIX are only prefix chars stored
943 for (int i = 0; i < defaultPrefixes.size(); i++) {
944 if (prefix.contains(defaultPrefixes[i])) {
945 _prefixes += defaultPrefixes[i];
946 _prefixModes += defaultPrefixModes[i];
950 if (!_prefixes.isNull())
953 // well... our assumption was obviously wrong...
954 // check if it's only prefix modes
955 for (int i = 0; i < defaultPrefixes.size(); i++) {
956 if (prefix.contains(defaultPrefixModes[i])) {
957 _prefixes += defaultPrefixes[i];
958 _prefixModes += defaultPrefixModes[i];
961 // now we've done all we've could...
966 /************************************************************************
968 ************************************************************************/
970 NetworkInfo::NetworkInfo()
973 useRandomServer(false),
974 useAutoIdentify(false),
975 autoIdentifyService("NickServ"),
977 useAutoReconnect(true),
978 autoReconnectInterval(60),
979 autoReconnectRetries(20),
980 unlimitedReconnectRetries(false),
986 bool NetworkInfo::operator==(const NetworkInfo &other) const
988 if (networkId != other.networkId) return false;
989 if (networkName != other.networkName) return false;
990 if (identity != other.identity) return false;
991 if (codecForServer != other.codecForServer) return false;
992 if (codecForEncoding != other.codecForEncoding) return false;
993 if (codecForDecoding != other.codecForDecoding) return false;
994 if (serverList != other.serverList) return false;
995 if (useRandomServer != other.useRandomServer) return false;
996 if (perform != other.perform) return false;
997 if (useAutoIdentify != other.useAutoIdentify) return false;
998 if (autoIdentifyService != other.autoIdentifyService) return false;
999 if (autoIdentifyPassword != other.autoIdentifyPassword) return false;
1000 if (useSasl != other.useSasl) return false;
1001 if (saslAccount != other.saslAccount) return false;
1002 if (saslPassword != other.saslPassword) return false;
1003 if (useAutoReconnect != other.useAutoReconnect) return false;
1004 if (autoReconnectInterval != other.autoReconnectInterval) return false;
1005 if (autoReconnectRetries != other.autoReconnectRetries) return false;
1006 if (unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
1007 if (rejoinChannels != other.rejoinChannels) return false;
1012 bool NetworkInfo::operator!=(const NetworkInfo &other) const
1014 return !(*this == other);
1018 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info)
1021 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
1022 i["NetworkName"] = info.networkName;
1023 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
1024 i["CodecForServer"] = info.codecForServer;
1025 i["CodecForEncoding"] = info.codecForEncoding;
1026 i["CodecForDecoding"] = info.codecForDecoding;
1027 i["ServerList"] = toVariantList(info.serverList);
1028 i["UseRandomServer"] = info.useRandomServer;
1029 i["Perform"] = info.perform;
1030 i["UseAutoIdentify"] = info.useAutoIdentify;
1031 i["AutoIdentifyService"] = info.autoIdentifyService;
1032 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
1033 i["UseSasl"] = info.useSasl;
1034 i["SaslAccount"] = info.saslAccount;
1035 i["SaslPassword"] = info.saslPassword;
1036 i["UseAutoReconnect"] = info.useAutoReconnect;
1037 i["AutoReconnectInterval"] = info.autoReconnectInterval;
1038 i["AutoReconnectRetries"] = info.autoReconnectRetries;
1039 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
1040 i["RejoinChannels"] = info.rejoinChannels;
1046 QDataStream &operator>>(QDataStream &in, NetworkInfo &info)
1050 info.networkId = i["NetworkId"].value<NetworkId>();
1051 info.networkName = i["NetworkName"].toString();
1052 info.identity = i["Identity"].value<IdentityId>();
1053 info.codecForServer = i["CodecForServer"].toByteArray();
1054 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
1055 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
1056 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
1057 info.useRandomServer = i["UseRandomServer"].toBool();
1058 info.perform = i["Perform"].toStringList();
1059 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
1060 info.autoIdentifyService = i["AutoIdentifyService"].toString();
1061 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
1062 info.useSasl = i["UseSasl"].toBool();
1063 info.saslAccount = i["SaslAccount"].toString();
1064 info.saslPassword = i["SaslPassword"].toString();
1065 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
1066 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
1067 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
1068 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
1069 info.rejoinChannels = i["RejoinChannels"].toBool();
1074 QDebug operator<<(QDebug dbg, const NetworkInfo &i)
1076 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
1077 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
1078 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
1079 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
1080 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
1081 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
1082 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
1083 << " rejoinChannels = " << i.rejoinChannels << ")";
1088 QDataStream &operator<<(QDataStream &out, const Network::Server &server)
1090 QVariantMap serverMap;
1091 serverMap["Host"] = server.host;
1092 serverMap["Port"] = server.port;
1093 serverMap["Password"] = server.password;
1094 serverMap["UseSSL"] = server.useSsl;
1095 serverMap["sslVersion"] = server.sslVersion;
1096 serverMap["UseProxy"] = server.useProxy;
1097 serverMap["ProxyType"] = server.proxyType;
1098 serverMap["ProxyHost"] = server.proxyHost;
1099 serverMap["ProxyPort"] = server.proxyPort;
1100 serverMap["ProxyUser"] = server.proxyUser;
1101 serverMap["ProxyPass"] = server.proxyPass;
1107 QDataStream &operator>>(QDataStream &in, Network::Server &server)
1109 QVariantMap serverMap;
1111 server.host = serverMap["Host"].toString();
1112 server.port = serverMap["Port"].toUInt();
1113 server.password = serverMap["Password"].toString();
1114 server.useSsl = serverMap["UseSSL"].toBool();
1115 server.sslVersion = serverMap["sslVersion"].toInt();
1116 server.useProxy = serverMap["UseProxy"].toBool();
1117 server.proxyType = serverMap["ProxyType"].toInt();
1118 server.proxyHost = serverMap["ProxyHost"].toString();
1119 server.proxyPort = serverMap["ProxyPort"].toUInt();
1120 server.proxyUser = serverMap["ProxyUser"].toString();
1121 server.proxyPass = serverMap["ProxyPass"].toString();
1126 bool Network::Server::operator==(const Server &other) const
1128 if (host != other.host) return false;
1129 if (port != other.port) return false;
1130 if (password != other.password) return false;
1131 if (useSsl != other.useSsl) return false;
1132 if (sslVersion != other.sslVersion) return false;
1133 if (useProxy != other.useProxy) return false;
1134 if (proxyType != other.proxyType) return false;
1135 if (proxyHost != other.proxyHost) return false;
1136 if (proxyPort != other.proxyPort) return false;
1137 if (proxyUser != other.proxyUser) return false;
1138 if (proxyPass != other.proxyPass) return false;
1143 bool Network::Server::operator!=(const Server &other) const
1145 return !(*this == other);
1149 QDebug operator<<(QDebug dbg, const Network::Server &server)
1151 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";