X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Finputwidget.cpp;h=e329b04de57a4a17b501e970e917e67e5753ad89;hp=55fc20ecd4c9885aae91f77225c29023fab7de65;hb=8c38d6c5248c1b364bf56e25be0069f32c4f0408;hpb=94c69fd074d45d523e1b45f7f1c6b13207e8074b diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index 55fc20ec..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), @@ -68,8 +66,8 @@ 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()); } @@ -77,10 +75,47 @@ 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; @@ -98,7 +133,6 @@ void InputWidget::updateNickSelector() const { nickIdx = 0; } - ui.ownNick->clear(); ui.ownNick->addItems(nicks); ui.ownNick->setCurrentIndex(nickIdx); }