/***************************************************************************
- * Copyright (C) 2005-07 by The Quassel IRC Development Team *
+ * Copyright (C) 2005-08 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
+ * (at your option) version 3. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#include "buffer.h"
#include "chatwidget.h"
+#include "client.h"
-MainWidget::MainWidget(QWidget *parent) : QWidget(parent) {
+MainWidget::MainWidget(QWidget *parent) : AbstractBufferContainer(parent) {
ui.setupUi(this);
-
-// ui.bufferLeft->setIcon(QIcon(":icon/left"));
-// ui.bufferRight->setIcon(QIcon(":icon/right"));
- //ui.bufferLeft->setIconSize(QSize(10, 10));
- //ui.bufferRight->setIconSize(QSize(10, 10));
- //ui.bufferLeft->setMaximumSize(QSize(10,10));
- //ui.bufferRight->setMaximumSize(QSize(10,10));
+ ui.inputLine->hide(); ui.topicBar->hide();
+ connect(ui.inputLine, SIGNAL(sendText(const QString &)), this, SLOT(userInput(const QString &)));
+ connect(this, SIGNAL(userInput(BufferInfo, QString)), Client::instance(), SIGNAL(sendInput(BufferInfo, QString)));
}
MainWidget::~MainWidget() {
}
+AbstractChatView *MainWidget::createChatView(BufferId id) {
+ Q_UNUSED(id)
+ ChatWidget *widget = new ChatWidget(this);
+ AbstractChatView *chatView = static_cast<AbstractChatView *>(widget); // can't use dynamic_cast on some Qtopia devices
+ Q_ASSERT(chatView);
+ _chatViews[id] = widget;
+ ui.stack->addWidget(widget);
+ widget->setFocusProxy(this);
+ return chatView;
+}
+
+void MainWidget::removeChatView(BufferId id) {
+ ChatWidget *view = _chatViews.value(id, 0);
+ if(!view) return;
+ ui.stack->removeWidget(view);
+ view->deleteLater();
+}
+
+void MainWidget::showChatView(BufferId id) {
+ if(id.isValid()) currentBufferInfo = Client::buffer(id)->bufferInfo();
+ else currentBufferInfo = BufferInfo();
+ ChatWidget *widget = _chatViews.value(id, 0);
+ if(!widget) ui.stack->setCurrentIndex(0);
+ else {
+ ui.stack->setCurrentWidget(widget);
+ ui.inputLine->show(); ui.topicBar->show();
+ ui.inputLine->setFocus();
+ }
+}
+
+
+/*
void MainWidget::setBuffer(Buffer *buf) {
+
+ if(!buf) {
+ ui.stack->setCurrentIndex(0);
+ currentBuffer = 0;
+ return;
+ }
// TODO update topic if changed; handle status buffer display
- QString title = QString("%1 (%2): \"%3\"").arg(buf->name()).arg(buf->networkName()).arg(buf->topic());
+// QString title = QString("%1 (%2): \"%3\"").arg(buf->bufferInfo().bufferName()).arg(buf->bufferInfo().networkName()).arg(buf->topic());
+ QString title = "foobar";
ui.topicBar->setContents(title);
//ui.chatWidget->setStyleSheet("div { color: #777777; }");
QList<ChatLine *> lines;
QList<AbstractUiMsg *> msgs = buf->contents();
foreach(AbstractUiMsg *msg, msgs) {
- lines.append((ChatLine*)(msg));
+ lines.append((ChatLine *)(msg));
}
chatWidget->setContents(lines);
connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *)));
connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *)));
- //connect(buf, SIGNAL(topicSet(QString)), this, SLOT(setTopic(QString)));
+ connect(buf, SIGNAL(topicSet(QString)), this, SLOT(setTopic(QString)));
//connect(buf, SIGNAL(ownNickSet(QString)), this, SLOT(setOwnNick(QString)));
ui.stack->addWidget(chatWidget);
chatWidgets.insert(buf, chatWidget);
- ui.stack->addWidget(chatWidget);
+ chatWidget->setFocusProxy(ui.inputLine);
} else chatWidget = chatWidgets[buf];
+ ui.inputLine->show(); ui.topicBar->show();
ui.stack->setCurrentWidget(chatWidget);
+ ui.inputLine->setFocus();
+ currentBuffer = buf;
+
+}
+*/
+
+void MainWidget::userInput(const QString &input) {
+ if(!currentBufferInfo.isValid()) return;
+ QStringList lines = input.split('\n', QString::SkipEmptyParts);
+ foreach(QString msg, lines) {
+ if(msg.isEmpty()) continue;
+ emit userInput(currentBufferInfo, msg);
+ }
+ ui.inputLine->clear();
}