f5024b2312e14e2f529183d441f3ec61166f44cc
[quassel.git] / gui / channelwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005 by The Quassel 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) any later version.                                   *
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 "channelwidget.h"
22 #include "guiproxy.h"
23
24 #include <QtGui>
25 #include <iostream>
26
27 ChannelWidget::ChannelWidget(QString netname, QString bufname, QWidget *parent) : QWidget(parent) {
28   ui.setupUi(this);
29   _networkName = netname;
30   _bufferName = bufname;
31   connect(ui.inputEdit, SIGNAL(returnPressed()), this, SLOT(enterPressed()));
32   //ui.inputEdit->setFocus();
33
34   // Define standard colors
35   stdCol = QColor("black");
36   noticeCol = QColor("darkblue");
37   serverCol = QColor("darkblue");
38   errorCol = QColor("red");
39   joinCol = QColor("green");
40   quitCol = QColor("firebrick");
41   partCol = QColor("firebrick");
42   
43 }
44
45 void ChannelWidget::enterPressed() {
46   emit sendMessage(networkName(), bufferName(), ui.inputEdit->text());
47   ui.inputEdit->clear();
48 }
49
50 void ChannelWidget::recvMessage(Message msg) {
51   QString s;
52   QColor c = stdCol;
53   switch(msg.type) {
54     case Message::Server:
55       c = serverCol; s = msg.msg;
56       break;
57     case Message::Error:
58       c = errorCol; s = msg.msg;
59       break;
60     default:
61       c = stdCol; s = QString("[%1] %2").arg(msg.sender).arg(msg.msg);
62       break;
63   }
64   ui.chatWidget->setTextColor(c);
65   ui.chatWidget->insertPlainText(QString("%1\n").arg(s));
66   ui.chatWidget->ensureCursorVisible();
67 }
68
69 void ChannelWidget::recvStatusMsg(QString msg) {
70   ui.chatWidget->insertPlainText(QString("[STATUS] %1").arg(msg));
71   ui.chatWidget->ensureCursorVisible();
72 }
73
74 void ChannelWidget::setTopic(QString topic) {
75   ui.topicEdit->setText(topic);
76 }
77
78 void ChannelWidget::setNicks(QStringList nicks) {
79
80
81 }
82
83 /**********************************************************************************************/
84
85
86 IrcWidget::IrcWidget(QWidget *parent) : QWidget(parent) {
87   ui.setupUi(this);
88   ui.tabWidget->removeTab(0);
89
90   connect(guiProxy, SIGNAL(csSendMessage(QString, QString, Message)), this, SLOT(recvMessage(QString, QString, Message)));
91   connect(guiProxy, SIGNAL(csSendStatusMsg(QString, QString)), this, SLOT(recvStatusMsg(QString, QString)));
92   connect(guiProxy, SIGNAL(csSetTopic(QString, QString, QString)), this, SLOT(setTopic(QString, QString, QString)));
93   connect(guiProxy, SIGNAL(csSetNicks(QString, QString, QStringList)), this, SLOT(setNicks(QString, QString, QStringList)));
94   connect(this, SIGNAL(sendMessage( QString, QString, QString )), guiProxy, SLOT(gsUserInput(QString, QString, QString)));
95 }
96
97 ChannelWidget * IrcWidget::getBuffer(QString net, QString buf) {
98   QString key = net + buf;
99   if(!buffers.contains(key)) {
100     ChannelWidget *cw = new ChannelWidget(net, buf);
101     connect(cw, SIGNAL(sendMessage(QString, QString, QString)), this, SLOT(userInput(QString, QString, QString)));
102     ui.tabWidget->addTab(cw, net+buf);
103     ui.tabWidget->setCurrentWidget(cw);
104     //cw->setFocus();
105     buffers[key] = cw;
106   }
107   return buffers[key];
108 }
109
110
111 void IrcWidget::recvMessage(QString net, QString buf, Message msg) {
112   ChannelWidget *cw = getBuffer(net, buf);
113   cw->recvMessage(msg);
114 }
115
116 void IrcWidget::recvStatusMsg(QString net, QString msg) {
117   recvMessage(net, "", QString("[STATUS] %1").arg(msg));
118
119 }
120
121 void IrcWidget::userInput(QString net, QString buf, QString msg) {
122   emit sendMessage(net, buf, msg);
123 }
124
125 void IrcWidget::setTopic(QString net, QString buf, QString topic) {
126   ChannelWidget *cw = getBuffer(net, buf);
127   cw->setTopic(topic);
128 }
129
130 void IrcWidget::setNicks(QString net, QString buf, QStringList nicks) {
131   ChannelWidget *cw = getBuffer(net, buf);
132   cw->setNicks(nicks);
133 }
134