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))
341 QByteArray Network::codecForEncoding() const {
342 if(_codecForEncoding)
343 return _codecForEncoding->name();
347 void Network::setCodecForEncoding(const QByteArray &name) {
348 setCodecForEncoding(QTextCodec::codecForName(name));
351 void Network::setCodecForEncoding(QTextCodec *codec) {
352 _codecForEncoding = codec;
353 QByteArray codecName = codecForEncoding();
354 SYNC_OTHER(setCodecForEncoding, ARG(codecName))
357 QByteArray Network::codecForDecoding() const {
358 if(_codecForDecoding)
359 return _codecForDecoding->name();
360 else return QByteArray();
363 void Network::setCodecForDecoding(const QByteArray &name) {
364 setCodecForDecoding(QTextCodec::codecForName(name));
367 void Network::setCodecForDecoding(QTextCodec *codec) {
368 _codecForDecoding = codec;
369 QByteArray codecName = codecForDecoding();
370 SYNC_OTHER(setCodecForDecoding, ARG(codecName))
373 // FIXME use server encoding if appropriate
374 QString Network::decodeString(const QByteArray &text) const {
375 if(_codecForDecoding)
376 return ::decodeString(text, _codecForDecoding);
377 else return ::decodeString(text, _defaultCodecForDecoding);
380 QByteArray Network::encodeString(const QString &string) const {
381 if(_codecForEncoding) {
382 return _codecForEncoding->fromUnicode(string);
384 if(_defaultCodecForEncoding) {
385 return _defaultCodecForEncoding->fromUnicode(string);
387 return string.toAscii();
390 QString Network::decodeServerString(const QByteArray &text) const {
392 return ::decodeString(text, _codecForServer);
394 return ::decodeString(text, _defaultCodecForServer);
397 QByteArray Network::encodeServerString(const QString &string) const {
398 if(_codecForServer) {
399 return _codecForServer->fromUnicode(string);
401 if(_defaultCodecForServer) {
402 return _defaultCodecForServer->fromUnicode(string);
404 return string.toAscii();
407 /*** Handle networks.ini ***/
409 QStringList Network::presetNetworks(bool onlyDefault) {
410 // lazily find the file, make sure to not call one of the other preset functions first (they'll fail else)
411 if(_networksIniPath.isNull()) {
412 _networksIniPath = Quassel::findDataFilePath("networks.ini");
413 if(_networksIniPath.isNull()) {
414 _networksIniPath = ""; // now we won't check again, as it's not null anymore
415 return QStringList();
418 if(!_networksIniPath.isEmpty()) {
419 QSettings s(_networksIniPath, QSettings::IniFormat);
420 QStringList networks = s.childGroups();
421 if(!networks.isEmpty()) {
422 // we sort the list case-insensitive
423 QMap<QString, QString> sorted;
424 foreach(QString net, networks) {
425 if(onlyDefault && !s.value(QString("%1/Default").arg(net)).toBool())
427 sorted[net.toLower()] = net;
429 return sorted.values();
432 return QStringList();
435 QStringList Network::presetDefaultChannels(const QString &networkName) {
436 if(_networksIniPath.isEmpty()) // be sure to have called presetNetworks() first, else this always fails
437 return QStringList();
438 QSettings s(_networksIniPath, QSettings::IniFormat);
439 return s.value(QString("%1/DefaultChannels").arg(networkName)).toStringList();
442 NetworkInfo Network::networkInfoFromPreset(const QString &networkName) {
444 if(!_networksIniPath.isEmpty()) {
445 info.networkName = networkName;
446 QSettings s(_networksIniPath, QSettings::IniFormat);
447 s.beginGroup(info.networkName);
448 foreach(QString server, s.value("Servers").toStringList()) {
450 QStringList splitserver = server.split(':', QString::SkipEmptyParts);
451 if(splitserver.count() != 2) {
452 qWarning() << "Invalid server entry in networks.conf:" << server;
455 if(splitserver[1].at(0) == '+')
457 uint port = splitserver[1].toUInt();
459 qWarning() << "Invalid port entry in networks.conf:" << server;
462 info.serverList << Network::Server(splitserver[0].trimmed(), port, QString(), ssl);
469 // ====================
471 // ====================
472 void Network::setNetworkName(const QString &networkName) {
473 _networkName = networkName;
474 SYNC(ARG(networkName))
475 emit networkNameSet(networkName);
478 void Network::setCurrentServer(const QString ¤tServer) {
479 _currentServer = currentServer;
480 SYNC(ARG(currentServer))
481 emit currentServerSet(currentServer);
484 void Network::setConnected(bool connected) {
485 if(_connected == connected)
488 _connected = connected;
490 setMyNick(QString());
491 setCurrentServer(QString());
492 removeChansAndUsers();
495 emit connectedSet(connected);
498 //void Network::setConnectionState(ConnectionState state) {
499 void Network::setConnectionState(int state) {
500 _connectionState = (ConnectionState)state;
501 //qDebug() << "netstate" << networkId() << networkName() << state;
503 emit connectionStateSet(_connectionState);
506 void Network::setMyNick(const QString &nickname) {
508 if(!_myNick.isEmpty() && !ircUser(myNick())) {
509 newIrcUser(myNick());
512 emit myNickSet(nickname);
515 void Network::setLatency(int latency) {
516 if(_latency == latency)
522 void Network::setIdentity(IdentityId id) {
525 emit identitySet(id);
528 void Network::setServerList(const QVariantList &serverList) {
529 _serverList = fromVariantList<Server>(serverList);
530 SYNC(ARG(serverList))
533 void Network::setUseRandomServer(bool use) {
534 _useRandomServer = use;
538 void Network::setPerform(const QStringList &perform) {
543 void Network::setUseAutoIdentify(bool use) {
544 _useAutoIdentify = use;
548 void Network::setAutoIdentifyService(const QString &service) {
549 _autoIdentifyService = service;
553 void Network::setAutoIdentifyPassword(const QString &password) {
554 _autoIdentifyPassword = password;
558 void Network::setUseAutoReconnect(bool use) {
559 _useAutoReconnect = use;
563 void Network::setAutoReconnectInterval(quint32 interval) {
564 _autoReconnectInterval = interval;
568 void Network::setAutoReconnectRetries(quint16 retries) {
569 _autoReconnectRetries = retries;
573 void Network::setUnlimitedReconnectRetries(bool unlimited) {
574 _unlimitedReconnectRetries = unlimited;
578 void Network::setRejoinChannels(bool rejoin) {
579 _rejoinChannels = rejoin;
583 void Network::addSupport(const QString ¶m, const QString &value) {
584 if(!_supports.contains(param)) {
585 _supports[param] = value;
586 SYNC(ARG(param), ARG(value))
590 void Network::removeSupport(const QString ¶m) {
591 if(_supports.contains(param)) {
592 _supports.remove(param);
597 QVariantMap Network::initSupports() const {
598 QVariantMap supports;
599 QHashIterator<QString, QString> iter(_supports);
600 while(iter.hasNext()) {
602 supports[iter.key()] = iter.value();
607 QVariantMap Network::initIrcUsersAndChannels() const {
608 QVariantMap usersAndChannels;
610 QVariantMap channels;
612 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
613 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
614 while(userIter != userIterEnd) {
615 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
618 usersAndChannels["users"] = users;
620 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
621 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
622 while(channelIter != channelIterEnd) {
623 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
626 usersAndChannels["channels"] = channels;
628 return usersAndChannels;
631 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
633 if(isInitialized()) {
634 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
638 QVariantMap users = usersAndChannels.value("users").toMap();
639 QVariantMap::const_iterator userIter = users.constBegin();
640 QVariantMap::const_iterator userIterEnd = users.constEnd();
641 while(userIter != userIterEnd) {
642 newIrcUser(userIter.key(), userIter.value().toMap());
646 QVariantMap channels = usersAndChannels.value("channels").toMap();
647 QVariantMap::const_iterator channelIter = channels.constBegin();
648 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
649 while(channelIter != channelIterEnd) {
650 newIrcChannel(channelIter.key(), channelIter.value().toMap());
655 void Network::initSetSupports(const QVariantMap &supports) {
656 QMapIterator<QString, QVariant> iter(supports);
657 while(iter.hasNext()) {
659 addSupport(iter.key(), iter.value().toString());
663 IrcUser *Network::updateNickFromMask(const QString &mask) {
664 QString nick(nickFromMask(mask).toLower());
667 if(_ircUsers.contains(nick)) {
668 ircuser = _ircUsers[nick];
669 ircuser->updateHostmask(mask);
671 ircuser = newIrcUser(mask);
676 void Network::ircUserNickChanged(QString newnick) {
677 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
682 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
684 if(myNick().toLower() == oldnick)
688 void Network::emitConnectionError(const QString &errorMsg) {
689 emit connectionError(errorMsg);
692 // ====================
694 // ====================
695 void Network::determinePrefixes() {
696 // seems like we have to construct them first
697 QString prefix = support("PREFIX");
699 if(prefix.startsWith("(") && prefix.contains(")")) {
700 _prefixes = prefix.section(")", 1);
701 _prefixModes = prefix.mid(1).section(")", 0, 0);
703 QString defaultPrefixes("~&@%+");
704 QString defaultPrefixModes("qaohv");
706 if(prefix.isEmpty()) {
707 _prefixes = defaultPrefixes;
708 _prefixModes = defaultPrefixModes;
712 // we just assume that in PREFIX are only prefix chars stored
713 for(int i = 0; i < defaultPrefixes.size(); i++) {
714 if(prefix.contains(defaultPrefixes[i])) {
715 _prefixes += defaultPrefixes[i];
716 _prefixModes += defaultPrefixModes[i];
720 if(!_prefixes.isNull())
723 // well... our assumption was obviously wrong...
724 // check if it's only prefix modes
725 for(int i = 0; i < defaultPrefixes.size(); i++) {
726 if(prefix.contains(defaultPrefixModes[i])) {
727 _prefixes += defaultPrefixes[i];
728 _prefixModes += defaultPrefixModes[i];
731 // now we've done all we've could...
735 /************************************************************************
737 ************************************************************************/
739 NetworkInfo::NetworkInfo()
742 useRandomServer(false),
743 useAutoIdentify(false),
744 autoIdentifyService("NickServ"),
745 useAutoReconnect(true),
746 autoReconnectInterval(60),
747 autoReconnectRetries(20),
748 unlimitedReconnectRetries(false),
754 bool NetworkInfo::operator==(const NetworkInfo &other) const {
755 if(networkId != other.networkId) return false;
756 if(networkName != other.networkName) return false;
757 if(identity != other.identity) return false;
758 if(codecForServer != other.codecForServer) return false;
759 if(codecForEncoding != other.codecForEncoding) return false;
760 if(codecForDecoding != other.codecForDecoding) return false;
761 if(serverList != other.serverList) return false;
762 if(useRandomServer != other.useRandomServer) return false;
763 if(perform != other.perform) return false;
764 if(useAutoIdentify != other.useAutoIdentify) return false;
765 if(autoIdentifyService != other.autoIdentifyService) return false;
766 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
767 if(useAutoReconnect != other.useAutoReconnect) return false;
768 if(autoReconnectInterval != other.autoReconnectInterval) return false;
769 if(autoReconnectRetries != other.autoReconnectRetries) return false;
770 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
771 if(rejoinChannels != other.rejoinChannels) return false;
775 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
776 return !(*this == other);
779 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
781 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
782 i["NetworkName"] = info.networkName;
783 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
784 i["CodecForServer"] = info.codecForServer;
785 i["CodecForEncoding"] = info.codecForEncoding;
786 i["CodecForDecoding"] = info.codecForDecoding;
787 i["ServerList"] = toVariantList(info.serverList);
788 i["UseRandomServer"] = info.useRandomServer;
789 i["Perform"] = info.perform;
790 i["UseAutoIdentify"] = info.useAutoIdentify;
791 i["AutoIdentifyService"] = info.autoIdentifyService;
792 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
793 i["UseAutoReconnect"] = info.useAutoReconnect;
794 i["AutoReconnectInterval"] = info.autoReconnectInterval;
795 i["AutoReconnectRetries"] = info.autoReconnectRetries;
796 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
797 i["RejoinChannels"] = info.rejoinChannels;
802 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
805 info.networkId = i["NetworkId"].value<NetworkId>();
806 info.networkName = i["NetworkName"].toString();
807 info.identity = i["Identity"].value<IdentityId>();
808 info.codecForServer = i["CodecForServer"].toByteArray();
809 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
810 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
811 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
812 info.useRandomServer = i["UseRandomServer"].toBool();
813 info.perform = i["Perform"].toStringList();
814 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
815 info.autoIdentifyService = i["AutoIdentifyService"].toString();
816 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
817 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
818 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
819 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
820 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
821 info.rejoinChannels = i["RejoinChannels"].toBool();
825 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
826 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
827 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
828 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
829 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
830 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
831 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
832 << " rejoinChannels = " << i.rejoinChannels << ")";
836 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
837 QVariantMap serverMap;
838 serverMap["Host"] = server.host;
839 serverMap["Port"] = server.port;
840 serverMap["Password"] = server.password;
841 serverMap["UseSSL"] = server.useSsl;
842 serverMap["sslVersion"] = server.sslVersion;
843 serverMap["UseProxy"] = server.useProxy;
844 serverMap["ProxyType"] = server.proxyType;
845 serverMap["ProxyHost"] = server.proxyHost;
846 serverMap["ProxyPort"] = server.proxyPort;
847 serverMap["ProxyUser"] = server.proxyUser;
848 serverMap["ProxyPass"] = server.proxyPass;
853 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
854 QVariantMap serverMap;
856 server.host = serverMap["Host"].toString();
857 server.port = serverMap["Port"].toUInt();
858 server.password = serverMap["Password"].toString();
859 server.useSsl = serverMap["UseSSL"].toBool();
860 server.sslVersion = serverMap["sslVersion"].toInt();
861 server.useProxy = serverMap["UseProxy"].toBool();
862 server.proxyType = serverMap["ProxyType"].toInt();
863 server.proxyHost = serverMap["ProxyHost"].toString();
864 server.proxyPort = serverMap["ProxyPort"].toUInt();
865 server.proxyUser = serverMap["ProxyUser"].toString();
866 server.proxyPass = serverMap["ProxyPass"].toString();
871 bool Network::Server::operator==(const Server &other) const {
872 if(host != other.host) return false;
873 if(port != other.port) return false;
874 if(password != other.password) return false;
875 if(useSsl != other.useSsl) return false;
876 if(sslVersion != other.sslVersion) return false;
877 if(useProxy != other.useProxy) return false;
878 if(proxyType != other.proxyType) return false;
879 if(proxyHost != other.proxyHost) return false;
880 if(proxyPort != other.proxyPort) return false;
881 if(proxyUser != other.proxyUser) return false;
882 if(proxyPass != other.proxyPass) return false;
886 bool Network::Server::operator!=(const Server &other) const {
887 return !(*this == other);
890 QDebug operator<<(QDebug dbg, const Network::Server &server) {
891 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";