Yearly copyright bump :)
[quassel.git] / src / common / ircuser.cpp
index ed875e0..8acb678 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-08 by the Quassel Project                          *
+ *   Copyright (C) 2005-09 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -37,9 +37,10 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net
     _awayMessage(),
     _away(false),
     _server(),
-    _idleTime(QDateTime::currentDateTime()),
+    // _idleTime(QDateTime::currentDateTime()),
     _ircOperator(),
     _lastAwayMessage(0),
+    _whoisServiceReply(),
     _network(network),
     _codecForEncoding(0),
     _codecForDecoding(0)
@@ -54,54 +55,16 @@ IrcUser::~IrcUser() {
 //  PUBLIC:
 // ====================
 
-QString IrcUser::user() const {
-  return _user;
-}
-
-QString IrcUser::host() const {
-  return _host;
-}
-
-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 {
+QDateTime IrcUser::idleTime() {
+  if(QDateTime::currentDateTime().toTime_t() - _idleTimeSet.toTime_t() > 1200)
+    _idleTime = QDateTime();
   return _idleTime;
 }
 
-QString IrcUser::ircOperator() const {
-  return _ircOperator;
-}
-
-int IrcUser::lastAwayMessage() const {
-  return _lastAwayMessage;
-}
-
-QString IrcUser::userModes() const {
-  return _userModes;
-}
-
 QStringList IrcUser::channels() const {
   QStringList chanList;
   IrcChannel *channel;
@@ -111,13 +74,6 @@ QStringList IrcUser::channels() const {
   return chanList;
 }
 
-Network* IrcUser::network() const {
-  return _network;
-}
-
-QTextCodec *IrcUser::codecForEncoding() const {
-  return _codecForEncoding;
-}
 
 void IrcUser::setCodecForEncoding(const QString &name) {
   setCodecForEncoding(QTextCodec::codecForName(name.toAscii()));
@@ -127,10 +83,6 @@ void IrcUser::setCodecForEncoding(QTextCodec *codec) {
   _codecForEncoding = codec;
 }
 
-QTextCodec *IrcUser::codecForDecoding() const {
-  return _codecForDecoding;
-}
-
 void IrcUser::setCodecForDecoding(const QString &name) {
   setCodecForDecoding(QTextCodec::codecForName(name.toAscii()));
 }
@@ -185,10 +137,18 @@ void IrcUser::setAwayMessage(const QString &awayMessage) {
 void IrcUser::setIdleTime(const QDateTime &idleTime) {
   if(idleTime.isValid() && _idleTime != idleTime) {
     _idleTime = idleTime;
+    _idleTimeSet = QDateTime::currentDateTime();
     emit idleTimeSet(idleTime);
   }
 }
 
+void IrcUser::setLoginTime(const QDateTime &loginTime) {
+  if(loginTime.isValid() && _loginTime != loginTime) {
+    _loginTime = loginTime;
+    emit loginTimeSet(loginTime);
+  }
+}
+
 void IrcUser::setServer(const QString &server) {
   if(!server.isEmpty() && _server != server) {
     _server = server;
@@ -225,6 +185,20 @@ void IrcUser::setNick(const QString &nick) {
   }
 }
 
+void IrcUser::setWhoisServiceReply(const QString &whoisServiceReply) {
+  if(!whoisServiceReply.isEmpty() && whoisServiceReply != _whoisServiceReply) {
+    _whoisServiceReply = whoisServiceReply;
+    emit whoisServiceReplySet(whoisServiceReply);
+  }
+}
+
+void IrcUser::setSuserHost(const QString &suserHost) {
+  if(!suserHost.isEmpty() && suserHost != _suserHost) {
+    _suserHost = suserHost;
+    emit suserHostSet(suserHost);
+  }
+}
+
 void IrcUser::updateObjectName() {
   renameObject(QString::number(network()->networkId().toInt()) + "/" + _nick);
 }
@@ -244,7 +218,6 @@ void IrcUser::joinChannel(IrcChannel *channel) {
   if(!_channels.contains(channel)) {
     _channels.insert(channel);
     channel->joinIrcUsers(this);
-    connect(channel, SIGNAL(destroyed()), this, SLOT(channelDestroyed()));
   }
 }
 
@@ -258,8 +231,8 @@ void IrcUser::partChannel(IrcChannel *channel) {
     disconnect(channel, 0, this, 0);
     channel->part(this);
     emit channelParted(channel->name());
-    if(_channels.isEmpty() && network()->isMe(this))
-      deleteLater();
+    if(_channels.isEmpty() && !network()->isMe(this))
+      quit();
   }
 }
 
@@ -272,13 +245,24 @@ void IrcUser::partChannel(const QString &channelname) {
   }
 }
 
+void IrcUser::quit() {
+  QList<IrcChannel *> channels = _channels.toList();
+  _channels.clear();
+  foreach(IrcChannel *channel, channels) {
+    disconnect(channel, 0, this, 0);
+    channel->part(this);
+  }
+  network()->removeIrcUser(this);
+  emit quited();
+}
+
 void IrcUser::channelDestroyed() {
   // private slot!
   IrcChannel *channel = static_cast<IrcChannel*>(sender());
   if(_channels.contains(channel)) {
     _channels.remove(channel);
-    if(_channels.isEmpty())
-      deleteLater();
+    if(_channels.isEmpty() && !network()->isMe(this))
+      quit();
   }
 }