Hide some of the bufferviews by default in order to not confuse new users too much.
[quassel.git] / src / qtui / bufferwidget.cpp
index 3a900d1..541ddb5 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
 #include "chatline-old.h"
 #include "chatwidget.h"
 #include "settings.h"
-
-BufferWidget::BufferWidget(QWidget *parent) : QWidget(parent) {
+#include "client.h"
+#include "network.h"
+
+BufferWidget::BufferWidget(QWidget *parent)
+  : QWidget(parent),
+    _currentBuffer(0),
+    _currentNetwork(0)
+{
   ui.setupUi(this);
+  ui.ownNick->clear();  // TODO add nick history
   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
 }
 
@@ -34,36 +41,24 @@ void BufferWidget::init() {
 }
 
 BufferWidget::~BufferWidget() {
-
 }
 
-void BufferWidget::setBuffer(Buffer *buf) {
-  /*
-  ChatView *chatView;
-  if(_chatViews.contains(buf->uid())) {
-    chatView = _chatViews[buf->uid()];
-  } else {
-    chatView = new ChatView(buf, this);
-    ui.stackedWidget->addWidget(chatView);
-    _chatViews[buf->uid()] = chatView;
-  }
-  ui.stackedWidget->setCurrentWidget(chatView);
-  disconnect(this, SIGNAL(userInput(QString)), 0, 0);
-  connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
-  //chatView->setFocusProxy(ui.inputEdit);
-  ui.inputEdit->setFocus();
-  ui.ownNick->clear();  // TODO add nick history
+BufferId BufferWidget::currentBuffer() const {
+  return _currentBuffer;
 }
-  */
-  
-  // ui.ownNick->addItem(state->ownNick);
 
+void BufferWidget::setCurrentBuffer(BufferId bufferId) {
   ChatWidget *chatWidget;
-  if(_chatWidgets.contains(buf->uid())) {
-     chatWidget = _chatWidgets[buf->uid()];
+  if(_chatWidgets.contains(bufferId)) {
+     chatWidget = _chatWidgets[bufferId];
   } else {
+    Buffer *buf = Client::buffer(bufferId);
+    if(!buf) {
+      qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
+      return;
+    }
     chatWidget = new ChatWidget(this);
-    chatWidget->init(buf->networkName(), buf->name());
+    chatWidget->init(bufferId);
     QList<ChatLine *> lines;
     QList<AbstractUiMsg *> msgs = buf->contents();
     foreach(AbstractUiMsg *msg, msgs) {
@@ -72,20 +67,41 @@ void BufferWidget::setBuffer(Buffer *buf) {
     chatWidget->setContents(lines);
     connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
     connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
-    _chatWidgets[buf->uid()] = chatWidget;
+    _chatWidgets[bufferId] = chatWidget;
     ui.stackedWidget->addWidget(chatWidget);
   }
   ui.stackedWidget->setCurrentWidget(chatWidget);
   disconnect(this, SIGNAL(userInput(QString)), 0, 0);
-  connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
+  connect(this, SIGNAL(userInput(QString)), Client::buffer(bufferId), SLOT(processUserInput(QString)));
   chatWidget->setFocusProxy(ui.inputEdit);
   ui.inputEdit->setFocus();
-  ui.ownNick->clear();  // TODO add nick history
-  // ui.ownNick->addItem(state->ownNick);
+
 }
 
-void BufferWidget::saveState() {
+NetworkId BufferWidget::currentNetwork() const {
+  return _currentNetwork;
+}
+
+void BufferWidget::setCurrentNetwork(NetworkId networkId) {
+  Network *net = Client::network(networkId);
+  if(!net)
+    return;
+  _currentNetwork = networkId;
+  
+  ui.ownNick->clear();
+  ui.ownNick->addItem(net->myNick());
+}
+
+void BufferWidget::removeBuffer(BufferId bufferId) {
+  if(!_chatWidgets.contains(bufferId))
+    return;
 
+  ChatWidget *chatWidget = _chatWidgets.take(bufferId);
+  ui.stackedWidget->removeWidget(chatWidget);
+  chatWidget->deleteLater();
+}
+
+void BufferWidget::saveState() {
 }
 
 QSize BufferWidget::sizeHint() const {
@@ -101,13 +117,6 @@ void BufferWidget::enterPressed() {
   ui.inputEdit->clear();
 }
 
-void BufferWidget::setActive(bool act) {
-  if(act != active) {
-    active = act;
-    //renderContents();
-    //scrollToEnd();
-  }
-}
 
 
 /*