1 /***************************************************************************
2 * Copyright (C) 2005-2012 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()));
66 emit aboutToBeDestroyed();
70 bool Network::isChannelName(const QString &channelname) const
72 if (channelname.isEmpty())
75 if (supports("CHANTYPES"))
76 return support("CHANTYPES").contains(channelname[0]);
78 return QString("#&!+").contains(channelname[0]);
82 NetworkInfo Network::networkInfo() const
85 info.networkName = networkName();
86 info.networkId = networkId();
87 info.identity = identity();
88 info.codecForServer = codecForServer();
89 info.codecForEncoding = codecForEncoding();
90 info.codecForDecoding = codecForDecoding();
91 info.serverList = serverList();
92 info.useRandomServer = useRandomServer();
93 info.perform = perform();
94 info.useAutoIdentify = useAutoIdentify();
95 info.autoIdentifyService = autoIdentifyService();
96 info.autoIdentifyPassword = autoIdentifyPassword();
97 info.useSasl = useSasl();
98 info.saslAccount = saslAccount();
99 info.saslPassword = saslPassword();
100 info.useAutoReconnect = useAutoReconnect();
101 info.autoReconnectInterval = autoReconnectInterval();
102 info.autoReconnectRetries = autoReconnectRetries();
103 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
104 info.rejoinChannels = rejoinChannels();
109 void Network::setNetworkInfo(const NetworkInfo &info)
111 // we don't set our ID!
112 if (!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
113 if (info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
114 if (info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
115 if (info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
116 if (info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
117 if (info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
118 if (info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
119 if (info.perform != perform()) setPerform(info.perform);
120 if (info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
121 if (info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
122 if (info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
123 if (info.useSasl != useSasl()) setUseSasl(info.useSasl);
124 if (info.saslAccount != saslAccount()) setSaslAccount(info.saslAccount);
125 if (info.saslPassword != saslPassword()) setSaslPassword(info.saslPassword);
126 if (info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
127 if (info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
128 if (info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
129 if (info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
130 if (info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
134 QString Network::prefixToMode(const QString &prefix) const
136 if (prefixes().contains(prefix))
137 return QString(prefixModes()[prefixes().indexOf(prefix)]);
143 QString Network::modeToPrefix(const QString &mode) const
145 if (prefixModes().contains(mode))
146 return QString(prefixes()[prefixModes().indexOf(mode)]);
152 QStringList Network::nicks() const
154 // we don't use _ircUsers.keys() since the keys may be
155 // not up to date after a nick change
157 foreach(IrcUser *ircuser, _ircUsers.values()) {
158 nicks << ircuser->nick();
164 QString Network::prefixes() const
166 if (_prefixes.isNull())
173 QString Network::prefixModes() const
175 if (_prefixModes.isNull())
182 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
183 Network::ChannelModeType Network::channelModeType(const QString &mode)
186 return NOT_A_CHANMODE;
188 QString chanmodes = support("CHANMODES");
189 if (chanmodes.isEmpty())
190 return NOT_A_CHANMODE;
192 ChannelModeType modeType = A_CHANMODE;
193 for (int i = 0; i < chanmodes.count(); i++) {
194 if (chanmodes[i] == mode[0])
196 else if (chanmodes[i] == ',')
197 modeType = (ChannelModeType)(modeType << 1);
199 if (modeType > D_CHANMODE) {
200 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
201 modeType = NOT_A_CHANMODE;
207 QString Network::support(const QString ¶m) const
209 QString support_ = param.toUpper();
210 if (_supports.contains(support_))
211 return _supports[support_];
217 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData)
219 QString nick(nickFromMask(hostmask).toLower());
220 if (!_ircUsers.contains(nick)) {
221 IrcUser *ircuser = ircUserFactory(hostmask);
222 if (!initData.isEmpty()) {
223 ircuser->fromVariantMap(initData);
224 ircuser->setInitialized();
228 proxy()->synchronize(ircuser);
230 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
232 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
234 _ircUsers[nick] = ircuser;
236 SYNC_OTHER(addIrcUser, ARG(hostmask))
237 // emit ircUserAdded(hostmask);
238 emit ircUserAdded(ircuser);
241 return _ircUsers[nick];
245 IrcUser *Network::ircUser(QString nickname) const
247 nickname = nickname.toLower();
248 if (_ircUsers.contains(nickname))
249 return _ircUsers[nickname];
255 void Network::removeIrcUser(IrcUser *ircuser)
257 QString nick = _ircUsers.key(ircuser);
261 _ircUsers.remove(nick);
262 disconnect(ircuser, 0, this, 0);
263 ircuser->deleteLater();
267 void Network::removeIrcChannel(IrcChannel *channel)
269 QString chanName = _ircChannels.key(channel);
270 if (chanName.isNull())
273 _ircChannels.remove(chanName);
274 disconnect(channel, 0, this, 0);
275 channel->deleteLater();
279 void Network::removeChansAndUsers()
281 QList<IrcUser *> users = ircUsers();
283 QList<IrcChannel *> channels = ircChannels();
284 _ircChannels.clear();
286 foreach(IrcChannel *channel, channels) {
287 proxy()->detachObject(channel);
288 disconnect(channel, 0, this, 0);
290 foreach(IrcUser *user, users) {
291 proxy()->detachObject(user);
292 disconnect(user, 0, this, 0);
295 // the second loop is needed because quit can have sideffects
296 foreach(IrcUser *user, users) {
301 qDeleteAll(channels);
305 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData)
307 if (!_ircChannels.contains(channelname.toLower())) {
308 IrcChannel *channel = ircChannelFactory(channelname);
309 if (!initData.isEmpty()) {
310 channel->fromVariantMap(initData);
311 channel->setInitialized();
315 proxy()->synchronize(channel);
317 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
319 _ircChannels[channelname.toLower()] = channel;
321 SYNC_OTHER(addIrcChannel, ARG(channelname))
322 // emit ircChannelAdded(channelname);
323 emit ircChannelAdded(channel);
325 return _ircChannels[channelname.toLower()];
329 IrcChannel *Network::ircChannel(QString channelname) const
331 channelname = channelname.toLower();
332 if (_ircChannels.contains(channelname))
333 return _ircChannels[channelname];
339 QByteArray Network::defaultCodecForServer()
341 if (_defaultCodecForServer)
342 return _defaultCodecForServer->name();
347 void Network::setDefaultCodecForServer(const QByteArray &name)
349 _defaultCodecForServer = QTextCodec::codecForName(name);
353 QByteArray Network::defaultCodecForEncoding()
355 if (_defaultCodecForEncoding)
356 return _defaultCodecForEncoding->name();
361 void Network::setDefaultCodecForEncoding(const QByteArray &name)
363 _defaultCodecForEncoding = QTextCodec::codecForName(name);
367 QByteArray Network::defaultCodecForDecoding()
369 if (_defaultCodecForDecoding)
370 return _defaultCodecForDecoding->name();
375 void Network::setDefaultCodecForDecoding(const QByteArray &name)
377 _defaultCodecForDecoding = QTextCodec::codecForName(name);
381 QByteArray Network::codecForServer() const
384 return _codecForServer->name();
389 void Network::setCodecForServer(const QByteArray &name)
391 setCodecForServer(QTextCodec::codecForName(name));
395 void Network::setCodecForServer(QTextCodec *codec)
397 _codecForServer = codec;
398 QByteArray codecName = codecForServer();
399 SYNC_OTHER(setCodecForServer, ARG(codecName))
400 emit configChanged();
404 QByteArray Network::codecForEncoding() const
406 if (_codecForEncoding)
407 return _codecForEncoding->name();
412 void Network::setCodecForEncoding(const QByteArray &name)
414 setCodecForEncoding(QTextCodec::codecForName(name));
418 void Network::setCodecForEncoding(QTextCodec *codec)
420 _codecForEncoding = codec;
421 QByteArray codecName = codecForEncoding();
422 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
423 emit configChanged();
427 QByteArray Network::codecForDecoding() const
429 if (_codecForDecoding)
430 return _codecForDecoding->name();
431 else return QByteArray();
435 void Network::setCodecForDecoding(const QByteArray &name)
437 setCodecForDecoding(QTextCodec::codecForName(name));
441 void Network::setCodecForDecoding(QTextCodec *codec)
443 _codecForDecoding = codec;
444 QByteArray codecName = codecForDecoding();
445 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
446 emit configChanged();
450 // FIXME use server encoding if appropriate
451 QString Network::decodeString(const QByteArray &text) const
453 if (_codecForDecoding)
454 return ::decodeString(text, _codecForDecoding);
455 else return ::decodeString(text, _defaultCodecForDecoding);
459 QByteArray Network::encodeString(const QString &string) const
461 if (_codecForEncoding) {
462 return _codecForEncoding->fromUnicode(string);
464 if (_defaultCodecForEncoding) {
465 return _defaultCodecForEncoding->fromUnicode(string);
467 return string.toAscii();
471 QString Network::decodeServerString(const QByteArray &text) const
474 return ::decodeString(text, _codecForServer);
476 return ::decodeString(text, _defaultCodecForServer);
480 QByteArray Network::encodeServerString(const QString &string) const
482 if (_codecForServer) {
483 return _codecForServer->fromUnicode(string);
485 if (_defaultCodecForServer) {
486 return _defaultCodecForServer->fromUnicode(string);
488 return string.toAscii();
492 /*** Handle networks.ini ***/
494 QStringList Network::presetNetworks(bool onlyDefault)
496 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
497 if (_networksIniPath.isNull()) {
498 _networksIniPath = Quassel::findDataFilePath("networks.ini");
499 if (_networksIniPath.isNull()) {
500 _networksIniPath = ""; // now we won't check again, as it's not null anymore
501 return QStringList();
504 if (!_networksIniPath.isEmpty()) {
505 QSettings s(_networksIniPath, QSettings::IniFormat);
506 QStringList networks = s.childGroups();
507 if (!networks.isEmpty()) {
508 // we sort the list case-insensitive
509 QMap<QString, QString> sorted;
510 foreach(QString net, networks) {
511 if (onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
513 sorted[net.toLower()] = net;
515 return sorted.values();
518 return QStringList();
522 QStringList Network::presetDefaultChannels(const QString &networkName)
524 if (_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
525 return QStringList();
526 QSettings s(_networksIniPath, QSettings::IniFormat);
527 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
531 NetworkInfo Network::networkInfoFromPreset(const QString &networkName)
534 if (!_networksIniPath.isEmpty()) {
535 info.networkName = networkName;
536 QSettings s(_networksIniPath, QSettings::IniFormat);
537 s.beginGroup(info.networkName);
538 foreach(QString server, s.value("Servers").toStringList()) {
540 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
541 if (splitserver.count() != 2) {
542 qWarning() << "Invalid server entry in networks.conf:" << server;
545 if (splitserver[1].at(0) == '+')
547 uint port = splitserver[1].toUInt();
549 qWarning() << "Invalid port entry in networks.conf:" << server;
552 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
559 // ====================
561 // ====================
562 void Network::setNetworkName(const QString &networkName)
564 _networkName = networkName;
565 SYNC(ARG(networkName))
566 emit networkNameSet(networkName);
567 emit configChanged();
571 void Network::setCurrentServer(const QString ¤tServer)
573 _currentServer = currentServer;
574 SYNC(ARG(currentServer))
575 emit currentServerSet(currentServer);
579 void Network::setConnected(bool connected)
581 if (_connected == connected)
584 _connected = connected;
586 setMyNick(QString());
587 setCurrentServer(QString());
588 removeChansAndUsers();
591 emit connectedSet(connected);
595 //void Network::setConnectionState(ConnectionState state) {
596 void Network::setConnectionState(int state)
598 _connectionState = (ConnectionState)state;
599 //qDebug() << "netstate" << networkId() << networkName() << state;
601 emit connectionStateSet(_connectionState);
605 void Network::setMyNick(const QString &nickname)
608 if (!_myNick.isEmpty() && !ircUser(myNick())) {
609 newIrcUser(myNick());
612 emit myNickSet(nickname);
616 void Network::setLatency(int latency)
618 if (_latency == latency)
625 void Network::setIdentity(IdentityId id)
629 emit identitySet(id);
630 emit configChanged();
634 void Network::setServerList(const QVariantList &serverList)
636 _serverList = fromVariantList<Server>(serverList);
637 SYNC(ARG(serverList))
638 emit configChanged();
642 void Network::setUseRandomServer(bool use)
644 _useRandomServer = use;
646 emit configChanged();
650 void Network::setPerform(const QStringList &perform)
654 emit configChanged();
658 void Network::setUseAutoIdentify(bool use)
660 _useAutoIdentify = use;
662 emit configChanged();
666 void Network::setAutoIdentifyService(const QString &service)
668 _autoIdentifyService = service;
670 emit configChanged();
674 void Network::setAutoIdentifyPassword(const QString &password)
676 _autoIdentifyPassword = password;
678 emit configChanged();
682 void Network::setUseSasl(bool use)
686 emit configChanged();
690 void Network::setSaslAccount(const QString &account)
692 _saslAccount = account;
694 emit configChanged();
698 void Network::setSaslPassword(const QString &password)
700 _saslPassword = password;
702 emit configChanged();
706 void Network::setUseAutoReconnect(bool use)
708 _useAutoReconnect = use;
710 emit configChanged();
714 void Network::setAutoReconnectInterval(quint32 interval)
716 _autoReconnectInterval = interval;
718 emit configChanged();
722 void Network::setAutoReconnectRetries(quint16 retries)
724 _autoReconnectRetries = retries;
726 emit configChanged();
730 void Network::setUnlimitedReconnectRetries(bool unlimited)
732 _unlimitedReconnectRetries = unlimited;
734 emit configChanged();
738 void Network::setRejoinChannels(bool rejoin)
740 _rejoinChannels = rejoin;
742 emit configChanged();
746 void Network::addSupport(const QString ¶m, const QString &value)
748 if (!_supports.contains(param)) {
749 _supports[param] = value;
750 SYNC(ARG(param), ARG(value))
755 void Network::removeSupport(const QString ¶m)
757 if (_supports.contains(param)) {
758 _supports.remove(param);
764 QVariantMap Network::initSupports() const
766 QVariantMap supports;
767 QHashIterator<QString, QString> iter(_supports);
768 while (iter.hasNext()) {
770 supports[iter.key()] = iter.value();
776 QVariantMap Network::initIrcUsersAndChannels() const
778 QVariantMap usersAndChannels;
780 QVariantMap channels;
782 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
783 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
784 while (userIter != userIterEnd) {
785 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
788 usersAndChannels["users"] = users;
790 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
791 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
792 while (channelIter != channelIterEnd) {
793 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
796 usersAndChannels["channels"] = channels;
798 return usersAndChannels;
802 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels)
805 if (isInitialized()) {
806 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
810 QVariantMap users = usersAndChannels.value("users").toMap();
811 QVariantMap::const_iterator userIter = users.constBegin();
812 QVariantMap::const_iterator userIterEnd = users.constEnd();
813 while (userIter != userIterEnd) {
814 newIrcUser(userIter.key(), userIter.value().toMap());
818 QVariantMap channels = usersAndChannels.value("channels").toMap();
819 QVariantMap::const_iterator channelIter = channels.constBegin();
820 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
821 while (channelIter != channelIterEnd) {
822 newIrcChannel(channelIter.key(), channelIter.value().toMap());
828 void Network::initSetSupports(const QVariantMap &supports)
830 QMapIterator<QString, QVariant> iter(supports);
831 while (iter.hasNext()) {
833 addSupport(iter.key(), iter.value().toString());
838 IrcUser *Network::updateNickFromMask(const QString &mask)
840 QString nick(nickFromMask(mask).toLower());
843 if (_ircUsers.contains(nick)) {
844 ircuser = _ircUsers[nick];
845 ircuser->updateHostmask(mask);
848 ircuser = newIrcUser(mask);
854 void Network::ircUserNickChanged(QString newnick)
856 QString oldnick = _ircUsers.key(qobject_cast<IrcUser *>(sender()));
858 if (oldnick.isNull())
861 if (newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
863 if (myNick().toLower() == oldnick)
868 void Network::emitConnectionError(const QString &errorMsg)
870 emit connectionError(errorMsg);
874 // ====================
876 // ====================
877 void Network::determinePrefixes() const
879 // seems like we have to construct them first
880 QString prefix = support("PREFIX");
882 if (prefix.startsWith("(") && prefix.contains(")")) {
883 _prefixes = prefix.section(")", 1);
884 _prefixModes = prefix.mid(1).section(")", 0, 0);
887 QString defaultPrefixes("~&@%+");
888 QString defaultPrefixModes("qaohv");
890 if (prefix.isEmpty()) {
891 _prefixes = defaultPrefixes;
892 _prefixModes = defaultPrefixModes;
895 // clear the existing modes, just in case we're run multiple times
896 _prefixes = QString();
897 _prefixModes = QString();
899 // we just assume that in PREFIX are only prefix chars stored
900 for (int i = 0; i < defaultPrefixes.size(); i++) {
901 if (prefix.contains(defaultPrefixes[i])) {
902 _prefixes += defaultPrefixes[i];
903 _prefixModes += defaultPrefixModes[i];
907 if (!_prefixes.isNull())
910 // well... our assumption was obviously wrong...
911 // check if it's only prefix modes
912 for (int i = 0; i < defaultPrefixes.size(); i++) {
913 if (prefix.contains(defaultPrefixModes[i])) {
914 _prefixes += defaultPrefixes[i];
915 _prefixModes += defaultPrefixModes[i];
918 // now we've done all we've could...
923 /************************************************************************
925 ************************************************************************/
927 NetworkInfo::NetworkInfo()
930 useRandomServer(false),
931 useAutoIdentify(false),
932 autoIdentifyService("NickServ"),
934 useAutoReconnect(true),
935 autoReconnectInterval(60),
936 autoReconnectRetries(20),
937 unlimitedReconnectRetries(false),
943 bool NetworkInfo::operator==(const NetworkInfo &other) const
945 if (networkId != other.networkId) return false;
946 if (networkName != other.networkName) return false;
947 if (identity != other.identity) return false;
948 if (codecForServer != other.codecForServer) return false;
949 if (codecForEncoding != other.codecForEncoding) return false;
950 if (codecForDecoding != other.codecForDecoding) return false;
951 if (serverList != other.serverList) return false;
952 if (useRandomServer != other.useRandomServer) return false;
953 if (perform != other.perform) return false;
954 if (useAutoIdentify != other.useAutoIdentify) return false;
955 if (autoIdentifyService != other.autoIdentifyService) return false;
956 if (autoIdentifyPassword != other.autoIdentifyPassword) return false;
957 if (useSasl != other.useSasl) return false;
958 if (saslAccount != other.saslAccount) return false;
959 if (saslPassword != other.saslPassword) return false;
960 if (useAutoReconnect != other.useAutoReconnect) return false;
961 if (autoReconnectInterval != other.autoReconnectInterval) return false;
962 if (autoReconnectRetries != other.autoReconnectRetries) return false;
963 if (unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
964 if (rejoinChannels != other.rejoinChannels) return false;
969 bool NetworkInfo::operator!=(const NetworkInfo &other) const
971 return !(*this == other);
975 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info)
978 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
979 i["NetworkName"] = info.networkName;
980 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
981 i["CodecForServer"] = info.codecForServer;
982 i["CodecForEncoding"] = info.codecForEncoding;
983 i["CodecForDecoding"] = info.codecForDecoding;
984 i["ServerList"] = toVariantList(info.serverList);
985 i["UseRandomServer"] = info.useRandomServer;
986 i["Perform"] = info.perform;
987 i["UseAutoIdentify"] = info.useAutoIdentify;
988 i["AutoIdentifyService"] = info.autoIdentifyService;
989 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
990 i["UseSasl"] = info.useSasl;
991 i["SaslAccount"] = info.saslAccount;
992 i["SaslPassword"] = info.saslPassword;
993 i["UseAutoReconnect"] = info.useAutoReconnect;
994 i["AutoReconnectInterval"] = info.autoReconnectInterval;
995 i["AutoReconnectRetries"] = info.autoReconnectRetries;
996 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
997 i["RejoinChannels"] = info.rejoinChannels;
1003 QDataStream &operator>>(QDataStream &in, NetworkInfo &info)
1007 info.networkId = i["NetworkId"].value<NetworkId>();
1008 info.networkName = i["NetworkName"].toString();
1009 info.identity = i["Identity"].value<IdentityId>();
1010 info.codecForServer = i["CodecForServer"].toByteArray();
1011 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
1012 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
1013 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
1014 info.useRandomServer = i["UseRandomServer"].toBool();
1015 info.perform = i["Perform"].toStringList();
1016 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
1017 info.autoIdentifyService = i["AutoIdentifyService"].toString();
1018 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
1019 info.useSasl = i["UseSasl"].toBool();
1020 info.saslAccount = i["SaslAccount"].toString();
1021 info.saslPassword = i["SaslPassword"].toString();
1022 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
1023 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
1024 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
1025 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
1026 info.rejoinChannels = i["RejoinChannels"].toBool();
1031 QDebug operator<<(QDebug dbg, const NetworkInfo &i)
1033 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
1034 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
1035 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
1036 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
1037 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
1038 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
1039 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
1040 << " rejoinChannels = " << i.rejoinChannels << ")";
1045 QDataStream &operator<<(QDataStream &out, const Network::Server &server)
1047 QVariantMap serverMap;
1048 serverMap["Host"] = server.host;
1049 serverMap["Port"] = server.port;
1050 serverMap["Password"] = server.password;
1051 serverMap["UseSSL"] = server.useSsl;
1052 serverMap["sslVersion"] = server.sslVersion;
1053 serverMap["UseProxy"] = server.useProxy;
1054 serverMap["ProxyType"] = server.proxyType;
1055 serverMap["ProxyHost"] = server.proxyHost;
1056 serverMap["ProxyPort"] = server.proxyPort;
1057 serverMap["ProxyUser"] = server.proxyUser;
1058 serverMap["ProxyPass"] = server.proxyPass;
1064 QDataStream &operator>>(QDataStream &in, Network::Server &server)
1066 QVariantMap serverMap;
1068 server.host = serverMap["Host"].toString();
1069 server.port = serverMap["Port"].toUInt();
1070 server.password = serverMap["Password"].toString();
1071 server.useSsl = serverMap["UseSSL"].toBool();
1072 server.sslVersion = serverMap["sslVersion"].toInt();
1073 server.useProxy = serverMap["UseProxy"].toBool();
1074 server.proxyType = serverMap["ProxyType"].toInt();
1075 server.proxyHost = serverMap["ProxyHost"].toString();
1076 server.proxyPort = serverMap["ProxyPort"].toUInt();
1077 server.proxyUser = serverMap["ProxyUser"].toString();
1078 server.proxyPass = serverMap["ProxyPass"].toString();
1083 bool Network::Server::operator==(const Server &other) const
1085 if (host != other.host) return false;
1086 if (port != other.port) return false;
1087 if (password != other.password) return false;
1088 if (useSsl != other.useSsl) return false;
1089 if (sslVersion != other.sslVersion) return false;
1090 if (useProxy != other.useProxy) return false;
1091 if (proxyType != other.proxyType) return false;
1092 if (proxyHost != other.proxyHost) return false;
1093 if (proxyPort != other.proxyPort) return false;
1094 if (proxyUser != other.proxyUser) return false;
1095 if (proxyPass != other.proxyPass) return false;
1100 bool Network::Server::operator!=(const Server &other) const
1102 return !(*this == other);
1106 QDebug operator<<(QDebug dbg, const Network::Server &server)
1108 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";