X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fclient%2Fbuffer.cpp;h=241e2e687ae8eeff26f7be1b0386b8aef1a79fae;hb=f8557ba65eb38ac4988bfbbb2c4ef579d4534cf0;hp=f5328d45c4c0b4779fed700ec3946ddcb823ea36;hpb=fd7c2c4a41b5bb9cffcfe7a8f86a28ab7f38ac27;p=quassel.git diff --git a/src/client/buffer.cpp b/src/client/buffer.cpp index f5328d45..241e2e68 100644 --- a/src/client/buffer.cpp +++ b/src/client/buffer.cpp @@ -21,184 +21,109 @@ #include "buffer.h" +#include "buffersyncer.h" #include "client.h" -#include "ircchannel.h" -#include "nickmodel.h" +#include "networkmodel.h" +#include "quasselui.h" #include "util.h" Buffer::Buffer(BufferInfo bufferid, QObject *parent) : QObject(parent), _bufferInfo(bufferid), - _active(false), - _ircChannel(0), _nickModel(0) + _isVisible(false), + _activityLevel(NoActivity) { - if(bufferid.buffer().isEmpty()) - _type = StatusType; - else if(isChannelName(bufferid.buffer())) - _type = ChannelType; - else - _type = QueryType; - - _nickModel = new NickModel(0, this); -/* - 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; -} - -Buffer::Type Buffer::bufferType() const { - return _type; -} -bool Buffer::isActive() const { - // FIXME determine status by checking for a network objekt - return true; } BufferInfo Buffer::bufferInfo() const { - return _bufferInfo; -} - -void Buffer::updateBufferInfo(BufferInfo bufferid) { - _bufferInfo = bufferid; -} - -uint Buffer::uid() const { - return bufferInfo().uid(); + // still needed by the gui *sigh* to request the backlogs *sigh* + return _bufferInfo; } -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 Buffer::contents() const { +const QList &Buffer::contents() const { return layoutedMsgs; } -QVariantMap Buffer::nickList() const { - // FIXME should return a Map or List of IrcUsers in the future - return QVariantMap(); -} - -QString Buffer::topic() const { - if(ircChannel()) return ircChannel()->topic(); - return QString(); -} - -QString Buffer::ownNick() const { - // FIXME if(ircChannel()) return ircChannel()->ownNick(); - return QString(); -} - -bool Buffer::isStatusBuffer() const { - return bufferType() == StatusType; -} - -void Buffer::setActive(bool a) { -// if(a != active) { -// active = a; -// emit bufferUpdated(this); -// } -} - 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) { + // check for duplicate first + if(!layoutedMsgs.isEmpty() && msg.msgId() >= layoutedMsgs.first()->msgId()) { + return; + } + updateActivityLevel(msg); layoutQueue.append(msg); } bool Buffer::layoutMsg() { - if(layoutQueue.count()) { - AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst()); - layoutedMsgs.prepend(m); - emit msgPrepended(m); + if(layoutQueue.isEmpty()) + return false; + + AbstractUiMsg *m = Client::layoutMsg(layoutQueue.takeFirst()); + layoutedMsgs.prepend(m); + emit msgPrepended(m); + + return !layoutQueue.isEmpty(); +} + +void Buffer::setVisible(bool visible) { + _isVisible = visible; + setActivityLevel(NoActivity); + //if(layoutedMsgs.isEmpty()) + // return; + //setLastSeenMsg(layoutedMsgs.last()->msgId()); + if(_lastRcvdMsg.msgId() > 0) setLastSeenMsg(_lastRcvdMsg.msgId()); + //qDebug() << "setting last seen" << _lastRcvdMsg.msgId(); +} + +void Buffer::setLastSeenMsg(const MsgId &msgId) { + // qDebug() << "want to set lastSeen:" << bufferInfo() << seen << lastSeen(); + const MsgId oldLastSeen = lastSeenMsg(); + if(!oldLastSeen.isValid() || (msgId.isValid() && msgId > oldLastSeen)) { + //qDebug() << "setting:" << bufferInfo().bufferName() << seen; + _lastSeenMsg = msgId; + Client::setBufferLastSeenMsg(bufferInfo().bufferId(), msgId); + //qDebug() << "setting lastSeen:" << bufferInfo() << lastSeen(); + setActivityLevel(NoActivity); } - 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(_bufferInfo, msg); +void Buffer::setActivityLevel(ActivityLevel level) { + _activityLevel = level; + if(bufferInfo().bufferId() > 0) { + Client::networkModel()->setBufferActivity(bufferInfo(), level); + //qDebug() << "setting level:" << bufferInfo() << lastSeen() << level; + } } -NickModel *Buffer::nickModel() const { - return _nickModel; -} +void Buffer::updateActivityLevel(const Message &msg) { + // FIXME dirty hack to allow the lastSeen stuff to continue to work + // will be made much nicer once Buffer dies, I hope... + if(msg.msgId() > _lastRcvdMsg.msgId()) _lastRcvdMsg = msg; -IrcChannel *Buffer::ircChannel() const { - return _ircChannel; -} + if(isVisible()) + return; -void Buffer::setIrcChannel(IrcChannel *ircchan) { - if(_ircChannel) { - disconnect(_ircChannel, 0, this, 0); - } - _ircChannel = ircchan; - if(_ircChannel) { - emit topicSet(_ircChannel->topic()); - connect(_ircChannel, SIGNAL(topicSet(QString)), this, SIGNAL(topicSet(QString))); - connect(_ircChannel, SIGNAL(destroyed()), this, SLOT(setIrcChannel())); - } - _nickModel->setIrcChannel(ircChannel()); -} + if(msg.flags() & Message::Self) // don't update activity for our own messages + return; -// no longer needed -// back reference: - -// 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); -// } + if(lastSeenMsg().isValid() && lastSeenMsg() >= msg.msgId()) + return; + + ActivityLevel level = activityLevel() | OtherActivity; + if(msg.type() & (Message::Plain | Message::Notice | Message::Action)) + level |= NewMessage; + + if(msg.flags() & Message::Highlight) + level |= Highlight; + + if(level != activityLevel()) + setActivityLevel(level); +}