From 8c38d6c5248c1b364bf56e25be0069f32c4f0408 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Sun, 3 Feb 2008 16:04:24 +0000 Subject: [PATCH] the nickselector should now react properly to any relevant changes (aka nickchanges, identity updates and stuff like that) --- src/client/networkmodel.cpp | 8 +++++++ src/client/networkmodel.h | 2 ++ src/qtui/inputwidget.cpp | 44 ++++++++++++++++++++++++++++++++----- src/qtui/inputwidget.h | 8 +++++-- version.inc | 2 +- 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 2970fb63..0401dca1 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -712,3 +712,11 @@ void NetworkModel::updateBufferActivity(const Message &msg) { bufferItem(msg.bufferInfo())->updateActivity(level); } +const Network *NetworkModel::networkByIndex(const QModelIndex &index) const { + QVariant netVariant = index.data(NetworkIdRole); + if(!netVariant.isValid()) + return 0; + + NetworkId networkId = netVariant.value(); + return Client::network(networkId); +} diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 7bd7219c..b038f9d2 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -236,6 +236,8 @@ public: //Buffer *getBufferByIndex(const QModelIndex &) const; QModelIndex bufferIndex(BufferId bufferId); + const Network *networkByIndex(const QModelIndex &index) const; + public slots: void bufferUpdated(BufferInfo bufferInfo); void updateBufferActivity(const Message &msg); 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); } diff --git a/src/qtui/inputwidget.h b/src/qtui/inputwidget.h index 01daa293..697f6541 100644 --- a/src/qtui/inputwidget.h +++ b/src/qtui/inputwidget.h @@ -27,8 +27,8 @@ #include "buffermodel.h" #include "bufferinfo.h" - -class Network; +#include "identity.h" +#include "network.h"; class InputWidget : public QWidget { Q_OBJECT @@ -59,6 +59,8 @@ private slots: void enterPressed(); void changeNick(const QString &newNick) const; + void setNetwork(const Network *network); + void setIdentity(const IdentityId &identityId); void updateNickSelector() const; signals: @@ -72,6 +74,8 @@ private: QPointer _bufferModel; QPointer _selectionModel; + NetworkId _networkId; + IdentityId _identityId; }; diff --git a/version.inc b/version.inc index e79ffe49..4868ad6e 100644 --- a/version.inc +++ b/version.inc @@ -5,7 +5,7 @@ quasselVersion = "0.2.0-pre"; quasselDate = "2008-02-03"; - quasselBuild = 452; + quasselBuild = 453; //! Minimum client build number the core needs clientBuildNeeded = 437; -- 2.20.1