fixes #543
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 17 Feb 2009 13:20:19 +0000 (14:20 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 17 Feb 2009 13:20:19 +0000 (14:20 +0100)
src/client/buffermodel.cpp
src/client/buffermodel.h

index e6bafd7..1a184ab 100644 (file)
@@ -35,6 +35,7 @@ BufferModel::BufferModel(NetworkModel *parent)
     connect(_selectionModelSynchronizer.selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
            this, SLOT(debug_currentChanged(const QModelIndex &, const QModelIndex &)));
   }
+  connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(newNetwork(NetworkId)));
 }
 
 bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const {
@@ -48,6 +49,29 @@ bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) con
   return false;
 }
 
+void BufferModel::newNetwork(NetworkId id) {
+  const Network *net = Client::network(id);
+  Q_ASSERT(net);
+  connect(net, SIGNAL(connectionStateSet(Network::ConnectionState)),
+         this, SLOT(networkConnectionChanged(Network::ConnectionState)));
+}
+
+void BufferModel::networkConnectionChanged(Network::ConnectionState state) {
+  switch(state) {
+  case Network::Connecting:
+  case Network::Initializing:
+  case Network::Initialized:
+    if(currentIndex().isValid())
+      return;
+    Network *net = qobject_cast<Network *>(sender());
+    Q_ASSERT(net);
+    setCurrentIndex(mapFromSource(Client::networkModel()->networkIndex(net->networkId())));
+    break;
+  default:
+    return;
+  }
+}
+
 void BufferModel::synchronizeView(QAbstractItemView *view) {
   _selectionModelSynchronizer.synchronizeSelectionModel(view->selectionModel());
 }
index cb9ffc4..578481b 100644 (file)
@@ -24,6 +24,7 @@
 #include <QSortFilterProxyModel>
 #include <QItemSelectionModel>
 
+#include "network.h"
 #include "types.h"
 #include "selectionmodelsynchronizer.h"
 
@@ -50,9 +51,11 @@ public slots:
   void setCurrentIndex(const QModelIndex &newCurrent);
   void switchToBuffer(const BufferId &bufferId);
   void switchToBufferIndex(const QModelIndex &bufferIdx);
-
+                                                       
 private slots:
   void debug_currentChanged(QModelIndex current, QModelIndex previous);
+  void newNetwork(NetworkId id);
+  void networkConnectionChanged(Network::ConnectionState state);
     
 private:
   SelectionModelSynchronizer _selectionModelSynchronizer;