From 16b0c5bdd6fdaf3e6844ea5ec32e61b20e441284 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Tue, 17 Feb 2009 14:20:19 +0100 Subject: [PATCH] fixes #543 --- src/client/buffermodel.cpp | 24 ++++++++++++++++++++++++ src/client/buffermodel.h | 5 ++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp index e6bafd70..1a184ab7 100644 --- a/src/client/buffermodel.cpp +++ b/src/client/buffermodel.cpp @@ -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(sender()); + Q_ASSERT(net); + setCurrentIndex(mapFromSource(Client::networkModel()->networkIndex(net->networkId()))); + break; + default: + return; + } +} + void BufferModel::synchronizeView(QAbstractItemView *view) { _selectionModelSynchronizer.synchronizeSelectionModel(view->selectionModel()); } diff --git a/src/client/buffermodel.h b/src/client/buffermodel.h index cb9ffc43..578481b8 100644 --- a/src/client/buffermodel.h +++ b/src/client/buffermodel.h @@ -24,6 +24,7 @@ #include #include +#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; -- 2.20.1