1 /***************************************************************************
2 * Copyright (C) 2005-09 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),
50 _useAutoReconnect(false),
51 _autoReconnectInterval(60),
52 _autoReconnectRetries(10),
53 _unlimitedReconnectRetries(false),
57 _autoAwayActive(false)
59 setObjectName(QString::number(networkid.toInt()));
63 emit aboutToBeDestroyed();
66 bool Network::isChannelName(const QString &channelname) const {
67 if(channelname.isEmpty())
70 if(supports("CHANTYPES"))
71 return support("CHANTYPES").contains(channelname[0]);
73 return QString("#&!+").contains(channelname[0]);
76 NetworkInfo Network::networkInfo() const {
78 info.networkName = networkName();
79 info.networkId = networkId();
80 info.identity = identity();
81 info.codecForServer = codecForServer();
82 info.codecForEncoding = codecForEncoding();
83 info.codecForDecoding = codecForDecoding();
84 info.serverList = serverList();
85 info.useRandomServer = useRandomServer();
86 info.perform = perform();
87 info.useAutoIdentify = useAutoIdentify();
88 info.autoIdentifyService = autoIdentifyService();
89 info.autoIdentifyPassword = autoIdentifyPassword();
90 info.useAutoReconnect = useAutoReconnect();
91 info.autoReconnectInterval = autoReconnectInterval();
92 info.autoReconnectRetries = autoReconnectRetries();
93 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
94 info.rejoinChannels = rejoinChannels();
98 void Network::setNetworkInfo(const NetworkInfo &info) {
99 // we don't set our ID!
100 if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
101 if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
102 if(info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
103 if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
104 if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
105 if(info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
106 if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
107 if(info.perform != perform()) setPerform(info.perform);
108 if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
109 if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
110 if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
111 if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
112 if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
113 if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
114 if(info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
115 if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
118 QString Network::prefixToMode(const QString &prefix) {
119 if(prefixes().contains(prefix))
120 return QString(prefixModes()[prefixes().indexOf(prefix)]);
125 QString Network::modeToPrefix(const QString &mode) {
126 if(prefixModes().contains(mode))
127 return QString(prefixes()[prefixModes().indexOf(mode)]);
132 QStringList Network::nicks() const {
133 // we don't use _ircUsers.keys() since the keys may be
134 // not up to date after a nick change
136 foreach(IrcUser *ircuser, _ircUsers.values()) {
137 nicks << ircuser->nick();
142 QString Network::prefixes() {
143 if(_prefixes.isNull())
149 QString Network::prefixModes() {
150 if(_prefixModes.isNull())
156 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
157 Network::ChannelModeType Network::channelModeType(const QString &mode) {
159 return NOT_A_CHANMODE;
161 QString chanmodes = support("CHANMODES");
162 if(chanmodes.isEmpty())
163 return NOT_A_CHANMODE;
165 ChannelModeType modeType = A_CHANMODE;
166 for(int i = 0; i < chanmodes.count(); i++) {
167 if(chanmodes[i] == mode[0])
169 else if(chanmodes[i] == ',')
170 modeType = (ChannelModeType)(modeType << 1);
172 if(modeType > D_CHANMODE) {
173 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
174 modeType = NOT_A_CHANMODE;
179 QString Network::support(const QString ¶m) const {
180 QString support_ = param.toUpper();
181 if(_supports.contains(support_))
182 return _supports[support_];
187 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) {
188 QString nick(nickFromMask(hostmask).toLower());
189 if(!_ircUsers.contains(nick)) {
190 IrcUser *ircuser = new IrcUser(hostmask, this);
191 if(!initData.isEmpty()) {
192 ircuser->fromVariantMap(initData);
193 ircuser->setInitialized();
197 proxy()->synchronize(ircuser);
199 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
201 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
203 _ircUsers[nick] = ircuser;
205 SYNC_OTHER(addIrcUser, ARG(hostmask))
206 // emit ircUserAdded(hostmask);
207 emit ircUserAdded(ircuser);
210 return _ircUsers[nick];
213 IrcUser *Network::ircUser(QString nickname) const {
214 nickname = nickname.toLower();
215 if(_ircUsers.contains(nickname))
216 return _ircUsers[nickname];
221 void Network::removeIrcUser(IrcUser *ircuser) {
222 QString nick = _ircUsers.key(ircuser);
226 _ircUsers.remove(nick);
227 disconnect(ircuser, 0, this, 0);
228 ircuser->deleteLater();
231 void Network::removeIrcChannel(IrcChannel *channel) {
232 QString chanName = _ircChannels.key(channel);
233 if(chanName.isNull())
236 _ircChannels.remove(chanName);
237 disconnect(channel, 0, this, 0);
238 channel->deleteLater();
241 void Network::removeChansAndUsers() {
242 QList<IrcUser *> users = ircUsers();
244 QList<IrcChannel *> channels = ircChannels();
245 _ircChannels.clear();
247 foreach(IrcChannel *channel, channels) {
248 proxy()->detachObject(channel);
249 disconnect(channel, 0, this, 0);
251 foreach(IrcUser *user, users) {
252 proxy()->detachObject(user);
253 disconnect(user, 0, this, 0);
256 // the second loop is needed because quit can have sideffects
257 foreach(IrcUser *user, users) {
262 qDeleteAll(channels);
265 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) {
266 if(!_ircChannels.contains(channelname.toLower())) {
267 IrcChannel *channel = ircChannelFactory(channelname);
268 if(!initData.isEmpty()) {
269 channel->fromVariantMap(initData);
270 channel->setInitialized();
274 proxy()->synchronize(channel);
276 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
278 _ircChannels[channelname.toLower()] = channel;
280 SYNC_OTHER(addIrcChannel, ARG(channelname))
281 // emit ircChannelAdded(channelname);
282 emit ircChannelAdded(channel);
284 return _ircChannels[channelname.toLower()];
287 IrcChannel *Network::ircChannel(QString channelname) const {
288 channelname = channelname.toLower();
289 if(_ircChannels.contains(channelname))
290 return _ircChannels[channelname];
295 QByteArray Network::defaultCodecForServer() {
296 if(_defaultCodecForServer)
297 return _defaultCodecForServer->name();
301 void Network::setDefaultCodecForServer(const QByteArray &name) {
302 _defaultCodecForServer = QTextCodec::codecForName(name);
305 QByteArray Network::defaultCodecForEncoding() {
306 if(_defaultCodecForEncoding)
307 return _defaultCodecForEncoding->name();
311 void Network::setDefaultCodecForEncoding(const QByteArray &name) {
312 _defaultCodecForEncoding = QTextCodec::codecForName(name);
315 QByteArray Network::defaultCodecForDecoding() {
316 if(_defaultCodecForDecoding)
317 return _defaultCodecForDecoding->name();
321 void Network::setDefaultCodecForDecoding(const QByteArray &name) {
322 _defaultCodecForDecoding = QTextCodec::codecForName(name);
325 QByteArray Network::codecForServer() const {
327 return _codecForServer->name();
331 void Network::setCodecForServer(const QByteArray &name) {
332 setCodecForServer(QTextCodec::codecForName(name));
335 void Network::setCodecForServer(QTextCodec *codec) {
336 _codecForServer = codec;
337 QByteArray codecName = codecForServer();
338 SYNC_OTHER(setCodecForServer, ARG(codecName))
339 emit configChanged();
342 QByteArray Network::codecForEncoding() const {
343 if(_codecForEncoding)
344 return _codecForEncoding->name();
348 void Network::setCodecForEncoding(const QByteArray &name) {
349 setCodecForEncoding(QTextCodec::codecForName(name));
352 void Network::setCodecForEncoding(QTextCodec *codec) {
353 _codecForEncoding = codec;
354 QByteArray codecName = codecForEncoding();
355 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
356 emit configChanged();
359 QByteArray Network::codecForDecoding() const {
360 if(_codecForDecoding)
361 return _codecForDecoding->name();
362 else return QByteArray();
365 void Network::setCodecForDecoding(const QByteArray &name) {
366 setCodecForDecoding(QTextCodec::codecForName(name));
369 void Network::setCodecForDecoding(QTextCodec *codec) {
370 _codecForDecoding = codec;
371 QByteArray codecName = codecForDecoding();
372 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
373 emit configChanged();
376 // FIXME use server encoding if appropriate
377 QString Network::decodeString(const QByteArray &text) const {
378 if(_codecForDecoding)
379 return ::decodeString(text, _codecForDecoding);
380 else return ::decodeString(text, _defaultCodecForDecoding);
383 QByteArray Network::encodeString(const QString &string) const {
384 if(_codecForEncoding) {
385 return _codecForEncoding->fromUnicode(string);
387 if(_defaultCodecForEncoding) {
388 return _defaultCodecForEncoding->fromUnicode(string);
390 return string.toAscii();
393 QString Network::decodeServerString(const QByteArray &text) const {
395 return ::decodeString(text, _codecForServer);
397 return ::decodeString(text, _defaultCodecForServer);
400 QByteArray Network::encodeServerString(const QString &string) const {
401 if(_codecForServer) {
402 return _codecForServer->fromUnicode(string);
404 if(_defaultCodecForServer) {
405 return _defaultCodecForServer->fromUnicode(string);
407 return string.toAscii();
410 /*** Handle networks.ini ***/
412 QStringList Network::presetNetworks(bool onlyDefault) {
413 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
414 if(_networksIniPath.isNull()) {
415 _networksIniPath = Quassel::findDataFilePath("networks.ini");
416 if(_networksIniPath.isNull()) {
417 _networksIniPath = ""; // now we won't check again, as it's not null anymore
418 return QStringList();
421 if(!_networksIniPath.isEmpty()) {
422 QSettings s(_networksIniPath, QSettings::IniFormat);
423 QStringList networks = s.childGroups();
424 if(!networks.isEmpty()) {
425 // we sort the list case-insensitive
426 QMap<QString, QString> sorted;
427 foreach(QString net, networks) {
428 if(onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
430 sorted[net.toLower()] = net;
432 return sorted.values();
435 return QStringList();
438 QStringList Network::presetDefaultChannels(const QString &networkName) {
439 if(_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
440 return QStringList();
441 QSettings s(_networksIniPath, QSettings::IniFormat);
442 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
445 NetworkInfo Network::networkInfoFromPreset(const QString &networkName) {
447 if(!_networksIniPath.isEmpty()) {
448 info.networkName = networkName;
449 QSettings s(_networksIniPath, QSettings::IniFormat);
450 s.beginGroup(info.networkName);
451 foreach(QString server, s.value("Servers").toStringList()) {
453 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
454 if(splitserver.count() != 2) {
455 qWarning() << "Invalid server entry in networks.conf:" << server;
458 if(splitserver[1].at(0) == '+')
460 uint port = splitserver[1].toUInt();
462 qWarning() << "Invalid port entry in networks.conf:" << server;
465 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
472 // ====================
474 // ====================
475 void Network::setNetworkName(const QString &networkName) {
476 _networkName = networkName;
477 SYNC(ARG(networkName))
478 emit networkNameSet(networkName);
479 emit configChanged();
482 void Network::setCurrentServer(const QString ¤tServer) {
483 _currentServer = currentServer;
484 SYNC(ARG(currentServer))
485 emit currentServerSet(currentServer);
488 void Network::setConnected(bool connected) {
489 if(_connected == connected)
492 _connected = connected;
494 setMyNick(QString());
495 setCurrentServer(QString());
496 removeChansAndUsers();
499 emit connectedSet(connected);
502 //void Network::setConnectionState(ConnectionState state) {
503 void Network::setConnectionState(int state) {
504 _connectionState = (ConnectionState)state;
505 //qDebug() << "netstate" << networkId() << networkName() << state;
507 emit connectionStateSet(_connectionState);
510 void Network::setMyNick(const QString &nickname) {
512 if(!_myNick.isEmpty() && !ircUser(myNick())) {
513 newIrcUser(myNick());
516 emit myNickSet(nickname);
519 void Network::setLatency(int latency) {
520 if(_latency == latency)
526 void Network::setIdentity(IdentityId id) {
529 emit identitySet(id);
530 emit configChanged();
533 void Network::setServerList(const QVariantList &serverList) {
534 _serverList = fromVariantList<Server>(serverList);
535 SYNC(ARG(serverList))
536 emit configChanged();
539 void Network::setUseRandomServer(bool use) {
540 _useRandomServer = use;
542 emit configChanged();
545 void Network::setPerform(const QStringList &perform) {
548 emit configChanged();
551 void Network::setUseAutoIdentify(bool use) {
552 _useAutoIdentify = use;
554 emit configChanged();
557 void Network::setAutoIdentifyService(const QString &service) {
558 _autoIdentifyService = service;
560 emit configChanged();
563 void Network::setAutoIdentifyPassword(const QString &password) {
564 _autoIdentifyPassword = password;
566 emit configChanged();
569 void Network::setUseAutoReconnect(bool use) {
570 _useAutoReconnect = use;
572 emit configChanged();
575 void Network::setAutoReconnectInterval(quint32 interval) {
576 _autoReconnectInterval = interval;
578 emit configChanged();
581 void Network::setAutoReconnectRetries(quint16 retries) {
582 _autoReconnectRetries = retries;
584 emit configChanged();
587 void Network::setUnlimitedReconnectRetries(bool unlimited) {
588 _unlimitedReconnectRetries = unlimited;
590 emit configChanged();
593 void Network::setRejoinChannels(bool rejoin) {
594 _rejoinChannels = rejoin;
596 emit configChanged();
599 void Network::addSupport(const QString ¶m, const QString &value) {
600 if(!_supports.contains(param)) {
601 _supports[param] = value;
602 SYNC(ARG(param), ARG(value))
606 void Network::removeSupport(const QString ¶m) {
607 if(_supports.contains(param)) {
608 _supports.remove(param);
613 QVariantMap Network::initSupports() const {
614 QVariantMap supports;
615 QHashIterator<QString, QString> iter(_supports);
616 while(iter.hasNext()) {
618 supports[iter.key()] = iter.value();
623 QVariantMap Network::initIrcUsersAndChannels() const {
624 QVariantMap usersAndChannels;
626 QVariantMap channels;
628 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
629 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
630 while(userIter != userIterEnd) {
631 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
634 usersAndChannels["users"] = users;
636 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
637 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
638 while(channelIter != channelIterEnd) {
639 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
642 usersAndChannels["channels"] = channels;
644 return usersAndChannels;
647 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
649 if(isInitialized()) {
650 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
654 QVariantMap users = usersAndChannels.value("users").toMap();
655 QVariantMap::const_iterator userIter = users.constBegin();
656 QVariantMap::const_iterator userIterEnd = users.constEnd();
657 while(userIter != userIterEnd) {
658 newIrcUser(userIter.key(), userIter.value().toMap());
662 QVariantMap channels = usersAndChannels.value("channels").toMap();
663 QVariantMap::const_iterator channelIter = channels.constBegin();
664 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
665 while(channelIter != channelIterEnd) {
666 newIrcChannel(channelIter.key(), channelIter.value().toMap());
671 void Network::initSetSupports(const QVariantMap &supports) {
672 QMapIterator<QString, QVariant> iter(supports);
673 while(iter.hasNext()) {
675 addSupport(iter.key(), iter.value().toString());
679 IrcUser *Network::updateNickFromMask(const QString &mask) {
680 QString nick(nickFromMask(mask).toLower());
683 if(_ircUsers.contains(nick)) {
684 ircuser = _ircUsers[nick];
685 ircuser->updateHostmask(mask);
687 ircuser = newIrcUser(mask);
692 void Network::ircUserNickChanged(QString newnick) {
693 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
698 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
700 if(myNick().toLower() == oldnick)
704 void Network::emitConnectionError(const QString &errorMsg) {
705 emit connectionError(errorMsg);
708 // ====================
710 // ====================
711 void Network::determinePrefixes() {
712 // seems like we have to construct them first
713 QString prefix = support("PREFIX");
715 if(prefix.startsWith("(") && prefix.contains(")")) {
716 _prefixes = prefix.section(")", 1);
717 _prefixModes = prefix.mid(1).section(")", 0, 0);
719 QString defaultPrefixes("~&@%+");
720 QString defaultPrefixModes("qaohv");
722 if(prefix.isEmpty()) {
723 _prefixes = defaultPrefixes;
724 _prefixModes = defaultPrefixModes;
728 // we just assume that in PREFIX are only prefix chars stored
729 for(int i = 0; i < defaultPrefixes.size(); i++) {
730 if(prefix.contains(defaultPrefixes[i])) {
731 _prefixes += defaultPrefixes[i];
732 _prefixModes += defaultPrefixModes[i];
736 if(!_prefixes.isNull())
739 // well... our assumption was obviously wrong...
740 // check if it's only prefix modes
741 for(int i = 0; i < defaultPrefixes.size(); i++) {
742 if(prefix.contains(defaultPrefixModes[i])) {
743 _prefixes += defaultPrefixes[i];
744 _prefixModes += defaultPrefixModes[i];
747 // now we've done all we've could...
751 /************************************************************************
753 ************************************************************************/
755 NetworkInfo::NetworkInfo()
758 useRandomServer(false),
759 useAutoIdentify(false),
760 autoIdentifyService("NickServ"),
761 useAutoReconnect(true),
762 autoReconnectInterval(60),
763 autoReconnectRetries(20),
764 unlimitedReconnectRetries(false),
770 bool NetworkInfo::operator==(const NetworkInfo &other) const {
771 if(networkId != other.networkId) return false;
772 if(networkName != other.networkName) return false;
773 if(identity != other.identity) return false;
774 if(codecForServer != other.codecForServer) return false;
775 if(codecForEncoding != other.codecForEncoding) return false;
776 if(codecForDecoding != other.codecForDecoding) return false;
777 if(serverList != other.serverList) return false;
778 if(useRandomServer != other.useRandomServer) return false;
779 if(perform != other.perform) return false;
780 if(useAutoIdentify != other.useAutoIdentify) return false;
781 if(autoIdentifyService != other.autoIdentifyService) return false;
782 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
783 if(useAutoReconnect != other.useAutoReconnect) return false;
784 if(autoReconnectInterval != other.autoReconnectInterval) return false;
785 if(autoReconnectRetries != other.autoReconnectRetries) return false;
786 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
787 if(rejoinChannels != other.rejoinChannels) return false;
791 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
792 return !(*this == other);
795 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
797 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
798 i["NetworkName"] = info.networkName;
799 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
800 i["CodecForServer"] = info.codecForServer;
801 i["CodecForEncoding"] = info.codecForEncoding;
802 i["CodecForDecoding"] = info.codecForDecoding;
803 i["ServerList"] = toVariantList(info.serverList);
804 i["UseRandomServer"] = info.useRandomServer;
805 i["Perform"] = info.perform;
806 i["UseAutoIdentify"] = info.useAutoIdentify;
807 i["AutoIdentifyService"] = info.autoIdentifyService;
808 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
809 i["UseAutoReconnect"] = info.useAutoReconnect;
810 i["AutoReconnectInterval"] = info.autoReconnectInterval;
811 i["AutoReconnectRetries"] = info.autoReconnectRetries;
812 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
813 i["RejoinChannels"] = info.rejoinChannels;
818 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
821 info.networkId = i["NetworkId"].value<NetworkId>();
822 info.networkName = i["NetworkName"].toString();
823 info.identity = i["Identity"].value<IdentityId>();
824 info.codecForServer = i["CodecForServer"].toByteArray();
825 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
826 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
827 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
828 info.useRandomServer = i["UseRandomServer"].toBool();
829 info.perform = i["Perform"].toStringList();
830 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
831 info.autoIdentifyService = i["AutoIdentifyService"].toString();
832 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
833 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
834 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
835 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
836 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
837 info.rejoinChannels = i["RejoinChannels"].toBool();
841 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
842 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
843 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
844 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
845 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
846 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
847 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
848 << " rejoinChannels = " << i.rejoinChannels << ")";
852 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
853 QVariantMap serverMap;
854 serverMap["Host"] = server.host;
855 serverMap["Port"] = server.port;
856 serverMap["Password"] = server.password;
857 serverMap["UseSSL"] = server.useSsl;
858 serverMap["sslVersion"] = server.sslVersion;
859 serverMap["UseProxy"] = server.useProxy;
860 serverMap["ProxyType"] = server.proxyType;
861 serverMap["ProxyHost"] = server.proxyHost;
862 serverMap["ProxyPort"] = server.proxyPort;
863 serverMap["ProxyUser"] = server.proxyUser;
864 serverMap["ProxyPass"] = server.proxyPass;
869 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
870 QVariantMap serverMap;
872 server.host = serverMap["Host"].toString();
873 server.port = serverMap["Port"].toUInt();
874 server.password = serverMap["Password"].toString();
875 server.useSsl = serverMap["UseSSL"].toBool();
876 server.sslVersion = serverMap["sslVersion"].toInt();
877 server.useProxy = serverMap["UseProxy"].toBool();
878 server.proxyType = serverMap["ProxyType"].toInt();
879 server.proxyHost = serverMap["ProxyHost"].toString();
880 server.proxyPort = serverMap["ProxyPort"].toUInt();
881 server.proxyUser = serverMap["ProxyUser"].toString();
882 server.proxyPass = serverMap["ProxyPass"].toString();
887 bool Network::Server::operator==(const Server &other) const {
888 if(host != other.host) return false;
889 if(port != other.port) return false;
890 if(password != other.password) return false;
891 if(useSsl != other.useSsl) return false;
892 if(sslVersion != other.sslVersion) return false;
893 if(useProxy != other.useProxy) return false;
894 if(proxyType != other.proxyType) return false;
895 if(proxyHost != other.proxyHost) return false;
896 if(proxyPort != other.proxyPort) return false;
897 if(proxyUser != other.proxyUser) return false;
898 if(proxyPass != other.proxyPass) return false;
902 bool Network::Server::operator!=(const Server &other) const {
903 return !(*this == other);
906 QDebug operator<<(QDebug dbg, const Network::Server &server) {
907 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";