static IrcBufferModel* createBufferModel(QObject* parent) { IrcConnection* connection = new IrcConnection(parent); connection->setNickName("communi"); IrcBufferModel* model = new IrcBufferModel(connection); IrcBuffer* server = new Server(model); server->setName("Lorem Ipsum"); server->setSticky(true); model->add(server); model->add(createChannel("donec", model)); model->add(createChannel("convallis", model)); model->add(createChannel("sagittis", model)); model->add(createChannel("magna", model)); model->add(createChannel("tincidunt", model)); model->add(createChannel("phasellus ", model)); model->add(createChannel("tellus", model)); model->add(createChannel("fermentum", model)); model->add(createChannel("pharetra", model)); model->add(createChannel("vehicula", model)); model->add(createChannel("aliquam", model)); model->add(createChannel("bibendum", model)); model->add(createChannel("semper", model)); model->add(createChannel("dictum", model)); model->add(createChannel("rhoncus", model)); return model; }
void tst_IrcBuffer::testTitleNamePrefix() { IrcBuffer buffer; QSignalSpy titleSpy(&buffer, SIGNAL(titleChanged(QString))); QSignalSpy nameSpy(&buffer, SIGNAL(nameChanged(QString))); QSignalSpy prefixSpy(&buffer, SIGNAL(prefixChanged(QString))); QVERIFY(titleSpy.isValid()); QVERIFY(nameSpy.isValid()); QVERIFY(prefixSpy.isValid()); buffer.setName("name"); QCOMPARE(buffer.title(), QString("name")); QCOMPARE(buffer.name(), QString("name")); QCOMPARE(buffer.prefix(), QString()); QCOMPARE(titleSpy.count(), 1); QCOMPARE(titleSpy.last().first().toString(), QString("name")); QCOMPARE(nameSpy.count(), 1); QCOMPARE(nameSpy.last().first().toString(), QString("name")); QCOMPARE(prefixSpy.count(), 0); buffer.setPrefix("prefix"); QCOMPARE(buffer.title(), QString("prefixname")); QCOMPARE(buffer.name(), QString("name")); QCOMPARE(buffer.prefix(), QString("prefix")); QCOMPARE(titleSpy.count(), 2); QCOMPARE(titleSpy.last().first().toString(), QString("prefixname")); QCOMPARE(nameSpy.count(), 1); QCOMPARE(prefixSpy.count(), 1); QCOMPARE(prefixSpy.last().first().toString(), QString("prefix")); }
void IrcClient::onBufferActivated(const QModelIndex& index) { IrcBuffer* buffer = index.data(Irc::BufferRole).value<IrcBuffer*>(); // document, user list and nick completion for the current buffer textEdit->setDocument(documents.value(buffer)); userList->setModel(userModels.value(buffer)); completer->setBuffer(buffer); // keep the command parser aware of the context if (buffer) parser->setTarget(buffer->title()); }
void IrcClientPage::onBufferActivated(const QModelIndex& index) { IrcBuffer* buffer = index.data(Irc::BufferRole).value<IrcBuffer*>(); // document, user list and nick completion for the current buffer ui->textEdit->setDocument(documents.value(buffer)); ui->textEdit->verticalScrollBar()->triggerAction(QScrollBar::SliderToMaximum); ui->userList->setModel(userModels.value(buffer)); completer->setBuffer(buffer); // keep the command parser aware of the context if (buffer) parser->setTarget(buffer->title()); }
void tst_IrcBuffer::testReceive() { Irc::registerMetaTypes(); IrcBuffer buffer; QSignalSpy spy(&buffer, SIGNAL(messageReceived(IrcMessage*))); QVERIFY(spy.isValid()); buffer.receiveMessage(0); QCOMPARE(spy.count(), 0); IrcMessage msg(0); buffer.receiveMessage(&msg); QCOMPARE(spy.count(), 1); QCOMPARE(spy.last().at(0).value<IrcMessage*>(), &msg); }
bool BufferFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { if (m_status == 0 && m_filter.isEmpty()) return true; QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); IrcBuffer* buffer = index.data(Irc::BufferRole).value<IrcBuffer*>(); if (buffer && !buffer->isSticky()) { if (!m_filter.isEmpty() && !buffer->title().contains(m_filter, Qt::CaseInsensitive)) return false; if (m_status > 0) { MessageModel* model = m_storage->model(buffer); if (model) { if (m_status == 1 && model->badge() <= 0) return false; if (m_status == 2 && model->activeHighlights() <= 0) return false; } } } return true; }
void tst_IrcBuffer::testDebug() { QString str; QDebug dbg(&str); dbg << static_cast<IrcBuffer*>(0); QCOMPARE(str.trimmed(), QString::fromLatin1("IrcBuffer(0x0)")); str.clear(); IrcBuffer buffer; dbg << &buffer; QVERIFY(QRegExp("IrcBuffer\\(0x[0-9A-Fa-f]+\\) ").exactMatch(str)); str.clear(); buffer.setObjectName("obj"); dbg << &buffer; QVERIFY(QRegExp("IrcBuffer\\(0x[0-9A-Fa-f]+, name=obj\\) ").exactMatch(str)); str.clear(); buffer.setName("buf"); dbg << &buffer; QVERIFY(QRegExp("IrcBuffer\\(0x[0-9A-Fa-f]+, name=obj, title=buf\\) ").exactMatch(str)); str.clear(); }
void tst_IrcBuffer::testPersistent() { IrcBuffer buffer; QVERIFY(!buffer.isPersistent()); QSignalSpy spy(&buffer, SIGNAL(persistentChanged(bool))); QVERIFY(spy.isValid()); buffer.setPersistent(true); QVERIFY(buffer.isPersistent()); QCOMPARE(spy.count(), 1); QVERIFY(spy.last().last().toBool()); buffer.setPersistent(false); QVERIFY(!buffer.isPersistent()); QCOMPARE(spy.count(), 2); QVERIFY(!spy.last().last().toBool()); }
void tst_IrcBuffer::testSticky() { IrcBuffer buffer; QVERIFY(!buffer.isSticky()); QSignalSpy spy(&buffer, SIGNAL(stickyChanged(bool))); QVERIFY(spy.isValid()); buffer.setSticky(true); QVERIFY(buffer.isSticky()); QCOMPARE(spy.count(), 1); QVERIFY(spy.last().last().toBool()); buffer.setSticky(false); QVERIFY(!buffer.isSticky()); QCOMPARE(spy.count(), 2); QVERIFY(!spy.last().last().toBool()); }
void tst_IrcBuffer::testDefaults() { IrcBuffer buffer; QVERIFY(buffer.title().isEmpty()); QVERIFY(buffer.name().isEmpty()); QVERIFY(buffer.prefix().isEmpty()); QVERIFY(!buffer.isChannel()); QVERIFY(!buffer.toChannel()); QVERIFY(!buffer.connection()); QVERIFY(!buffer.network()); QVERIFY(!buffer.model()); QVERIFY(!buffer.isActive()); QVERIFY(!buffer.isSticky()); QVERIFY(!buffer.isPersistent()); }