00001 #include <qhbox.h>
00002 #include <qwhatsthis.h>
00003 #include "ircquerytab.h"
00004 #include "ircservertab.h"
00005
00006 IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
00007 m_mainWindow = mainWindow;
00008 m_parentTab = parentTab;
00009 m_lines = 0;
00010 m_person = new IRCPerson(*person);
00011 m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>");
00012 QHBox *hbox = new QHBox(this);
00013 m_textview = new QTextView(hbox);
00014 m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
00015 m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
00016 m_textview->setTextFormat(RichText);
00017 QWhatsThis::add(m_textview, tr("Private discussion"));
00018 m_field = new IRCHistoryLineEdit(this);
00019
00020 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab()));
00021 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab()));
00022 connect(m_field, SIGNAL(closeTab()),this, SLOT(remove()));
00023 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus()));
00024
00025 QWhatsThis::add(m_field, tr("Type your text here in order to send a message to the other person"));
00026 m_layout->add(hbox);
00027 hbox->show();
00028 m_layout->add(m_field);
00029
00030 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
00031 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
00032 settingsChanged();
00033 m_field->setFocus();
00034 m_field->setActiveWindow();
00035 }
00036
00037 void IRCQueryTab::scrolling(){
00038 m_textview->ensureVisible(0, m_textview->contentsHeight());
00039 }
00040
00041
00042 void IRCQueryTab::appendText(QString text) {
00043
00044 QString txt = m_textview->text() + text + "\n";
00045 if (m_maxLines > 0 && m_lines >= m_maxLines) {
00046 int firstBreak = txt.find('\n');
00047 if (firstBreak != -1) {
00048 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1));
00049 }
00050 } else {
00051 m_lines++;
00052 }
00053 m_textview->setText(txt);
00054 m_textview->ensureVisible(0, m_textview->contentsHeight());
00055
00056 if ( IRCServerTab::containsPing( text, m_parentTab ) )
00057 emit ping( title() );
00058
00059 emit changed(this);
00060 }
00061
00062 IRCQueryTab::~IRCQueryTab() {
00063 m_parentTab->removeQueryTab(this);
00064 delete m_person;
00065 }
00066
00067 void IRCQueryTab::processCommand() {
00068 QString text = m_field->text();
00069 if (text.length()>0) {
00070 if (session()->isSessionActive()) {
00071 if (text.startsWith("/") && !text.startsWith("//")) {
00072
00073 m_parentTab->executeCommand(this, text);;
00074 } else {
00075 if (text.startsWith("//"))
00076 text = text.right(text.length()-1);
00077 session()->sendMessage(m_person, m_field->text());
00078 appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">> "+IRCOutput::toHTML(m_field->text())+"</font><br>");
00079 }
00080 } else {
00081 appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>");
00082 }
00083 }
00084 m_field->clear();
00085 }
00086
00087 void IRCQueryTab::display(IRCOutput output) {
00088 if (output.type() == OUTPUT_QUERYPRIVMSG) {
00089 appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+m_person->nick()+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage() + "</font><br>");
00090 } else if (output.type() == OUTPUT_QUERYACTION) {
00091 appendText("<font color=\"" + m_otherColor + "\">" + output.htmlMessage() + "<br>");
00092 }
00093 }
00094
00095 void IRCQueryTab::settingsChanged() {
00096 m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>");
00097 m_lines = 0;
00098 }
00099
00100 QString IRCQueryTab::title() {
00101 return m_person->nick();
00102 }
00103
00104 IRCSession *IRCQueryTab::session() {
00105 return m_parentTab->session();
00106 }
00107
00108 void IRCQueryTab::remove() {
00109 m_mainWindow->killTab(this);
00110 }
00111
00112 IRCPerson *IRCQueryTab::person() {
00113 return m_person;
00114 }
00115