#include "client.h"
#include "bufferinfo.h"
+#include "buffermodel.h"
+#include "buffersettings.h"
#include "buffersyncer.h"
+#include "bufferviewmanager.h"
+#include "clientbacklogmanager.h"
+#include "clientirclisthelper.h"
#include "global.h"
#include "identity.h"
#include "ircchannel.h"
#include "ircuser.h"
#include "message.h"
+#ifdef SPUTDEV
+# include "messagemodel.h"
+#endif
#include "network.h"
#include "networkmodel.h"
-#include "buffermodel.h"
#include "quasselui.h"
#include "signalproxy.h"
#include "util.h"
_networkModel(0),
_bufferModel(0),
_bufferSyncer(0),
+ _backlogManager(new ClientBacklogManager(this)),
+ _bufferViewManager(0),
+ _ircListHelper(new ClientIrcListHelper(this)),
+ _messageModel(0),
_connectedToCore(false),
_syncedToCore(false)
{
_monitorBuffer = new Buffer(BufferInfo(), this);
+ _signalProxy->synchronize(_ircListHelper);
+
+ connect(_backlogManager, SIGNAL(backlog(BufferId, const QVariantList &)),
+ this, SLOT(receiveBacklog(BufferId, const QVariantList &)));
}
Client::~Client() {
void Client::init() {
_currentCoreAccount = 0;
_networkModel = new NetworkModel(this);
+
connect(this, SIGNAL(bufferUpdated(BufferInfo)),
_networkModel, SLOT(bufferUpdated(BufferInfo)));
connect(this, SIGNAL(networkRemoved(NetworkId)),
_networkModel, SLOT(networkRemoved(NetworkId)));
_bufferModel = new BufferModel(_networkModel);
-
+#ifdef SPUTDEV
+ _messageModel = mainUi->createMessageModel(this);
+#endif
SignalProxy *p = signalProxy();
p->attachSlot(SIGNAL(displayMsg(const Message &)), this, SLOT(recvMessage(const Message &)));
p->attachSlot(SIGNAL(displayStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
- p->attachSlot(SIGNAL(backlogData(BufferInfo, const QVariantList &, bool)), this, SLOT(recvBacklogData(BufferInfo, const QVariantList &, bool)));
p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), this, SLOT(updateBufferInfo(BufferInfo)));
p->attachSignal(this, SIGNAL(sendInput(BufferInfo, QString)));
p->attachSignal(this, SIGNAL(requestNetworkStates()));
}
-// FIXME remove
+Buffer *Client::statusBuffer(const NetworkId &networkId) const {
+ if(_statusBuffers.contains(networkId))
+ return _statusBuffers[networkId];
+ else
+ return 0;
+}
+
Buffer *Client::buffer(BufferId bufferId) {
if(instance()->_buffers.contains(bufferId))
return instance()->_buffers[bufferId];
return 0;
}
-// FIXME remove
Buffer *Client::buffer(BufferInfo bufferInfo) {
Buffer *buff = buffer(bufferInfo.bufferId());
if(!buff) {
Client *client = Client::instance();
buff = new Buffer(bufferInfo, client);
- connect(buff, SIGNAL(destroyed()),
- client, SLOT(bufferDestroyed()));
+ connect(buff, SIGNAL(destroyed()), client, SLOT(bufferDestroyed()));
client->_buffers[bufferInfo.bufferId()] = buff;
+ if(bufferInfo.type() == BufferInfo::StatusBuffer)
+ client->_statusBuffers[bufferInfo.networkId()] = buff;
+
emit client->bufferUpdated(bufferInfo);
// I don't like this: but currently there isn't really a prettier way:
- QModelIndex bufferIdx = networkModel()->bufferIndex(bufferInfo.bufferId());
- bufferModel()->setCurrentIndex(bufferModel()->mapFromSource(bufferIdx));
+ if(isSynced()) { // this slows down syncing a lot, so disable it during sync
+ QModelIndex bufferIdx = networkModel()->bufferIndex(bufferInfo.bufferId());
+ bufferModel()->setCurrentIndex(bufferModel()->mapFromSource(bufferIdx));
+ }
}
Q_ASSERT(buff);
return buff;
}
void Client::coreNetworkRemoved(NetworkId id) {
- if(!_networks.contains(id)) return;
+ if(!_networks.contains(id))
+ return;
Network *net = _networks.take(id);
emit networkRemoved(net->networkId());
net->deleteLater();
// create buffersyncer
Q_ASSERT(!_bufferSyncer);
_bufferSyncer = new BufferSyncer(this);
- connect(bufferSyncer(), SIGNAL(lastSeenSet(BufferId, const QDateTime &)), this, SLOT(updateLastSeen(BufferId, const QDateTime &)));
+ connect(bufferSyncer(), SIGNAL(lastSeenMsgSet(BufferId, MsgId)), this, SLOT(updateLastSeenMsg(BufferId, MsgId)));
connect(bufferSyncer(), SIGNAL(bufferRemoved(BufferId)), this, SLOT(bufferRemoved(BufferId)));
connect(bufferSyncer(), SIGNAL(bufferRenamed(BufferId, QString)), this, SLOT(bufferRenamed(BufferId, QString)));
signalProxy()->synchronize(bufferSyncer());
+ // attach backlog manager
+ signalProxy()->synchronize(backlogManager());
+
+ // create a new BufferViewManager
+ _bufferViewManager = new BufferViewManager(signalProxy(), this);
+
_syncedToCore = true;
emit connected();
emit coreConnectionStateChanged(true);
}
+void Client::setSecuredConnection() {
+ emit securedConnection();
+}
+
void Client::disconnectFromCore() {
if(!isConnected())
return;
+ _connectedToCore = false;
if(socket) {
socket->close();
socket->deleteLater();
}
- _connectedToCore = false;
_syncedToCore = false;
- setCurrentCoreAccount(0);
emit disconnected();
emit coreConnectionStateChanged(false);
// Clear internal data. Hopefully nothing relies on it at this point.
+ setCurrentCoreAccount(0);
+
if(_bufferSyncer) {
_bufferSyncer->deleteLater();
_bufferSyncer = 0;
}
+
+ if(_bufferViewManager) {
+ _bufferViewManager->deleteLater();
+ _bufferViewManager = 0;
+ }
+
_networkModel->clear();
QHash<BufferId, Buffer *>::iterator bufferIter = _buffers.begin();
}
Q_ASSERT(_buffers.isEmpty());
+ _statusBuffers.clear();
+
QHash<NetworkId, Network*>::iterator netIter = _networks.begin();
while(netIter != _networks.end()) {
Network *net = netIter.value();
}
iter++;
}
+
+ QHash<NetworkId, Buffer *>::iterator statusIter = _statusBuffers.begin();
+ while(statusIter != _statusBuffers.end()) {
+ if(statusIter.value() == buffer) {
+ statusIter = _statusBuffers.erase(statusIter);
+ break;
+ }
+ statusIter++;
+ }
}
void Client::networkDestroyed() {
}
}
+#ifndef SPUTDEV
void Client::recvMessage(const Message &message) {
Message msg = message;
Buffer *b;
-
- if(msg.type() == Message::Error) {
- b = buffer(msg.bufferInfo().bufferId());
- if(!b) {
- // FIXME: if buffer doesn't exist, forward the message to the status or current buffer
- b = buffer(msg.bufferInfo());
+
+ checkForHighlight(msg);
+
+ // FIXME clean up code! (dup)
+
+ // TODO: make redirected messages show up in the correct buffer!
+
+ if(msg.flags() & Message::Redirected) {
+ BufferSettings bufferSettings;
+ bool inStatus = bufferSettings.value("UserMessagesInStatusBuffer", QVariant(true)).toBool();
+ bool inQuery = bufferSettings.value("UserMessagesInQueryBuffer", QVariant(false)).toBool();
+ bool inCurrent = bufferSettings.value("UserMessagesInCurrentBuffer", QVariant(false)).toBool();
+
+ if(inStatus) {
+ b = statusBuffer(msg.bufferInfo().networkId());
+ if(b) {
+ b->appendMsg(msg);
+ } else if(!inQuery && !inCurrent) { // make sure the message get's shown somewhere
+ b = buffer(msg.bufferInfo());
+ b->appendMsg(msg);
+ }
+ }
+
+ if(inQuery) {
+ b = buffer(msg.bufferInfo().bufferId());
+ if(b) {
+ b->appendMsg(msg);
+ } else if(!inStatus && !inCurrent) { // make sure the message get's shown somewhere
+ b = statusBuffer(msg.bufferInfo().networkId());
+ if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways...
+ b->appendMsg(msg);
+ }
+ }
+
+ if(inCurrent) {
+ BufferId currentId = bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>();
+ b = buffer(currentId);
+ if(b && currentId != msg.bufferInfo().bufferId() && !inQuery) {
+ b->appendMsg(msg);
+ } else if(!inStatus && !inQuery) { // make sure the message get's shown somewhere
+ b = statusBuffer(msg.bufferInfo().networkId());
+ if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways...
+ b->appendMsg(msg);
+ }
}
} else {
+ // the regular case: we can deliver where it was supposed to go
b = buffer(msg.bufferInfo());
+ b->appendMsg(msg);
}
-
- checkForHighlight(msg);
- b->appendMsg(msg);
//bufferModel()->updateBufferActivity(msg);
if(msg.type() == Message::Plain || msg.type() == Message::Notice || msg.type() == Message::Action) {
? net->networkName() + ":"
: QString();
QString sender = networkName + msg.bufferInfo().bufferName() + ":" + msg.sender();
- Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.text(), sender, msg.flags());
+ Message mmsg = Message(msg.timestamp(), msg.bufferInfo(), msg.type(), msg.contents(), sender, msg.flags());
monitorBuffer()->appendMsg(mmsg);
}
+ emit messageReceived(msg);
+}
+#else
+
+void Client::recvMessage(const Message &msg) {
+ //checkForHighlight(msg);
+ _messageModel->insertMessage(msg);
}
+#endif /* SPUTDEV */
+
void Client::recvStatusMsg(QString /*net*/, QString /*msg*/) {
//recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg)));
}
-void Client::recvBacklogData(BufferInfo id, QVariantList msgs, bool /*done*/) {
- Buffer *b = buffer(id);
+#ifdef SPUTDEV
+void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) {
+ //checkForHighlight(msg);
foreach(QVariant v, msgs) {
- Message msg = v.value<Message>();
+ _messageModel->insertMessage(v.value<Message>());
+ }
+}
+
+#else
+
+void Client::receiveBacklog(BufferId bufferId, const QVariantList &msgs) {
+ Buffer *buffer_ = buffer(bufferId);
+ if(!buffer_) {
+ qWarning() << "Client::receiveBacklog(): received Backlog for unknown Buffer:" << bufferId;
+ return;
+ }
+
+ if(msgs.isEmpty())
+ return; // no work to be done...
+
+ QVariantList::const_iterator msgIter = msgs.constBegin();
+ QVariantList::const_iterator msgIterEnd = msgs.constEnd();
+ Message msg;
+ while(msgIter != msgIterEnd) {
+ msg = (*msgIter).value<Message>();
checkForHighlight(msg);
- b->prependMsg(msg);
- //networkModel()->updateBufferActivity(msg);
- if(!layoutQueue.contains(b)) layoutQueue.append(b);
+ buffer_->prependMsg(msg);
+ msgIter++;
+ }
+
+ if(!layoutQueue.contains(buffer_))
+ layoutQueue.append(buffer_);
+
+ if(!layoutTimer->isActive()) {
+ layoutTimer->start();
}
- if(layoutQueue.count() && !layoutTimer->isActive()) layoutTimer->start();
}
+#endif /* SPUTDEV */
void Client::layoutMsg() {
- if(layoutQueue.count()) {
- Buffer *b = layoutQueue.takeFirst(); // TODO make this the current buffer
- if(b->layoutMsg())
- layoutQueue.append(b); // Buffer has more messages in its queue --> Round Robin
+ if(layoutQueue.isEmpty()) {
+ layoutTimer->stop();
+ return;
}
- if(!layoutQueue.count())
+ Buffer *buffer = layoutQueue.takeFirst();
+ if(buffer->layoutMsg()) {
+ layoutQueue.append(buffer); // Buffer has more messages in its queue --> Round Robin
+ return;
+ }
+
+ if(layoutQueue.isEmpty())
layoutTimer->stop();
}
}
void Client::checkForHighlight(Message &msg) {
+ NotificationSettings notificationSettings;
const Network *net = network(msg.bufferInfo().networkId());
if(net && !net->myNick().isEmpty()) {
- QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(net->myNick()) + "(\\W.*)?$");
- if((msg.type() & (Message::Plain | Message::Notice | Message::Action)) && nickRegExp.exactMatch(msg.text()))
- msg.setFlags(msg.flags() | Message::Highlight);
+ QStringList nickList;
+ if(notificationSettings.highlightNick() == NotificationSettings::CurrentNick) {
+ nickList << net->myNick();
+ } else if(notificationSettings.highlightNick() == NotificationSettings::AllNicks) {
+ const Identity *myIdentity = identity(net->identity());
+ if(myIdentity)
+ nickList = myIdentity->nicks();
+ }
+ foreach(QString nickname, nickList) {
+ QRegExp nickRegExp("^(.*\\W)?" + QRegExp::escape(nickname) + "(\\W.*)?$");
+ if((msg.type() & (Message::Plain | Message::Notice | Message::Action))
+ && !(msg.flags() & Message::Self)
+ && nickRegExp.exactMatch(msg.contents())) {
+ msg.setFlags(msg.flags() | Message::Highlight);
+ return;
+ }
+ }
+
+ foreach(QVariant highlight, notificationSettings.highlightList()) {
+ QVariantMap highlightRule = highlight.toMap();
+ if(!highlightRule["enable"].toBool())
+ continue;
+ Qt::CaseSensitivity caseSensitivity = highlightRule["cs"].toBool() ? Qt::CaseSensitive : Qt::CaseInsensitive;
+ QString name = highlightRule["name"].toString();
+ QRegExp userRegExp;
+ if(highlightRule["regex"].toBool()) {
+ userRegExp = QRegExp(name, caseSensitivity);
+ } else {
+ userRegExp = QRegExp("^(.*\\W)?" + QRegExp::escape(name) + "(\\W.*)?$", caseSensitivity);
+ }
+ if((msg.type() & (Message::Plain | Message::Notice | Message::Action))
+ && !(msg.flags() & Message::Self)
+ && userRegExp.exactMatch(msg.contents())) {
+ msg.setFlags(msg.flags() | Message::Highlight);
+ return;
+ }
+ }
}
}
-void Client::updateLastSeen(BufferId id, const QDateTime &lastSeen) {
+void Client::updateLastSeenMsg(BufferId id, const MsgId &msgId) {
Buffer *b = buffer(id);
if(!b) {
qWarning() << "Client::updateLastSeen(): Unknown buffer" << id;
return;
}
- b->setLastSeen(lastSeen);
+ b->setLastSeenMsg(msgId);
}
-void Client::setBufferLastSeen(BufferId id, const QDateTime &lastSeen) {
- if(!bufferSyncer()) return;
- bufferSyncer()->requestSetLastSeen(id, lastSeen);
+void Client::setBufferLastSeenMsg(BufferId id, const MsgId &msgId) {
+ if(!bufferSyncer())
+ return;
+ bufferSyncer()->requestSetLastSeenMsg(id, msgId);
}
void Client::removeBuffer(BufferId id) {
}
void Client::bufferRemoved(BufferId bufferId) {
+ // first remove the buffer from hash. this prohibits further lastSeenUpdates
+ Buffer *buff = 0;
+ if(_buffers.contains(bufferId)) {
+ buff = _buffers.take(bufferId);
+ layoutQueue.removeAll(buff);
+ disconnect(buff, 0, this, 0);
+ }
+
+ // then we select a sane buffer (status buffer)
+ /* we have to manually select a buffer because otherwise inconsitent changes
+ * to the model might occur:
+ * the result of a buffer removal triggers a change in the selection model.
+ * the newly selected buffer might be a channel that hasn't been selected yet
+ * and a new nickview would be created (which never heard of the "rowsAboutToBeRemoved").
+ * this new view (and/or) its sort filter will then only receive a "rowsRemoved" signal.
+ */
QModelIndex current = bufferModel()->currentIndex();
if(current.data(NetworkModel::BufferIdRole).value<BufferId>() == bufferId) {
- // select the status buffer if the currently displayed buffer is about to be removed
bufferModel()->setCurrentIndex(current.sibling(0,0));
}
-
+
+ // and remove it from the model
networkModel()->removeBuffer(bufferId);
- if(_buffers.contains(bufferId)) {
- Buffer *buff = _buffers.take(bufferId);
- disconnect(buff, 0, this, 0);
+
+ if(buff)
buff->deleteLater();
- }
}
void Client::bufferRenamed(BufferId bufferId, const QString &newName) {