uint -> NetworkId, uint -> BufferId almost everywhere. Conversion will be made explic...
[quassel.git] / src / qtui / bufferwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
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) version 3.                                           *
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-old.h"
24 #include "chatwidget.h"
25 #include "settings.h"
26 #include "client.h"
27
28 BufferWidget::BufferWidget(QWidget *parent)
29   : QWidget(parent),
30     _currentBuffer(0)
31 {
32   ui.setupUi(this);
33   ui.ownNick->clear();  // TODO add nick history
34   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
35 }
36
37 void BufferWidget::init() {
38
39 }
40
41 BufferWidget::~BufferWidget() {
42 }
43
44 BufferId BufferWidget::currentBuffer() const {
45   return _currentBuffer;
46 }
47
48 void BufferWidget::setCurrentBuffer(BufferId bufferId) {
49   ChatWidget *chatWidget;
50   if(_chatWidgets.contains(bufferId)) {
51      chatWidget = _chatWidgets[bufferId];
52   } else {
53     Buffer *buf = Client::buffer(bufferId);
54     if(!buf) {
55       qWarning() << "BufferWidget::setBuffer(BufferId): Can't show unknown Buffer:" << bufferId;
56       return;
57     }
58     chatWidget = new ChatWidget(this);
59     chatWidget->init(bufferId);
60     QList<ChatLine *> lines;
61     QList<AbstractUiMsg *> msgs = buf->contents();
62     foreach(AbstractUiMsg *msg, msgs) {
63       lines.append(dynamic_cast<ChatLine*>(msg));
64     }
65     chatWidget->setContents(lines);
66     connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
67     connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
68     _chatWidgets[bufferId] = chatWidget;
69     ui.stackedWidget->addWidget(chatWidget);
70   }
71   ui.stackedWidget->setCurrentWidget(chatWidget);
72   disconnect(this, SIGNAL(userInput(QString)), 0, 0);
73   connect(this, SIGNAL(userInput(QString)), Client::buffer(bufferId), SLOT(processUserInput(QString)));
74   chatWidget->setFocusProxy(ui.inputEdit);
75   ui.inputEdit->setFocus();
76
77 }
78
79 void BufferWidget::removeBuffer(BufferId bufferId) {
80   if(!_chatWidgets.contains(bufferId))
81     return;
82
83   ChatWidget *chatWidget = _chatWidgets.take(bufferId);
84   ui.stackedWidget->removeWidget(chatWidget);
85   chatWidget->deleteLater();
86 }
87
88 void BufferWidget::saveState() {
89 }
90
91 QSize BufferWidget::sizeHint() const {
92   return QSize(800,400);
93 }
94
95 void BufferWidget::enterPressed() {
96   QStringList lines = ui.inputEdit->text().split('\n', QString::SkipEmptyParts);
97   foreach(QString msg, lines) {
98     if(msg.isEmpty()) continue;
99     emit userInput(msg);
100   }
101   ui.inputEdit->clear();
102 }
103
104
105
106 /*
107 void BufferWidget::displayMsg(Message msg) {
108   chatWidget->appendMsg(msg);
109 }
110 */
111