X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Finputwidget.cpp;h=e329b04de57a4a17b501e970e917e67e5753ad89;hp=af6d25a095abcce00f6b8771fa4f95496d0f874d;hb=8c38d6c5248c1b364bf56e25be0069f32c4f0408;hpb=453731c6d3c5eac2df5e98c4f179afabed4451a1 diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index af6d25a0..e329b04d 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -22,8 +22,6 @@ #include "client.h" #include "networkmodel.h" -#include "network.h" -#include "identity.h" InputWidget::InputWidget(QWidget *parent) : QWidget(parent), @@ -34,7 +32,7 @@ InputWidget::InputWidget(QWidget *parent) ui.setupUi(this); connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed())); connect(ui.ownNick, SIGNAL(activated(QString)), this, SLOT(changeNick(QString))); - connect(this, SIGNAL(userInput(BufferInfo, QString)), Client::instance(), SLOT(userInput(BufferInfo, QString))); + connect(this, SIGNAL(userInput(BufferInfo, QString)), Client::instance(), SIGNAL(sendInput(BufferInfo, QString))); setFocusProxy(ui.inputEdit); } @@ -68,17 +66,56 @@ void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex & return; currentBufferInfo = current.data(NetworkModel::BufferInfoRole).value(); + setNetwork(Client::networkModel()->networkByIndex(current)); updateNickSelector(); + ui.inputEdit->setEnabled(current.data(NetworkModel::ItemActiveRole).value()); } const Network *InputWidget::currentNetwork() const { if(!validBuffer) return 0; - return Client::network(currentBufferInfo.networkId()); + return Client::network(_networkId); +} + +void InputWidget::setNetwork(const Network *network) { + if(_networkId == network->networkId()) + return; + + const Network *previousNet = Client::network(_networkId); + if(previousNet) + disconnect(previousNet, 0, this, 0); + + if(network) { + _networkId = network->networkId(); + connect(network, SIGNAL(myNickSet(QString)), + this, SLOT(updateNickSelector())); + connect(network, SIGNAL(identitySet(IdentityId)), + this, SLOT(setIdentity(IdentityId))); + } + setIdentity(network->identity()); +} + +void InputWidget::setIdentity(const IdentityId &identityId) { + if(_identityId == identityId) + return; + + const Identity *previousIdentity = Client::identity(_identityId); + if(previousIdentity) + disconnect(previousIdentity, 0, this, 0); + + const Identity *identity = Client::identity(identityId); + if(identity) { + _identityId = identityId; + connect(identity, SIGNAL(nicksSet(QStringList)), + this, SLOT(updateNickSelector())); + } + updateNickSelector(); } void InputWidget::updateNickSelector() const { + ui.ownNick->clear(); + const Network *net = currentNetwork(); if(!net) return; @@ -96,7 +133,6 @@ void InputWidget::updateNickSelector() const { nickIdx = 0; } - ui.ownNick->clear(); ui.ownNick->addItems(nicks); ui.ownNick->setCurrentIndex(nickIdx); }