From: Manuel Nickschas Date: Tue, 15 May 2007 15:24:40 +0000 (+0000) Subject: Fixed some bugs concerning BufferIds. X-Git-Tag: 0.1.0~240 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=36487046917c42304bdc066f9142c82683bfb084 Fixed some bugs concerning BufferIds. --- diff --git a/core/backlog.cpp b/core/backlog.cpp index 51e1d6b2..6a222afc 100644 --- a/core/backlog.cpp +++ b/core/backlog.cpp @@ -82,8 +82,8 @@ void Backlog::init(QString _user) { "Text BLOB" ")").arg(tname)); query.exec(QString("INSERT OR REPLACE INTO %1 (MsgId, SenderId, Text) VALUES (0, '$VERSION$', %2)").arg(tname).arg(DBVERSION)); - query.exec(QString("CREATE TABLE IF NOT EXISTS 'Senders$%1$' (SenderId INTEGER PRIMARY KEY AUTOINCREMENT, Sender BLOB)").arg(user)); - query.exec(QString("CREATE TABLE IF NOT EXISTS 'Buffers$%1$' (BufferId INTEGER PRIMARY KEY AUTOINCREMENT, GroupId INTEGER, Network BLOB, Buffer BLOB)").arg(user)); + query.exec(QString("CREATE TABLE IF NOT EXISTS 'Senders$%1$' (SenderId INTEGER PRIMARY KEY AUTOINCREMENT, Sender TEXT)").arg(user)); + query.exec(QString("CREATE TABLE IF NOT EXISTS 'Buffers$%1$' (BufferId INTEGER PRIMARY KEY AUTOINCREMENT, GroupId INTEGER, Network TEXT, Buffer TEXT)").arg(user)); if(query.lastError().isValid()) { qWarning(tr("Could not create backlog table: %1").arg(query.lastError().text()).toAscii()); qWarning(tr("Disabling logging...").toAscii()); @@ -123,13 +123,13 @@ uint Backlog::logMessage(Message msg) { bool ok; logDb.transaction(); QSqlQuery query(logDb); - QString s = msg.sender; s.replace('\'', "''"); QByteArray bs = s.toUtf8().toHex(); + QString s = msg.sender; s.replace('\'', "''"); QString t = msg.text; t.replace('\'', "''"); // Let's do some space-saving optimizations... - query.exec(QString("SELECT SenderId FROM 'Senders$%1$' WHERE Sender == X'%2'").arg(user).arg(bs.constData())); + query.exec(QString("SELECT SenderId FROM 'Senders$%1$' WHERE Sender == '%2'").arg(user).arg(s)); int suid; if(!query.first()) { - query.exec(QString("INSERT INTO 'Senders$%1$' (SenderId, Sender) VALUES (%2, X'%3')").arg(user).arg(nextSenderId).arg(bs.constData())); + query.exec(QString("INSERT INTO 'Senders$%1$' (SenderId, Sender) VALUES (%2, '%3')").arg(user).arg(nextSenderId).arg(s)); suid = nextSenderId; } else suid = query.value(0).toInt(); query.exec(QString("INSERT INTO 'Backlog$%1$' (MsgId, Time, BufferId, Type, Flags, SenderId, Text) VALUES (%2, %3, %4, %5, %6, %7, X'%8')").arg(user) @@ -152,19 +152,23 @@ BufferId Backlog::getBufferId(QString net, QString buf) { if(!backlogEnabled) { return BufferId(0, net, buf); } - QByteArray n = net.toUtf8().toHex(); - QByteArray b = buf.toUtf8().toHex(); + //QByteArray n = net.toUtf8().toHex(); + //QByteArray b = buf.toUtf8().toHex(); + bool flg = false; logDb.transaction(); QSqlQuery query(logDb); int uid = -1; - query.exec(QString("SELECT BufferId FROM 'Buffers$%1$' WHERE Network == X'%2' AND Buffer == X'%3'").arg(user).arg(n.constData()).arg(b.constData())); + query.exec(QString("SELECT BufferId FROM 'Buffers$%1$' WHERE Network == '%2' AND Buffer == '%3'").arg(user).arg(net).arg(buf)); if(!query.first()) { // TODO: joined buffers/queries - query.exec(QString("INSERT INTO 'Buffers$%1$' (BufferId, GroupId, Network, Buffer) VALUES (%2, %2, X'%3', X'%4')").arg(user).arg(nextBufferId).arg(n.constData()).arg(b.constData())); + query.exec(QString("INSERT INTO 'Buffers$%1$' (BufferId, GroupId, Network, Buffer) VALUES (%2, %2, '%3', '%4')").arg(user).arg(nextBufferId).arg(net).arg(buf)); uid = nextBufferId++; + flg = true; } else uid = query.value(0).toInt(); logDb.commit(); - return BufferId(uid, net, buf, uid); // FIXME (joined buffers) + BufferId id(uid, net, buf, uid); // FIXME (joined buffers) + if(flg) emit bufferIdUpdated(id); + return id; // FIXME (joined buffers) } QList Backlog::requestBuffers(QDateTime since) { @@ -177,7 +181,7 @@ QList Backlog::requestBuffers(QDateTime since) { "WHERE Time >= %2").arg(user).arg(since.toTime_t())); } while(query.next()) { - result.append(BufferId(query.value(0).toUInt(), QString::fromUtf8(query.value(2).toByteArray()), QString::fromUtf8(query.value(3).toByteArray()), query.value(1).toUInt())); + result.append(BufferId(query.value(0).toUInt(), query.value(2).toString(), query.value(3).toString(), query.value(1).toUInt())); } return result; } @@ -192,7 +196,7 @@ QList Backlog::requestMsgs(BufferId id, int lastlines, int offset) { while(query.next()) { if(offset >= 0 && query.value(0).toInt() >= offset) continue; Message msg(QDateTime::fromTime_t(query.value(1).toInt()), id, (Message::Type)query.value(2).toUInt(), QString::fromUtf8(query.value(5).toByteArray()), - QString::fromUtf8(query.value(4).toByteArray()), query.value(3).toUInt()); + query.value(4).toString(), query.value(3).toUInt()); msg.msgId = query.value(0).toUInt(); result.append(msg); } diff --git a/core/backlog.h b/core/backlog.h index 709125ad..9dc0dcf1 100644 --- a/core/backlog.h +++ b/core/backlog.h @@ -51,6 +51,9 @@ class Backlog : public QObject { public slots: void importOldBacklog(); + signals: + void bufferIdUpdated(BufferId); // sent also if a new bufferid is created + private: QString user; bool backlogEnabled; diff --git a/core/core.cpp b/core/core.cpp index 07e0c73e..f9de45ff 100644 --- a/core/core.cpp +++ b/core/core.cpp @@ -38,7 +38,8 @@ Core::Core() { connect(this, SIGNAL(displayMsg(Message)), coreProxy, SLOT(csDisplayMsg(Message))); connect(this, SIGNAL(displayStatusMsg(QString, QString)), coreProxy, SLOT(csDisplayStatusMsg(QString, QString))); connect(this, SIGNAL(backlogData(BufferId, QList, bool)), coreProxy, SLOT(csBacklogData(BufferId, QList, bool))); - + connect(&backlog, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); + connect(this, SIGNAL(bufferIdUpdated(BufferId)), coreProxy, SLOT(csUpdateBufferId(BufferId))); // Read global settings from config file QSettings s; s.beginGroup("Global"); diff --git a/core/core.h b/core/core.h index c5d266c6..459c6847 100644 --- a/core/core.h +++ b/core/core.h @@ -56,6 +56,8 @@ class Core : public QObject { void backlogData(BufferId, QList, bool done); + void bufferIdUpdated(BufferId); + private slots: //void serverStatesRequested(); void globalDataUpdated(QString); diff --git a/core/coreproxy.h b/core/coreproxy.h index 44ccdf99..6e724d59 100644 --- a/core/coreproxy.h +++ b/core/coreproxy.h @@ -55,6 +55,7 @@ class CoreProxy : public QObject { inline void csOwnNickSet(QString net, QString nick) { send(CS_OWN_NICK_SET, net, nick); } inline void csQueryRequested(QString net, QString nick) { send(CS_QUERY_REQUESTED, net, nick); } inline void csBacklogData(BufferId id, QList msg, bool done) { send(CS_BACKLOG_DATA, QVariant::fromValue(id), msg, done); } + inline void csUpdateBufferId(BufferId id) { send(CS_UPDATE_BUFFERID, QVariant::fromValue(id)); } signals: void gsPutGlobalData(QString, QVariant); diff --git a/core/server.cpp b/core/server.cpp index 45c9da1a..090431a6 100644 --- a/core/server.cpp +++ b/core/server.cpp @@ -420,6 +420,7 @@ void Server::handleUserVoice(QString bufname, QString msg) { void Server::handleServerJoin(QString prefix, QStringList params) { Q_ASSERT(params.count() == 1); QString nick = updateNickFromMask(prefix); + emit displayMsg(Message::Join, params[0], params[0], prefix); if(nick == ownNick) { // Q_ASSERT(!buffers.contains(params[0])); // cannot join a buffer twice! // Buffer *buf = new Buffer(params[0]); @@ -445,7 +446,7 @@ void Server::handleServerJoin(QString prefix, QStringList params) { nicks[nick] = n; emit nickAdded(network, nick, n); } - emit displayMsg(Message::Join, params[0], params[0], prefix); + //emit displayMsg(Message::Join, params[0], params[0], prefix); //} } diff --git a/gui/guiproxy.cpp b/gui/guiproxy.cpp index 717f1bc9..373bf69f 100644 --- a/gui/guiproxy.cpp +++ b/gui/guiproxy.cpp @@ -44,6 +44,7 @@ void GUIProxy::recv(CoreSignal sig, QVariant arg1, QVariant arg2, QVariant arg3) case CS_OWN_NICK_SET: emit csOwnNickSet(arg1.toString(), arg2.toString()); break; case CS_QUERY_REQUESTED: emit csQueryRequested(arg1.toString(), arg2.toString()); break; case CS_BACKLOG_DATA: emit csBacklogData(arg1.value(), arg2.toList(), arg3.toBool()); break; + case CS_UPDATE_BUFFERID: emit csUpdateBufferId(arg1.value()); break; default: qWarning() << "Unknown signal in GUIProxy::recv: " << sig; } diff --git a/gui/guiproxy.h b/gui/guiproxy.h index 7fe0c18d..b34bd33a 100644 --- a/gui/guiproxy.h +++ b/gui/guiproxy.h @@ -67,6 +67,7 @@ class GUIProxy : public QObject { void csOwnNickSet(QString, QString); void csQueryRequested(QString, QString); void csBacklogData(BufferId, QList, bool); + void csUpdateBufferId(BufferId); void csGeneric(int, QVariant, QVariant); diff --git a/gui/identities.cpp b/gui/identities.cpp index 9ef5a913..873039ff 100644 --- a/gui/identities.cpp +++ b/gui/identities.cpp @@ -44,7 +44,7 @@ IdentitiesDlg::IdentitiesDlg(QWidget *parent, QString selected) : QDialog(parent } updateWidgets(); lastIdentity = getCurIdentity(); - connect(ui.identityList, SIGNAL(triggered(QString)), this, SLOT(identityChanged(QString))); + connect(ui.identityList, SIGNAL(activated(QString)), this, SLOT(identityChanged(QString))); connect(ui.editIdentitiesButton, SIGNAL(clicked()), this, SLOT(editIdentities())); connect(ui.nickList, SIGNAL(itemSelectionChanged()), this, SLOT(nickSelectionChanged())); connect(ui.addNickButton, SIGNAL(clicked()), this, SLOT(addNick())); diff --git a/gui/mainwin.cpp b/gui/mainwin.cpp index 84835ad8..d90abf91 100644 --- a/gui/mainwin.cpp +++ b/gui/mainwin.cpp @@ -69,6 +69,7 @@ void MainWin::init() { connect(guiProxy, SIGNAL(csNickUpdated(QString, QString, VarMap)), this, SLOT(updateNick(QString, QString, VarMap))); connect(guiProxy, SIGNAL(csOwnNickSet(QString, QString)), this, SLOT(setOwnNick(QString, QString))); connect(guiProxy, SIGNAL(csBacklogData(BufferId, QList, bool)), this, SLOT(recvBacklogData(BufferId, QList, bool))); + connect(guiProxy, SIGNAL(csUpdateBufferId(BufferId)), this, SLOT(updateBufferId(BufferId))); connect(this, SIGNAL(sendInput(BufferId, QString)), guiProxy, SLOT(gsUserInput(BufferId, QString))); connect(this, SIGNAL(requestBacklog(BufferId, QVariant, QVariant)), guiProxy, SLOT(gsRequestBacklog(BufferId, QVariant, QVariant))); @@ -89,12 +90,9 @@ void MainWin::init() { setupSettingsDlg(); - //Buffer::init(); setupMenus(); setupViews(); - //bufferWidget = 0; - QSettings s; s.beginGroup("Geometry"); //resize(s.value("MainWinSize", QSize(500, 400)).toSize()); @@ -102,35 +100,6 @@ void MainWin::init() { if(s.contains("MainWinState")) restoreState(s.value("MainWinState").toByteArray()); s.endGroup(); - // replay backlog - // FIXME do this right - /* - QHash > hash; - Buffer *b; - - foreach(QString net, coreBackLog.keys()) { - //if(net != "MoepNet") continue; - while(coreBackLog[net].count()) { - //recvMessage(net, coreBackLog[net].takeFirst()); - Message msg = coreBackLog[net].takeLast(); - if(msg.flags & Message::PrivMsg) { - // query - if(msg.flags & Message::Self) b = getBuffer(net, msg.target); - else b = getBuffer(net, nickFromMask(msg.sender)); - } else { - b = getBuffer(net, msg.target); - } - hash[b].prepend(msg); - if(hash[b].count() >= 5) { - ui.bufferWidget->prependMessages(b, hash.take(b)); - } - } - } - foreach(Buffer *buf, hash.keys()) { - ui.bufferWidget->prependMessages(buf, hash.take(buf)); - } -*/ - /* make lookups by id faster */ foreach(BufferId id, coreBuffers) { bufferIds[id.uid()] = id; // make lookups by id faster @@ -205,12 +174,6 @@ void MainWin::registerNetView(NetworkView *view) { connect(this, SIGNAL(bufferUpdated(Buffer *)), view, SLOT(bufferUpdated(Buffer *))); connect(this, SIGNAL(bufferDestroyed(Buffer *)), view, SLOT(bufferDestroyed(Buffer *))); connect(view, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *))); - //QList bufs; - //typedef QHash bufhash; - //QList foo = buffers.values(); - //foreach(bufhash h, foo) { - // bufs += h.values(); - //} view->setBuffers(buffers.values()); view->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); netViews.append(view); @@ -255,7 +218,6 @@ void MainWin::showBuffer(BufferId id) { } void MainWin::showBuffer(Buffer *b) { - //currentBuffer = b->bufferName(); currentNetwork = b->networkName(); currentBuffer = b->bufferId().groupId(); //emit bufferSelected(b); //qApp->processEvents(); @@ -265,9 +227,9 @@ void MainWin::showBuffer(Buffer *b) { void MainWin::networkConnected(QString net) { connected[net] = true; - BufferId id = getStatusBufferId(net); - Buffer *b = getBuffer(id); - b->setActive(true); + //BufferId id = getStatusBufferId(net); + //Buffer *b = getBuffer(id); + //b->setActive(true); //b->displayMsg(Message(id, Message::Server, tr("Connected."))); FIXME // TODO buffersUpdated(); } @@ -283,6 +245,11 @@ void MainWin::networkDisconnected(QString net) { connected[net] = false; } +void MainWin::updateBufferId(BufferId id) { + bufferIds[id.uid()] = id; // make lookups by id faster + getBuffer(id); +} + BufferId MainWin::getBufferId(QString net, QString buf) { foreach(BufferId id, buffers.keys()) { if(id.network() == net && id.buffer() == buf) return id; diff --git a/gui/mainwin.h b/gui/mainwin.h index 0ce3c72b..06a12fee 100644 --- a/gui/mainwin.h +++ b/gui/mainwin.h @@ -79,6 +79,7 @@ class MainWin : public QMainWindow { void updateNick(QString net, QString nick, VarMap props); void setOwnNick(QString net, QString nick); void recvBacklogData(BufferId, QList, bool); + void updateBufferId(BufferId); void showServerList(); void showSettingsDlg(); diff --git a/main/proxy_common.h b/main/proxy_common.h index ab2b7d37..208bb88d 100644 --- a/main/proxy_common.h +++ b/main/proxy_common.h @@ -29,7 +29,7 @@ enum GUISignal { GS_CLIENT_INIT, GS_USER_INPUT, GS_REQUEST_CONNECT, GS_UPDATE_GL enum CoreSignal { CS_CORE_STATE, CS_SERVER_CONNECTED, CS_SERVER_DISCONNECTED, CS_SERVER_STATE, CS_DISPLAY_MSG, CS_DISPLAY_STATUS_MSG, CS_UPDATE_GLOBAL_DATA, CS_MODE_SET, CS_TOPIC_SET, CS_SET_NICKS, CS_NICK_ADDED, CS_NICK_REMOVED, CS_NICK_RENAMED, CS_NICK_UPDATED, - CS_OWN_NICK_SET, CS_QUERY_REQUESTED, CS_BACKLOG_DATA + CS_OWN_NICK_SET, CS_QUERY_REQUESTED, CS_BACKLOG_DATA, CS_UPDATE_BUFFERID };