- state->chatWidget->setContents(lines);
- connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), state->chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
- connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), state->chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
- connect(buf, SIGNAL(topicSet(QString)), this, SLOT(setTopic(QString)));
- connect(buf, SIGNAL(ownNickSet(QString)), this, SLOT(setOwnNick(QString)));
- ui.stackedWidget->addWidget(s->page);
- }
- ui.stackedWidget->setCurrentWidget(state->page);
- ui.topicEdit->setText(buf->topic());
- chatWidget = state->chatWidget;
- nickTree = state->nickTree;
- splitter = state->splitter;
- //ui.ownNick->set
- disconnect(this, SIGNAL(userInput(QString)), 0, 0);
- connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
- state->chatWidget->setFocusProxy(ui.inputEdit);
- ui.inputEdit->setFocus();
- ui.topicEdit->setText(state->topic);
- ui.ownNick->clear(); // TODO add nick history
- ui.ownNick->addItem(state->ownNick);
- updateTitle();
-}
-
-void BufferWidget::saveState() {
- foreach(Buffer *buf, states.keys()) {
- BufferState *s = states[buf];
- if(s->splitter) Settings::setGuiValue(QString("BufferStates/%1/%2/splitter").arg(buf->networkName()).arg(buf->bufferName()), s->splitter->saveState());
- Settings::setGuiValue(QString("BufferStates/%1/%2/currentLine").arg(buf->networkName()).arg(buf->bufferName()), s->currentLine);
- Settings::setGuiValue(QString("BufferStates/%1/%2/opsExpanded").arg(buf->networkName()).arg(buf->bufferName()), s->opsExpanded);
- Settings::setGuiValue(QString("BufferStates/%1/%2/voicedExpanded").arg(buf->networkName()).arg(buf->bufferName()), s->voicedExpanded);
- Settings::setGuiValue(QString("BufferStates/%1/%2/usersExpanded").arg(buf->networkName()).arg(buf->bufferName()), s->usersExpanded);
- }
-}
-
-QSize BufferWidget::sizeHint() const {
- return QSize(800,400);
-}
-
-void BufferWidget::updateTitle() {
- QString title = QString("%1 in %2 [%3]: %4").arg(ui.ownNick->currentText()).arg(bufferName).arg(networkName).arg(ui.topicEdit->text());
- setWindowTitle(title);
-}
-
-void BufferWidget::enterPressed() {
- QStringList lines = ui.inputEdit->text().split('\n', QString::SkipEmptyParts);
- foreach(QString msg, lines) {
- if(msg.isEmpty()) continue;
- emit userInput(msg);
- }
- ui.inputEdit->clear();
-}
-
-void BufferWidget::setActive(bool act) {
- if(act != active) {
- active = act;
- //renderContents();
- //scrollToEnd();
- }
-}
-
-void BufferWidget::resizeEvent ( QResizeEvent * event ) {
- //qDebug() << "resizing:" << bufferName << event->size();
- QWidget::resizeEvent(event);
-
-}
-
-/*
-void BufferWidget::displayMsg(Message msg) {
- chatWidget->appendMsg(msg);
-}
-*/
-
-void BufferWidget::setOwnNick(QString nick) {
- Buffer *buf = qobject_cast<Buffer*>(sender());
- Q_ASSERT(buf);
- states[buf]->ownNick = nick;
- if(buf == curBuf) {
- ui.ownNick->clear();
- ui.ownNick->addItem(nick);
- updateTitle();
- }
-}
-
-void BufferWidget::setTopic(QString topic) {
- Buffer *buf = qobject_cast<Buffer*>(sender());
- Q_ASSERT(buf);
- states[buf]->topic = topic;
- if(buf == curBuf) {
- ui.topicEdit->setText(topic);
- updateTitle();
- }
-}
-
-
-void BufferWidget::updateNickList(QVariantMap nicks) {
- Buffer *buf = qobject_cast<Buffer*>(sender());
- Q_ASSERT(buf);
- updateNickList(states[buf], nicks);
-}
-
-// TODO Use 005
-void BufferWidget::updateNickList(BufferState *state, QVariantMap nicks) {
- emit nickListUpdated(nicks.keys());
- QTreeWidget *tree = state->nickTree;
- if(!tree) return;
- tree->clear();
- if(nicks.count() != 1) tree->setHeaderLabel(tr("%1 Users").arg(nicks.count()));
- else tree->setHeaderLabel(tr("1 User"));
- QTreeWidgetItem *ops = new QTreeWidgetItem();
- QTreeWidgetItem *voiced = new QTreeWidgetItem();
- QTreeWidgetItem *users = new QTreeWidgetItem();
- // To sort case-insensitive, we have to put all nicks in a map which is sorted by (lowercase) key...
- QMap<QString, QString> sorted;
- foreach(QString n, nicks.keys()) { sorted[n.toLower()] = n; }
- foreach(QString n, sorted.keys()) {
- QString nick = sorted[n];
- QString mode = nicks[nick].toMap()["Channels"].toMap()[bufferName].toMap()["Mode"].toString();
- if(mode.contains('o')) { new QTreeWidgetItem(ops, QStringList(QString("@%1").arg(nick))); }
- else if(mode.contains('v')) { new QTreeWidgetItem(voiced, QStringList(QString("+%1").arg(nick))); }
- else new QTreeWidgetItem(users, QStringList(nick));
- }
- if(ops->childCount()) {
- ops->setText(0, tr("%1 Operators").arg(ops->childCount()));
- tree->addTopLevelItem(ops);
- ops->setExpanded(state->opsExpanded);
- } else delete ops;
- if(voiced->childCount()) {
- voiced->setText(0, tr("%1 Voiced").arg(voiced->childCount()));
- tree->addTopLevelItem(voiced);
- voiced->setExpanded(state->voicedExpanded);
- } else delete voiced;
- if(users->childCount()) {
- users->setText(0, tr("%1 Users").arg(users->childCount()));
- tree->addTopLevelItem(users);
- users->setExpanded(state->usersExpanded);
- } else delete users;
-}
-
-// TODO Use 005 and additional user modes
-void BufferWidget::itemExpansionChanged(QTreeWidgetItem *item) {
- if(item->child(0)->text(0).startsWith('@')) states[curBuf]->opsExpanded = item->isExpanded();
- else if(item->child(0)->text(0).startsWith('+')) states[curBuf]->voicedExpanded = item->isExpanded();
- else states[curBuf]->usersExpanded = item->isExpanded();