-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 17 | ||||
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.h | 20 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 53 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 27 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 15 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.h | 6 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 15 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.h | 4 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.cpp | 60 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.h | 18 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircversion.h | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 5 | ||||
-rw-r--r-- | noncore/net/opieirc/opie-irc.control | 3 |
16 files changed, 186 insertions, 66 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index ddd6cf1..f19e019 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp @@ -1,126 +1,139 @@ #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qcursor.h> +#include <stdio.h> #include <qhbox.h> #include "ircchanneltab.h" #include "ircservertab.h" IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { m_mainWindow = mainWindow; m_parentTab = parentTab; m_channel = channel; m_description->setText(tr("Talking on channel") + " <b>" + channel->channelname() + "</b>"); QHBox *hbox = new QHBox(this); m_textview = new QTextView(hbox); m_textview->setHScrollBarMode(QScrollView::AlwaysOff); m_textview->setVScrollBarMode(QScrollView::AlwaysOn); m_listVisible = TRUE; m_listButton = new QPushButton(">", m_textview); m_textview->setCornerWidget(m_listButton); m_textview->setTextFormat(RichText); connect(m_listButton, SIGNAL(clicked()), this, SLOT(toggleList())); m_list = new IRCChannelList(m_channel, hbox); m_list->update(); m_list->setMaximumWidth(LISTWIDTH); - m_field = new QLineEdit(this); + m_field = new IRCHistoryLineEdit(this); m_popup = new QPopupMenu(m_list); + m_lines = 0; /* Required so that embedded-style "right" clicks work */ QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold); connect(m_list, SIGNAL(mouseButtonPressed(int, QListBoxItem *, const QPoint&)), this, SLOT(mouseButtonPressed(int, QListBoxItem *, const QPoint &))); + /* Construct the popup menu */ QPopupMenu *ctcpMenu = new QPopupMenu(m_list); m_popup->insertItem(Resource::loadPixmap("opieirc/ctcp"), tr("CTCP"), ctcpMenu); m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery())); ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing())); ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion())); ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois())); m_layout->add(hbox); hbox->show(); m_layout->add(m_field); m_field->setFocus(); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); settingsChanged(); } void IRCChannelTab::appendText(QString text) { /* not using append because it creates layout problems */ - m_textview->setText(m_textview->text() + text); + QString txt = m_textview->text() + text + "\n"; + if (m_maxLines > 0 && m_lines >= m_maxLines) { + int firstBreak = txt.find('\n'); + if (firstBreak != -1) { + txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); + } + } else { + m_lines++; + } + m_textview->setText(txt); m_textview->ensureVisible(0, m_textview->contentsHeight()); emit changed(this); } IRCChannelTab::~IRCChannelTab() { m_parentTab->removeChannelTab(this); } void IRCChannelTab::processCommand() { QString text = m_field->text(); if (text.length()>0) { if (session()->isSessionActive()) { if (text.startsWith("/") && !text.startsWith("//")) { /* Command mode */ m_parentTab->executeCommand(this, text);; } else { if (text.startsWith("//")) text = text.right(text.length()-1); session()->sendMessage(m_channel, m_field->text()); 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>"); } } else { appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); } } m_field->clear(); } void IRCChannelTab::settingsChanged() { m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); + m_lines = 0; } void IRCChannelTab::toggleList() { if (m_listVisible) { m_list->setMaximumWidth(0); m_listButton->setText("<"); } else { m_list->setMaximumWidth(LISTWIDTH); m_listButton->setText(">"); } m_listVisible = !m_listVisible; } void IRCChannelTab::mouseButtonPressed(int mouse, QListBoxItem *, const QPoint &point) { switch (mouse) { case 1: break; case 2: m_popup->popup(point); break; }; } void IRCChannelTab::popupQuery() { if (m_list->currentItem() != -1) { IRCPerson *person = session()->getPerson(m_list->item(m_list->currentItem())->text()); if (person) { IRCQueryTab *tab = m_parentTab->getTabForQuery(person); if (!tab) { tab = new IRCQueryTab(person, m_parentTab, m_mainWindow, (QWidget *)parent()); m_parentTab->addQueryTab(tab); m_mainWindow->addTab(tab); } } } } void IRCChannelTab::popupPing() { } void IRCChannelTab::popupVersion() { } void IRCChannelTab::popupWhois() { } QString IRCChannelTab::title() { return m_channel->channelname(); diff --git a/noncore/net/opieirc/ircchanneltab.h b/noncore/net/opieirc/ircchanneltab.h index 971614b..a03ee3e 100644 --- a/noncore/net/opieirc/ircchanneltab.h +++ b/noncore/net/opieirc/ircchanneltab.h @@ -1,70 +1,72 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCCHANNELTAB_H #define __IRCCHANNELTAB_H #include <qpopupmenu.h> #include <qpushbutton.h> #include "irctab.h" #include "ircsession.h" +#include "ircmisc.h" #include "mainwindow.h" #include "ircchannellist.h" #define LISTWIDTH 70 class IRCServerTab; class IRCChannelTab : public IRCTab { Q_OBJECT public: /* IRCTab implementation */ IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); ~IRCChannelTab(); QString title(); IRCSession *session(); IRCChannel *channel(); IRCChannelList *list(); public: void appendText(QString text); public slots: void remove(); void settingsChanged(); protected slots: void processCommand(); void toggleList(); void mouseButtonPressed(int mouse, QListBoxItem *item, const QPoint &point); /* Popup slots */ void popupQuery(); void popupPing(); void popupVersion(); void popupWhois(); protected: - IRCServerTab *m_parentTab; - IRCChannel *m_channel; - IRCChannelList *m_list; - QPushButton *m_listButton; - MainWindow *m_mainWindow; - QTextView *m_textview; - QLineEdit *m_field; - QPopupMenu *m_popup; - bool m_listVisible; + IRCServerTab *m_parentTab; + IRCChannel *m_channel; + IRCChannelList *m_list; + QPushButton *m_listButton; + MainWindow *m_mainWindow; + QTextView *m_textview; + IRCHistoryLineEdit *m_field; + QPopupMenu *m_popup; + bool m_listVisible; + int m_lines; }; #endif /* __IRCCHANNELTAB_H */ diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index a95c64e..e8d3b1a 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -472,50 +472,50 @@ void IRCMessageParser::parseNumericalNames(IRCMessage *message) { m_session->addPerson(person); } chan_person->person = person; chan_person->flags = flag; channel->addPerson(chan_person); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } } void IRCMessageParser::parseNumericalEndOfNames(IRCMessage *message) { /* Done syncing to channel */ IRCChannel *channel = m_session->getChannel(message->param(1).lower()); if (channel) { channel->setHasPeople(TRUE); /* Yes, we want the names before anything happens inside the GUI */ IRCOutput output(OUTPUT_SELFJOIN, tr("You joined channel ") + channel->channelname()); output.addParam(channel); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Server message with unknown channel"))); } } void IRCMessageParser::parseNumericalNicknameInUse(IRCMessage *) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname is in use, please reconnect with a different nickname"))); m_session->endSession(); } void IRCMessageParser::parseNumericalNoSuchNick(IRCMessage *) { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("No such nickname"))); } void IRCMessageParser::parseNumericalTopic(IRCMessage *message) { IRCChannel *channel = m_session->getChannel(message->param(1).lower()); if (channel) { IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + channel->channelname() + " is \"" + message->param(2) + "\"")); output.addParam(channel); emit outputReady(output); } else { IRCOutput output(OUTPUT_TOPIC, tr("Topic for channel " + message->param(1) + " is \"" + message->param(2) + "\"")); output.addParam(0); emit outputReady(output); } } -void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *message) { +void IRCMessageParser::parseNumericalTopicWhoTime(IRCMessage *) { } diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp index dd7292c..2e7f316 100644 --- a/noncore/net/opieirc/ircmisc.cpp +++ b/noncore/net/opieirc/ircmisc.cpp @@ -1,66 +1,97 @@ #include <opie/colordialog.h> #include <qlayout.h> #include <stdio.h> #include "ircmisc.h" IRCColorLabel::IRCColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QLabel(parent, name, f) { m_color = color; setAlignment(AlignVCenter | AlignCenter); setFrameStyle(QFrame::StyledPanel); setFrameShadow(QFrame::Sunken); setBackgroundColor(m_color); } void IRCColorLabel::mousePressEvent(QMouseEvent *) { m_color = OColorDialog::getColor(m_color); setBackgroundColor(m_color); } QColor IRCColorLabel::color() { return m_color; } IRCFramedColorLabel::IRCFramedColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { QVBoxLayout *layout = new QVBoxLayout(this, 10, 0); m_label = new IRCColorLabel(color, this); layout->addWidget(m_label); } QColor IRCFramedColorLabel::color() { return m_label->color(); } + IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) { } int IRCTabBar::insertTab(QTab *tab, int index = -1) { - if (m_colors.size() == (unsigned int)count()) - m_colors.resize(m_colors.size() * 2 + 1); - if (index == -1) - m_colors.insert(count(), &black); - else - m_colors.insert(index, &black); - return QTabBar::insertTab(tab, index); + /* FIXME: find some nicer way to do this */ + QExtTab *ext = new QExtTab(); + ext->color = black; + ext->label = tab->text(); + ext->r = tab->rect(); + ext->enabled = tab->isEnabled(); + ext->iconset = tab->iconSet(); + delete tab; + return QTabBar::insertTab(ext, index); } -void IRCTabBar::setTabColor(int index, const QColor *color) { - m_colors.insert(index, color); +void IRCTabBar::setTabColor(int index, QColor color) { + ((QExtTab *)tab(index))->color = color; update(); } void IRCTabBar::paintLabel(QPainter* p, const QRect& br, QTab* t, bool focus) const { QRect r = br; QTabBar::paintLabel(p, br, t, focus); if (t->id == currentTab()) r.setBottom(r.bottom() - style().defaultFrameWidth()); - p->setPen(*m_colors.at(t->id)); + p->setPen(((QExtTab *)t)->color); p->drawText(r, AlignCenter | ShowPrefix, t->label); } IRCTabWidget::IRCTabWidget(QWidget *parent, const char *name) : QTabWidget(parent, name) { setTabBar(new IRCTabBar(this, "tab control")); } -void IRCTabWidget::setTabColor(int index, const QColor *color) { +void IRCTabWidget::setTabColor(int index, QColor color) { ((IRCTabBar *)tabBar())->setTabColor(index, color); } + + +IRCHistoryLineEdit::IRCHistoryLineEdit(QWidget *parent, const char *name) : QLineEdit(parent, name) { + m_index = -1; +} + +void IRCHistoryLineEdit::keyPressEvent(QKeyEvent *event) { + int key = event->key(); + if (key == Key_Up) { + if (m_history.count() > 0 && m_index < (signed int)m_history.count()-1) { + m_index++; + setText(m_history[m_index]); + } + } else if (key == Key_Down) { + if (m_history.count() > 0 && m_index > 0) { + m_index--; + setText(m_history[m_index]); + } + if (m_index == 0) { + m_index = -1; + setText(""); + } + } else if (key == Key_Return) { + m_history.prepend(text()); + m_index = -1; + } + QLineEdit::keyPressEvent(event); +} diff --git a/noncore/net/opieirc/ircmisc.h b/noncore/net/opieirc/ircmisc.h index 4df6ce0..7151e6b 100644 --- a/noncore/net/opieirc/ircmisc.h +++ b/noncore/net/opieirc/ircmisc.h @@ -1,72 +1,91 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCMISC_H #define __IRCMISC_H #include <qtabwidget.h> +#include <qlineedit.h> #include <qtabbar.h> #include <qlabel.h> #include <qcolor.h> -#include <qvector.h> +#include <qarray.h> /* IRCFramedColorLabel is used to display a color */ class IRCColorLabel : public QLabel { Q_OBJECT public: IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); QColor color(); void mousePressEvent(QMouseEvent *event); protected: QColor m_color; }; class IRCFramedColorLabel : public QWidget { Q_OBJECT public: IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); QColor color(); protected: IRCColorLabel *m_label; }; /* Custom colored QTabWidget */ +class QExtTab : public QTab { +public: + QColor color; +}; + class IRCTabWidget : public QTabWidget { Q_OBJECT public: IRCTabWidget(QWidget *parent = 0, const char *name = 0); - void setTabColor(int index, const QColor *color); + void setTabColor(int index, QColor color); }; class IRCTabBar : public QTabBar { Q_OBJECT public: IRCTabBar(QWidget *parent = 0, const char *name = 0); - void setTabColor(int index, const QColor *color); + void setTabColor(int index, QColor color); protected: void paintLabel(QPainter*, const QRect&, QTab*, bool) const; int insertTab(QTab *, int index = -1); protected: - QVector<QColor> m_colors; + QArray<QColor> m_colors; +}; + +/* A QLineEdit with history functionality */ + +class IRCHistoryLineEdit : public QLineEdit { + Q_OBJECT +public: + IRCHistoryLineEdit(QWidget *parent = 0, const char *name = 0); +protected: + void keyPressEvent(QKeyEvent *); +protected: + QStringList m_history; + int m_index; }; #endif /* __IRCMISC_H */ diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp index b946174..869e4f7 100644 --- a/noncore/net/opieirc/ircquerytab.cpp +++ b/noncore/net/opieirc/ircquerytab.cpp @@ -1,83 +1,94 @@ #include <qhbox.h> #include "ircquerytab.h" #include "ircservertab.h" IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { m_mainWindow = mainWindow; m_parentTab = parentTab; + m_lines = 0; m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */ m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>"); QHBox *hbox = new QHBox(this); m_textview = new QTextView(hbox); m_textview->setHScrollBarMode(QScrollView::AlwaysOff); m_textview->setVScrollBarMode(QScrollView::AlwaysOn); m_textview->setTextFormat(RichText); - m_field = new QLineEdit(this); + m_field = new IRCHistoryLineEdit(this); m_layout->add(hbox); hbox->show(); m_layout->add(m_field); m_field->setFocus(); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); settingsChanged(); } void IRCQueryTab::appendText(QString text) { /* not using append because it creates layout problems */ - m_textview->setText(m_textview->text() + text); + QString txt = m_textview->text() + text + "\n"; + if (m_maxLines > 0 && m_lines >= m_maxLines) { + int firstBreak = txt.find('\n'); + if (firstBreak != -1) { + txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); + } + } else { + m_lines++; + } + m_textview->setText(txt); m_textview->ensureVisible(0, m_textview->contentsHeight()); emit changed(this); } IRCQueryTab::~IRCQueryTab() { m_parentTab->removeQueryTab(this); delete m_person; } void IRCQueryTab::processCommand() { QString text = m_field->text(); if (text.length()>0) { if (session()->isSessionActive()) { if (text.startsWith("/") && !text.startsWith("//")) { /* Command mode */ m_parentTab->executeCommand(this, text);; } else { if (text.startsWith("//")) text = text.right(text.length()-1); session()->sendMessage(m_person, m_field->text()); 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>"); } } else { appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); } } m_field->clear(); } void IRCQueryTab::display(IRCOutput output) { if (output.type() == OUTPUT_QUERYPRIVMSG) { appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+m_person->nick()+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage() + "</font><br>"); } else if (output.type() == OUTPUT_QUERYACTION) { appendText("<font color=\"" + m_otherColor + "\">" + output.htmlMessage() + "<br>"); } } void IRCQueryTab::settingsChanged() { m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); + m_lines = 0; } QString IRCQueryTab::title() { return m_person->nick(); } IRCSession *IRCQueryTab::session() { return m_parentTab->session(); } void IRCQueryTab::remove() { m_mainWindow->killTab(this); } IRCPerson *IRCQueryTab::person() { return m_person; } diff --git a/noncore/net/opieirc/ircquerytab.h b/noncore/net/opieirc/ircquerytab.h index 07fa57f..f9cc8e1 100644 --- a/noncore/net/opieirc/ircquerytab.h +++ b/noncore/net/opieirc/ircquerytab.h @@ -1,52 +1,54 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCQUERYTAB_H #define __IRCQUERYTAB_H -#include "ircsession.h" #include "mainwindow.h" +#include "ircsession.h" +#include "ircmisc.h" class IRCServerTab; class IRCQueryTab : public IRCTab { Q_OBJECT public: /* IRCTab implementation */ IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); ~IRCQueryTab(); QString title(); IRCSession *session(); IRCPerson *person(); void appendText(QString text); public slots: void remove(); void processCommand(); void display(IRCOutput output); void settingsChanged(); protected: bool m_close; MainWindow *m_mainWindow; IRCServerTab *m_parentTab; IRCPerson *m_person; QTextView *m_textview; - QLineEdit *m_field; + IRCHistoryLineEdit *m_field; + int m_lines; }; #endif /* __IRCQUERYTAB_H */ diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 4ed5364..5d1e290 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,108 +1,119 @@ #include <qpe/config.h> #include <qtextstream.h> #include "ircservertab.h" IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { m_server = server; m_session = new IRCSession(&m_server); m_mainWindow = mainWindow; m_close = FALSE; + m_lines = 0; m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); m_textview = new QTextView(this); m_textview->setHScrollBarMode(QScrollView::AlwaysOff); m_textview->setVScrollBarMode(QScrollView::AlwaysOn); m_textview->setTextFormat(RichText); m_layout->add(m_textview); - m_field = new QLineEdit(this); + m_field = new IRCHistoryLineEdit(this); m_layout->add(m_field); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); m_field->setFocus(); connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); settingsChanged(); } void IRCServerTab::appendText(QString text) { /* not using append because it creates layout problems */ - m_textview->setText(m_textview->text() + text); + QString txt = m_textview->text() + text + "\n"; + if (m_maxLines > 0 && m_lines >= m_maxLines) { + int firstBreak = txt.find('\n'); + if (firstBreak != -1) { + txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); + } + } else { + m_lines++; + } + m_textview->setText(txt); m_textview->ensureVisible(0, m_textview->contentsHeight()); emit changed(this); } IRCServerTab::~IRCServerTab() { delete m_session; } void IRCServerTab::removeChannelTab(IRCChannelTab *tab) { m_channelTabs.remove(tab); } void IRCServerTab::removeQueryTab(IRCQueryTab *tab) { m_queryTabs.remove(tab); } void IRCServerTab::addQueryTab(IRCQueryTab *tab) { m_queryTabs.append(tab); } QString IRCServerTab::title() { return "Server"; } IRCSession *IRCServerTab::session() { return m_session; } IRCServer *IRCServerTab::server() { return &m_server; } void IRCServerTab::settingsChanged() { m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); + m_lines = 0; } void IRCServerTab::executeCommand(IRCTab *tab, QString line) { QTextIStream stream(&line); QString command; stream >> command; command = command.upper().right(command.length()-1); if (command == "JOIN") { QString channel; stream >> channel; if (channel.length() > 0 && (channel.startsWith("#") || channel.startsWith("+"))) { m_session->join(channel); } else { tab->appendText("<font color=\"" + m_errorColor + "\">Unknown channel format!</font><br>"); } } else if (command == "ME") { QString text = line.right(line.length()-4); if (text.length() > 0) { if (tab->isA("IRCChannelTab")) { tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); m_session->sendAction(((IRCChannelTab *)tab)->channel(), text); } else if (tab->isA("IRCQueryTab")) { tab->appendText("<font color=\"" + m_selfColor + "\">*" + IRCOutput::toHTML(m_server.nick()) + " " + IRCOutput::toHTML(text) + "</font><br>"); m_session->sendAction(((IRCQueryTab *)tab)->person(), text); } else { tab->appendText("<font color=\"" + m_errorColor + "\">Invalid tab for this command</font><br>"); } } } else if (command == "MSG") { QString nickname; stream >> nickname; if (nickname.length() > 0) { if (line.length() > 6 + nickname.length()) { QString text = line.right(line.length()-nickname.length()-6); IRCPerson person; person.setNick(nickname); tab->appendText("<font color=\"" + m_textColor + "\">></font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(nickname)+"</font><font color=\"" + m_textColor + "\">< "+IRCOutput::toHTML(text)+"</font><br>"); m_session->sendMessage(&person, text); } } } else { tab->appendText("<font color=\"" + m_errorColor + "\">Unknown command</font><br>"); } } void IRCServerTab::processCommand() { QString text = m_field->text(); diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h index 698689a..8d24cba 100644 --- a/noncore/net/opieirc/ircservertab.h +++ b/noncore/net/opieirc/ircservertab.h @@ -1,73 +1,75 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCSERVERTAB_H #define __IRCSERVERTAB_H #include "irctab.h" #include "ircsession.h" #include "mainwindow.h" #include "ircchanneltab.h" #include "ircquerytab.h" +#include "ircmisc.h" class IRCServerTab : public IRCTab { Q_OBJECT public: /* IRCTab implementation */ IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent = 0, const char *name = 0, WFlags f = 0); ~IRCServerTab(); QString title(); IRCSession *session(); IRCServer *server(); /* Start the server session */ void doConnect(); /* Remove tabs from the internal tab lists */ void removeChannelTab(IRCChannelTab *tab); void removeQueryTab(IRCQueryTab *tab); /* Return tabs from the internal tab lists */ IRCChannelTab *getTabForChannel(IRCChannel *channel); IRCQueryTab *getTabForQuery(IRCPerson *person); /* Add tabs to the internal tab lists */ void addQueryTab(IRCQueryTab *tab); /* Execute a user command such as /join, /msg etc */ void executeCommand(IRCTab *tab, QString line); protected: void appendText(QString text); public slots: void remove(); void processCommand(); void settingsChanged(); protected slots: void display(IRCOutput output); protected: + int m_lines; bool m_close; IRCServer m_server; IRCSession *m_session; MainWindow *m_mainWindow; QTextView *m_textview; - QLineEdit *m_field; + IRCHistoryLineEdit *m_field; /* Channel tabs associated with this server tab */ QList<IRCChannelTab> m_channelTabs; /* Query tabs associated with this server tab */ QList<IRCQueryTab> m_queryTabs; }; #endif /* __IRCSERVERTAB_H */ diff --git a/noncore/net/opieirc/ircsettings.cpp b/noncore/net/opieirc/ircsettings.cpp index d1fef67..1903e87 100644 --- a/noncore/net/opieirc/ircsettings.cpp +++ b/noncore/net/opieirc/ircsettings.cpp @@ -1,71 +1,95 @@ #include <qlayout.h> +#include <qvalidator.h> +#include <qscrollview.h> #include "ircsettings.h" #include "irctab.h" #include "ircmisc.h" -#include <stdio.h> IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags f) : QDialog(parent, name, modal, f) { + setCaption("Settings"); m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); - - setCaption("Settings"); - QGridLayout *layout = new QGridLayout(this, 7, 2, 5, 0); - QLabel *label = new QLabel(tr("Background color :"), this); + QHBoxLayout *l = new QHBoxLayout(this, 2, 2); + QTabWidget *tw = new QTabWidget(this); + l->addWidget(tw); + /* General Configuration */ + QWidget *widget = new QWidget(tw); + QGridLayout *layout = new QGridLayout(widget, 1, 2, 5, 0); + QLabel *label = new QLabel(tr("Lines displayed :"), widget); + layout->addWidget(label, 0, 0); + m_lines = new QLineEdit(m_config->readEntry("Lines", "100"), widget); + QIntValidator *validator = new QIntValidator(this); + validator->setTop(10000); + validator->setBottom(0); + m_lines->setValidator(validator); + layout->addWidget(m_lines, 0, 1); + tw->addTab(widget, tr("General")); + + /* Color configuration */ + QScrollView *view = new QScrollView(tw); + view->setResizePolicy(QScrollView::AutoOneFit); + widget = new QWidget(view->viewport()); + view->addChild(widget); + layout = new QGridLayout(widget, 7, 2, 5, 0); + label = new QLabel(tr("Background color :"), widget); layout->addWidget(label, 0, 0); - m_background = new IRCFramedColorLabel(QColor(m_config->readEntry("BackgroundColor", "#FFFFFF")), this); + m_background = new IRCFramedColorLabel(QColor(m_config->readEntry("BackgroundColor", "#FFFFFF")), widget); layout->addWidget(m_background, 0, 1); - label = new QLabel(tr("Normal text color :"), this); + label = new QLabel(tr("Normal text color :"), widget); layout->addWidget(label, 1, 0); - m_text = new IRCFramedColorLabel(m_config->readEntry("TextColor", "#000000"), this); + m_text = new IRCFramedColorLabel(m_config->readEntry("TextColor", "#000000"), widget); layout->addWidget(m_text, 1, 1); - label = new QLabel(tr("Error color :"), this); + label = new QLabel(tr("Error color :"), widget); layout->addWidget(label, 2, 0); - m_error = new IRCFramedColorLabel(m_config->readEntry("ErrorColor", "#FF0000"), this); + m_error = new IRCFramedColorLabel(m_config->readEntry("ErrorColor", "#FF0000"), widget); layout->addWidget(m_error, 2, 1); - label = new QLabel(tr("Text written by yourself :"), this); + label = new QLabel(tr("Text written by yourself :"), widget); layout->addWidget(label, 3, 0); - m_self = new IRCFramedColorLabel(m_config->readEntry("SelfColor", "#CC0000"), this); + m_self = new IRCFramedColorLabel(m_config->readEntry("SelfColor", "#CC0000"), widget); layout->addWidget(m_self, 3, 1); - label = new QLabel(tr("Text written by others :"), this); + label = new QLabel(tr("Text written by others :"), widget); layout->addWidget(label, 4, 0); - m_other = new IRCFramedColorLabel(m_config->readEntry("OtherColor", "#0000BB"), this); + m_other = new IRCFramedColorLabel(m_config->readEntry("OtherColor", "#0000BB"), widget); layout->addWidget(m_other, 4, 1); - label = new QLabel(tr("Text written by the server :"), this); + label = new QLabel(tr("Text written by the server :"), widget); layout->addWidget(label, 5, 0); - m_server = new IRCFramedColorLabel(m_config->readEntry("ServerColor", "#0000FF"), this); + m_server = new IRCFramedColorLabel(m_config->readEntry("ServerColor", "#0000FF"), widget); layout->addWidget(m_server, 5, 1); - label = new QLabel(tr("Notifications :"), this); + label = new QLabel(tr("Notifications :"), widget); layout->addWidget(label, 6, 0); - m_notification = new IRCFramedColorLabel(m_config->readEntry("NotificationColor", "#AAE300"), this); + m_notification = new IRCFramedColorLabel(m_config->readEntry("NotificationColor", "#AAE300"), widget); layout->addWidget(m_notification, 6, 1); + tw->addTab(view, tr("Colors")); showMaximized(); } QString IRCSettings::getColorString(QWidget *widget) { QColor color = ((IRCFramedColorLabel *)widget)->color(); QString temp; temp.sprintf("#%02x%02x%02x", color.red(), color.green(), color.blue()); return temp; } void IRCSettings::accept() { IRCTab::m_backgroundColor = getColorString(m_background); IRCTab::m_textColor = getColorString(m_text); IRCTab::m_errorColor = getColorString(m_error); IRCTab::m_selfColor = getColorString(m_self); IRCTab::m_otherColor = getColorString(m_other); IRCTab::m_serverColor = getColorString(m_server); IRCTab::m_notificationColor = getColorString(m_notification); + IRCTab::m_maxLines = m_lines->text().toInt(); m_config->writeEntry("BackgroundColor", getColorString(m_background)); m_config->writeEntry("TextColor", getColorString(m_text)); m_config->writeEntry("ErrorColor", getColorString(m_error)); m_config->writeEntry("SelfColor", getColorString(m_self)); m_config->writeEntry("OtherColor", getColorString(m_other)); m_config->writeEntry("ServerColor", getColorString(m_server)); m_config->writeEntry("NotificationColor", getColorString(m_notification)); + m_config->writeEntry("Lines", m_lines->text()); QDialog::accept(); } IRCSettings::~IRCSettings() { delete m_config; } diff --git a/noncore/net/opieirc/ircsettings.h b/noncore/net/opieirc/ircsettings.h index 1d3aeb7..190abaf 100644 --- a/noncore/net/opieirc/ircsettings.h +++ b/noncore/net/opieirc/ircsettings.h @@ -1,46 +1,48 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCSETTINGS_H #define __IRCSETTINGS_H #include <qpe/config.h> #include <qdialog.h> +#include <qlineedit.h> class IRCSettings : public QDialog { Q_OBJECT public: IRCSettings(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); QString getColorString(QWidget *widget); ~IRCSettings(); protected slots: void accept(); protected: - Config *m_config; - QWidget *m_background; - QWidget *m_text; - QWidget *m_error; - QWidget *m_self; - QWidget *m_server; - QWidget *m_other; - QWidget *m_notification; + Config *m_config; + QWidget *m_background; + QWidget *m_text; + QWidget *m_error; + QWidget *m_self; + QWidget *m_server; + QWidget *m_other; + QWidget *m_notification; + QLineEdit *m_lines; }; #endif /* __IRCSETTINGS_H */ diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp index a4dd7e2..0bb9d4c 100644 --- a/noncore/net/opieirc/irctab.cpp +++ b/noncore/net/opieirc/irctab.cpp @@ -1,36 +1,36 @@ #include <qpe/resource.h> #include <qpixmap.h> #include <qpushbutton.h> #include "irctab.h" QString IRCTab::m_errorColor; QString IRCTab::m_serverColor; QString IRCTab::m_textColor; QString IRCTab::m_backgroundColor; QString IRCTab::m_selfColor; QString IRCTab::m_otherColor; QString IRCTab::m_notificationColor; - +int IRCTab::m_maxLines; IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { m_layout = new QVBoxLayout(this); QHBoxLayout *descLayout = new QHBoxLayout(m_layout); descLayout->setMargin(5); m_description = new QLabel(tr("Missing description"), this); descLayout->addWidget(m_description); descLayout->setStretchFactor(m_description, 5); QPushButton *close = new QPushButton(this); close->setPixmap(Resource::loadPixmap("close")); connect(close, SIGNAL(clicked()), this, SLOT(remove())); descLayout->addWidget(close); descLayout->setStretchFactor(m_description, 1); } void IRCTab::setID(int id) { m_id = id; } int IRCTab::id() { return m_id; } diff --git a/noncore/net/opieirc/irctab.h b/noncore/net/opieirc/irctab.h index e3a1857..7a2d0a2 100644 --- a/noncore/net/opieirc/irctab.h +++ b/noncore/net/opieirc/irctab.h @@ -1,63 +1,66 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCTAB_H #define __IRCTAB_H #include <qwidget.h> #include <qtextview.h> #include <qlineedit.h> #include <qlabel.h> #include <qlayout.h> #include "ircsession.h" /* This is the base class for any tabs which need to be integrated into the main GUI tab widget */ class IRCTab : public QWidget { Q_OBJECT public: IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0); + /* The ID is required to store the position of this IRCTab inside the IRCTabWidget */ void setID(int id); int id(); virtual QString title() = 0; virtual IRCSession *session() = 0; virtual void appendText(QString text) = 0; signals: void changed(IRCTab *); public slots: virtual void remove() = 0; virtual void settingsChanged() = 0; protected: QLabel *m_description; QVBoxLayout *m_layout; int m_id; public: /* Configuration shared accross all instances - contains HTML style colors (#rrggbb) */ static QString m_errorColor; static QString m_serverColor; static QString m_textColor; static QString m_backgroundColor; static QString m_selfColor; static QString m_otherColor; static QString m_notificationColor; + /* Max number of lines to be displayed */ + static int m_maxLines; }; #endif /* __IRCTAB_H */ diff --git a/noncore/net/opieirc/ircversion.h b/noncore/net/opieirc/ircversion.h index f0f196e..ec6acfa 100644 --- a/noncore/net/opieirc/ircversion.h +++ b/noncore/net/opieirc/ircversion.h @@ -1,27 +1,27 @@ /* OpieIRC - An embedded IRC client Copyright (C) 2002 Wenzel Jakob 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. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCVERSION_H #define __IRCVERSION_H -#define APP_VERSION "OpieIRC 0.3" +#define APP_VERSION "OpieIRC 0.4" #define APP_COPYSTR "(c) 2002 by Wenzel Jakob" #endif /* __IRCVERSION_H */ diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index fe59c3b..bb03a1c 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -1,83 +1,84 @@ #include <qpe/qpemenubar.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpopupmenu.h> #include "mainwindow.h" #include "ircservertab.h" #include "ircserverlist.h" #include "ircsettings.h" MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { setCaption(tr("IRC Client")); m_tabWidget = new IRCTabWidget(this); connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *))); setCentralWidget(m_tabWidget); setToolBarsMovable(FALSE); QPEMenuBar *menuBar = new QPEMenuBar(this); QPopupMenu *irc = new QPopupMenu(this); menuBar->insertItem(tr("IRC"), irc); QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); connect(a, SIGNAL(activated()), this, SLOT(newConnection())); a->addTo(irc); a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); connect(a, SIGNAL(activated()), this, SLOT(settings())); a->addTo(irc); loadSettings(); } void MainWindow::loadSettings() { Config config("OpieIRC"); config.setGroup("OpieIRC"); IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); + IRCTab::m_maxLines = config.readNumEntry("Lines", 100); } void MainWindow::selected(QWidget *) { - m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), &black); + m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); } void MainWindow::addTab(IRCTab *tab) { connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *))); m_tabWidget->addTab(tab, tab->title()); m_tabWidget->showPage(tab); tab->setID(m_tabWidget->currentPageIndex()); m_tabs.append(tab); } void MainWindow::changeEvent(IRCTab *tab) { if (tab->id() != m_tabWidget->currentPageIndex()) - m_tabWidget->setTabColor(tab->id(), &blue); + m_tabWidget->setTabColor(tab->id(), blue); } void MainWindow::killTab(IRCTab *tab) { m_tabWidget->removePage(tab); m_tabs.remove(tab); /* there might be nicer ways to do this .. */ delete tab; } void MainWindow::newConnection() { IRCServerList list(this, "ServerList", TRUE); if (list.exec() == QDialog::Accepted && list.hasServer()) { IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); addTab(serverTab); serverTab->doConnect(); } } void MainWindow::settings() { IRCSettings settings(this, "Settings", TRUE); if (settings.exec() == QDialog::Accepted) { QListIterator<IRCTab> it(m_tabs); for (; it.current(); ++it) { /* Inform all tabs about the new settings */ it.current()->settingsChanged(); } } } diff --git a/noncore/net/opieirc/opie-irc.control b/noncore/net/opieirc/opie-irc.control index 9e93991..aada957 100644 --- a/noncore/net/opieirc/opie-irc.control +++ b/noncore/net/opieirc/opie-irc.control @@ -1,9 +1,8 @@ Files: bin/opieirc pics/opieirc apps/Applications/opieirc.desktop Priority: optional Section: Communications Maintainer: Wenzel Jakob <root@wazlaf.de> Architecture: arm Version: $QPE_VERSION-$SUB_VERSION Depends: opie-base ($QPE_VERSION) -Description: The Opie IRC client lets you chat on your favorite - IRC server using your zaurus or ipaq +Description: The Opie IRC client lets you chat on your favorite IRC server using your handheld computer |