(Hoperfully) fixing activity syncing. We really shouldn't refuse to update
[quassel.git] / src / client / buffer.cpp
index c8f375d..e94cf55 100644 (file)
@@ -1,11 +1,11 @@
 /***************************************************************************
- *   Copyright (C) 2005-07 by The Quassel Team                             *
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
+ *   (at your option) version 3.                                           *
  *                                                                         *
  *   This program is distributed in the hope that it will be useful,       *
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+#include <QDebug>
 
-#include "client.h"
 #include "buffer.h"
-#include "util.h"
-
-/*
-Buffer::Buffer(QString netname, QString bufname) {
-  Buffer(BufferId(0, netname, bufname));
-
-
-}
-*/
-
-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;
-
-  active = false;
-/*
-  QSettings s;
-  s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(netname).arg(bufname));
-  state->splitterState = s.value("Splitter").toByteArray();
-  s.endGroup();
-  */
-  emit bufferUpdated(this);
-}
 
-Buffer::~Buffer() {
-  //delete widget;
-  /*
-  QSettings s;
-  s.beginGroup(QString("GUI/BufferStates/%1/%2").arg(networkName).arg(bufferName));
-  s.setValue("Splitter", state->splitterState);
-  s.endGroup();
-*/
-  //delete state;
-  emit bufferDestroyed(this);
-}
-
-Buffer::Type Buffer::bufferType() const {
-   return type;
-}
+#include "buffersyncer.h"
+#include "client.h"
+#include "networkmodel.h"
+#include "quasselui.h"
+#include "util.h"
 
-bool Buffer::isActive() const {
-   return active;
-}
 
-QString Buffer::networkName() const {
-   return _networkName;
-}
+Buffer::Buffer(BufferInfo bufferid, QObject *parent)
+  : QObject(parent),
+    _bufferInfo(bufferid),
+    _isVisible(false),
+    _activityLevel(NoActivity)
+{
 
-QString Buffer::bufferName() const {
-   return _bufferName;
 }
 
-QString Buffer::displayName() const {
-  if(bufferType() == ServerBuffer)
-    return tr("Status Buffer");
-  else
-    return bufferName();
-}
-
-BufferId Buffer::bufferId() const {
-   return id;
+BufferInfo Buffer::bufferInfo() const {
+  // still needed by the gui *sigh* to request the backlogs *sigh*
+  return _bufferInfo;
 }
 
 QList<AbstractUiMsg *> Buffer::contents() const {
-   return layoutedMsgs;
-}
-
-VarMap Buffer::nickList() const {
-   return nicks;
-}
-
-QString Buffer::topic() const {
-   return _topic;
-}
-
-QString Buffer::ownNick() const {
-   return _ownNick;
-}
-
-bool Buffer::isStatusBuffer() const {
-   return bufferType() == ServerBuffer;
-}
-
-void Buffer::setActive(bool a) {
-  if(a != active) {
-    active = a;
-    emit bufferUpdated(this);
-  }
+  return layoutedMsgs;
 }
 
 void Buffer::appendMsg(const Message &msg) {
+  updateActivityLevel(msg);
   AbstractUiMsg *m = Client::layoutMsg(msg);
   layoutedMsgs.append(m);
   emit msgAppended(m);
 }
 
 void Buffer::prependMsg(const Message &msg) {
+  updateActivityLevel(msg);
   layoutQueue.append(msg);
 }
 
@@ -134,47 +67,38 @@ bool Buffer::layoutMsg() {
   return layoutQueue.count();
 }
 
-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::setVisible(bool visible) {
+  _isVisible = visible;
+  setActivityLevel(NoActivity);
+  if(!layoutedMsgs.count()) return;
+  setLastSeen(layoutedMsgs.last()->timestamp());
 }
 
-void Buffer::addNick(QString nick, VarMap props) {
-  if(nick == ownNick()) setActive(true);
-  nicks[nick] = props;
-  emit nickListChanged(nicks);
+void Buffer::setLastSeen(const QDateTime &seen) {
+  if(!lastSeen().isValid() || seen.isValid() && seen > lastSeen()) { //qDebug() << "setting:" << bufferInfo().bufferName() << seen;
+    _lastSeen = seen;
+    Client::bufferSyncer()->requestSetLastSeen(bufferInfo().bufferId(), seen);
+    //qDebug() << "setting lastSeen:" << bufferInfo() << lastSeen();
+    setActivityLevel(NoActivity);
+  }
 }
 
-void Buffer::updateNick(QString nick, VarMap props) {
-  nicks[nick] = props;
-  emit nickListChanged(nicks);
+void Buffer::setActivityLevel(ActivityLevel level) {
+  _activityLevel = level;
+  if(bufferInfo().bufferId() > 0) {
+    Client::networkModel()->setBufferActivity(bufferInfo(), level);
+    //qDebug() << "setting level:" << bufferInfo() << lastSeen() << level;
+  }
 }
 
-void Buffer::renameNick(QString oldnick, QString newnick) {
-  QVariant v = nicks.take(oldnick);
-  nicks[newnick] = v;
-  emit nickListChanged(nicks);
-}
+void Buffer::updateActivityLevel(const Message &msg) {
+  if(isVisible()) return;
+  if(lastSeen().isValid() && lastSeen() >= msg.timestamp()) return;
+  //qDebug() << "recv msg" << bufferInfo() << msg.timestamp();
 
-void Buffer::removeNick(QString nick) {
-  if(nick == ownNick()) setActive(false);
-  nicks.remove(nick);
-  emit nickListChanged(nicks);
-}
+  ActivityLevel level = activityLevel() | OtherActivity;
+  if(msg.type() == Message::Plain || msg.type() == Message::Notice) level |= NewMessage;
+  if(msg.flags() & Message::Highlight) level |= Highlight;
 
-void Buffer::setOwnNick(QString nick) {
-  _ownNick = nick;
-  emit ownNickSet(nick);
+  if(level != activityLevel()) setActivityLevel(level);
 }
-
-/****************************************************************************************/
-
-
-/****************************************************************************************/
-