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 "mainwidget.h"
24 #include "chatwidget.h"
27 MainWidget::MainWidget(QWidget *parent) : AbstractBufferContainer(parent) {
29 ui.inputLine->hide(); ui.topicBar->hide();
30 connect(ui.inputLine, SIGNAL(sendText(const QString &)), this, SLOT(userInput(const QString &)));
31 connect(this, SIGNAL(userInput(BufferInfo, QString)), Client::instance(), SIGNAL(sendInput(BufferInfo, QString)));
34 MainWidget::~MainWidget() {
40 AbstractChatView *MainWidget::createChatView(BufferId id) {
42 ChatWidget *widget = new ChatWidget(this);
43 AbstractChatView *chatView = static_cast<AbstractChatView *>(widget); // can't use dynamic_cast on some Qtopia devices
45 _chatViews[id] = widget;
46 ui.stack->addWidget(widget);
47 widget->setFocusProxy(this);
51 void MainWidget::removeChatView(BufferId id) {
52 ChatWidget *view = _chatViews.value(id, 0);
54 ui.stack->removeWidget(view);
58 void MainWidget::showChatView(BufferId id) {
59 if(id.isValid()) currentBufferInfo = Client::buffer(id)->bufferInfo();
60 else currentBufferInfo = BufferInfo();
61 ChatWidget *widget = _chatViews.value(id, 0);
62 if(!widget) ui.stack->setCurrentIndex(0);
64 ui.stack->setCurrentWidget(widget);
65 ui.inputLine->show(); ui.topicBar->show();
66 ui.inputLine->setFocus();
72 void MainWidget::setBuffer(Buffer *buf) {
75 ui.stack->setCurrentIndex(0);
79 // TODO update topic if changed; handle status buffer display
80 // QString title = QString("%1 (%2): \"%3\"").arg(buf->bufferInfo().bufferName()).arg(buf->bufferInfo().networkName()).arg(buf->topic());
81 QString title = "foobar";
82 ui.topicBar->setContents(title);
84 //ui.chatWidget->setStyleSheet("div { color: #777777; }");
85 //ui.chatWidget->setHtml("<style type=\"text/css\">.foo { color: #777777; } .bar { font-style: italic }</style>"
86 // "<div class=\"foo\">foo</div> <div class=\"bar\">bar</div> baz");
87 //ui.chatWidget->moveCursor(QTextCursor::End);
88 //ui.chatWidget->insertHtml("<div class=\"foo\"> brumm</div>");
90 ChatWidget *chatWidget;
91 if(!chatWidgets.contains(buf)) {
92 chatWidget = new ChatWidget(this);
93 QList<ChatLine *> lines;
94 QList<AbstractUiMsg *> msgs = buf->contents();
95 foreach(AbstractUiMsg *msg, msgs) {
96 lines.append((ChatLine *)(msg));
98 chatWidget->setContents(lines);
99 connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
100 connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
101 connect(buf, SIGNAL(topicSet(QString)), this, SLOT(setTopic(QString)));
102 //connect(buf, SIGNAL(ownNickSet(QString)), this, SLOT(setOwnNick(QString)));
103 ui.stack->addWidget(chatWidget);
104 chatWidgets.insert(buf, chatWidget);
105 chatWidget->setFocusProxy(ui.inputLine);
106 } else chatWidget = chatWidgets[buf];
107 ui.inputLine->show(); ui.topicBar->show();
108 ui.stack->setCurrentWidget(chatWidget);
109 ui.inputLine->setFocus();
115 void MainWidget::userInput(const QString &input) {
116 if(!currentBufferInfo.isValid()) return;
117 QStringList lines = input.split('\n', QString::SkipEmptyParts);
118 foreach(QString msg, lines) {
119 if(msg.isEmpty()) continue;
120 emit userInput(currentBufferInfo, msg);
122 ui.inputLine->clear();