the nickselector should now react properly to any relevant changes (aka nickchanges...
authorMarcus Eggenberger <egs@quassel-irc.org>
Sun, 3 Feb 2008 16:04:24 +0000 (16:04 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Sun, 3 Feb 2008 16:04:24 +0000 (16:04 +0000)
src/client/networkmodel.cpp
src/client/networkmodel.h
src/qtui/inputwidget.cpp
src/qtui/inputwidget.h
version.inc

index 2970fb6..0401dca 100644 (file)
@@ -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<NetworkId>();
+  return Client::network(networkId);
+}
index 7bd7219..b038f9d 100644 (file)
@@ -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);
index 55fc20e..e329b04 100644 (file)
@@ -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 &current, const QModelIndex &
     return;
 
   currentBufferInfo  = current.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
+  setNetwork(Client::networkModel()->networkByIndex(current));
   updateNickSelector();
-
   ui.inputEdit->setEnabled(current.data(NetworkModel::ItemActiveRole).value<bool>());
 }
 
@@ -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);
 }
index 01daa29..697f654 100644 (file)
@@ -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> _bufferModel;
   QPointer<QItemSelectionModel> _selectionModel;
+  NetworkId _networkId;
+  IdentityId _identityId;
 
 };
 
index e79ffe4..4868ad6 100644 (file)
@@ -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;