futher internal prettifications of the buffer switching process
[quassel.git] / src / qtui / bufferwidget.cpp
index 8831a28..0ebcffb 100644 (file)
@@ -48,8 +48,11 @@ void BufferWidget::setModel(BufferModel *bufferModel) {
     disconnect(_bufferModel, 0, this, 0);
   }
   _bufferModel = bufferModel;
-  connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
-         this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+
+  if(bufferModel) {
+    connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+           this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+  }
 }
 
 void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
@@ -57,8 +60,11 @@ void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
     disconnect(_selectionModel, 0, this, 0);
   }
   _selectionModel = selectionModel;
-  connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
-         this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+
+  if(selectionModel) {
+    connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+           this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+  }
 }
 
 void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
@@ -103,16 +109,18 @@ void BufferWidget::removeBuffer(BufferId bufferId) {
 }
 
 void BufferWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
-  Q_UNUSED(previous);
-  QVariant variant;
-
-  variant = current.data(NetworkModel::BufferIdRole);
-  if(!variant.isValid())
-    return;
-  setCurrentBuffer(variant.value<BufferId>());
+  BufferId newBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>();
+  BufferId oldBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>();
+  if(newBufferId != oldBufferId)
+    setCurrentBuffer(newBufferId);
 }
 
 void BufferWidget::setCurrentBuffer(BufferId bufferId) {
+  if(!bufferId.isValid()) {
+    ui.stackedWidget->setCurrentWidget(ui.page);
+    return;
+  }
+  
   ChatWidget *chatWidget = 0;
   Buffer *buf = Client::buffer(bufferId);
   if(!buf) {