1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 SYNC_OTHER(addIrcUser, ARG(hostmask))
238 // emit ircUserAdded(hostmask);
239 emit ircUserAdded(ircuser);
242 return _ircUsers[nick];
246 IrcUser *Network::ircUser(QString nickname) const
248 nickname = nickname.toLower();
249 if (_ircUsers.contains(nickname))
250 return _ircUsers[nickname];
256 void Network::removeIrcUser(IrcUser *ircuser)
258 QString nick = _ircUsers.key(ircuser);
262 _ircUsers.remove(nick);
263 disconnect(ircuser, 0, this, 0);
264 ircuser->deleteLater();
268 void Network::removeIrcChannel(IrcChannel *channel)
270 QString chanName = _ircChannels.key(channel);
271 if (chanName.isNull())
274 _ircChannels.remove(chanName);
275 disconnect(channel, 0, this, 0);
276 channel->deleteLater();
280 void Network::removeChansAndUsers()
282 QList<IrcUser *> users = ircUsers();
284 QList<IrcChannel *> channels = ircChannels();
285 _ircChannels.clear();
287 foreach(IrcChannel *channel, channels) {
288 proxy()->detachObject(channel);
289 disconnect(channel, 0, this, 0);
291 foreach(IrcUser *user, users) {
292 proxy()->detachObject(user);
293 disconnect(user, 0, this, 0);
296 // the second loop is needed because quit can have sideffects
297 foreach(IrcUser *user, users) {
302 qDeleteAll(channels);
306 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData)
308 if (!_ircChannels.contains(channelname.toLower())) {
309 IrcChannel *channel = ircChannelFactory(channelname);
310 if (!initData.isEmpty()) {
311 channel->fromVariantMap(initData);
312 channel->setInitialized();
316 proxy()->synchronize(channel);
318 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
320 _ircChannels[channelname.toLower()] = channel;
322 SYNC_OTHER(addIrcChannel, ARG(channelname))
323 // emit ircChannelAdded(channelname);
324 emit ircChannelAdded(channel);
326 return _ircChannels[channelname.toLower()];
330 IrcChannel *Network::ircChannel(QString channelname) const
332 channelname = channelname.toLower();
333 if (_ircChannels.contains(channelname))
334 return _ircChannels[channelname];
340 QByteArray Network::defaultCodecForServer()
342 if (_defaultCodecForServer)
343 return _defaultCodecForServer->name();
348 void Network::setDefaultCodecForServer(const QByteArray &name)
350 _defaultCodecForServer = QTextCodec::codecForName(name);
354 QByteArray Network::defaultCodecForEncoding()
356 if (_defaultCodecForEncoding)
357 return _defaultCodecForEncoding->name();
362 void Network::setDefaultCodecForEncoding(const QByteArray &name)
364 _defaultCodecForEncoding = QTextCodec::codecForName(name);
368 QByteArray Network::defaultCodecForDecoding()
370 if (_defaultCodecForDecoding)
371 return _defaultCodecForDecoding->name();
376 void Network::setDefaultCodecForDecoding(const QByteArray &name)
378 _defaultCodecForDecoding = QTextCodec::codecForName(name);
382 QByteArray Network::codecForServer() const
385 return _codecForServer->name();
390 void Network::setCodecForServer(const QByteArray &name)
392 setCodecForServer(QTextCodec::codecForName(name));
396 void Network::setCodecForServer(QTextCodec *codec)
398 _codecForServer = codec;
399 QByteArray codecName = codecForServer();
400 SYNC_OTHER(setCodecForServer, ARG(codecName))
401 emit configChanged();
405 QByteArray Network::codecForEncoding() const
407 if (_codecForEncoding)
408 return _codecForEncoding->name();
413 void Network::setCodecForEncoding(const QByteArray &name)
415 setCodecForEncoding(QTextCodec::codecForName(name));
419 void Network::setCodecForEncoding(QTextCodec *codec)
421 _codecForEncoding = codec;
422 QByteArray codecName = codecForEncoding();
423 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
424 emit configChanged();
428 QByteArray Network::codecForDecoding() const
430 if (_codecForDecoding)
431 return _codecForDecoding->name();
432 else return QByteArray();
436 void Network::setCodecForDecoding(const QByteArray &name)
438 setCodecForDecoding(QTextCodec::codecForName(name));
442 void Network::setCodecForDecoding(QTextCodec *codec)
444 _codecForDecoding = codec;
445 QByteArray codecName = codecForDecoding();
446 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
447 emit configChanged();
451 // FIXME use server encoding if appropriate
452 QString Network::decodeString(const QByteArray &text) const
454 if (_codecForDecoding)
455 return ::decodeString(text, _codecForDecoding);
456 else return ::decodeString(text, _defaultCodecForDecoding);
460 QByteArray Network::encodeString(const QString &string) const
462 if (_codecForEncoding) {
463 return _codecForEncoding->fromUnicode(string);
465 if (_defaultCodecForEncoding) {
466 return _defaultCodecForEncoding->fromUnicode(string);
468 return string.toAscii();
472 QString Network::decodeServerString(const QByteArray &text) const
475 return ::decodeString(text, _codecForServer);
477 return ::decodeString(text, _defaultCodecForServer);
481 QByteArray Network::encodeServerString(const QString &string) const
483 if (_codecForServer) {
484 return _codecForServer->fromUnicode(string);
486 if (_defaultCodecForServer) {
487 return _defaultCodecForServer->fromUnicode(string);
489 return string.toAscii();
493 /*** Handle networks.ini ***/
495 QStringList Network::presetNetworks(bool onlyDefault)
497 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
498 if (_networksIniPath.isNull()) {
499 _networksIniPath = Quassel::findDataFilePath("networks.ini");
500 if (_networksIniPath.isNull()) {
501 _networksIniPath = ""; // now we won't check again, as it's not null anymore
502 return QStringList();
505 if (!_networksIniPath.isEmpty()) {
506 QSettings s(_networksIniPath, QSettings::IniFormat);
507 QStringList networks = s.childGroups();
508 if (!networks.isEmpty()) {
509 // we sort the list case-insensitive
510 QMap<QString, QString> sorted;
511 foreach(QString net, networks) {
512 if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
514 sorted[net.toLower()] = net;
516 return sorted.values();
519 return QStringList();
523 QStringList Network::presetDefaultChannels(const QString &networkName)
525 if (_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
526 return QStringList();
527 QSettings s(_networksIniPath, QSettings::IniFormat);
528 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
532 NetworkInfo Network::networkInfoFromPreset(const QString &networkName)
535 if (!_networksIniPath.isEmpty()) {
536 info.networkName = networkName;
537 QSettings s(_networksIniPath, QSettings::IniFormat);
538 s.beginGroup(info.networkName);
539 foreach(QString server, s.value("Servers").toStringList()) {
541 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
542 if (splitserver.count() != 2) {
543 qWarning() << "Invalid server entry in networks.conf:" << server;
546 if (splitserver[1].at(0) == '+')
548 uint port = splitserver[1].toUInt();
550 qWarning() << "Invalid port entry in networks.conf:" << server;
553 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
560 // ====================
562 // ====================
563 void Network::setNetworkName(const QString &networkName)
565 _networkName = networkName;
566 SYNC(ARG(networkName))
567 emit networkNameSet(networkName);
568 emit configChanged();
572 void Network::setCurrentServer(const QString ¤tServer)
574 _currentServer = currentServer;
575 SYNC(ARG(currentServer))
576 emit currentServerSet(currentServer);
580 void Network::setConnected(bool connected)
582 if (_connected == connected)
585 _connected = connected;
587 setMyNick(QString());
588 setCurrentServer(QString());
589 removeChansAndUsers();
592 emit connectedSet(connected);
596 //void Network::setConnectionState(ConnectionState state) {
597 void Network::setConnectionState(int state)
599 _connectionState = (ConnectionState)state;
600 //qDebug() << "netstate" << networkId() << networkName() << state;
602 emit connectionStateSet(_connectionState);
606 void Network::setMyNick(const QString &nickname)
609 if (!_myNick.isEmpty() && !ircUser(myNick())) {
610 newIrcUser(myNick());
613 emit myNickSet(nickname);
617 void Network::setLatency(int latency)
619 if (_latency == latency)
626 void Network::setIdentity(IdentityId id)
630 emit identitySet(id);
631 emit configChanged();
635 void Network::setServerList(const QVariantList &serverList)
637 _serverList = fromVariantList<Server>(serverList);
638 SYNC(ARG(serverList))
639 emit configChanged();
643 void Network::setUseRandomServer(bool use)
645 _useRandomServer = use;
647 emit configChanged();
651 void Network::setPerform(const QStringList &perform)
655 emit configChanged();
659 void Network::setUseAutoIdentify(bool use)
661 _useAutoIdentify = use;
663 emit configChanged();
667 void Network::setAutoIdentifyService(const QString &service)
669 _autoIdentifyService = service;
671 emit configChanged();
675 void Network::setAutoIdentifyPassword(const QString &password)
677 _autoIdentifyPassword = password;
679 emit configChanged();
683 void Network::setUseSasl(bool use)
687 emit configChanged();
691 void Network::setSaslAccount(const QString &account)
693 _saslAccount = account;
695 emit configChanged();
699 void Network::setSaslPassword(const QString &password)
701 _saslPassword = password;
703 emit configChanged();
707 void Network::setUseAutoReconnect(bool use)
709 _useAutoReconnect = use;
711 emit configChanged();
715 void Network::setAutoReconnectInterval(quint32 interval)
717 _autoReconnectInterval = interval;
719 emit configChanged();
723 void Network::setAutoReconnectRetries(quint16 retries)
725 _autoReconnectRetries = retries;
727 emit configChanged();
731 void Network::setUnlimitedReconnectRetries(bool unlimited)
733 _unlimitedReconnectRetries = unlimited;
735 emit configChanged();
739 void Network::setRejoinChannels(bool rejoin)
741 _rejoinChannels = rejoin;
743 emit configChanged();
747 void Network::addSupport(const QString ¶m, const QString &value)
749 if (!_supports.contains(param)) {
750 _supports[param] = value;
751 SYNC(ARG(param), ARG(value))
756 void Network::removeSupport(const QString ¶m)
758 if (_supports.contains(param)) {
759 _supports.remove(param);
765 QVariantMap Network::initSupports() const
767 QVariantMap supports;
768 QHashIterator<QString, QString> iter(_supports);
769 while (iter.hasNext()) {
771 supports[iter.key()] = iter.value();
777 QVariantMap Network::initIrcUsersAndChannels() const
779 QVariantMap usersAndChannels;
781 QVariantMap channels;
783 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
784 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
785 while (userIter != userIterEnd) {
786 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
789 usersAndChannels["users"] = users;
791 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
792 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
793 while (channelIter != channelIterEnd) {
794 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
797 usersAndChannels["channels"] = channels;
799 return usersAndChannels;
803 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels)
806 if (isInitialized()) {
807 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
811 QVariantMap users = usersAndChannels.value("users").toMap();
812 QVariantMap::const_iterator userIter = users.constBegin();
813 QVariantMap::const_iterator userIterEnd = users.constEnd();
814 while (userIter != userIterEnd) {
815 newIrcUser(userIter.key(), userIter.value().toMap());
819 QVariantMap channels = usersAndChannels.value("channels").toMap();
820 QVariantMap::const_iterator channelIter = channels.constBegin();
821 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
822 while (channelIter != channelIterEnd) {
823 newIrcChannel(channelIter.key(), channelIter.value().toMap());
829 void Network::initSetSupports(const QVariantMap &supports)
831 QMapIterator<QString, QVariant> iter(supports);
832 while (iter.hasNext()) {
834 addSupport(iter.key(), iter.value().toString());
839 IrcUser *Network::updateNickFromMask(const QString &mask)
841 QString nick(nickFromMask(mask).toLower());
844 if (_ircUsers.contains(nick)) {
845 ircuser = _ircUsers[nick];
846 ircuser->updateHostmask(mask);
849 ircuser = newIrcUser(mask);
855 void Network::ircUserNickChanged(QString newnick)
857 QString oldnick = _ircUsers.key(qobject_cast<IrcUser *>(sender()));
859 if (oldnick.isNull())
862 if (newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
864 if (myNick().toLower() == oldnick)
869 void Network::emitConnectionError(const QString &errorMsg)
871 emit connectionError(errorMsg);
875 // ====================
877 // ====================
878 void Network::determinePrefixes() const
880 // seems like we have to construct them first
881 QString prefix = support("PREFIX");
883 if (prefix.startsWith("(") && prefix.contains(")")) {
884 _prefixes = prefix.section(")", 1);
885 _prefixModes = prefix.mid(1).section(")", 0, 0);
888 QString defaultPrefixes("~&@%+");
889 QString defaultPrefixModes("qaohv");
891 if (prefix.isEmpty()) {
892 _prefixes = defaultPrefixes;
893 _prefixModes = defaultPrefixModes;
896 // clear the existing modes, just in case we're run multiple times
897 _prefixes = QString();
898 _prefixModes = QString();
900 // we just assume that in PREFIX are only prefix chars stored
901 for (int i = 0; i < defaultPrefixes.size(); i++) {
902 if (prefix.contains(defaultPrefixes[i])) {
903 _prefixes += defaultPrefixes[i];
904 _prefixModes += defaultPrefixModes[i];
908 if (!_prefixes.isNull())
911 // well... our assumption was obviously wrong...
912 // check if it's only prefix modes
913 for (int i = 0; i < defaultPrefixes.size(); i++) {
914 if (prefix.contains(defaultPrefixModes[i])) {
915 _prefixes += defaultPrefixes[i];
916 _prefixModes += defaultPrefixModes[i];
919 // now we've done all we've could...
924 /************************************************************************
926 ************************************************************************/
928 NetworkInfo::NetworkInfo()
931 useRandomServer(false),
932 useAutoIdentify(false),
933 autoIdentifyService("NickServ"),
935 useAutoReconnect(true),
936 autoReconnectInterval(60),
937 autoReconnectRetries(20),
938 unlimitedReconnectRetries(false),
944 bool NetworkInfo::operator==(const NetworkInfo &other) const
946 if (networkId != other.networkId) return false;
947 if (networkName != other.networkName) return false;
948 if (identity != other.identity) return false;
949 if (codecForServer != other.codecForServer) return false;
950 if (codecForEncoding != other.codecForEncoding) return false;
951 if (codecForDecoding != other.codecForDecoding) return false;
952 if (serverList != other.serverList) return false;
953 if (useRandomServer != other.useRandomServer) return false;
954 if (perform != other.perform) return false;
955 if (useAutoIdentify != other.useAutoIdentify) return false;
956 if (autoIdentifyService != other.autoIdentifyService) return false;
957 if (autoIdentifyPassword != other.autoIdentifyPassword) return false;
958 if (useSasl != other.useSasl) return false;
959 if (saslAccount != other.saslAccount) return false;
960 if (saslPassword != other.saslPassword) return false;
961 if (useAutoReconnect != other.useAutoReconnect) return false;
962 if (autoReconnectInterval != other.autoReconnectInterval) return false;
963 if (autoReconnectRetries != other.autoReconnectRetries) return false;
964 if (unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
965 if (rejoinChannels != other.rejoinChannels) return false;
970 bool NetworkInfo::operator!=(const NetworkInfo &other) const
972 return !(*this == other);
976 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info)
979 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
980 i["NetworkName"] = info.networkName;
981 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
982 i["CodecForServer"] = info.codecForServer;
983 i["CodecForEncoding"] = info.codecForEncoding;
984 i["CodecForDecoding"] = info.codecForDecoding;
985 i["ServerList"] = toVariantList(info.serverList);
986 i["UseRandomServer"] = info.useRandomServer;
987 i["Perform"] = info.perform;
988 i["UseAutoIdentify"] = info.useAutoIdentify;
989 i["AutoIdentifyService"] = info.autoIdentifyService;
990 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
991 i["UseSasl"] = info.useSasl;
992 i["SaslAccount"] = info.saslAccount;
993 i["SaslPassword"] = info.saslPassword;
994 i["UseAutoReconnect"] = info.useAutoReconnect;
995 i["AutoReconnectInterval"] = info.autoReconnectInterval;
996 i["AutoReconnectRetries"] = info.autoReconnectRetries;
997 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
998 i["RejoinChannels"] = info.rejoinChannels;
1004 QDataStream &operator>>(QDataStream &in, NetworkInfo &info)
1008 info.networkId = i["NetworkId"].value<NetworkId>();
1009 info.networkName = i["NetworkName"].toString();
1010 info.identity = i["Identity"].value<IdentityId>();
1011 info.codecForServer = i["CodecForServer"].toByteArray();
1012 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
1013 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
1014 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
1015 info.useRandomServer = i["UseRandomServer"].toBool();
1016 info.perform = i["Perform"].toStringList();
1017 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
1018 info.autoIdentifyService = i["AutoIdentifyService"].toString();
1019 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
1020 info.useSasl = i["UseSasl"].toBool();
1021 info.saslAccount = i["SaslAccount"].toString();
1022 info.saslPassword = i["SaslPassword"].toString();
1023 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
1024 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
1025 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
1026 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
1027 info.rejoinChannels = i["RejoinChannels"].toBool();
1032 QDebug operator<<(QDebug dbg, const NetworkInfo &i)
1034 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
1035 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
1036 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
1037 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
1038 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
1039 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
1040 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
1041 << " rejoinChannels = " << i.rejoinChannels << ")";
1046 QDataStream &operator<<(QDataStream &out, const Network::Server &server)
1048 QVariantMap serverMap;
1049 serverMap["Host"] = server.host;
1050 serverMap["Port"] = server.port;
1051 serverMap["Password"] = server.password;
1052 serverMap["UseSSL"] = server.useSsl;
1053 serverMap["sslVersion"] = server.sslVersion;
1054 serverMap["UseProxy"] = server.useProxy;
1055 serverMap["ProxyType"] = server.proxyType;
1056 serverMap["ProxyHost"] = server.proxyHost;
1057 serverMap["ProxyPort"] = server.proxyPort;
1058 serverMap["ProxyUser"] = server.proxyUser;
1059 serverMap["ProxyPass"] = server.proxyPass;
1065 QDataStream &operator>>(QDataStream &in, Network::Server &server)
1067 QVariantMap serverMap;
1069 server.host = serverMap["Host"].toString();
1070 server.port = serverMap["Port"].toUInt();
1071 server.password = serverMap["Password"].toString();
1072 server.useSsl = serverMap["UseSSL"].toBool();
1073 server.sslVersion = serverMap["sslVersion"].toInt();
1074 server.useProxy = serverMap["UseProxy"].toBool();
1075 server.proxyType = serverMap["ProxyType"].toInt();
1076 server.proxyHost = serverMap["ProxyHost"].toString();
1077 server.proxyPort = serverMap["ProxyPort"].toUInt();
1078 server.proxyUser = serverMap["ProxyUser"].toString();
1079 server.proxyPass = serverMap["ProxyPass"].toString();
1084 bool Network::Server::operator==(const Server &other) const
1086 if (host != other.host) return false;
1087 if (port != other.port) return false;
1088 if (password != other.password) return false;
1089 if (useSsl != other.useSsl) return false;
1090 if (sslVersion != other.sslVersion) return false;
1091 if (useProxy != other.useProxy) return false;
1092 if (proxyType != other.proxyType) return false;
1093 if (proxyHost != other.proxyHost) return false;
1094 if (proxyPort != other.proxyPort) return false;
1095 if (proxyUser != other.proxyUser) return false;
1096 if (proxyPass != other.proxyPass) return false;
1101 bool Network::Server::operator!=(const Server &other) const
1103 return !(*this == other);
1107 QDebug operator<<(QDebug dbg, const Network::Server &server)
1109 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";