Ripped the guts out of the BufferWidget (which is basically the StackedWidget contain...
[quassel.git] / src / qtui / bufferwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #include "bufferwidget.h"
22 #include "buffer.h"
23 #include "chatline.h"
24 #include "chatwidget.h"
25 #include "settings.h"
26
27 BufferWidget::BufferWidget(QWidget *parent) : QWidget(parent) {
28   ui.setupUi(this);
29   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
30 }
31
32 void BufferWidget::init() {
33 }
34
35 BufferWidget::~BufferWidget() {
36 }
37
38 void BufferWidget::setBuffer(Buffer *buf) {
39   ChatWidget *chatWidget;
40   if(_chatWidgets.contains(buf->uid())) {
41      chatWidget = _chatWidgets[buf->uid()];
42   } else {
43     chatWidget = new ChatWidget(this);
44     chatWidget->init(networkName, bufferName);
45     QList<ChatLine *> lines;
46     QList<AbstractUiMsg *> msgs = buf->contents();
47     foreach(AbstractUiMsg *msg, msgs) {
48       lines.append(dynamic_cast<ChatLine*>(msg));
49     }
50     chatWidget->setContents(lines);
51     connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
52     connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
53     _chatWidgets[buf->uid()] = chatWidget;
54     ui.stackedWidget->addWidget(chatWidget);
55   }
56   ui.stackedWidget->setCurrentWidget(chatWidget);
57   disconnect(this, SIGNAL(userInput(QString)), 0, 0);
58   connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
59   chatWidget->setFocusProxy(ui.inputEdit);
60   ui.inputEdit->setFocus();
61   ui.ownNick->clear();  // TODO add nick history
62   // ui.ownNick->addItem(state->ownNick);
63 }
64
65 void BufferWidget::saveState() {
66 }
67
68 QSize BufferWidget::sizeHint() const {
69   return QSize(800,400);
70 }
71
72 void BufferWidget::enterPressed() {
73   QStringList lines = ui.inputEdit->text().split('\n', QString::SkipEmptyParts);
74   foreach(QString msg, lines) {
75     if(msg.isEmpty()) continue;
76     emit userInput(msg);
77   }
78   ui.inputEdit->clear();
79 }
80
81 void BufferWidget::setActive(bool act) {
82   if(act != active) {
83     active = act;
84     //renderContents();
85     //scrollToEnd();
86   }
87 }
88
89
90 /*
91 void BufferWidget::displayMsg(Message msg) {
92   chatWidget->appendMsg(msg);
93 }
94 */
95