Fixed annoying bug where the nicklist wouldn't be shown sometimes because of an incon...
[quassel.git] / src / client / buffer.cpp
index 7f4d885..023263b 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+#include <QDebug>
+
 #include "buffer.h"
 
 #include "client.h"
+#include "ircchannel.h"
+#include "nickmodel.h"
 #include "util.h"
 
 
-Buffer::Buffer(BufferId bufid) {
-  id = bufid;
-  _networkName = bufid.network();
-  _bufferName = bufid.buffer();
-
-  if(_bufferName.isEmpty()) type = ServerBuffer;
-  else if(isChannelName(_bufferName)) type = ChannelBuffer;
-  else type = QueryBuffer;
+Buffer::Buffer(BufferInfo bufferid, QObject *parent)
+  : QObject(parent),
+    _bufferInfo(bufferid),
+    _active(false),
+    _ircChannel(0), _nickModel(0)
+{
+  if(bufferid.buffer().isEmpty())
+    _type = StatusType;
+  else if(isChannelName(bufferid.buffer()))
+    _type = ChannelType;
+  else
+    _type = QueryType;
 
-  active = false;
+  _nickModel = new NickModel(0, this);
 /*
   QSettings s;
   s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname));
@@ -51,61 +59,72 @@ Buffer::~Buffer() {
   s.endGroup();
 */
   //delete state;
-  emit bufferDestroyed(this);
 }
 
 Buffer::Type Buffer::bufferType() const {
-   return type;
+  return _type;
 }
 
 bool Buffer::isActive() const {
-   return active;
+  // FIXME determine status by checking for a networkInfo objekt
+  return true;
 }
 
-QString Buffer::networkName() const {
-   return _networkName;
+BufferInfo Buffer::bufferInfo() const {
+   return _bufferInfo;
 }
 
-QString Buffer::bufferName() const {
-   return _bufferName;
+void Buffer::updateBufferInfo(BufferInfo bufferid) {
+  _bufferInfo = bufferid;
 }
 
-QString Buffer::displayName() const {
-  if(bufferType() == ServerBuffer)
-    return tr("Status Buffer");
-  else
-    return bufferName();
+uint Buffer::uid() const {
+  return bufferInfo().uid();
 }
 
-BufferId Buffer::bufferId() const {
-   return id;
+uint Buffer::networkId() const {
+  return bufferInfo().networkId();
+}
+
+QString Buffer::networkName() const {
+  return bufferInfo().network();
+}
+
+QString Buffer::name() const {
+  if(bufferType() == StatusType)
+    return tr("Status Buffer");
+  else
+    return bufferInfo().buffer();
 }
 
 QList<AbstractUiMsg *> Buffer::contents() const {
-   return layoutedMsgs;
+  return layoutedMsgs;
 }
 
-VarMap Buffer::nickList() const {
-   return nicks;
+QVariantMap Buffer::nickList() const {
+  // FIXME should return a Map or List of IrcUsers in the future
+  return QVariantMap();
 }
 
 QString Buffer::topic() const {
-   return _topic;
+  // FIXME check if we got a networkInfo() object
+  return QString();
 }
 
 QString Buffer::ownNick() const {
-   return _ownNick;
+  // FIXME check if we got a networkInfo() object
+  return QString();
 }
 
 bool Buffer::isStatusBuffer() const {
-   return bufferType() == ServerBuffer;
+   return bufferType() == StatusType;
 }
 
 void Buffer::setActive(bool a) {
-  if(a != active) {
-    active = a;
-    emit bufferUpdated(this);
-  }
+//   if(a != active) {
+//     active = a;
+//     emit bufferUpdated(this);
+//  }
 }
 
 void Buffer::appendMsg(const Message &msg) {
@@ -129,39 +148,60 @@ bool Buffer::layoutMsg() {
 
 void Buffer::processUserInput(QString msg) {
   // TODO User Input processing (plugins) -> well, this goes through MainWin into Core for processing... so...
-  emit userInput(id, msg);
-}
-
-void Buffer::setTopic(QString t) {
-  _topic = t;
-  emit topicSet(t);
-  emit bufferUpdated(this);
-}
-
-void Buffer::addNick(QString nick, VarMap props) {
-  if(nick == ownNick()) setActive(true);
-  nicks[nick] = props;
-  emit nickListChanged(nicks);
-}
-
-void Buffer::updateNick(QString nick, VarMap props) {
-  nicks[nick] = props;
-  emit nickListChanged(nicks);
+  emit userInput(_bufferInfo, msg);
 }
 
-void Buffer::renameNick(QString oldnick, QString newnick) {
-  QVariant v = nicks.take(oldnick);
-  nicks[newnick] = v;
-  emit nickListChanged(nicks);
+NickModel *Buffer::nickModel() const {
+  return _nickModel;
 }
 
-void Buffer::removeNick(QString nick) {
-  if(nick == ownNick()) setActive(false);
-  nicks.remove(nick);
-  emit nickListChanged(nicks);
+IrcChannel *Buffer::ircChannel() const {
+  return _ircChannel;
 }
 
-void Buffer::setOwnNick(QString nick) {
-  _ownNick = nick;
-  emit ownNickSet(nick);
-}
+void Buffer::setIrcChannel(IrcChannel *ircchan) {
+  if(_ircChannel) {
+    disconnect(_ircChannel, 0, this, 0);
+  }
+  _ircChannel = ircchan;
+  if(_ircChannel) {
+    connect(_ircChannel, SIGNAL(destroyed()), this, SLOT(setIrcChannel()));
+  }
+  _nickModel->setIrcChannel(ircChannel());
+}
+
+// no longer needed
+// back reference:
+// void Buffer::setTopic(QString t) {
+//   _topic = t;
+//   emit topicSet(t);
+//   emit bufferUpdated(this);
+// }
+
+// void Buffer::addNick(QString nick, QVariantMap props) {
+//   if(nick == ownNick()) setActive(true);
+//   nicks[nick] = props;
+//   emit nickListChanged(nicks);
+// }
+
+// void Buffer::updateNick(QString nick, QVariantMap props) {
+//   nicks[nick] = props;
+//   emit nickListChanged(nicks);
+// }
+
+// void Buffer::renameNick(QString oldnick, QString newnick) {
+//   QVariant v = nicks.take(oldnick);
+//   nicks[newnick] = v;
+//   emit nickListChanged(nicks);
+// }
+
+// void Buffer::removeNick(QString nick) {
+//   if(nick == ownNick()) setActive(false);
+//   nicks.remove(nick);
+//   emit nickListChanged(nicks);
+// }
+
+// void Buffer::setOwnNick(QString nick) {
+//   _ownNick = nick;
+//   emit ownNickSet(nick);
+// }