X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fnetwork.cpp;h=1098b0a33c14e9294c14fd51e48d8662204d47ae;hp=1388060aacf908ea684541868e524252a6362ab8;hb=1514aaae673660c7a3e2a82545b8c3947ea3f9b7;hpb=d1b6499b0b848d4287efae89107576548533502c diff --git a/src/common/network.cpp b/src/common/network.cpp index 1388060a..1098b0a3 100644 --- a/src/common/network.cpp +++ b/src/common/network.cpp @@ -19,61 +19,45 @@ ***************************************************************************/ #include "network.h" -#include "signalproxy.h" -#include "ircuser.h" -#include "ircchannel.h" - #include #include #include "util.h" +QTextCodec *Network::_defaultCodecForServer = 0; +QTextCodec *Network::_defaultCodecForEncoding = 0; +QTextCodec *Network::_defaultCodecForDecoding = 0; // ==================== // Public: // ==================== -Network::Network(const NetworkId &networkid, QObject *parent) : SyncableObject(parent), +Network::Network(const NetworkId &networkid, QObject *parent) + : SyncableObject(parent), + _proxy(0), _networkId(networkid), _identity(0), _myNick(QString()), + _latency(0), _networkName(QString("")), _currentServer(QString()), + _connected(false), + _connectionState(Disconnected), _prefixes(QString()), _prefixModes(QString()), - _proxy(0), + _useRandomServer(false), + _useAutoIdentify(false), + _useAutoReconnect(false), + _autoReconnectInterval(60), + _autoReconnectRetries(10), + _unlimitedReconnectRetries(false), + _codecForServer(0), _codecForEncoding(0), _codecForDecoding(0) { - setObjectName(QString::number(networkid)); -} - -// I think this is unnecessary since IrcUsers have us as their daddy :) -//Network::~Network() { -// QHashIterator ircuser(_ircUsers); -// while (ircuser.hasNext()) { -// ircuser.next(); -// delete ircuser.value(); -// } -//} - -NetworkId Network::networkId() const { - return _networkId; -} - -SignalProxy *Network::proxy() const { - return _proxy; -} - -void Network::setProxy(SignalProxy *proxy) { - _proxy = proxy; - //proxy->synchronize(this); // we should to this explicitly from the outside! + setObjectName(QString::number(networkid.toInt())); } -bool Network::isMyNick(const QString &nick) const { - return (myNick().toLower() == nick.toLower()); -} - -bool Network::isMe(IrcUser *ircuser) const { - return (ircuser->nick().toLower() == myNick().toLower()); +Network::~Network() { + emit aboutToBeDestroyed(); } bool Network::isChannelName(const QString &channelname) const { @@ -86,6 +70,48 @@ bool Network::isChannelName(const QString &channelname) const { return QString("#&!+").contains(channelname[0]); } +NetworkInfo Network::networkInfo() const { + NetworkInfo info; + info.networkName = networkName(); + info.networkId = networkId(); + info.identity = identity(); + info.codecForServer = codecForServer(); + info.codecForEncoding = codecForEncoding(); + info.codecForDecoding = codecForDecoding(); + info.serverList = serverList(); + info.useRandomServer = useRandomServer(); + info.perform = perform(); + info.useAutoIdentify = useAutoIdentify(); + info.autoIdentifyService = autoIdentifyService(); + info.autoIdentifyPassword = autoIdentifyPassword(); + info.useAutoReconnect = useAutoReconnect(); + info.autoReconnectInterval = autoReconnectInterval(); + info.autoReconnectRetries = autoReconnectRetries(); + info.unlimitedReconnectRetries = unlimitedReconnectRetries(); + info.rejoinChannels = rejoinChannels(); + return info; +} + +void Network::setNetworkInfo(const NetworkInfo &info) { + // we don't set our ID! + if(!info.networkName.isEmpty() && info.networkName != networkName()) setNetworkName(info.networkName); + if(info.identity > 0 && info.identity != identity()) setIdentity(info.identity); + if(info.codecForServer != codecForServer()) setCodecForServer(QTextCodec::codecForName(info.codecForServer)); + if(info.codecForEncoding != codecForEncoding()) setCodecForEncoding(QTextCodec::codecForName(info.codecForEncoding)); + if(info.codecForDecoding != codecForDecoding()) setCodecForDecoding(QTextCodec::codecForName(info.codecForDecoding)); + if(info.serverList.count()) setServerList(info.serverList); // FIXME compare components + if(info.useRandomServer != useRandomServer()) setUseRandomServer(info.useRandomServer); + if(info.perform != perform()) setPerform(info.perform); + if(info.useAutoIdentify != useAutoIdentify()) setUseAutoIdentify(info.useAutoIdentify); + if(info.autoIdentifyService != autoIdentifyService()) setAutoIdentifyService(info.autoIdentifyService); + if(info.autoIdentifyPassword != autoIdentifyPassword()) setAutoIdentifyPassword(info.autoIdentifyPassword); + if(info.useAutoReconnect != useAutoReconnect()) setUseAutoReconnect(info.useAutoReconnect); + if(info.autoReconnectInterval != autoReconnectInterval()) setAutoReconnectInterval(info.autoReconnectInterval); + if(info.autoReconnectRetries != autoReconnectRetries()) setAutoReconnectRetries(info.autoReconnectRetries); + if(info.unlimitedReconnectRetries != unlimitedReconnectRetries()) setUnlimitedReconnectRetries(info.unlimitedReconnectRetries); + if(info.rejoinChannels != rejoinChannels()) setRejoinChannels(info.rejoinChannels); +} + QString Network::prefixToMode(const QString &prefix) { if(prefixes().contains(prefix)) return QString(prefixModes()[prefixes().indexOf(prefix)]); @@ -93,10 +119,6 @@ QString Network::prefixToMode(const QString &prefix) { return QString(); } -QString Network::prefixToMode(const QCharRef &prefix) { - return prefixToMode(QString(prefix)); -} - QString Network::modeToPrefix(const QString &mode) { if(prefixModes().contains(mode)) return QString(prefixes()[prefixModes().indexOf(mode)]); @@ -104,26 +126,6 @@ QString Network::modeToPrefix(const QString &mode) { return QString(); } -QString Network::modeToPrefix(const QCharRef &mode) { - return modeToPrefix(QString(mode)); -} - -QString Network::networkName() const { - return _networkName; -} - -QString Network::currentServer() const { - return _currentServer; -} - -QString Network::myNick() const { - return _myNick; -} - -IdentityId Network::identity() const { - return _identity; -} - QStringList Network::nicks() const { // we don't use _ircUsers.keys() since the keys may be // not up to date after a nick change @@ -134,14 +136,6 @@ QStringList Network::nicks() const { return nicks; } -QStringList Network::channels() const { - return _ircChannels.keys(); -} - -QList Network::serverList() const { - return _serverList; -} - QString Network::prefixes() { if(_prefixes.isNull()) determinePrefixes(); @@ -156,8 +150,27 @@ QString Network::prefixModes() { return _prefixModes; } -bool Network::supports(const QString ¶m) const { - return _supports.contains(param); +// example Unreal IRCD: CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMTG +Network::ChannelModeType Network::channelModeType(const QString &mode) { + if(mode.isEmpty()) + return NOT_A_CHANMODE; + + QString chanmodes = support("CHANMODES"); + if(chanmodes.isEmpty()) + return NOT_A_CHANMODE; + + ChannelModeType modeType = A_CHANMODE; + for(int i = 0; i < chanmodes.count(); i++) { + if(chanmodes[i] == mode[0]) + break; + else if(chanmodes[i] == ',') + modeType = (ChannelModeType)(modeType << 1); + } + if(modeType > D_CHANMODE) { + qWarning() << "Network" << networkId() << "supplied invalid CHANMODES:" << chanmodes; + modeType = NOT_A_CHANMODE; + } + return modeType; } QString Network::support(const QString ¶m) const { @@ -172,9 +185,7 @@ IrcUser *Network::newIrcUser(const QString &hostmask) { QString nick(nickFromMask(hostmask).toLower()); if(!_ircUsers.contains(nick)) { IrcUser *ircuser = new IrcUser(hostmask, this); - // mark IrcUser as already initialized to keep the SignalProxy from requesting initData - //if(isInitialized()) - // ircuser->setInitialized(); + if(proxy()) proxy()->synchronize(ircuser); else @@ -190,8 +201,19 @@ IrcUser *Network::newIrcUser(const QString &hostmask) { return _ircUsers[nick]; } -IrcUser *Network::newIrcUser(const QByteArray &hostmask) { - return newIrcUser(decodeString(hostmask)); +void Network::ircUserDestroyed() { + IrcUser *ircUser = static_cast(sender()); + if(!ircUser) + return; + + QHash::iterator ircUserIter = _ircUsers.begin(); + while(ircUserIter != _ircUsers.end()) { + if(ircUser == *ircUserIter) { + ircUserIter = _ircUsers.erase(ircUserIter); + break; + } + ircUserIter++; + } } void Network::removeIrcUser(IrcUser *ircuser) { @@ -200,17 +222,29 @@ void Network::removeIrcUser(IrcUser *ircuser) { return; _ircUsers.remove(nick); + disconnect(ircuser, 0, this, 0); emit ircUserRemoved(nick); emit ircUserRemoved(ircuser); ircuser->deleteLater(); } -void Network::removeIrcUser(QString nick) { +void Network::removeIrcUser(const QString &nick) { IrcUser *ircuser; if((ircuser = ircUser(nick)) != 0) removeIrcUser(ircuser); } +void Network::removeChansAndUsers() { + QList users = ircUsers(); + foreach(IrcUser *user, users) { + removeIrcUser(user); + } + QList channels = ircChannels(); + foreach(IrcChannel *channel, channels) { + removeIrcChannel(channel); + } +} + IrcUser *Network::ircUser(QString nickname) const { nickname = nickname.toLower(); if(_ircUsers.contains(nickname)) @@ -219,24 +253,9 @@ IrcUser *Network::ircUser(QString nickname) const { return 0; } -IrcUser *Network::ircUser(const QByteArray &nickname) const { - return ircUser(decodeString(nickname)); -} - -QList Network::ircUsers() const { - return _ircUsers.values(); -} - -quint32 Network::ircUserCount() const { - return _ircUsers.count(); -} - IrcChannel *Network::newIrcChannel(const QString &channelname) { if(!_ircChannels.contains(channelname.toLower())) { IrcChannel *channel = new IrcChannel(channelname, this); - // mark IrcUser as already initialized to keep the SignalProxy from requesting initData - //if(isInitialized()) - // channel->setInitialized(); if(proxy()) proxy()->synchronize(channel); @@ -252,11 +271,7 @@ IrcChannel *Network::newIrcChannel(const QString &channelname) { return _ircChannels[channelname.toLower()]; } -IrcChannel *Network::newIrcChannel(const QByteArray &channelname) { - return newIrcChannel(decodeString(channelname)); -} - -IrcChannel *Network::ircChannel(QString channelname) { +IrcChannel *Network::ircChannel(QString channelname) const { channelname = channelname.toLower(); if(_ircChannels.contains(channelname)) return _ircChannels[channelname]; @@ -264,21 +279,54 @@ IrcChannel *Network::ircChannel(QString channelname) { return 0; } -IrcChannel *Network::ircChannel(const QByteArray &channelname) { - return ircChannel(decodeString(channelname)); +QByteArray Network::defaultCodecForServer() { + if(_defaultCodecForServer) + return _defaultCodecForServer->name(); + return QByteArray(); } +void Network::setDefaultCodecForServer(const QByteArray &name) { + _defaultCodecForServer = QTextCodec::codecForName(name); +} -QList Network::ircChannels() const { - return _ircChannels.values(); +QByteArray Network::defaultCodecForEncoding() { + if(_defaultCodecForEncoding) + return _defaultCodecForEncoding->name(); + return QByteArray(); } -quint32 Network::ircChannelCount() const { - return _ircChannels.count(); +void Network::setDefaultCodecForEncoding(const QByteArray &name) { + _defaultCodecForEncoding = QTextCodec::codecForName(name); +} + +QByteArray Network::defaultCodecForDecoding() { + if(_defaultCodecForDecoding) + return _defaultCodecForDecoding->name(); + return QByteArray(); +} + +void Network::setDefaultCodecForDecoding(const QByteArray &name) { + _defaultCodecForDecoding = QTextCodec::codecForName(name); +} + +QByteArray Network::codecForServer() const { + if(_codecForServer) + return _codecForServer->name(); + return QByteArray(); +} + +void Network::setCodecForServer(const QByteArray &name) { + setCodecForServer(QTextCodec::codecForName(name)); +} + +void Network::setCodecForServer(QTextCodec *codec) { + _codecForServer = codec; + emit codecForServerSet(codecForServer()); } QByteArray Network::codecForEncoding() const { - if(_codecForEncoding) return _codecForEncoding->name(); + if(_codecForEncoding) + return _codecForEncoding->name(); return QByteArray(); } @@ -288,10 +336,12 @@ void Network::setCodecForEncoding(const QByteArray &name) { void Network::setCodecForEncoding(QTextCodec *codec) { _codecForEncoding = codec; + emit codecForEncodingSet(codecForEncoding()); } QByteArray Network::codecForDecoding() const { - if(_codecForDecoding) return _codecForDecoding->name(); + if(_codecForDecoding) + return _codecForDecoding->name(); else return QByteArray(); } @@ -301,16 +351,40 @@ void Network::setCodecForDecoding(const QByteArray &name) { void Network::setCodecForDecoding(QTextCodec *codec) { _codecForDecoding = codec; + emit codecForDecodingSet(codecForDecoding()); } +// FIXME use server encoding if appropriate QString Network::decodeString(const QByteArray &text) const { - return ::decodeString(text, _codecForDecoding); + if(_codecForDecoding) + return ::decodeString(text, _codecForDecoding); + else return ::decodeString(text, _defaultCodecForDecoding); } -QByteArray Network::encodeString(const QString string) const { +QByteArray Network::encodeString(const QString &string) const { if(_codecForEncoding) { return _codecForEncoding->fromUnicode(string); } + if(_defaultCodecForEncoding) { + return _defaultCodecForEncoding->fromUnicode(string); + } + return string.toAscii(); +} + +QString Network::decodeServerString(const QByteArray &text) const { + if(_codecForServer) + return ::decodeString(text, _codecForServer); + else + return ::decodeString(text, _defaultCodecForServer); +} + +QByteArray Network::encodeServerString(const QString &string) const { + if(_codecForServer) { + return _codecForServer->fromUnicode(string); + } + if(_defaultCodecForServer) { + return _defaultCodecForServer->fromUnicode(string); + } return string.toAscii(); } @@ -327,21 +401,102 @@ void Network::setCurrentServer(const QString ¤tServer) { emit currentServerSet(currentServer); } +void Network::setConnected(bool connected) { + if(_connected == connected) + return; + + _connected = connected; + if(!connected) { + setMyNick(QString()); + setCurrentServer(QString()); + removeChansAndUsers(); + } + emit connectedSet(connected); +} + +//void Network::setConnectionState(ConnectionState state) { +void Network::setConnectionState(int state) { + _connectionState = (ConnectionState)state; + //qDebug() << "netstate" << networkId() << networkName() << state; + emit connectionStateSet(state); + emit connectionStateSet(_connectionState); +} + void Network::setMyNick(const QString &nickname) { _myNick = nickname; + if(!_myNick.isEmpty() && !ircUser(myNick())) { + newIrcUser(myNick()); + } emit myNickSet(nickname); } +void Network::setLatency(int latency) { + if(_latency == latency) + return; + _latency = latency; + emit latencySet(latency); +} + void Network::setIdentity(IdentityId id) { _identity = id; emit identitySet(id); } -void Network::setServerList(const QList &serverList) { +void Network::setServerList(const QVariantList &serverList) { _serverList = serverList; emit serverListSet(serverList); } +void Network::setUseRandomServer(bool use) { + _useRandomServer = use; + emit useRandomServerSet(use); +} + +void Network::setPerform(const QStringList &perform) { + _perform = perform; + emit performSet(perform); +} + +void Network::setUseAutoIdentify(bool use) { + _useAutoIdentify = use; + emit useAutoIdentifySet(use); +} + +void Network::setAutoIdentifyService(const QString &service) { + _autoIdentifyService = service; + emit autoIdentifyServiceSet(service); +} + +void Network::setAutoIdentifyPassword(const QString &password) { + _autoIdentifyPassword = password; + emit autoIdentifyPasswordSet(password); +} + +void Network::setUseAutoReconnect(bool use) { + _useAutoReconnect = use; + emit useAutoReconnectSet(use); +} + +void Network::setAutoReconnectInterval(quint32 interval) { + _autoReconnectInterval = interval; + emit autoReconnectIntervalSet(interval); +} + +void Network::setAutoReconnectRetries(quint16 retries) { + _autoReconnectRetries = retries; + emit autoReconnectRetriesSet(retries); +} + +void Network::setUnlimitedReconnectRetries(bool unlimited) { + _unlimitedReconnectRetries = unlimited; + emit unlimitedReconnectRetriesSet(unlimited); +} + +void Network::setRejoinChannels(bool rejoin) { + _rejoinChannels = rejoin; + emit rejoinChannelsSet(rejoin); +} + void Network::addSupport(const QString ¶m, const QString &value) { if(!_supports.contains(param)) { _supports[param] = value; @@ -366,22 +521,86 @@ QVariantMap Network::initSupports() const { return supports; } -QVariantList Network::initServerList() const { - QList list; - foreach(QVariantMap serverdata, serverList()) list << QVariant(serverdata); - return list; -} +QVariantMap Network::initIrcUsersAndChannels() const { + QVariantMap usersAndChannels; + QVariantMap users; + QVariantMap channels; + + QHash::const_iterator userIter = _ircUsers.constBegin(); + QHash::const_iterator userIterEnd = _ircUsers.constEnd(); + while(userIter != userIterEnd) { + users[userIter.value()->hostmask()] = userIter.value()->toVariantMap(); + userIter++; + } + usersAndChannels["users"] = users; -QStringList Network::initIrcUsers() const { - QStringList hostmasks; - foreach(IrcUser *ircuser, ircUsers()) { - hostmasks << ircuser->hostmask(); + QHash::const_iterator channelIter = _ircChannels.constBegin(); + QHash::const_iterator channelIterEnd = _ircChannels.constEnd(); + while(channelIter != channelIterEnd) { + channels[channelIter.value()->name()] = channelIter.value()->toVariantMap(); + channelIter++; } - return hostmasks; + usersAndChannels["channels"] = channels; + + return usersAndChannels; } -QStringList Network::initIrcChannels() const { - return _ircChannels.keys(); +void Network::initSetIrcUsersAndChannels(const QVariantMap &usersAndChannels) { + Q_ASSERT(proxy()); + if(isInitialized()) { + qWarning() << "Network" << networkId() << "received init data for users and channels allthough there allready are known users or channels!"; + return; + } + + QVariantMap users = usersAndChannels.value("users").toMap(); + + QVariantMap::const_iterator userIter = users.constBegin(); + QVariantMap::const_iterator userIterEnd = users.constEnd(); + IrcUser *ircUser = 0; + QString hostmask; + while(userIter != userIterEnd) { + hostmask = userIter.key(); + ircUser = new IrcUser(hostmask, this); + ircUser->fromVariantMap(userIter.value().toMap()); + ircUser->setInitialized(); + proxy()->synchronize(ircUser); + + connect(ircUser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickChanged(QString))); + connect(ircUser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); + + _ircUsers[nickFromMask(hostmask).toLower()] = ircUser; + + emit ircUserAdded(hostmask); + emit ircUserAdded(ircUser); + emit ircUserInitDone(ircUser); + + userIter++; + } + + + QVariantMap channels = usersAndChannels.value("channels").toMap(); + QVariantMap::const_iterator channelIter = channels.constBegin(); + QVariantMap::const_iterator channelIterEnd = channels.constEnd(); + IrcChannel *ircChannel = 0; + QString channelName; + + while(channelIter != channelIterEnd) { + channelName = channelIter.key(); + ircChannel = new IrcChannel(channelName, this); + ircChannel->fromVariantMap(channelIter.value().toMap()); + ircChannel->setInitialized(); + proxy()->synchronize(ircChannel); + + connect(ircChannel, SIGNAL(destroyed()), this, SLOT(channelDestroyed())); + _ircChannels[channelName.toLower()] = ircChannel; + + emit ircChannelAdded(channelName); + emit ircChannelAdded(ircChannel); + emit ircChannelInitDone(ircChannel); + + channelIter++; + } + } void Network::initSetSupports(const QVariantMap &supports) { @@ -392,27 +611,6 @@ void Network::initSetSupports(const QVariantMap &supports) { } } -void Network::initSetServerList(const QVariantList & serverList) { - QList slist; - foreach(QVariant v, serverList) slist << v.toMap(); - setServerList(slist); -} - -void Network::initSetIrcUsers(const QStringList &hostmasks) { - if(!_ircUsers.empty()) - return; - foreach(QString hostmask, hostmasks) { - newIrcUser(hostmask); - } -} - -void Network::initSetChannels(const QStringList &channels) { - if(!_ircChannels.empty()) - return; - foreach(QString channel, channels) - newIrcChannel(channel); -} - IrcUser *Network::updateNickFromMask(const QString &mask) { QString nick(nickFromMask(mask).toLower()); IrcUser *ircuser; @@ -441,32 +639,44 @@ void Network::ircUserNickChanged(QString newnick) { void Network::ircUserInitDone() { IrcUser *ircuser = static_cast(sender()); Q_ASSERT(ircuser); + connect(ircuser, SIGNAL(initDone()), this, SLOT(ircUserInitDone())); emit ircUserInitDone(ircuser); } void Network::ircChannelInitDone() { - IrcChannel *ircchannel = static_cast(sender()); - Q_ASSERT(ircchannel); - emit ircChannelInitDone(ircchannel); + IrcChannel *ircChannel = static_cast(sender()); + Q_ASSERT(ircChannel); + disconnect(ircChannel, SIGNAL(initDone()), this, SLOT(ircChannelInitDone())); + emit ircChannelInitDone(ircChannel); } -void Network::ircUserDestroyed() { - IrcUser *ircuser = static_cast(sender()); - Q_ASSERT(ircuser); - removeIrcUser(ircuser); +void Network::removeIrcChannel(IrcChannel *channel) { + QString chanName = _ircChannels.key(channel); + if(chanName.isNull()) + return; + + _ircChannels.remove(chanName); + disconnect(channel, 0, this, 0); + emit ircChannelRemoved(chanName); + emit ircChannelRemoved(channel); + channel->deleteLater(); +} + +void Network::removeIrcChannel(const QString &channel) { + IrcChannel *chan; + if((chan = ircChannel(channel)) != 0) + removeIrcChannel(chan); } void Network::channelDestroyed() { IrcChannel *channel = static_cast(sender()); Q_ASSERT(channel); - emit ircChannelRemoved(sender()); _ircChannels.remove(_ircChannels.key(channel)); + emit ircChannelRemoved(channel); } -void Network::requestConnect() { - if(!proxy()) return; - if(proxy()->proxyMode() == SignalProxy::Client) emit connectRequested(); // on the client this triggers calling this slot on the core - else emit connectRequested(networkId()); // and this is for CoreSession :) +void Network::emitConnectionError(const QString &errorMsg) { + emit connectionError(errorMsg); } // ==================== @@ -474,18 +684,24 @@ void Network::requestConnect() { // ==================== void Network::determinePrefixes() { // seems like we have to construct them first - QString PREFIX = support("PREFIX"); + QString prefix = support("PREFIX"); - if(PREFIX.startsWith("(") && PREFIX.contains(")")) { - _prefixes = PREFIX.section(")", 1); - _prefixModes = PREFIX.mid(1).section(")", 0, 0); + if(prefix.startsWith("(") && prefix.contains(")")) { + _prefixes = prefix.section(")", 1); + _prefixModes = prefix.mid(1).section(")", 0, 0); } else { QString defaultPrefixes("~&@%+"); QString defaultPrefixModes("qaohv"); + if(prefix.isEmpty()) { + _prefixes = defaultPrefixes; + _prefixModes = defaultPrefixModes; + return; + } + // we just assume that in PREFIX are only prefix chars stored for(int i = 0; i < defaultPrefixes.size(); i++) { - if(PREFIX.contains(defaultPrefixes[i])) { + if(prefix.contains(defaultPrefixes[i])) { _prefixes += defaultPrefixes[i]; _prefixModes += defaultPrefixModes[i]; } @@ -497,7 +713,7 @@ void Network::determinePrefixes() { // well... our assumption was obviously wrong... // check if it's only prefix modes for(int i = 0; i < defaultPrefixes.size(); i++) { - if(PREFIX.contains(defaultPrefixModes[i])) { + if(prefix.contains(defaultPrefixModes[i])) { _prefixes += defaultPrefixes[i]; _prefixModes += defaultPrefixModes[i]; } @@ -506,3 +722,88 @@ void Network::determinePrefixes() { } } +/************************************************************************ + * NetworkInfo + ************************************************************************/ + +bool NetworkInfo::operator==(const NetworkInfo &other) const { + if(networkId != other.networkId) return false; + if(networkName != other.networkName) return false; + if(identity != other.identity) return false; + if(codecForServer != other.codecForServer) return false; + if(codecForEncoding != other.codecForEncoding) return false; + if(codecForDecoding != other.codecForDecoding) return false; + if(serverList != other.serverList) return false; + if(useRandomServer != other.useRandomServer) return false; + if(perform != other.perform) return false; + if(useAutoIdentify != other.useAutoIdentify) return false; + if(autoIdentifyService != other.autoIdentifyService) return false; + if(autoIdentifyPassword != other.autoIdentifyPassword) return false; + if(useAutoReconnect != other.useAutoReconnect) return false; + if(autoReconnectInterval != other.autoReconnectInterval) return false; + if(autoReconnectRetries != other.autoReconnectRetries) return false; + if(unlimitedReconnectRetries != other.unlimitedReconnectRetries) return false; + if(rejoinChannels != other.rejoinChannels) return false; + return true; +} + +bool NetworkInfo::operator!=(const NetworkInfo &other) const { + return !(*this == other); +} + +QDataStream &operator<<(QDataStream &out, const NetworkInfo &info) { + QVariantMap i; + i["NetworkId"] = QVariant::fromValue(info.networkId); + i["NetworkName"] = info.networkName; + i["Identity"] = QVariant::fromValue(info.identity); + i["CodecForServer"] = info.codecForServer; + i["CodecForEncoding"] = info.codecForEncoding; + i["CodecForDecoding"] = info.codecForDecoding; + i["ServerList"] = info.serverList; + i["UseRandomServer"] = info.useRandomServer; + i["Perform"] = info.perform; + i["UseAutoIdentify"] = info.useAutoIdentify; + i["AutoIdentifyService"] = info.autoIdentifyService; + i["AutoIdentifyPassword"] = info.autoIdentifyPassword; + i["UseAutoReconnect"] = info.useAutoReconnect; + i["AutoReconnectInterval"] = info.autoReconnectInterval; + i["AutoReconnectRetries"] = info.autoReconnectRetries; + i["UnlimitedReconnectRetries"] = info.unlimitedReconnectRetries; + i["RejoinChannels"] = info.rejoinChannels; + out << i; + return out; +} + +QDataStream &operator>>(QDataStream &in, NetworkInfo &info) { + QVariantMap i; + in >> i; + info.networkId = i["NetworkId"].value(); + info.networkName = i["NetworkName"].toString(); + info.identity = i["Identity"].value(); + info.codecForServer = i["CodecForServer"].toByteArray(); + info.codecForEncoding = i["CodecForEncoding"].toByteArray(); + info.codecForDecoding = i["CodecForDecoding"].toByteArray(); + info.serverList = i["ServerList"].toList(); + info.useRandomServer = i["UseRandomServer"].toBool(); + info.perform = i["Perform"].toStringList(); + info.useAutoIdentify = i["UseAutoIdentify"].toBool(); + info.autoIdentifyService = i["AutoIdentifyService"].toString(); + info.autoIdentifyPassword = i["AutoIdentifyPassword"].toString(); + info.useAutoReconnect = i["UseAutoReconnect"].toBool(); + info.autoReconnectInterval = i["AutoReconnectInterval"].toUInt(); + info.autoReconnectRetries = i["AutoReconnectRetries"].toInt(); + info.unlimitedReconnectRetries = i["UnlimitedReconnectRetries"].toBool(); + info.rejoinChannels = i["RejoinChannels"].toBool(); + return in; +} + +QDebug operator<<(QDebug dbg, const NetworkInfo &i) { + dbg.nospace() << "(id = " << i.networkId << " name = " << i.networkName << " identity = " << i.identity + << " codecForServer = " << i.codecForServer << " codecForEncoding = " << i.codecForEncoding << " codecForDecoding = " << i.codecForDecoding + << " serverList = " << i.serverList << " useRandomServer = " << i.useRandomServer << " perform = " << i.perform + << " useAutoIdentify = " << i.useAutoIdentify << " autoIdentifyService = " << i.autoIdentifyService << " autoIdentifyPassword = " << i.autoIdentifyPassword + << " useAutoReconnect = " << i.useAutoReconnect << " autoReconnectInterval = " << i.autoReconnectInterval + << " autoReconnectRetries = " << i.autoReconnectRetries << " unlimitedReconnectRetries = " << i.unlimitedReconnectRetries + << " rejoinChannels = " << i.rejoinChannels << ")"; + return dbg.space(); +}