From: Sebastian Goth Date: Fri, 9 Jul 2010 13:37:09 +0000 (+0200) Subject: Rethink buffer preselection X-Git-Tag: 0.7-beta1~14 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=d5f5ce565bf61a020029f52c16fd3ea4f494d23e Rethink buffer preselection As automatic buffer selection on startup clears the activity, this will hopefully be the best solution without another clientsetting.. All versions will select the statusbuffer of a connecting network if no valid buffer is currently selected. Monolithic version will always start with the last selected buffer. There is just no activity until next start. Client will now only preselect the last buffer if the connection was not closed by the user. If the connection was closed manually or after fresh client start, the statusbuffer of some connected network will be shown. --- diff --git a/src/client/coreconnection.cpp b/src/client/coreconnection.cpp index 8ad692e2..717fff39 100644 --- a/src/client/coreconnection.cpp +++ b/src/client/coreconnection.cpp @@ -42,7 +42,9 @@ CoreConnection::CoreConnection(CoreAccountModel *model, QObject *parent) _wantReconnect(false), _progressMinimum(0), _progressMaximum(-1), - _progressValue(-1) + _progressValue(-1), + _wasReconnect(false), + _requestedDisconnect(false) { qRegisterMetaType("CoreConnection::ConnectionState"); } @@ -256,6 +258,7 @@ void CoreConnection::coreSocketError(QAbstractSocket::SocketError) { void CoreConnection::coreSocketDisconnected() { // qDebug() << Q_FUNC_INFO; + _wasReconnect = !_requestedDisconnect; resetConnection(true); // FIXME handle disconnects gracefully } @@ -304,6 +307,7 @@ void CoreConnection::coreHasData() { } void CoreConnection::disconnectFromCore() { + _requestedDisconnect = true; disconnectFromCore(QString(), false); // requested disconnect, so don't try to reconnect } @@ -311,6 +315,8 @@ void CoreConnection::disconnectFromCore(const QString &errorString, bool wantRec if(!wantReconnect) _reconnectTimer.stop(); + _wasReconnect = wantReconnect; // store if disconnect was requested + if(errorString.isEmpty()) emit connectionError(tr("Disconnected")); else @@ -328,6 +334,7 @@ void CoreConnection::resetConnection(bool wantReconnect) { _socket->deleteLater(); _socket = 0; } + _requestedDisconnect = false; _blockSize = 0; _coreMsgBuffer.clear(); diff --git a/src/client/coreconnection.h b/src/client/coreconnection.h index a1d6cda0..11c8d500 100644 --- a/src/client/coreconnection.h +++ b/src/client/coreconnection.h @@ -71,6 +71,9 @@ public: inline int progressValue() const; inline QString progressText() const; + //! Check if we consider the last connect as reconnect + inline bool wasReconnect() const { return _wasReconnect; } + #ifdef HAVE_SSL inline const QSslSocket *sslSocket() const; #endif @@ -182,6 +185,8 @@ private: QString _progressText; QString _coreInfoString(const QVariantMap &); + bool _wasReconnect; + bool _requestedDisconnect; inline CoreAccountModel *accountModel() const; diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 68a5f8e1..3e978351 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -920,10 +920,13 @@ void MainWin::setConnectedState() { wizard->show(); } else { - QtUiSettings s; - BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt()); - if(lastUsedBufferId.isValid()) - Client::bufferModel()->switchToBuffer(lastUsedBufferId); + // Monolithic always preselects last used buffer - Client only if the connection died + if(Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) { + QtUiSettings s; + BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt()); + if(lastUsedBufferId.isValid()) + Client::bufferModel()->switchToBuffer(lastUsedBufferId); + } } } @@ -976,10 +979,12 @@ void MainWin::disconnectedFromCore() { } } + // store last active buffer QtUiSettings s; - BufferId lastBufId = Client::bufferModel()->currentBuffer(); + BufferId lastBufId = _bufferWidget->currentBuffer(); if(lastBufId.isValid()) { s.setValue("LastUsedBufferId", lastBufId.toInt()); + // clear the current selection Client::bufferModel()->standardSelectionModel()->clearSelection(); } restoreState(s.value("MainWinState").toByteArray()); @@ -1307,6 +1312,14 @@ void MainWin::clientNetworkUpdated() { switch(net->connectionState()) { case Network::Initialized: action->setIcon(SmallIcon("network-connect")); + // if we have no currently selected buffer, jump to the first connecting statusbuffer + if(!bufferWidget()->currentBuffer().isValid()) { + QModelIndex idx = Client::networkModel()->networkIndex(net->networkId()); + if(idx.isValid()) { + BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value(); + Client::bufferModel()->switchToBuffer(statusBufferId); + } + } break; case Network::Disconnected: action->setIcon(SmallIcon("network-disconnect")); diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 5ab79aa2..c9144613 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -66,6 +66,9 @@ void AbstractBufferContainer::removeBuffer(BufferId bufferId) { _chatViews.take(bufferId); } +/* + Switching to first buffer is now handled in MainWin::clientNetworkUpdated() + void AbstractBufferContainer::rowsInserted(const QModelIndex &parent, int start, int end) { Q_UNUSED(end) @@ -80,6 +83,7 @@ void AbstractBufferContainer::rowsInserted(const QModelIndex &parent, int start, setCurrentBuffer(id); } } +*/ void AbstractBufferContainer::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { Q_UNUSED(previous) diff --git a/src/uisupport/abstractbuffercontainer.h b/src/uisupport/abstractbuffercontainer.h index 474e10a4..29117552 100644 --- a/src/uisupport/abstractbuffercontainer.h +++ b/src/uisupport/abstractbuffercontainer.h @@ -60,7 +60,6 @@ protected: protected slots: virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); - virtual void rowsInserted(const QModelIndex &parent, int start, int end); //! Show the given chat view /** This method is called when the given chat view should be displayed. Use this e.g. for