1 /***************************************************************************
2 * Copyright (C) 2005-08 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 ***************************************************************************/
25 QTextCodec *Network::_defaultCodecForServer = 0;
26 QTextCodec *Network::_defaultCodecForEncoding = 0;
27 QTextCodec *Network::_defaultCodecForDecoding = 0;
29 // ====================
31 // ====================
32 Network::Network(const NetworkId &networkid, QObject *parent)
33 : SyncableObject(parent),
35 _networkId(networkid),
39 _networkName(QString("<not initialized>")),
40 _currentServer(QString()),
42 _connectionState(Disconnected),
44 _prefixModes(QString()),
45 _useRandomServer(false),
46 _useAutoIdentify(false),
47 _useAutoReconnect(false),
48 _autoReconnectInterval(60),
49 _autoReconnectRetries(10),
50 _unlimitedReconnectRetries(false),
54 _autoAwayActive(false)
56 setObjectName(QString::number(networkid.toInt()));
60 emit aboutToBeDestroyed();
63 bool Network::isChannelName(const QString &channelname) const {
64 if(channelname.isEmpty())
67 if(supports("CHANTYPES"))
68 return support("CHANTYPES").contains(channelname[0]);
70 return QString("#&!+").contains(channelname[0]);
73 NetworkInfo Network::networkInfo() const {
75 info.networkName = networkName();
76 info.networkId = networkId();
77 info.identity = identity();
78 info.codecForServer = codecForServer();
79 info.codecForEncoding = codecForEncoding();
80 info.codecForDecoding = codecForDecoding();
81 info.serverList = serverList();
82 info.useRandomServer = useRandomServer();
83 info.perform = perform();
84 info.useAutoIdentify = useAutoIdentify();
85 info.autoIdentifyService = autoIdentifyService();
86 info.autoIdentifyPassword = autoIdentifyPassword();
87 info.useAutoReconnect = useAutoReconnect();
88 info.autoReconnectInterval = autoReconnectInterval();
89 info.autoReconnectRetries = autoReconnectRetries();
90 info.unlimitedReconnectRetries = unlimitedReconnectRetries();
91 info.rejoinChannels = rejoinChannels();
95 void Network::setNetworkInfo(const NetworkInfo &info) {
96 // we don't set our ID!
97 if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName);
98 if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity);
99 if(info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer));
100 if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding));
101 if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding));
102 if(info.serverList.count()) setServerList(toVariantList(info.serverList)); // FIXME compare components
103 if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer);
104 if(info.perform != perform()) setPerform(info.perform);
105 if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify);
106 if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService);
107 if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword);
108 if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect);
109 if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval);
110 if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries);
111 if(info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries);
112 if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels);
115 QString Network::prefixToMode(const QString &prefix) {
116 if(prefixes().contains(prefix))
117 return QString(prefixModes()[prefixes().indexOf(prefix)]);
122 QString Network::modeToPrefix(const QString &mode) {
123 if(prefixModes().contains(mode))
124 return QString(prefixes()[prefixModes().indexOf(mode)]);
129 QStringList Network::nicks() const {
130 // we don't use _ircUsers.keys() since the keys may be
131 // not up to date after a nick change
133 foreach(IrcUser *ircuser, _ircUsers.values()) {
134 nicks << ircuser->nick();
139 QString Network::prefixes() {
140 if(_prefixes.isNull())
146 QString Network::prefixModes() {
147 if(_prefixModes.isNull())
153 // example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG
154 Network::ChannelModeType Network::channelModeType(const QString &mode) {
156 return NOT_A_CHANMODE;
158 QString chanmodes = support("CHANMODES");
159 if(chanmodes.isEmpty())
160 return NOT_A_CHANMODE;
162 ChannelModeType modeType = A_CHANMODE;
163 for(int i = 0; i < chanmodes.count(); i++) {
164 if(chanmodes[i] == mode[0])
166 else if(chanmodes[i] == ',')
167 modeType = (ChannelModeType)(modeType << 1);
169 if(modeType > D_CHANMODE) {
170 qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes;
171 modeType = NOT_A_CHANMODE;
176 QString Network::support(const QString ¶m) const {
177 QString support_ = param.toUpper();
178 if(_supports.contains(support_))
179 return _supports[support_];
184 IrcUser *Network::newIrcUser(const QString &hostmask, const QVariantMap &initData) {
185 QString nick(nickFromMask(hostmask).toLower());
186 if(!_ircUsers.contains(nick)) {
187 IrcUser *ircuser = new IrcUser(hostmask, this);
188 if(!initData.isEmpty()) {
189 ircuser->fromVariantMap(initData);
190 ircuser->setInitialized();
194 proxy()->synchronize(ircuser);
196 qWarning() << "unable to synchronize new IrcUser" << hostmask << "forgot to call Network::setProxy(SignalProxy *)?";
198 connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString)));
200 _ircUsers[nick] = ircuser;
202 emit ircUserAdded(hostmask);
203 emit ircUserAdded(ircuser);
206 return _ircUsers[nick];
209 IrcUser *Network::ircUser(QString nickname) const {
210 nickname = nickname.toLower();
211 if(_ircUsers.contains(nickname))
212 return _ircUsers[nickname];
217 void Network::removeIrcUser(IrcUser *ircuser) {
218 QString nick = _ircUsers.key(ircuser);
222 _ircUsers.remove(nick);
223 disconnect(ircuser, 0, this, 0);
224 ircuser->deleteLater();
227 void Network::removeIrcChannel(IrcChannel *channel) {
228 QString chanName = _ircChannels.key(channel);
229 if(chanName.isNull())
232 _ircChannels.remove(chanName);
233 disconnect(channel, 0, this, 0);
234 channel->deleteLater();
237 void Network::removeChansAndUsers() {
238 QList<IrcUser *> users = ircUsers();
240 QList<IrcChannel *> channels = ircChannels();
241 _ircChannels.clear();
243 foreach(IrcChannel *channel, channels) {
244 proxy()->detachObject(channel);
245 disconnect(channel, 0, this, 0);
247 foreach(IrcUser *user, users) {
248 proxy()->detachObject(user);
249 disconnect(user, 0, this, 0);
252 // the second loop is needed because quit can have sideffects
253 foreach(IrcUser *user, users) {
258 qDeleteAll(channels);
261 IrcChannel *Network::newIrcChannel(const QString &channelname, const QVariantMap &initData) {
262 if(!_ircChannels.contains(channelname.toLower())) {
263 IrcChannel *channel = ircChannelFactory(channelname);
264 if(!initData.isEmpty()) {
265 channel->fromVariantMap(initData);
266 channel->setInitialized();
270 proxy()->synchronize(channel);
272 qWarning() << "unable to synchronize new IrcChannel" << channelname << "forgot to call Network::setProxy(SignalProxy *)?";
274 _ircChannels[channelname.toLower()] = channel;
276 emit ircChannelAdded(channelname);
277 emit ircChannelAdded(channel);
279 return _ircChannels[channelname.toLower()];
282 IrcChannel *Network::ircChannel(QString channelname) const {
283 channelname = channelname.toLower();
284 if(_ircChannels.contains(channelname))
285 return _ircChannels[channelname];
290 QByteArray Network::defaultCodecForServer() {
291 if(_defaultCodecForServer)
292 return _defaultCodecForServer->name();
296 void Network::setDefaultCodecForServer(const QByteArray &name) {
297 _defaultCodecForServer = QTextCodec::codecForName(name);
300 QByteArray Network::defaultCodecForEncoding() {
301 if(_defaultCodecForEncoding)
302 return _defaultCodecForEncoding->name();
306 void Network::setDefaultCodecForEncoding(const QByteArray &name) {
307 _defaultCodecForEncoding = QTextCodec::codecForName(name);
310 QByteArray Network::defaultCodecForDecoding() {
311 if(_defaultCodecForDecoding)
312 return _defaultCodecForDecoding->name();
316 void Network::setDefaultCodecForDecoding(const QByteArray &name) {
317 _defaultCodecForDecoding = QTextCodec::codecForName(name);
320 QByteArray Network::codecForServer() const {
322 return _codecForServer->name();
326 void Network::setCodecForServer(const QByteArray &name) {
327 setCodecForServer(QTextCodec::codecForName(name));
330 void Network::setCodecForServer(QTextCodec *codec) {
331 _codecForServer = codec;
332 emit codecForServerSet(codecForServer());
335 QByteArray Network::codecForEncoding() const {
336 if(_codecForEncoding)
337 return _codecForEncoding->name();
341 void Network::setCodecForEncoding(const QByteArray &name) {
342 setCodecForEncoding(QTextCodec::codecForName(name));
345 void Network::setCodecForEncoding(QTextCodec *codec) {
346 _codecForEncoding = codec;
347 emit codecForEncodingSet(codecForEncoding());
350 QByteArray Network::codecForDecoding() const {
351 if(_codecForDecoding)
352 return _codecForDecoding->name();
353 else return QByteArray();
356 void Network::setCodecForDecoding(const QByteArray &name) {
357 setCodecForDecoding(QTextCodec::codecForName(name));
360 void Network::setCodecForDecoding(QTextCodec *codec) {
361 _codecForDecoding = codec;
362 emit codecForDecodingSet(codecForDecoding());
365 // FIXME use server encoding if appropriate
366 QString Network::decodeString(const QByteArray &text) const {
367 if(_codecForDecoding)
368 return ::decodeString(text, _codecForDecoding);
369 else return ::decodeString(text, _defaultCodecForDecoding);
372 QByteArray Network::encodeString(const QString &string) const {
373 if(_codecForEncoding) {
374 return _codecForEncoding->fromUnicode(string);
376 if(_defaultCodecForEncoding) {
377 return _defaultCodecForEncoding->fromUnicode(string);
379 return string.toAscii();
382 QString Network::decodeServerString(const QByteArray &text) const {
384 return ::decodeString(text, _codecForServer);
386 return ::decodeString(text, _defaultCodecForServer);
389 QByteArray Network::encodeServerString(const QString &string) const {
390 if(_codecForServer) {
391 return _codecForServer->fromUnicode(string);
393 if(_defaultCodecForServer) {
394 return _defaultCodecForServer->fromUnicode(string);
396 return string.toAscii();
399 // ====================
401 // ====================
402 void Network::setNetworkName(const QString &networkName) {
403 _networkName = networkName;
404 emit networkNameSet(networkName);
407 void Network::setCurrentServer(const QString ¤tServer) {
408 _currentServer = currentServer;
409 emit currentServerSet(currentServer);
412 void Network::setConnected(bool connected) {
413 if(_connected == connected)
416 _connected = connected;
418 setMyNick(QString());
419 setCurrentServer(QString());
420 removeChansAndUsers();
422 emit connectedSet(connected);
425 //void Network::setConnectionState(ConnectionState state) {
426 void Network::setConnectionState(int state) {
427 _connectionState = (ConnectionState)state;
428 //qDebug() << "netstate" << networkId() << networkName() << state;
429 emit connectionStateSet(state);
430 emit connectionStateSet(_connectionState);
433 void Network::setMyNick(const QString &nickname) {
435 if(!_myNick.isEmpty() && !ircUser(myNick())) {
436 newIrcUser(myNick());
438 emit myNickSet(nickname);
441 void Network::setLatency(int latency) {
442 if(_latency == latency)
445 emit latencySet(latency);
448 void Network::setIdentity(IdentityId id) {
450 emit identitySet(id);
453 void Network::setServerList(const QVariantList &serverList) {
454 _serverList = fromVariantList<Server>(serverList);
455 emit serverListSet(serverList);
458 void Network::setUseRandomServer(bool use) {
459 _useRandomServer = use;
460 emit useRandomServerSet(use);
463 void Network::setPerform(const QStringList &perform) {
465 emit performSet(perform);
468 void Network::setUseAutoIdentify(bool use) {
469 _useAutoIdentify = use;
470 emit useAutoIdentifySet(use);
473 void Network::setAutoIdentifyService(const QString &service) {
474 _autoIdentifyService = service;
475 emit autoIdentifyServiceSet(service);
478 void Network::setAutoIdentifyPassword(const QString &password) {
479 _autoIdentifyPassword = password;
480 emit autoIdentifyPasswordSet(password);
483 void Network::setUseAutoReconnect(bool use) {
484 _useAutoReconnect = use;
485 emit useAutoReconnectSet(use);
488 void Network::setAutoReconnectInterval(quint32 interval) {
489 _autoReconnectInterval = interval;
490 emit autoReconnectIntervalSet(interval);
493 void Network::setAutoReconnectRetries(quint16 retries) {
494 _autoReconnectRetries = retries;
495 emit autoReconnectRetriesSet(retries);
498 void Network::setUnlimitedReconnectRetries(bool unlimited) {
499 _unlimitedReconnectRetries = unlimited;
500 emit unlimitedReconnectRetriesSet(unlimited);
503 void Network::setRejoinChannels(bool rejoin) {
504 _rejoinChannels = rejoin;
505 emit rejoinChannelsSet(rejoin);
508 void Network::addSupport(const QString ¶m, const QString &value) {
509 if(!_supports.contains(param)) {
510 _supports[param] = value;
511 emit supportAdded(param, value);
515 void Network::removeSupport(const QString ¶m) {
516 if(_supports.contains(param)) {
517 _supports.remove(param);
518 emit supportRemoved(param);
522 QVariantMap Network::initSupports() const {
523 QVariantMap supports;
524 QHashIterator<QString, QString> iter(_supports);
525 while(iter.hasNext()) {
527 supports[iter.key()] = iter.value();
532 QVariantMap Network::initIrcUsersAndChannels() const {
533 QVariantMap usersAndChannels;
535 QVariantMap channels;
537 QHash<QString, IrcUser *>::const_iterator userIter = _ircUsers.constBegin();
538 QHash<QString, IrcUser *>::const_iterator userIterEnd = _ircUsers.constEnd();
539 while(userIter != userIterEnd) {
540 users[userIter.value()->hostmask()] = userIter.value()->toVariantMap();
543 usersAndChannels["users"] = users;
545 QHash<QString, IrcChannel *>::const_iterator channelIter = _ircChannels.constBegin();
546 QHash<QString, IrcChannel *>::const_iterator channelIterEnd = _ircChannels.constEnd();
547 while(channelIter != channelIterEnd) {
548 channels[channelIter.value()->name()] = channelIter.value()->toVariantMap();
551 usersAndChannels["channels"] = channels;
553 return usersAndChannels;
556 void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) {
558 if(isInitialized()) {
559 qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!";
563 QVariantMap users = usersAndChannels.value("users").toMap();
564 QVariantMap::const_iterator userIter = users.constBegin();
565 QVariantMap::const_iterator userIterEnd = users.constEnd();
566 while(userIter != userIterEnd) {
567 newIrcUser(userIter.key(), userIter.value().toMap());
571 QVariantMap channels = usersAndChannels.value("channels").toMap();
572 QVariantMap::const_iterator channelIter = channels.constBegin();
573 QVariantMap::const_iterator channelIterEnd = channels.constEnd();
574 while(channelIter != channelIterEnd) {
575 newIrcChannel(channelIter.key(), channelIter.value().toMap());
580 void Network::initSetSupports(const QVariantMap &supports) {
581 QMapIterator<QString, QVariant> iter(supports);
582 while(iter.hasNext()) {
584 addSupport(iter.key(), iter.value().toString());
588 IrcUser *Network::updateNickFromMask(const QString &mask) {
589 QString nick(nickFromMask(mask).toLower());
592 if(_ircUsers.contains(nick)) {
593 ircuser = _ircUsers[nick];
594 ircuser->updateHostmask(mask);
596 ircuser = newIrcUser(mask);
601 void Network::ircUserNickChanged(QString newnick) {
602 QString oldnick = _ircUsers.key(qobject_cast<IrcUser*>(sender()));
607 if(newnick.toLower() != oldnick) _ircUsers[newnick.toLower()] = _ircUsers.take(oldnick);
609 if(myNick().toLower() == oldnick)
613 void Network::emitConnectionError(const QString &errorMsg) {
614 emit connectionError(errorMsg);
617 // ====================
619 // ====================
620 void Network::determinePrefixes() {
621 // seems like we have to construct them first
622 QString prefix = support("PREFIX");
624 if(prefix.startsWith("(") && prefix.contains(")")) {
625 _prefixes = prefix.section(")", 1);
626 _prefixModes = prefix.mid(1).section(")", 0, 0);
628 QString defaultPrefixes("~&@%+");
629 QString defaultPrefixModes("qaohv");
631 if(prefix.isEmpty()) {
632 _prefixes = defaultPrefixes;
633 _prefixModes = defaultPrefixModes;
637 // we just assume that in PREFIX are only prefix chars stored
638 for(int i = 0; i < defaultPrefixes.size(); i++) {
639 if(prefix.contains(defaultPrefixes[i])) {
640 _prefixes += defaultPrefixes[i];
641 _prefixModes += defaultPrefixModes[i];
645 if(!_prefixes.isNull())
648 // well... our assumption was obviously wrong...
649 // check if it's only prefix modes
650 for(int i = 0; i < defaultPrefixes.size(); i++) {
651 if(prefix.contains(defaultPrefixModes[i])) {
652 _prefixes += defaultPrefixes[i];
653 _prefixModes += defaultPrefixModes[i];
656 // now we've done all we've could...
660 /************************************************************************
662 ************************************************************************/
664 bool NetworkInfo::operator==(const NetworkInfo &other) const {
665 if(networkId != other.networkId) return false;
666 if(networkName != other.networkName) return false;
667 if(identity != other.identity) return false;
668 if(codecForServer != other.codecForServer) return false;
669 if(codecForEncoding != other.codecForEncoding) return false;
670 if(codecForDecoding != other.codecForDecoding) return false;
671 if(serverList != other.serverList) return false;
672 if(useRandomServer != other.useRandomServer) return false;
673 if(perform != other.perform) return false;
674 if(useAutoIdentify != other.useAutoIdentify) return false;
675 if(autoIdentifyService != other.autoIdentifyService) return false;
676 if(autoIdentifyPassword != other.autoIdentifyPassword) return false;
677 if(useAutoReconnect != other.useAutoReconnect) return false;
678 if(autoReconnectInterval != other.autoReconnectInterval) return false;
679 if(autoReconnectRetries != other.autoReconnectRetries) return false;
680 if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false;
681 if(rejoinChannels != other.rejoinChannels) return false;
685 bool NetworkInfo::operator!=(const NetworkInfo &other) const {
686 return !(*this == other);
689 QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) {
691 i["NetworkId"] = QVariant::fromValue<NetworkId>(info.networkId);
692 i["NetworkName"] = info.networkName;
693 i["Identity"] = QVariant::fromValue<IdentityId>(info.identity);
694 i["CodecForServer"] = info.codecForServer;
695 i["CodecForEncoding"] = info.codecForEncoding;
696 i["CodecForDecoding"] = info.codecForDecoding;
697 i["ServerList"] = toVariantList(info.serverList);
698 i["UseRandomServer"] = info.useRandomServer;
699 i["Perform"] = info.perform;
700 i["UseAutoIdentify"] = info.useAutoIdentify;
701 i["AutoIdentifyService"] = info.autoIdentifyService;
702 i["AutoIdentifyPassword"] = info.autoIdentifyPassword;
703 i["UseAutoReconnect"] = info.useAutoReconnect;
704 i["AutoReconnectInterval"] = info.autoReconnectInterval;
705 i["AutoReconnectRetries"] = info.autoReconnectRetries;
706 i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries;
707 i["RejoinChannels"] = info.rejoinChannels;
712 QDataStream &operator>>(QDataStream &in, NetworkInfo &info) {
715 info.networkId = i["NetworkId"].value<NetworkId>();
716 info.networkName = i["NetworkName"].toString();
717 info.identity = i["Identity"].value<IdentityId>();
718 info.codecForServer = i["CodecForServer"].toByteArray();
719 info.codecForEncoding = i["CodecForEncoding"].toByteArray();
720 info.codecForDecoding = i["CodecForDecoding"].toByteArray();
721 info.serverList = fromVariantList<Network::Server>(i["ServerList"].toList());
722 info.useRandomServer = i["UseRandomServer"].toBool();
723 info.perform = i["Perform"].toStringList();
724 info.useAutoIdentify = i["UseAutoIdentify"].toBool();
725 info.autoIdentifyService = i["AutoIdentifyService"].toString();
726 info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString();
727 info.useAutoReconnect = i["UseAutoReconnect"].toBool();
728 info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt();
729 info.autoReconnectRetries = i["AutoReconnectRetries"].toInt();
730 info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool();
731 info.rejoinChannels = i["RejoinChannels"].toBool();
735 QDebug operator<<(QDebug dbg, const NetworkInfo &i) {
736 dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity
737 << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding
738 << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform
739 << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword
740 << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval
741 << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries
742 << " rejoinChannels = " << i.rejoinChannels << ")";
746 QDataStream &operator<<(QDataStream &out, const Network::Server &server) {
747 QVariantMap serverMap;
748 serverMap["Host"] = server.host;
749 serverMap["Port"] = server.port;
750 serverMap["Password"] = server.password;
751 serverMap["UseSSL"] = server.useSsl;
752 serverMap["sslVersion"] = server.sslVersion;
753 serverMap["UseProxy"] = server.useProxy;
754 serverMap["ProxyType"] = server.proxyType;
755 serverMap["ProxyHost"] = server.proxyHost;
756 serverMap["ProxyPort"] = server.proxyPort;
757 serverMap["ProxyUser"] = server.proxyUser;
758 serverMap["ProxyPass"] = server.proxyPass;
763 QDataStream &operator>>(QDataStream &in, Network::Server &server) {
764 QVariantMap serverMap;
766 server.host = serverMap["Host"].toString();
767 server.port = serverMap["Port"].toUInt();
768 server.password = serverMap["Password"].toString();
769 server.useSsl = serverMap["UseSSL"].toBool();
770 server.sslVersion = serverMap["sslVersion"].toInt();
771 server.useProxy = serverMap["UseProxy"].toBool();
772 server.proxyType = serverMap["ProxyType"].toInt();
773 server.proxyHost = serverMap["ProxyHost"].toString();
774 server.proxyPort = serverMap["ProxyPort"].toUInt();
775 server.proxyUser = serverMap["ProxyUser"].toString();
776 server.proxyPass = serverMap["ProxyPass"].toString();
781 bool Network::Server::operator==(const Server &other) const {
782 if(host != other.host) return false;
783 if(port != other.port) return false;
784 if(password != other.password) return false;
785 if(useSsl != other.useSsl) return false;
786 if(sslVersion != other.sslVersion) return false;
787 if(useProxy != other.useProxy) return false;
788 if(proxyType != other.proxyType) return false;
789 if(proxyHost != other.proxyHost) return false;
790 if(proxyPort != other.proxyPort) return false;
791 if(proxyUser != other.proxyUser) return false;
792 if(proxyPass != other.proxyPass) return false;
796 bool Network::Server::operator!=(const Server &other) const {
797 return !(*this == other);
800 QDebug operator<<(QDebug dbg, const Network::Server &server) {
801 dbg.nospace() << "Server(host = " << server.host << ":" << server.port << ", useSsl = " << server.useSsl << ")";