1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
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) version 3. *
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. *
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 ***************************************************************************/
21 #include "bufferwidget.h"
23 #include "chatline-old.h"
24 #include "chatwidget.h"
29 BufferWidget::BufferWidget(QWidget *parent)
35 ui.ownNick->clear(); // TODO add nick history
36 connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
39 void BufferWidget::init() {
43 BufferWidget::~BufferWidget() {
46 BufferId BufferWidget::currentBuffer() const {
47 return _currentBuffer;
50 void BufferWidget::setCurrentBuffer(BufferId bufferId) {
51 ChatWidget *chatWidget;
52 if(_chatWidgets.contains(bufferId)) {
53 chatWidget = _chatWidgets[bufferId];
55 Buffer *buf = Client::buffer(bufferId);
57 qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
60 chatWidget = new ChatWidget(this);
61 chatWidget->init(bufferId);
62 QList<ChatLine *> lines;
63 QList<AbstractUiMsg *> msgs = buf->contents();
64 foreach(AbstractUiMsg *msg, msgs) {
65 lines.append(dynamic_cast<ChatLine*>(msg));
67 chatWidget->setContents(lines);
68 connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
69 connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
70 _chatWidgets[bufferId] = chatWidget;
71 ui.stackedWidget->addWidget(chatWidget);
73 ui.stackedWidget->setCurrentWidget(chatWidget);
74 disconnect(this, SIGNAL(userInput(QString)), 0, 0);
75 connect(this, SIGNAL(userInput(QString)), Client::buffer(bufferId), SLOT(processUserInput(QString)));
76 chatWidget->setFocusProxy(ui.inputEdit);
77 ui.inputEdit->setFocus();
81 NetworkId BufferWidget::currentNetwork() const {
82 return _currentNetwork;
85 void BufferWidget::setCurrentNetwork(NetworkId networkId) {
86 Network *net = Client::network(networkId);
89 _currentNetwork = networkId;
92 ui.ownNick->addItem(net->myNick());
95 void BufferWidget::removeBuffer(BufferId bufferId) {
96 if(!_chatWidgets.contains(bufferId))
99 ChatWidget *chatWidget = _chatWidgets.take(bufferId);
100 ui.stackedWidget->removeWidget(chatWidget);
101 chatWidget->deleteLater();
104 void BufferWidget::saveState() {
107 QSize BufferWidget::sizeHint() const {
108 return QSize(800,400);
111 void BufferWidget::enterPressed() {
112 QStringList lines = ui.inputEdit->text().split('\n', QString::SkipEmptyParts);
113 foreach(QString msg, lines) {
114 if(msg.isEmpty()) continue;
117 ui.inputEdit->clear();
123 void BufferWidget::displayMsg(Message msg) {
124 chatWidget->appendMsg(msg);