1 /***************************************************************************
2 * Copyright (C) 2005-2010 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 QTextCodec *Network::_defaultCodecForServer = 0;
27 QTextCodec *Network::_defaultCodecForEncoding = 0;
28 QTextCodec *Network::_defaultCodecForDecoding = 0;
29 QString Network::_networksIniPath = QString();
31 // ====================
33 // ====================
34 INIT_SYNCABLE_OBJECT(Network)
35 Network::Network(const NetworkId &networkid, QObject *parent)
36 : SyncableObject(parent),
38 _networkId(networkid),
42 _networkName(QString("<not initialized>")),
43 _currentServer(QString()),
45 _connectionState(Disconnected),
47 _prefixModes(QString()),
48 _useRandomServer(false),
49 _useAutoIdentify(false),
51 _useAutoReconnect(false),
52 _autoReconnectInterval(60),
53 _autoReconnectRetries(10),
54 _unlimitedReconnectRetries(false),
58 _autoAwayActive(false)
60 setObjectName(QString::number(networkid.toInt()));
64 emit aboutToBeDestroyed();
67 bool Network::isChannelName(const QString &channelname) const {
68 if(channelname.isEmpty())
71 if(supports("CHANTYPES"))
72 return support("CHANTYPES").contains(channelname[0]);
74 return QString("#&!+").contains(channelname[0]);
77 NetworkInfo Network::networkInfo() const {
79 info.networkName = networkName();
80 info.networkId = networkId();
81 info.identity = identity();
82 info.codecForServer = codecForServer();
83 info.codecForEncoding = codecForEncoding();
84 info.codecForDecoding = codecForDecoding();
85 info.serverList = serverList();
86 info.useRandomServer = useRandomServer();
87 info.perform = perform();
88 info.useAutoIdentify = useAutoIdentify();
89 info.autoIdentifyService = autoIdentifyService();
90 info.autoIdentifyPassword = autoIdentifyPassword();
91 info.useSasl = useSasl();
92 info.saslAccount = saslAccount();
93 info.saslPassword = saslPassword();
94 info.useAutoReconnect = useAutoReconnect();
95 info.autoReconnectInterval = autoReconnectInterval();
96 info.autoReconnectRetries = autoReconnectRetries();
97 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
98 info.rejoinChannels = rejoinChannels();
102 void Network::setNetworkInfo(const NetworkInfo &info) {
103 // we don't set our ID!
104 if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
105 if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
106 if(info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
107 if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
108 if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
109 if(info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
110 if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
111 if(info.perform != perform()) setPerform(info.perform);
112 if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
113 if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
114 if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
115 if(info.useSasl != useSasl()) setUseSasl(info.useSasl);
116 if(info.saslAccount != saslAccount()) setSaslAccount(info.saslAccount);
117 if(info.saslPassword != saslPassword()) setSaslPassword(info.saslPassword);
118 if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
119 if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
120 if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
121 if(info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
122 if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
125 QString Network::prefixToMode(const QString &prefix) {
126 if(prefixes().contains(prefix))
127 return QString(prefixModes()[prefixes().indexOf(prefix)]);
132 QString Network::modeToPrefix(const QString &mode) {
133 if(prefixModes().contains(mode))
134 return QString(prefixes()[prefixModes().indexOf(mode)]);
139 QStringList Network::nicks() const {
140 // we don't use _ircUsers.keys() since the keys may be
141 // not up to date after a nick change
143 foreach(IrcUser *ircuser, _ircUsers.values()) {
144 nicks << ircuser->nick();
149 QString Network::prefixes() {
150 if(_prefixes.isNull())
156 QString Network::prefixModes() {
157 if(_prefixModes.isNull())
163 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
164 Network::ChannelModeType Network::channelModeType(const QString &mode) {
166 return NOT_A_CHANMODE;
168 QString chanmodes = support("CHANMODES");
169 if(chanmodes.isEmpty())
170 return NOT_A_CHANMODE;
172 ChannelModeType modeType = A_CHANMODE;
173 for(int i = 0; i < chanmodes.count(); i++) {
174 if(chanmodes[i] == mode[0])
176 else if(chanmodes[i] == ',')
177 modeType = (ChannelModeType)(modeType << 1);
179 if(modeType > D_CHANMODE) {
180 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
181 modeType = NOT_A_CHANMODE;
186 QString Network::support(const QString ¶m) const {
187 QString support_ = param.toUpper();
188 if(_supports.contains(support_))
189 return _supports[support_];
194 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) {
195 QString nick(nickFromMask(hostmask).toLower());
196 if(!_ircUsers.contains(nick)) {
197 IrcUser *ircuser = ircUserFactory(hostmask);
198 if(!initData.isEmpty()) {
199 ircuser->fromVariantMap(initData);
200 ircuser->setInitialized();
204 proxy()->synchronize(ircuser);
206 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
208 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
210 _ircUsers[nick] = ircuser;
212 SYNC_OTHER(addIrcUser, ARG(hostmask))
213 // emit ircUserAdded(hostmask);
214 emit ircUserAdded(ircuser);
217 return _ircUsers[nick];
220 IrcUser *Network::ircUser(QString nickname) const {
221 nickname = nickname.toLower();
222 if(_ircUsers.contains(nickname))
223 return _ircUsers[nickname];
228 void Network::removeIrcUser(IrcUser *ircuser) {
229 QString nick = _ircUsers.key(ircuser);
233 _ircUsers.remove(nick);
234 disconnect(ircuser, 0, this, 0);
235 ircuser->deleteLater();
238 void Network::removeIrcChannel(IrcChannel *channel) {
239 QString chanName = _ircChannels.key(channel);
240 if(chanName.isNull())
243 _ircChannels.remove(chanName);
244 disconnect(channel, 0, this, 0);
245 channel->deleteLater();
248 void Network::removeChansAndUsers() {
249 QList<IrcUser *> users = ircUsers();
251 QList<IrcChannel *> channels = ircChannels();
252 _ircChannels.clear();
254 foreach(IrcChannel *channel, channels) {
255 proxy()->detachObject(channel);
256 disconnect(channel, 0, this, 0);
258 foreach(IrcUser *user, users) {
259 proxy()->detachObject(user);
260 disconnect(user, 0, this, 0);
263 // the second loop is needed because quit can have sideffects
264 foreach(IrcUser *user, users) {
269 qDeleteAll(channels);
272 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) {
273 if(!_ircChannels.contains(channelname.toLower())) {
274 IrcChannel *channel = ircChannelFactory(channelname);
275 if(!initData.isEmpty()) {
276 channel->fromVariantMap(initData);
277 channel->setInitialized();
281 proxy()->synchronize(channel);
283 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
285 _ircChannels[channelname.toLower()] = channel;
287 SYNC_OTHER(addIrcChannel, ARG(channelname))
288 // emit ircChannelAdded(channelname);
289 emit ircChannelAdded(channel);
291 return _ircChannels[channelname.toLower()];
294 IrcChannel *Network::ircChannel(QString channelname) const {
295 channelname = channelname.toLower();
296 if(_ircChannels.contains(channelname))
297 return _ircChannels[channelname];
302 QByteArray Network::defaultCodecForServer() {
303 if(_defaultCodecForServer)
304 return _defaultCodecForServer->name();
308 void Network::setDefaultCodecForServer(const QByteArray &name) {
309 _defaultCodecForServer = QTextCodec::codecForName(name);
312 QByteArray Network::defaultCodecForEncoding() {
313 if(_defaultCodecForEncoding)
314 return _defaultCodecForEncoding->name();
318 void Network::setDefaultCodecForEncoding(const QByteArray &name) {
319 _defaultCodecForEncoding = QTextCodec::codecForName(name);
322 QByteArray Network::defaultCodecForDecoding() {
323 if(_defaultCodecForDecoding)
324 return _defaultCodecForDecoding->name();
328 void Network::setDefaultCodecForDecoding(const QByteArray &name) {
329 _defaultCodecForDecoding = QTextCodec::codecForName(name);
332 QByteArray Network::codecForServer() const {
334 return _codecForServer->name();
338 void Network::setCodecForServer(const QByteArray &name) {
339 setCodecForServer(QTextCodec::codecForName(name));
342 void Network::setCodecForServer(QTextCodec *codec) {
343 _codecForServer = codec;
344 QByteArray codecName = codecForServer();
345 SYNC_OTHER(setCodecForServer, ARG(codecName))
346 emit configChanged();
349 QByteArray Network::codecForEncoding() const {
350 if(_codecForEncoding)
351 return _codecForEncoding->name();
355 void Network::setCodecForEncoding(const QByteArray &name) {
356 setCodecForEncoding(QTextCodec::codecForName(name));
359 void Network::setCodecForEncoding(QTextCodec *codec) {
360 _codecForEncoding = codec;
361 QByteArray codecName = codecForEncoding();
362 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
363 emit configChanged();
366 QByteArray Network::codecForDecoding() const {
367 if(_codecForDecoding)
368 return _codecForDecoding->name();
369 else return QByteArray();
372 void Network::setCodecForDecoding(const QByteArray &name) {
373 setCodecForDecoding(QTextCodec::codecForName(name));
376 void Network::setCodecForDecoding(QTextCodec *codec) {
377 _codecForDecoding = codec;
378 QByteArray codecName = codecForDecoding();
379 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
380 emit configChanged();
383 // FIXME use server encoding if appropriate
384 QString Network::decodeString(const QByteArray &text) const {
385 if(_codecForDecoding)
386 return ::decodeString(text, _codecForDecoding);
387 else return ::decodeString(text, _defaultCodecForDecoding);
390 QByteArray Network::encodeString(const QString &string) const {
391 if(_codecForEncoding) {
392 return _codecForEncoding->fromUnicode(string);
394 if(_defaultCodecForEncoding) {
395 return _defaultCodecForEncoding->fromUnicode(string);
397 return string.toAscii();
400 QString Network::decodeServerString(const QByteArray &text) const {
402 return ::decodeString(text, _codecForServer);
404 return ::decodeString(text, _defaultCodecForServer);
407 QByteArray Network::encodeServerString(const QString &string) const {
408 if(_codecForServer) {
409 return _codecForServer->fromUnicode(string);
411 if(_defaultCodecForServer) {
412 return _defaultCodecForServer->fromUnicode(string);
414 return string.toAscii();
417 /*** Handle networks.ini ***/
419 QStringList Network::presetNetworks(bool onlyDefault) {
420 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
421 if(_networksIniPath.isNull()) {
422 _networksIniPath = Quassel::findDataFilePath("networks.ini");
423 if(_networksIniPath.isNull()) {
424 _networksIniPath = ""; // now we won't check again, as it's not null anymore
425 return QStringList();
428 if(!_networksIniPath.isEmpty()) {
429 QSettings s(_networksIniPath, QSettings::IniFormat);
430 QStringList networks = s.childGroups();
431 if(!networks.isEmpty()) {
432 // we sort the list case-insensitive
433 QMap<QString, QString> sorted;
434 foreach(QString net, networks) {
435 if(onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
437 sorted[net.toLower()] = net;
439 return sorted.values();
442 return QStringList();
445 QStringList Network::presetDefaultChannels(const QString &networkName) {
446 if(_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
447 return QStringList();
448 QSettings s(_networksIniPath, QSettings::IniFormat);
449 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
452 NetworkInfo Network::networkInfoFromPreset(const QString &networkName) {
454 if(!_networksIniPath.isEmpty()) {
455 info.networkName = networkName;
456 QSettings s(_networksIniPath, QSettings::IniFormat);
457 s.beginGroup(info.networkName);
458 foreach(QString server, s.value("Servers").toStringList()) {
460 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
461 if(splitserver.count() != 2) {
462 qWarning() << "Invalid server entry in networks.conf:" << server;
465 if(splitserver[1].at(0) == '+')
467 uint port = splitserver[1].toUInt();
469 qWarning() << "Invalid port entry in networks.conf:" << server;
472 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
478 // ====================
480 // ====================
481 void Network::setNetworkName(const QString &networkName) {
482 _networkName = networkName;
483 SYNC(ARG(networkName))
484 emit networkNameSet(networkName);
485 emit configChanged();
488 void Network::setCurrentServer(const QString ¤tServer) {
489 _currentServer = currentServer;
490 SYNC(ARG(currentServer))
491 emit currentServerSet(currentServer);
494 void Network::setConnected(bool connected) {
495 if(_connected == connected)
498 _connected = connected;
500 setMyNick(QString());
501 setCurrentServer(QString());
502 removeChansAndUsers();
505 emit connectedSet(connected);
508 //void Network::setConnectionState(ConnectionState state) {
509 void Network::setConnectionState(int state) {
510 _connectionState = (ConnectionState)state;
511 //qDebug() << "netstate" << networkId() << networkName() << state;
513 emit connectionStateSet(_connectionState);
516 void Network::setMyNick(const QString &nickname) {
518 if(!_myNick.isEmpty() && !ircUser(myNick())) {
519 newIrcUser(myNick());
522 emit myNickSet(nickname);
525 void Network::setLatency(int latency) {
526 if(_latency == latency)
532 void Network::setIdentity(IdentityId id) {
535 emit identitySet(id);
536 emit configChanged();
539 void Network::setServerList(const QVariantList &serverList) {
540 _serverList = fromVariantList<Server>(serverList);
541 SYNC(ARG(serverList))
542 emit configChanged();
545 void Network::setUseRandomServer(bool use) {
546 _useRandomServer = use;
548 emit configChanged();
551 void Network::setPerform(const QStringList &perform) {
554 emit configChanged();
557 void Network::setUseAutoIdentify(bool use) {
558 _useAutoIdentify = use;
560 emit configChanged();
563 void Network::setAutoIdentifyService(const QString &service) {
564 _autoIdentifyService = service;
566 emit configChanged();
569 void Network::setAutoIdentifyPassword(const QString &password) {
570 _autoIdentifyPassword = password;
572 emit configChanged();
575 void Network::setUseSasl(bool use) {
578 emit configChanged();
581 void Network::setSaslAccount(const QString &account) {
582 _saslAccount = account;
584 emit configChanged();
587 void Network::setSaslPassword(const QString &password) {
588 _saslPassword = password;
590 emit configChanged();
593 void Network::setUseAutoReconnect(bool use) {
594 _useAutoReconnect = use;
596 emit configChanged();
599 void Network::setAutoReconnectInterval(quint32 interval) {
600 _autoReconnectInterval = interval;
602 emit configChanged();
605 void Network::setAutoReconnectRetries(quint16 retries) {
606 _autoReconnectRetries = retries;
608 emit configChanged();
611 void Network::setUnlimitedReconnectRetries(bool unlimited) {
612 _unlimitedReconnectRetries = unlimited;
614 emit configChanged();
617 void Network::setRejoinChannels(bool rejoin) {
618 _rejoinChannels = rejoin;
620 emit configChanged();
623 void Network::addSupport(const QString ¶m, const QString &value) {
624 if(!_supports.contains(param)) {
625 _supports[param] = value;
626 SYNC(ARG(param), ARG(value))
630 void Network::removeSupport(const QString ¶m) {
631 if(_supports.contains(param)) {
632 _supports.remove(param);
637 QVariantMap Network::initSupports() const {
638 QVariantMap supports;
639 QHashIterator<QString, QString> iter(_supports);
640 while(iter.hasNext()) {
642 supports[iter.key()] = iter.value();
647 QVariantMap Network::initIrcUsersAndChannels() const {
648 QVariantMap usersAndChannels;
650 QVariantMap channels;
652 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
653 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
654 while(userIter != userIterEnd) {
655 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
658 usersAndChannels["users"] = users;
660 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
661 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
662 while(channelIter != channelIterEnd) {
663 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
666 usersAndChannels["channels"] = channels;
668 return usersAndChannels;
671 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
673 if(isInitialized()) {
674 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
678 QVariantMap users = usersAndChannels.value("users").toMap();
679 QVariantMap::const_iterator userIter = users.constBegin();
680 QVariantMap::const_iterator userIterEnd = users.constEnd();
681 while(userIter != userIterEnd) {
682 newIrcUser(userIter.key(), userIter.value().toMap());
686 QVariantMap channels = usersAndChannels.value("channels").toMap();
687 QVariantMap::const_iterator channelIter = channels.constBegin();
688 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
689 while(channelIter != channelIterEnd) {
690 newIrcChannel(channelIter.key(), channelIter.value().toMap());
695 void Network::initSetSupports(const QVariantMap &supports) {
696 QMapIterator<QString, QVariant> iter(supports);
697 while(iter.hasNext()) {
699 addSupport(iter.key(), iter.value().toString());
703 IrcUser *Network::updateNickFromMask(const QString &mask) {
704 QString nick(nickFromMask(mask).toLower());
707 if(_ircUsers.contains(nick)) {
708 ircuser = _ircUsers[nick];
709 ircuser->updateHostmask(mask);
711 ircuser = newIrcUser(mask);
716 void Network::ircUserNickChanged(QString newnick) {
717 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
722 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
724 if(myNick().toLower() == oldnick)
728 void Network::emitConnectionError(const QString &errorMsg) {
729 emit connectionError(errorMsg);
732 // ====================
734 // ====================
735 void Network::determinePrefixes() {
736 // seems like we have to construct them first
737 QString prefix = support("PREFIX");
739 if(prefix.startsWith("(") && prefix.contains(")")) {
740 _prefixes = prefix.section(")", 1);
741 _prefixModes = prefix.mid(1).section(")", 0, 0);
743 QString defaultPrefixes("~&@%+");
744 QString defaultPrefixModes("qaohv");
746 if(prefix.isEmpty()) {
747 _prefixes = defaultPrefixes;
748 _prefixModes = defaultPrefixModes;
751 // clear the existing modes, just in case we're run multiple times
752 _prefixes = QString();
753 _prefixModes = QString();
755 // we just assume that in PREFIX are only prefix chars stored
756 for(int i = 0; i < defaultPrefixes.size(); i++) {
757 if(prefix.contains(defaultPrefixes[i])) {
758 _prefixes += defaultPrefixes[i];
759 _prefixModes += defaultPrefixModes[i];
763 if(!_prefixes.isNull())
766 // well... our assumption was obviously wrong...
767 // check if it's only prefix modes
768 for(int i = 0; i < defaultPrefixes.size(); i++) {
769 if(prefix.contains(defaultPrefixModes[i])) {
770 _prefixes += defaultPrefixes[i];
771 _prefixModes += defaultPrefixModes[i];
774 // now we've done all we've could...
778 /************************************************************************
780 ************************************************************************/
782 NetworkInfo::NetworkInfo()
785 useRandomServer(false),
786 useAutoIdentify(false),
787 autoIdentifyService("NickServ"),
789 useAutoReconnect(true),
790 autoReconnectInterval(60),
791 autoReconnectRetries(20),
792 unlimitedReconnectRetries(false),
798 bool NetworkInfo::operator==(const NetworkInfo &other) const {
799 if(networkId != other.networkId) return false;
800 if(networkName != other.networkName) return false;
801 if(identity != other.identity) return false;
802 if(codecForServer != other.codecForServer) return false;
803 if(codecForEncoding != other.codecForEncoding) return false;
804 if(codecForDecoding != other.codecForDecoding) return false;
805 if(serverList != other.serverList) return false;
806 if(useRandomServer != other.useRandomServer) return false;
807 if(perform != other.perform) return false;
808 if(useAutoIdentify != other.useAutoIdentify) return false;
809 if(autoIdentifyService != other.autoIdentifyService) return false;
810 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
811 if(useSasl != other.useSasl) return false;
812 if(saslAccount != other.saslAccount) return false;
813 if(saslPassword != other.saslPassword) return false;
814 if(useAutoReconnect != other.useAutoReconnect) return false;
815 if(autoReconnectInterval != other.autoReconnectInterval) return false;
816 if(autoReconnectRetries != other.autoReconnectRetries) return false;
817 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
818 if(rejoinChannels != other.rejoinChannels) return false;
822 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
823 return !(*this == other);
826 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
828 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
829 i["NetworkName"] = info.networkName;
830 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
831 i["CodecForServer"] = info.codecForServer;
832 i["CodecForEncoding"] = info.codecForEncoding;
833 i["CodecForDecoding"] = info.codecForDecoding;
834 i["ServerList"] = toVariantList(info.serverList);
835 i["UseRandomServer"] = info.useRandomServer;
836 i["Perform"] = info.perform;
837 i["UseAutoIdentify"] = info.useAutoIdentify;
838 i["AutoIdentifyService"] = info.autoIdentifyService;
839 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
840 i["UseSasl"] = info.useSasl;
841 i["SaslAccount"] = info.saslAccount;
842 i["SaslPassword"] = info.saslPassword;
843 i["UseAutoReconnect"] = info.useAutoReconnect;
844 i["AutoReconnectInterval"] = info.autoReconnectInterval;
845 i["AutoReconnectRetries"] = info.autoReconnectRetries;
846 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
847 i["RejoinChannels"] = info.rejoinChannels;
852 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
855 info.networkId = i["NetworkId"].value<NetworkId>();
856 info.networkName = i["NetworkName"].toString();
857 info.identity = i["Identity"].value<IdentityId>();
858 info.codecForServer = i["CodecForServer"].toByteArray();
859 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
860 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
861 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
862 info.useRandomServer = i["UseRandomServer"].toBool();
863 info.perform = i["Perform"].toStringList();
864 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
865 info.autoIdentifyService = i["AutoIdentifyService"].toString();
866 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
867 info.useSasl = i["UseSasl"].toBool();
868 info.saslAccount = i["SaslAccount"].toString();
869 info.saslPassword = i["SaslPassword"].toString();
870 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
871 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
872 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
873 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
874 info.rejoinChannels = i["RejoinChannels"].toBool();
878 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
879 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
880 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
881 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
882 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
883 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
884 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
885 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
886 << " rejoinChannels = " << i.rejoinChannels << ")";
890 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
891 QVariantMap serverMap;
892 serverMap["Host"] = server.host;
893 serverMap["Port"] = server.port;
894 serverMap["Password"] = server.password;
895 serverMap["UseSSL"] = server.useSsl;
896 serverMap["sslVersion"] = server.sslVersion;
897 serverMap["UseProxy"] = server.useProxy;
898 serverMap["ProxyType"] = server.proxyType;
899 serverMap["ProxyHost"] = server.proxyHost;
900 serverMap["ProxyPort"] = server.proxyPort;
901 serverMap["ProxyUser"] = server.proxyUser;
902 serverMap["ProxyPass"] = server.proxyPass;
907 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
908 QVariantMap serverMap;
910 server.host = serverMap["Host"].toString();
911 server.port = serverMap["Port"].toUInt();
912 server.password = serverMap["Password"].toString();
913 server.useSsl = serverMap["UseSSL"].toBool();
914 server.sslVersion = serverMap["sslVersion"].toInt();
915 server.useProxy = serverMap["UseProxy"].toBool();
916 server.proxyType = serverMap["ProxyType"].toInt();
917 server.proxyHost = serverMap["ProxyHost"].toString();
918 server.proxyPort = serverMap["ProxyPort"].toUInt();
919 server.proxyUser = serverMap["ProxyUser"].toString();
920 server.proxyPass = serverMap["ProxyPass"].toString();
925 bool Network::Server::operator==(const Server &other) const {
926 if(host != other.host) return false;
927 if(port != other.port) return false;
928 if(password != other.password) return false;
929 if(useSsl != other.useSsl) return false;
930 if(sslVersion != other.sslVersion) return false;
931 if(useProxy != other.useProxy) return false;
932 if(proxyType != other.proxyType) return false;
933 if(proxyHost != other.proxyHost) return false;
934 if(proxyPort != other.proxyPort) return false;
935 if(proxyUser != other.proxyUser) return false;
936 if(proxyPass != other.proxyPass) return false;
940 bool Network::Server::operator!=(const Server &other) const {
941 return !(*this == other);
944 QDebug operator<<(QDebug dbg, const Network::Server &server) {
945 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";