+#include "network.h"
+#include "signalproxy.h"
+#include "ircchannel.h"
+
+#include <QTextCodec>
+#include <QDebug>
+
+INIT_SYNCABLE_OBJECT(IrcUser)
+IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(network),
+ _initialized(false),
+ _nick(nickFromMask(hostmask)),
+ _user(userFromMask(hostmask)),
+ _host(hostFromMask(hostmask)),
+ _realName(),
+ _awayMessage(),
+ _away(false),
+ _server(),
+ // _idleTime(QDateTime::currentDateTime()),
+ _ircOperator(),
+ _lastAwayMessage(0),
+ _whoisServiceReply(),
+ _encrypted(false),
+ _network(network),
+ _codecForEncoding(0),
+ _codecForDecoding(0)
+{
+ updateObjectName();
+}
+
+
+IrcUser::~IrcUser()
+{
+}
+
+
+// ====================
+// PUBLIC:
+// ====================
+
+QString IrcUser::hostmask() const
+{
+ return QString("%1!%2@%3").arg(nick()).arg(user()).arg(host());
+}
+
+
+QDateTime IrcUser::idleTime()
+{
+ if (QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200)
+ _idleTime = QDateTime();
+ return _idleTime;
+}
+
+
+QStringList IrcUser::channels() const
+{
+ QStringList chanList;
+ IrcChannel *channel;
+ foreach(channel, _channels) {
+ chanList << channel->name();
+ }
+ return chanList;
+}
+
+
+void IrcUser::setCodecForEncoding(const QString &name)
+{
+ setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
+}
+
+
+void IrcUser::setCodecForEncoding(QTextCodec *codec)
+{
+ _codecForEncoding = codec;
+}
+
+
+void IrcUser::setCodecForDecoding(const QString &name)
+{
+ setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
+}
+
+
+void IrcUser::setCodecForDecoding(QTextCodec *codec)
+{
+ _codecForDecoding = codec;
+}
+
+
+QString IrcUser::decodeString(const QByteArray &text) const
+{
+ if (!codecForDecoding()) return network()->decodeString(text);
+ return ::decodeString(text, codecForDecoding());
+}
+
+
+QByteArray IrcUser::encodeString(const QString &string) const
+{
+ if (codecForEncoding()) {
+ return codecForEncoding()->fromUnicode(string);
+ }
+ return network()->encodeString(string);
+}
+
+
+// ====================
+// PUBLIC SLOTS:
+// ====================
+void IrcUser::setUser(const QString &user)
+{
+ if (!user.isEmpty() && _user != user) {
+ _user = user;
+ SYNC(ARG(user));
+ }
+}
+
+
+void IrcUser::setRealName(const QString &realName)
+{
+ if (!realName.isEmpty() && _realName != realName) {
+ _realName = realName;
+ SYNC(ARG(realName))
+ }
+}
+
+
+void IrcUser::setAway(const bool &away)
+{
+ if (away != _away) {
+ _away = away;
+ SYNC(ARG(away))
+ emit awaySet(away);
+ }