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),
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 = new IrcUser(hostmask, this);
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);
479 // ====================
481 // ====================
482 void Network::setNetworkName(const QString &networkName) {
483 _networkName = networkName;
484 SYNC(ARG(networkName))
485 emit networkNameSet(networkName);
486 emit configChanged();
489 void Network::setCurrentServer(const QString ¤tServer) {
490 _currentServer = currentServer;
491 SYNC(ARG(currentServer))
492 emit currentServerSet(currentServer);
495 void Network::setConnected(bool connected) {
496 if(_connected == connected)
499 _connected = connected;
501 setMyNick(QString());
502 setCurrentServer(QString());
503 removeChansAndUsers();
506 emit connectedSet(connected);
509 //void Network::setConnectionState(ConnectionState state) {
510 void Network::setConnectionState(int state) {
511 _connectionState = (ConnectionState)state;
512 //qDebug() << "netstate" << networkId() << networkName() << state;
514 emit connectionStateSet(_connectionState);
517 void Network::setMyNick(const QString &nickname) {
519 if(!_myNick.isEmpty() && !ircUser(myNick())) {
520 newIrcUser(myNick());
523 emit myNickSet(nickname);
526 void Network::setLatency(int latency) {
527 if(_latency == latency)
533 void Network::setIdentity(IdentityId id) {
536 emit identitySet(id);
537 emit configChanged();
540 void Network::setServerList(const QVariantList &serverList) {
541 _serverList = fromVariantList<Server>(serverList);
542 SYNC(ARG(serverList))
543 emit configChanged();
546 void Network::setUseRandomServer(bool use) {
547 _useRandomServer = use;
549 emit configChanged();
552 void Network::setPerform(const QStringList &perform) {
555 emit configChanged();
558 void Network::setUseAutoIdentify(bool use) {
559 _useAutoIdentify = use;
561 emit configChanged();
564 void Network::setAutoIdentifyService(const QString &service) {
565 _autoIdentifyService = service;
567 emit configChanged();
570 void Network::setAutoIdentifyPassword(const QString &password) {
571 _autoIdentifyPassword = password;
573 emit configChanged();
576 void Network::setUseSasl(bool use) {
579 emit configChanged();
582 void Network::setSaslAccount(const QString &account) {
583 _saslAccount = account;
585 emit configChanged();
588 void Network::setSaslPassword(const QString &password) {
589 _saslPassword = password;
591 emit configChanged();
594 void Network::setUseAutoReconnect(bool use) {
595 _useAutoReconnect = use;
597 emit configChanged();
600 void Network::setAutoReconnectInterval(quint32 interval) {
601 _autoReconnectInterval = interval;
603 emit configChanged();
606 void Network::setAutoReconnectRetries(quint16 retries) {
607 _autoReconnectRetries = retries;
609 emit configChanged();
612 void Network::setUnlimitedReconnectRetries(bool unlimited) {
613 _unlimitedReconnectRetries = unlimited;
615 emit configChanged();
618 void Network::setRejoinChannels(bool rejoin) {
619 _rejoinChannels = rejoin;
621 emit configChanged();
624 void Network::addSupport(const QString ¶m, const QString &value) {
625 if(!_supports.contains(param)) {
626 _supports[param] = value;
627 SYNC(ARG(param), ARG(value))
631 void Network::removeSupport(const QString ¶m) {
632 if(_supports.contains(param)) {
633 _supports.remove(param);
638 QVariantMap Network::initSupports() const {
639 QVariantMap supports;
640 QHashIterator<QString, QString> iter(_supports);
641 while(iter.hasNext()) {
643 supports[iter.key()] = iter.value();
648 QVariantMap Network::initIrcUsersAndChannels() const {
649 QVariantMap usersAndChannels;
651 QVariantMap channels;
653 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
654 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
655 while(userIter != userIterEnd) {
656 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
659 usersAndChannels["users"] = users;
661 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
662 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
663 while(channelIter != channelIterEnd) {
664 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
667 usersAndChannels["channels"] = channels;
669 return usersAndChannels;
672 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
674 if(isInitialized()) {
675 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
679 QVariantMap users = usersAndChannels.value("users").toMap();
680 QVariantMap::const_iterator userIter = users.constBegin();
681 QVariantMap::const_iterator userIterEnd = users.constEnd();
682 while(userIter != userIterEnd) {
683 newIrcUser(userIter.key(), userIter.value().toMap());
687 QVariantMap channels = usersAndChannels.value("channels").toMap();
688 QVariantMap::const_iterator channelIter = channels.constBegin();
689 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
690 while(channelIter != channelIterEnd) {
691 newIrcChannel(channelIter.key(), channelIter.value().toMap());
696 void Network::initSetSupports(const QVariantMap &supports) {
697 QMapIterator<QString, QVariant> iter(supports);
698 while(iter.hasNext()) {
700 addSupport(iter.key(), iter.value().toString());
704 IrcUser *Network::updateNickFromMask(const QString &mask) {
705 QString nick(nickFromMask(mask).toLower());
708 if(_ircUsers.contains(nick)) {
709 ircuser = _ircUsers[nick];
710 ircuser->updateHostmask(mask);
712 ircuser = newIrcUser(mask);
717 void Network::ircUserNickChanged(QString newnick) {
718 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
723 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
725 if(myNick().toLower() == oldnick)
729 void Network::emitConnectionError(const QString &errorMsg) {
730 emit connectionError(errorMsg);
733 // ====================
735 // ====================
736 void Network::determinePrefixes() {
737 // seems like we have to construct them first
738 QString prefix = support("PREFIX");
740 if(prefix.startsWith("(") && prefix.contains(")")) {
741 _prefixes = prefix.section(")", 1);
742 _prefixModes = prefix.mid(1).section(")", 0, 0);
744 QString defaultPrefixes("~&@%+");
745 QString defaultPrefixModes("qaohv");
747 if(prefix.isEmpty()) {
748 _prefixes = defaultPrefixes;
749 _prefixModes = defaultPrefixModes;
753 // we just assume that in PREFIX are only prefix chars stored
754 for(int i = 0; i < defaultPrefixes.size(); i++) {
755 if(prefix.contains(defaultPrefixes[i])) {
756 _prefixes += defaultPrefixes[i];
757 _prefixModes += defaultPrefixModes[i];
761 if(!_prefixes.isNull())
764 // well... our assumption was obviously wrong...
765 // check if it's only prefix modes
766 for(int i = 0; i < defaultPrefixes.size(); i++) {
767 if(prefix.contains(defaultPrefixModes[i])) {
768 _prefixes += defaultPrefixes[i];
769 _prefixModes += defaultPrefixModes[i];
772 // now we've done all we've could...
776 /************************************************************************
778 ************************************************************************/
780 NetworkInfo::NetworkInfo()
783 useRandomServer(false),
784 useAutoIdentify(false),
785 autoIdentifyService("NickServ"),
787 useAutoReconnect(true),
788 autoReconnectInterval(60),
789 autoReconnectRetries(20),
790 unlimitedReconnectRetries(false),
796 bool NetworkInfo::operator==(const NetworkInfo &other) const {
797 if(networkId != other.networkId) return false;
798 if(networkName != other.networkName) return false;
799 if(identity != other.identity) return false;
800 if(codecForServer != other.codecForServer) return false;
801 if(codecForEncoding != other.codecForEncoding) return false;
802 if(codecForDecoding != other.codecForDecoding) return false;
803 if(serverList != other.serverList) return false;
804 if(useRandomServer != other.useRandomServer) return false;
805 if(perform != other.perform) return false;
806 if(useAutoIdentify != other.useAutoIdentify) return false;
807 if(autoIdentifyService != other.autoIdentifyService) return false;
808 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
809 if(useSasl != other.useSasl) return false;
810 if(saslAccount != other.saslAccount) return false;
811 if(saslPassword != other.saslPassword) return false;
812 if(useAutoReconnect != other.useAutoReconnect) return false;
813 if(autoReconnectInterval != other.autoReconnectInterval) return false;
814 if(autoReconnectRetries != other.autoReconnectRetries) return false;
815 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
816 if(rejoinChannels != other.rejoinChannels) return false;
820 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
821 return !(*this == other);
824 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
826 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
827 i["NetworkName"] = info.networkName;
828 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
829 i["CodecForServer"] = info.codecForServer;
830 i["CodecForEncoding"] = info.codecForEncoding;
831 i["CodecForDecoding"] = info.codecForDecoding;
832 i["ServerList"] = toVariantList(info.serverList);
833 i["UseRandomServer"] = info.useRandomServer;
834 i["Perform"] = info.perform;
835 i["UseAutoIdentify"] = info.useAutoIdentify;
836 i["AutoIdentifyService"] = info.autoIdentifyService;
837 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
838 i["UseSasl"] = info.useSasl;
839 i["SaslAccount"] = info.saslAccount;
840 i["SaslPassword"] = info.saslPassword;
841 i["UseAutoReconnect"] = info.useAutoReconnect;
842 i["AutoReconnectInterval"] = info.autoReconnectInterval;
843 i["AutoReconnectRetries"] = info.autoReconnectRetries;
844 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
845 i["RejoinChannels"] = info.rejoinChannels;
850 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
853 info.networkId = i["NetworkId"].value<NetworkId>();
854 info.networkName = i["NetworkName"].toString();
855 info.identity = i["Identity"].value<IdentityId>();
856 info.codecForServer = i["CodecForServer"].toByteArray();
857 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
858 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
859 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
860 info.useRandomServer = i["UseRandomServer"].toBool();
861 info.perform = i["Perform"].toStringList();
862 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
863 info.autoIdentifyService = i["AutoIdentifyService"].toString();
864 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
865 info.useSasl = i["UseSasl"].toBool();
866 info.saslAccount = i["SaslAccount"].toString();
867 info.saslPassword = i["SaslPassword"].toString();
868 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
869 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
870 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
871 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
872 info.rejoinChannels = i["RejoinChannels"].toBool();
876 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
877 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
878 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
879 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
880 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
881 << " useSasl = " << i.useSasl << " saslAccount = " << i.saslAccount << " saslPassword = " << i.saslPassword
882 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
883 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
884 << " rejoinChannels = " << i.rejoinChannels << ")";
888 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
889 QVariantMap serverMap;
890 serverMap["Host"] = server.host;
891 serverMap["Port"] = server.port;
892 serverMap["Password"] = server.password;
893 serverMap["UseSSL"] = server.useSsl;
894 serverMap["sslVersion"] = server.sslVersion;
895 serverMap["UseProxy"] = server.useProxy;
896 serverMap["ProxyType"] = server.proxyType;
897 serverMap["ProxyHost"] = server.proxyHost;
898 serverMap["ProxyPort"] = server.proxyPort;
899 serverMap["ProxyUser"] = server.proxyUser;
900 serverMap["ProxyPass"] = server.proxyPass;
905 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
906 QVariantMap serverMap;
908 server.host = serverMap["Host"].toString();
909 server.port = serverMap["Port"].toUInt();
910 server.password = serverMap["Password"].toString();
911 server.useSsl = serverMap["UseSSL"].toBool();
912 server.sslVersion = serverMap["sslVersion"].toInt();
913 server.useProxy = serverMap["UseProxy"].toBool();
914 server.proxyType = serverMap["ProxyType"].toInt();
915 server.proxyHost = serverMap["ProxyHost"].toString();
916 server.proxyPort = serverMap["ProxyPort"].toUInt();
917 server.proxyUser = serverMap["ProxyUser"].toString();
918 server.proxyPass = serverMap["ProxyPass"].toString();
923 bool Network::Server::operator==(const Server &other) const {
924 if(host != other.host) return false;
925 if(port != other.port) return false;
926 if(password != other.password) return false;
927 if(useSsl != other.useSsl) return false;
928 if(sslVersion != other.sslVersion) return false;
929 if(useProxy != other.useProxy) return false;
930 if(proxyType != other.proxyType) return false;
931 if(proxyHost != other.proxyHost) return false;
932 if(proxyPort != other.proxyPort) return false;
933 if(proxyUser != other.proxyUser) return false;
934 if(proxyPass != other.proxyPass) return false;
938 bool Network::Server::operator!=(const Server &other) const {
939 return !(*this == other);
942 QDebug operator<<(QDebug dbg, const Network::Server &server) {
943 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";