Some more translation. Added a missing tr() in qtui/serverlist.cpp (ha! beat you...
[quassel.git] / src / qtui / bufferwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC 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) 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
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
36 BufferWidget::~BufferWidget() {
37
38 }
39
40 void BufferWidget::setBuffer(Buffer *buf) {
41   /*
42   ChatView *chatView;
43   if(_chatViews.contains(buf->uid())) {
44     chatView = _chatViews[buf->uid()];
45   } else {
46     chatView = new ChatView(buf, this);
47     ui.stackedWidget->addWidget(chatView);
48     _chatViews[buf->uid()] = chatView;
49   }
50   ui.stackedWidget->setCurrentWidget(chatView);
51   disconnect(this, SIGNAL(userInput(QString)), 0, 0);
52   connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
53   //chatView->setFocusProxy(ui.inputEdit);
54   ui.inputEdit->setFocus();
55   ui.ownNick->clear();  // TODO add nick history
56 }
57   */
58   
59   // ui.ownNick->addItem(state->ownNick);
60
61   ChatWidget *chatWidget;
62   if(_chatWidgets.contains(buf)) {
63      chatWidget = _chatWidgets[buf];
64   } else {
65     chatWidget = new ChatWidget(this);
66     chatWidget->init(buf->networkName(), buf->name());
67     QList<ChatLine *> lines;
68     QList<AbstractUiMsg *> msgs = buf->contents();
69     foreach(AbstractUiMsg *msg, msgs) {
70       lines.append(dynamic_cast<ChatLine*>(msg));
71     }
72     chatWidget->setContents(lines);
73     connect(buf, SIGNAL(destroyed(QObject *)), this, SLOT(bufferDestroyed(QObject *)));
74     connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
75     connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
76     _chatWidgets[buf] = chatWidget;
77     ui.stackedWidget->addWidget(chatWidget);
78   }
79   ui.stackedWidget->setCurrentWidget(chatWidget);
80   disconnect(this, SIGNAL(userInput(QString)), 0, 0);
81   connect(this, SIGNAL(userInput(QString)), buf, SLOT(processUserInput(QString)));
82   chatWidget->setFocusProxy(ui.inputEdit);
83   ui.inputEdit->setFocus();
84   ui.ownNick->clear();  // TODO add nick history
85   // ui.ownNick->addItem(state->ownNick);
86 }
87
88 void BufferWidget::bufferDestroyed(QObject *buf) {
89   QWidget *widget = _chatWidgets[(Buffer*)buf];
90   ui.stackedWidget->removeWidget(widget);
91   widget->deleteLater();
92 }
93
94 void BufferWidget::saveState() {
95
96 }
97
98 QSize BufferWidget::sizeHint() const {
99   return QSize(800,400);
100 }
101
102 void BufferWidget::enterPressed() {
103   QStringList lines = ui.inputEdit->text().split('\n', QString::SkipEmptyParts);
104   foreach(QString msg, lines) {
105     if(msg.isEmpty()) continue;
106     emit userInput(msg);
107   }
108   ui.inputEdit->clear();
109 }
110
111 void BufferWidget::setActive(bool act) {
112   if(act != active) {
113     active = act;
114     //renderContents();
115     //scrollToEnd();
116   }
117 }
118
119
120
121 /*
122 void BufferWidget::displayMsg(Message msg) {
123   chatWidget->appendMsg(msg);
124 }
125 */
126