X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fircuser.cpp;h=efa7541557dc327024e8653e9be1c02a68c9631c;hp=a313fc685ab110b49282c9903b15e854106b96f8;hb=1ed8c48b0e7d309e1a92c905a19fcb7128b73d3d;hpb=b797e5f581b10a517c30f78cb53f813af741e261 diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index a313fc68..efa75415 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -21,20 +21,26 @@ #include "ircuser.h" #include "util.h" -#include "networkinfo.h" +#include "network.h" #include "signalproxy.h" #include "ircchannel.h" #include #include -IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo) - : SyncableObject(networkinfo), +IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network), _initialized(false), _nick(nickFromMask(hostmask)), _user(userFromMask(hostmask)), _host(hostFromMask(hostmask)), - networkInfo(networkinfo), + _realName(), + _awayMessage(), + _away(false), + _server(), + _idleTime(QDateTime::currentDateTime()), + _ircOperator(), + _lastAwayMessage(0), + _network(network), _codecForEncoding(0), _codecForDecoding(0) { @@ -42,15 +48,11 @@ IrcUser::IrcUser(const QString &hostmask, NetworkInfo *networkinfo) } IrcUser::~IrcUser() { - //qDebug() << nick() << "destroyed."; } // ==================== // PUBLIC: // ==================== -bool IrcUser::initialized() const { - return _initialized; -} QString IrcUser::user() const { return _user; @@ -64,10 +66,38 @@ QString IrcUser::nick() const { return _nick; } +QString IrcUser::realName() const { + return _realName; +} + QString IrcUser::hostmask() const { return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host()); } +bool IrcUser::isAway() const { + return _away; +} + +QString IrcUser::awayMessage() const { + return _awayMessage; +} + +QString IrcUser::server() const { + return _server; +} + +QDateTime IrcUser::idleTime() const { + return _idleTime; +} + +QString IrcUser::ircOperator() const { + return _ircOperator; +} + +int IrcUser::lastAwayMessage() const { + return _lastAwayMessage; +} + QString IrcUser::userModes() const { return _userModes; } @@ -81,6 +111,10 @@ QStringList IrcUser::channels() const { return chanList; } +Network* IrcUser::network() const { + return _network; +} + QTextCodec *IrcUser::codecForEncoding() const { return _codecForEncoding; } @@ -106,15 +140,15 @@ void IrcUser::setCodecForDecoding(QTextCodec *codec) { } QString IrcUser::decodeString(const QByteArray &text) const { - if(!codecForDecoding()) return networkInfo->decodeString(text); + if(!codecForDecoding()) return network()->decodeString(text); return ::decodeString(text, codecForDecoding()); } -QByteArray IrcUser::encodeString(const QString string) const { +QByteArray IrcUser::encodeString(const QString &string) const { if(codecForEncoding()) { return codecForEncoding()->fromUnicode(string); } - return networkInfo->encodeString(string); + return network()->encodeString(string); } // ==================== @@ -127,6 +161,55 @@ void IrcUser::setUser(const QString &user) { } } +void IrcUser::setRealName(const QString &realName) { + if (!realName.isEmpty() && _realName != realName) { + _realName = realName; + emit realNameSet(realName); + } +} + +void IrcUser::setAway(const bool &away) { + if(away != _away) { + _away = away; + emit awaySet(away); + } +} + +void IrcUser::setAwayMessage(const QString &awayMessage) { + if(!awayMessage.isEmpty() && _awayMessage != awayMessage) { + _awayMessage = awayMessage; + emit awayMessageSet(awayMessage); + } +} + +void IrcUser::setIdleTime(const QDateTime &idleTime) { + if(idleTime.isValid() && _idleTime != idleTime) { + _idleTime = idleTime; + emit idleTimeSet(idleTime); + } +} + +void IrcUser::setServer(const QString &server) { + if(!server.isEmpty() && _server != server) { + _server = server; + emit serverSet(server); + } +} + +void IrcUser::setIrcOperator(const QString &ircOperator) { + if(!ircOperator.isEmpty() && _ircOperator != ircOperator) { + _ircOperator = ircOperator; + emit ircOperatorSet(ircOperator); + } +} + +void IrcUser::setLastAwayMessage(const int &lastAwayMessage) { + if(lastAwayMessage > _lastAwayMessage) { + _lastAwayMessage = lastAwayMessage; + emit lastAwayMessageSet(lastAwayMessage); + } +} + void IrcUser::setHost(const QString &host) { if(!host.isEmpty() && _host != host) { _host = host; @@ -143,12 +226,7 @@ void IrcUser::setNick(const QString &nick) { } void IrcUser::updateObjectName() { - QString newName = QString::number(networkInfo->networkId()) + "/" + _nick; - QString oldName = objectName(); - if(oldName != newName) { - setObjectName(newName); - emit renameObject(oldName, newName); - } + renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick); } void IrcUser::updateHostmask(const QString &mask) { @@ -172,7 +250,7 @@ void IrcUser::joinChannel(IrcChannel *channel) { } void IrcUser::joinChannel(const QString &channelname) { - joinChannel(networkInfo->newIrcChannel(channelname)); + joinChannel(network()->newIrcChannel(channelname)); } void IrcUser::partChannel(IrcChannel *channel) { @@ -181,11 +259,13 @@ void IrcUser::partChannel(IrcChannel *channel) { disconnect(channel, 0, this, 0); channel->part(this); emit channelParted(channel->name()); + if(_channels.isEmpty()) + deleteLater(); } } void IrcUser::partChannel(const QString &channelname) { - IrcChannel *channel = networkInfo->ircChannel(channelname); + IrcChannel *channel = network()->ircChannel(channelname); if(channel == 0) { qWarning() << "IrcUser::partChannel(): received part for unknown Channel" << channelname; } else { @@ -196,10 +276,8 @@ void IrcUser::partChannel(const QString &channelname) { void IrcUser::channelDestroyed() { // private slot! IrcChannel *channel = static_cast(sender()); - Q_ASSERT(channel); if(_channels.contains(channel)) { _channels.remove(channel); - disconnect(channel, 0, this, 0); } } @@ -228,8 +306,3 @@ void IrcUser::initSetChannels(const QStringList channels) { } } -void IrcUser::setInitialized() { - _initialized = true; - emit initDone(); -} -