Rethink buffer preselection
authorSebastian Goth <seezer@roath.org>
Fri, 9 Jul 2010 13:37:09 +0000 (15:37 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 11 Aug 2010 14:06:07 +0000 (16:06 +0200)
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.

src/client/coreconnection.cpp
src/client/coreconnection.h
src/qtui/mainwin.cpp
src/uisupport/abstractbuffercontainer.cpp
src/uisupport/abstractbuffercontainer.h

index 8ad692e..717fff3 100644 (file)
@@ -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<ConnectionState>("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();
index a1d6cda..11c8d50 100644 (file)
@@ -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;
 
index 68a5f8e..3e97835 100644 (file)
@@ -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<BufferId>();
+        Client::bufferModel()->switchToBuffer(statusBufferId);
+      }
+    }
     break;
   case Network::Disconnected:
     action->setIcon(SmallIcon("network-disconnect"));
index 5ab79aa..c914461 100644 (file)
@@ -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 &current, const QModelIndex &previous) {
   Q_UNUSED(previous)
index 474e10a..2911755 100644 (file)
@@ -60,7 +60,6 @@ protected:
 protected slots:
   virtual void currentChanged(const QModelIndex &current, 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