Add rudimentary keyboard navigation for previous/next buffer
[quassel.git] / src / qtui / mainwin.cpp
index a144904..e264c6c 100644 (file)
@@ -425,7 +425,11 @@ void MainWin::setupActions() {
   coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
                                                this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
   coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
-                                                   this, SLOT(previousBufferView()), QKeySequence(QKeySequence::Back)));
+                                                   this, SLOT(previousBufferView()), QKeySequence::Back));
+  coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
+                                           this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
+  coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
+                                               this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
 }
 
 void MainWin::setupMenus() {
@@ -612,6 +616,28 @@ BufferView *MainWin::activeBufferView() const {
   return dock->isActive() ? qobject_cast<BufferView*>(dock->widget()) : 0;
 }
 
+void MainWin::changeActiveBufferView(int bufferViewId) {
+  if(bufferViewId < 0)
+    return;
+
+  BufferView *current = activeBufferView();
+  if(current) {
+    qobject_cast<BufferViewDock*>(current->parent())->setActive(false);
+    _activeBufferViewIndex = -1;
+  }
+
+  for(int i = 0; i < _bufferViews.count(); i++) {
+    BufferViewDock *dock = _bufferViews.at(i);
+    if(dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
+      _activeBufferViewIndex = i;
+      dock->setActive(true);
+      return;
+    }
+  }
+
+  nextBufferView(); // fallback
+}
+
 void MainWin::changeActiveBufferView(bool backwards) {
   BufferView *current = activeBufferView();
   if(current)
@@ -649,6 +675,18 @@ void MainWin::previousBufferView() {
   changeActiveBufferView(true);
 }
 
+void MainWin::nextBuffer() {
+  BufferView *view = activeBufferView();
+  if(view)
+    view->nextBuffer();
+}
+
+void MainWin::previousBuffer() {
+  BufferView *view = activeBufferView();
+  if(view)
+    view->previousBuffer();
+}
+
 void MainWin::showNotificationsDlg() {
   SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
   dlg.exec();
@@ -893,14 +931,21 @@ void MainWin::loadLayout() {
   }
 
   restoreState(state, accountId);
+  int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
+  if(bufferViewId >= 0)
+    changeActiveBufferView(bufferViewId);
+
   _layoutLoaded = true;
 }
 
 void MainWin::saveLayout() {
   QtUiSettings s;
   int accountId = _bufferViews.count()? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
-  if(accountId > 0)
+  if(accountId > 0) {
     s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
+    BufferView *view = activeBufferView();
+    s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
+  }
 }
 
 void MainWin::disconnectedFromCore() {