author | zecke <zecke> | 2004-09-08 21:51:06 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-08 21:51:06 (UTC) |
commit | ebb830522c9662bda4c4453e532bcc29631c5d60 (patch) (side-by-side diff) | |
tree | 5cf95975e91cb2db78be5cdf47c01a340109c1f4 | |
parent | f0fdb800d57e9a1d95ba593185e9462300539eea (diff) | |
download | opie-ebb830522c9662bda4c4453e532bcc29631c5d60.zip opie-ebb830522c9662bda4c4453e532bcc29631c5d60.tar.gz opie-ebb830522c9662bda4c4453e532bcc29631c5d60.tar.bz2 |
-Close Tab Keyboard Accelerator with delayed deletion of the tab
-Optionally add a TimeStamp to the Tab
-Remove not implemented CTCP actions from the Channel PopupMenu
-Give Focus to the Edit Line
-Some more ping handling
patch inspired and copied from zautrix fork
-rw-r--r-- | noncore/net/opieirc/.cvsignore | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 22 | ||||
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.h | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 34 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 5 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 9 | ||||
-rw-r--r-- | noncore/net/opieirc/ircserverlist.cpp | 9 | ||||
-rw-r--r-- | noncore/net/opieirc/ircserverlist.h | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 25 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.cpp | 18 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.h | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.cpp | 16 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.h | 4 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 32 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.h | 5 |
16 files changed, 152 insertions, 36 deletions
diff --git a/noncore/net/opieirc/.cvsignore b/noncore/net/opieirc/.cvsignore index d5423d6..0ccbade 100644 --- a/noncore/net/opieirc/.cvsignore +++ b/noncore/net/opieirc/.cvsignore @@ -1,4 +1,5 @@ Makefile Makefile.in moc_*.cpp .moc
\ No newline at end of file +*.gch
\ No newline at end of file diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index b6e3954..7610058 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp @@ -1,181 +1,189 @@ #include <qpe/resource.h> #include <qwhatsthis.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_listButton->setFlat( true ); m_textview->setCornerWidget(m_listButton); m_textview->setTextFormat(RichText); QWhatsThis::add(m_textview, tr("Channel discussion")); 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 IRCHistoryLineEdit(this); connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); - connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); + connect(m_field, SIGNAL(closeTab()), this, SLOT(remove())); connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); QWhatsThis::add(m_field, tr("Type your message here to participate in the channel discussion")); 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())); connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); m_layout->add(hbox); hbox->show(); m_layout->add(m_field); m_field->setFocus(); m_field->setActiveWindow(); connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); + connect(m_list, SIGNAL(doubleClicked ( QListBoxItem * ) ), this, SLOT(popupQuery( QListBoxItem * ) )); settingsChanged(); } void IRCChannelTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); } void IRCChannelTab::appendText(QString text) { /* not using append because it creates layout problems */ - QString txt = m_textview->text() + text + "\n"; + QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); 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->ensureVisible(0, m_textview->contentsHeight()); m_textview->setText(txt); m_textview->ensureVisible(0, m_textview->contentsHeight()); int p1, p2; - if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) { + if ( text.contains( IRCMessageParser::tr("Received a CTCP PING from ") ) ) + emit ping( title() ); + else if ( (p1 = text.find("ping", 0, false) )!= -1 && (p2 = text.find( m_parentTab->server()->nick(), 0,false )) != -1 ) { int col = text.findRev("color", -1, false); if ( col < p2 ) emit ping( title() ); } 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()); +void IRCChannelTab::popupQuery( QListBoxItem *item) { + if (item) { + IRCPerson *person = session()->getPerson(item->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::popupQuery() { + if ( m_list->currentItem() != -1 ) + popupQuery( m_list->item(m_list->currentItem())); +} + void IRCChannelTab::popupPing() { //HAHA, no wonder these don't work } void IRCChannelTab::popupVersion() { } void IRCChannelTab::popupWhois() { } QString IRCChannelTab::title() { return m_channel->channelname(); } IRCSession *IRCChannelTab::session() { return m_parentTab->session(); } void IRCChannelTab::remove() { if (session()->isSessionActive()) { session()->part(m_channel); } else { m_mainWindow->killTab(this); } } IRCChannel *IRCChannelTab::channel() { return m_channel; } IRCChannelList *IRCChannelTab::list() { return m_list; } diff --git a/noncore/net/opieirc/ircchanneltab.h b/noncore/net/opieirc/ircchanneltab.h index 001c96d..70b212c 100644 --- a/noncore/net/opieirc/ircchanneltab.h +++ b/noncore/net/opieirc/ircchanneltab.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 __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(); void scrolling(); protected slots: void processCommand(); void toggleList(); void mouseButtonPressed(int mouse, QListBoxItem *item, const QPoint &point); /* Popup slots */ + void popupQuery(QListBoxItem*); 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; 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 90280d7..ecc7e9a 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -94,384 +94,418 @@ void IRCMessageParser::parse(IRCMessage *message) { void IRCMessageParser::nullFunc(IRCMessage *) { /* Do nothing */ } void IRCMessageParser::parseLiteralPing(IRCMessage *message) { m_session->m_connection->sendLine("PONG " + message->allParameters()); } void IRCMessageParser::parseLiteralNotice(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); } void IRCMessageParser::parseLiteralJoin(IRCMessage *message) { QString channelName = message->param(0).lower(); IRCPerson mask(message->prefix()); IRCChannel *channel = m_session->getChannel(channelName); if (!channel) { /* We joined */ if (mask.nick() == m_session->m_server->nick()) { channel = new IRCChannel(channelName); m_session->addChannel(channel); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nonexistant channel join - desynchronized?"))); } } else { /* Someone else joined */ if (mask.nick() != m_session->m_server->nick()) { if (!channel->getPerson(mask.nick())) { IRCChannelPerson *chanperson = new IRCChannelPerson(); IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { person = new IRCPerson(message->prefix()); m_session->addPerson(person); } chanperson->flags = 0; chanperson->person = person; channel->addPerson(chanperson); IRCOutput output(OUTPUT_OTHERJOIN ,tr("%1 joined channel %2").arg( mask.nick() ).arg( channelName )); output.addParam(channel); output.addParam(chanperson); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Person has already joined the channel - desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("You already joined the channel - desynchronized?"))); } } } void IRCMessageParser::parseLiteralPart(IRCMessage *message) { QString channelName = message->param(0).lower(); IRCChannel *channel = m_session->getChannel(channelName); IRCPerson mask(message->prefix()); if (channel) { if (mask.nick() == m_session->m_server->nick()) { m_session->removeChannel(channel); IRCOutput output(OUTPUT_SELFPART, tr("You left channel %1").arg( channelName )); output.addParam(channel); emit outputReady(output); delete channel; } else { IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { channel->removePerson(person); IRCOutput output(OUTPUT_OTHERPART, tr("%1 left channel %2").arg( mask.nick() ).arg( channelName) ); output.addParam(channel); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Parting person not found - desynchronized?"))); } } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel for part not found - desynchronized?"))); } } void IRCMessageParser::parseLiteralPrivMsg(IRCMessage *message) { if (m_session->m_server->nick().lower() == message->param(0).lower() ) { /* IRC Query message detected, verify sender and display it */ IRCPerson mask(message->prefix()); IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { /* Person not yet known, create and add to the current session */ person = new IRCPerson(message->prefix()); m_session->addPerson(person); } IRCOutput output(OUTPUT_QUERYPRIVMSG, message->param(1)); output.addParam(person); emit outputReady(output); } else if (message->param(0).at(0) == '#' || message->param(0).at(0) == '+') { /* IRC Channel message detected, verify sender, channel and display it */ IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { IRCPerson mask(message->prefix()); IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_CHANPRIVMSG, message->param(1)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown sender"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Channel message with unknown channel %1").arg(message->param(0).lower()) )); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Received PRIVMSG of unknown type"))); } } void IRCMessageParser::parseLiteralNick(IRCMessage *message) { IRCPerson mask(message->prefix()); /* this way of handling nick changes really sucks */ if (mask.nick() == m_session->m_server->nick()) { /* We are changing our nickname */ m_session->m_server->setNick(message->param(0)); IRCOutput output(OUTPUT_NICKCHANGE, tr("You are now known as %1").arg( message->param(0))); output.addParam(0); emit outputReady(output); } else { /* Someone else is */ IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { //IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); /* new code starts here -- this removes the person from all channels */ QList<IRCChannel> channels; m_session->getChannelsByPerson(person, channels); QListIterator<IRCChannel> it(channels); for (;it.current(); ++it) { IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); it.current()->removePerson(chanperson); chanperson->person->setNick(message->param(0)); it.current()->addPerson(chanperson); IRCOutput output(OUTPUT_NICKCHANGE, tr("%1 is now known as %2").arg( mask.nick() ).arg( message->param(0))); output.addParam(person); emit outputReady(output); } /* new code ends here */ } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Nickname change of an unknown person"))); } } } void IRCMessageParser::parseLiteralQuit(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCPerson *person = m_session->getPerson(mask.nick()); if (person) { QList<IRCChannel> channels; m_session->getChannelsByPerson(person, channels); QListIterator<IRCChannel> it(channels); for (;it.current(); ++it) { IRCChannelPerson *chanperson = it.current()->getPerson(mask.nick()); it.current()->removePerson(chanperson); delete chanperson; } m_session->removePerson(person); IRCOutput output(OUTPUT_QUIT, tr("%1 has quit (%2)" ).arg( mask.nick() ).arg( message->param(0) )); output.addParam(person); emit outputReady(output); delete person; } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person quit - desynchronized?"))); } } void IRCMessageParser::parseLiteralTopic(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { IRCOutput output(OUTPUT_TOPIC, mask.nick() + tr(" changed topic to ") + "\"" + message->param(1) + "\""); output.addParam(channel); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel topic - desynchronized?"))); } } void IRCMessageParser::parseLiteralError(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_ERROR, message->allParameters())); } void IRCMessageParser::parseCTCPPing(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), "PING " + message->allParameters()); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP PING from ")+mask.nick())); + + //IRCPerson mask(message->prefix()); + QString dest = message->ctcpDestination(); + if (dest.startsWith("#")) { + IRCChannel *channel = m_session->getChannel(dest.lower()); + if (channel) { + IRCChannelPerson *person = channel->getPerson(mask.nick()); + if (person) { + IRCOutput output(OUTPUT_CHANACTION, tr("Received a CTCP PING from ")+ mask.nick()) ; + output.addParam(channel); + output.addParam(person); + emit outputReady(output); + } else { + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown person - Desynchronized?"))); + } + } else { + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with unknown channel - Desynchronized?"))); + } + } else { + if (message->ctcpDestination() == m_session->m_server->nick()) { + IRCPerson *person = m_session->getPerson(mask.nick()); + if (!person) { + /* Person not yet known, create and add to the current session */ + person = new IRCPerson(message->prefix()); + m_session->addPerson(person); + } + IRCOutput output(OUTPUT_QUERYACTION, tr("Received a CTCP PING from ")+ mask.nick() ); + output.addParam(person); + emit outputReady(output); + } else { + emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP PING with bad recipient"))); + } + } + } void IRCMessageParser::parseCTCPVersion(IRCMessage *message) { IRCPerson mask(message->prefix()); m_session->m_connection->sendCTCP(mask.nick(), APP_VERSION " " APP_COPYSTR); emit outputReady(IRCOutput(OUTPUT_CTCP, tr("Received a CTCP VERSION from ")+mask.nick())); } void IRCMessageParser::parseCTCPAction(IRCMessage *message) { IRCPerson mask(message->prefix()); QString dest = message->ctcpDestination(); if (dest.startsWith("#")) { IRCChannel *channel = m_session->getChannel(dest.lower()); if (channel) { IRCChannelPerson *person = channel->getPerson(mask.nick()); if (person) { IRCOutput output(OUTPUT_CHANACTION, "*" + mask.nick() + message->param(0)); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown person - Desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with unknown channel - Desynchronized?"))); } } else { if (message->ctcpDestination() == m_session->m_server->nick()) { IRCPerson *person = m_session->getPerson(mask.nick()); if (!person) { /* Person not yet known, create and add to the current session */ person = new IRCPerson(message->prefix()); m_session->addPerson(person); } IRCOutput output(OUTPUT_QUERYACTION, "*" + mask.nick() + message->param(0)); output.addParam(person); emit outputReady(output); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("CTCP ACTION with bad recipient"))); } } } void IRCMessageParser::parseLiteralMode(IRCMessage *message) { IRCPerson mask(message->prefix()); if (message->param(0).startsWith("#")) { IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { QString temp, parameters = message->allParameters().right(message->allParameters().length() - channel->channelname().length() - 1); QTextIStream stream(¶meters); bool set = FALSE; while (!stream.atEnd()) { stream >> temp; if (temp.startsWith("+")) { set = TRUE; temp = temp.right(1); } else if (temp.startsWith("-")) { set = FALSE; temp = temp.right(1); } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change has unknown type"))); return; } if (temp == "o") { stream >> temp; IRCChannelPerson *person = channel->getPerson(temp); if (person) { if (set) { person->flags |= PERSON_FLAG_OP; IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives channel operator status to " + person->person->nick())); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { person->flags &= 0xFFFF - PERSON_FLAG_OP; IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes channel operator status from " + person->person->nick())); output.addParam(channel); output.addParam(person); emit outputReady(output); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); } } else if (temp == "v") { stream >> temp; IRCChannelPerson *person = channel->getPerson(temp); if (person) { if (set) { person->flags |= PERSON_FLAG_VOICE; IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" gives voice to " + person->person->nick())); output.addParam(channel); output.addParam(person); emit outputReady(output); } else { person->flags &= 0xFFFF - PERSON_FLAG_VOICE; IRCOutput output(OUTPUT_CHANPERSONMODE, mask.nick() + tr(" removes voice from " + person->person->nick())); output.addParam(channel); output.addParam(person); emit outputReady(output); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown person - Desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown flag"))); } } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Mode change with unknown kannel - Desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("User modes not supported yet"))); } } void IRCMessageParser::parseLiteralKick(IRCMessage *message) { IRCPerson mask(message->prefix()); IRCChannel *channel = m_session->getChannel(message->param(0).lower()); if (channel) { IRCChannelPerson *person = channel->getPerson(message->param(1)); if (person) { if (person->person->nick() == m_session->m_server->nick()) { m_session->removeChannel(channel); IRCOutput output(OUTPUT_SELFKICK, tr("You were kicked from ") + channel->channelname() + tr(" by ") + mask.nick() + " (" + message->param(2) + ")"); output.addParam(channel); emit outputReady(output); } else { /* someone else got kicked */ channel->removePerson(person); IRCOutput output(OUTPUT_OTHERKICK, person->person->nick() + tr(" was kicked from ") + channel->channelname() + tr(" by ") + mask.nick()+ " (" + message->param(2) + ")"); output.addParam(channel); output.addParam(person); emit outputReady(output); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown person kick - desynchronized?"))); } } else { emit outputReady(IRCOutput(OUTPUT_ERROR, tr("Unknown channel kick - desynchronized?"))); } } void IRCMessageParser::parseNumerical001(IRCMessage *message) { /* Welcome to IRC message, display */ emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); } void IRCMessageParser::parseNumerical002(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); } void IRCMessageParser::parseNumerical003(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); } void IRCMessageParser::parseNumerical004(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); } void IRCMessageParser::parseNumerical005(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->allParameters())); } void IRCMessageParser::parseNumericalStats(IRCMessage *message) { emit outputReady(IRCOutput(OUTPUT_SERVERMESSAGE, message->param(1))); } void IRCMessageParser::parseNumericalNames(IRCMessage *message) { /* Name list sent when joining a channel */ IRCChannel *channel = m_session->getChannel(message->param(2).lower()); if (channel != 0) { QString people = message->param(3); QTextIStream stream(&people); QString temp; while (!stream.atEnd()) { stream >> temp; char flagch = temp.at(0).latin1(); int flag = 0; QString nick; /* Parse person flags */ if (flagch == '@' || flagch == '+' || flagch=='%' || flagch == '*') { nick = temp.right(temp.length()-1); switch (flagch) { case '@': flag = PERSON_FLAG_OP; break; case '+': flag = PERSON_FLAG_VOICE; break; case '%': flag = PERSON_FLAG_HALFOP; break; default : flag = 0; break; } diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp index 9b9bff8..6fc5ba0 100644 --- a/noncore/net/opieirc/ircmisc.cpp +++ b/noncore/net/opieirc/ircmisc.cpp @@ -1,133 +1,138 @@ #include "ircmisc.h" /* OPIE */ #include <opie2/odebug.h> #include <opie2/oconfig.h> #include <opie2/okeyconfigmanager.h> using namespace Opie::Core; IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) { } int IRCTabBar::insertTab(QTab *tab, int 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, 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(((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, QColor color) { ((IRCTabBar *)tabBar())->setTabColor(index, color); } static OKeyConfigManager* s_manager = 0; OKeyConfigManager* IRCHistoryLineEdit::keyConfigInstance() { if ( !s_manager ) { /* * black list with the DeviceButtons as default * because we do not grab the keyboard and they * wouldn't work */ OKeyPair::List blackList = OKeyPair::hardwareKeys(); blackList.append( OKeyPair::returnKey() ); blackList.append( OKeyPair::leftArrowKey() ); blackList.append( OKeyPair::upArrowKey() ); blackList.append( OKeyPair::downArrowKey() ); s_manager = new OKeyConfigManager(new OConfig("opieirc-keys"), "keys", blackList, false, 0, "irc_history_line_keyconfigm" ); s_manager->addKeyConfig( OKeyConfigItem( tr("Next Tab"), "next_tab", QPixmap(), KeyNextTab, OKeyPair(Qt::Key_N, Qt::ControlButton) )); s_manager->addKeyConfig( OKeyConfigItem( tr("Previous Tab"), "prev_tab", QPixmap(), KeyPrevTab, OKeyPair(Qt::Key_P, Qt::ControlButton) )); + s_manager->addKeyConfig( OKeyConfigItem( tr("Close Tab"), "close_tab", + QPixmap(), KeyCloseTab, + OKeyPair(Qt::Key_C, Qt::ControlButton) )); s_manager->load(); } return s_manager; } IRCHistoryLineEdit::IRCHistoryLineEdit(QWidget *parent, const char *name) : QLineEdit(parent, name) { m_index = -1; installEventFilter(this); } 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; } switch( keyConfigInstance()->handleKeyEventId( event ) ) { case KeyNextTab: emit nextTab(); return; case KeyPrevTab: emit prevTab(); return; + case KeyCloseTab: + emit closeTab(); default: break; } QLineEdit::keyPressEvent(event); } bool IRCHistoryLineEdit::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *k = (QKeyEvent *) event; /* Catch tab characters */ if (k->key() == Key_Tab) { emit nextTab(); return TRUE; } } return QLineEdit::eventFilter(object, event); } void IRCHistoryLineEdit::setEditFocus() { setActiveWindow(); setFocus(); } diff --git a/noncore/net/opieirc/ircmisc.h b/noncore/net/opieirc/ircmisc.h index 37eed28..3cf64df 100644 --- a/noncore/net/opieirc/ircmisc.h +++ b/noncore/net/opieirc/ircmisc.h @@ -1,93 +1,94 @@ /* 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 <qarray.h> namespace Opie { namespace Core { class OKeyConfigManager; } } /* 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, QColor color); }; class IRCTabBar : public QTabBar { Q_OBJECT public: IRCTabBar(QWidget *parent = 0, const char *name = 0); void setTabColor(int index, QColor color); protected: void paintLabel(QPainter*, const QRect&, QTab*, bool) const; int insertTab(QTab *, int index = -1); protected: QArray<QColor> m_colors; }; /* A QLineEdit with history functionality and tab completion */ class IRCHistoryLineEdit : public QLineEdit { Q_OBJECT public: enum KeyMode { KeyNextTab, - KeyPrevTab + KeyPrevTab, + KeyCloseTab }; static Opie::Core::OKeyConfigManager* keyConfigInstance(); IRCHistoryLineEdit(QWidget *parent = 0, const char *name = 0); virtual bool eventFilter(QObject *object, QEvent *event); public slots: void setEditFocus(); signals: void nextTab(); void prevTab(); void closeTab(); 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 1fddc6d..53474b9 100644 --- a/noncore/net/opieirc/ircquerytab.cpp +++ b/noncore/net/opieirc/ircquerytab.cpp @@ -1,112 +1,115 @@ #include <qhbox.h> #include <qwhatsthis.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); QWhatsThis::add(m_textview, tr("Private discussion")); m_field = new IRCHistoryLineEdit(this); + connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); - connect(m_field, SIGNAL(closeTab()),this, SIGNAL(closeTab())); - + connect(m_field, SIGNAL(closeTab()),this, SLOT(remove())); + connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); QWhatsThis::add(m_field, tr("Type your text here in order to send a message to the other person")); m_layout->add(hbox); hbox->show(); m_layout->add(m_field); - m_field->setFocus(); + connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); settingsChanged(); + m_field->setFocus(); + m_field->setActiveWindow(); } void IRCQueryTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); } void IRCQueryTab::appendText(QString text) { /* not using append because it creates layout problems */ 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()); if ( IRCServerTab::containsPing( text, m_parentTab ) ) emit ping( title() ); 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/ircserverlist.cpp b/noncore/net/opieirc/ircserverlist.cpp index 62bfc17..3e78469 100644 --- a/noncore/net/opieirc/ircserverlist.cpp +++ b/noncore/net/opieirc/ircserverlist.cpp @@ -1,161 +1,170 @@ #include "ircserverlist.h" #include "ircservereditor.h" /* OPIE */ #include <qpe/qpeapplication.h> /* QT */ #include <qlayout.h> #include <qlabel.h> #include <qhbox.h> #include <qpushbutton.h> #include <qwhatsthis.h> class IRCListBoxServer : public QListBoxText { public: IRCListBoxServer(IRCServer server) : QListBoxText(server.name()) { m_server = server; } IRCServer server() { return m_server; } void setServer(IRCServer server) { m_server = server; setText(m_server.name()); } protected: IRCServer m_server; }; IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { QVBoxLayout *layout = new QVBoxLayout(this, 5, 5); setCaption(tr("Serverlist Browser")); QLabel *label = new QLabel(tr("Please choose a server profile"), this); label->setAlignment(AlignHCenter); layout->addWidget(label); m_list = new QListBox(this); QWhatsThis::add(m_list, tr("Select a server profile from this list and then tap on OK in the upper-right corner")); layout->addWidget(m_list); QHBox *buttons = new QHBox(this); QPushButton *del = new QPushButton(tr("Delete"), buttons); QPushButton *edit = new QPushButton(tr("Edit"), buttons); QPushButton *add = new QPushButton(tr("Add"), buttons); QWhatsThis::add(del, tr("Delete the currently selected server profile")); QWhatsThis::add(edit, tr("Edit the currently selected server profile")); QWhatsThis::add(add, tr("Add a new server profile")); connect(del, SIGNAL(clicked()), this, SLOT(delServer())); connect(edit, SIGNAL(clicked()), this, SLOT(editServer())); connect(add, SIGNAL(clicked()), this, SLOT(addServer())); layout->addWidget(buttons); /* Load the configuration file */ m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); int count = m_config->readNumEntry("ServerCount", 0); if (count) { for (int i=0; i<count; i++) { m_config->setGroup("OpieIRC"); QString name = m_config->readEntry("Server"+QString::number(i)); if (name.length() > 0) { IRCServer server; m_config->setGroup(name); server.setName(name); server.setHostname(m_config->readEntry("Hostname")); server.setPort(m_config->readNumEntry("Port")); server.setUsername(m_config->readEntry("Username")); server.setPassword(m_config->readEntry("Password")); server.setNick(m_config->readEntry("Nick")); server.setRealname(m_config->readEntry("Realname")); server.setChannels(m_config->readEntry("Channels")); m_list->insertItem(new IRCListBoxServer(server)); } } } + connect(m_list, SIGNAL(doubleClicked(QListBoxItem*)), + this, SLOT(acceptOnClick(QListBoxItem *))); + connect(m_list, SIGNAL(returnPressed(QListBoxItem*)), + this, SLOT(acceptOnClick(QListBoxItem*))); + QPEApplication::showDialog( this ); } void IRCServerList::addServer() { IRCServer server; IRCServerEditor editor(server, this, "ServerEditor", TRUE); if (editor.exec() == QDialog::Accepted) { server = editor.getServer(); /* Gets deleted by QListBox, so this is ok */ m_list->insertItem(new IRCListBoxServer(server)); } } void IRCServerList::delServer() { int index = m_list->currentItem(); if (index != -1) { m_list->removeItem(index); } } void IRCServerList::editServer() { int index = m_list->currentItem(); if (index != -1) { IRCListBoxServer *item = (IRCListBoxServer *)m_list->item(index); IRCServer server = item->server(); IRCServerEditor editor(server, this, "ServerEditor", TRUE); if (editor.exec() == QDialog::Accepted) { server = editor.getServer(); item->setServer(server); } } } +void IRCServerList::acceptOnClick( QListBoxItem* ) { + accept(); +} + int IRCServerList::exec() { int returncode = QDialog::exec(); /* Now save the changes */ m_config->setGroup("OpieIRC"); m_config->writeEntry("ServerCount", QString::number(m_list->count())); for (unsigned int i=0; i<m_list->count(); i++) { IRCServer server = ((IRCListBoxServer *)m_list->item(i))->server(); m_config->setGroup("OpieIRC"); m_config->writeEntry("Server"+QString::number(i), server.name()); m_config->setGroup(server.name()); m_config->writeEntry("Hostname", server.hostname()); m_config->writeEntry("Port", QString::number(server.port())); m_config->writeEntry("Username", server.username()); m_config->writeEntry("Password", server.password()); m_config->writeEntry("Nick", server.nick()); m_config->writeEntry("Realname", server.realname()); m_config->writeEntry("Channels", server.channels()); } return returncode; } bool IRCServerList::hasServer() { return (m_list->currentItem() != -1); } IRCServer IRCServerList::server() { return ((IRCListBoxServer *)m_list->item(m_list->currentItem()))->server(); } IRCServerList::~IRCServerList() { delete m_config; } diff --git a/noncore/net/opieirc/ircserverlist.h b/noncore/net/opieirc/ircserverlist.h index d61210e..869b26f 100644 --- a/noncore/net/opieirc/ircserverlist.h +++ b/noncore/net/opieirc/ircserverlist.h @@ -1,50 +1,51 @@ /* 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 __IRCSERVERLIST_H #define __IRCSERVERLIST_H #include <qdialog.h> #include <qpe/config.h> #include <qlistbox.h> #include <qlist.h> #include "ircserver.h" class IRCServerList : public QDialog { Q_OBJECT public: IRCServerList(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); int exec(); /* Check whether a server was selected */ bool hasServer(); /* Return the selected server */ IRCServer server(); ~IRCServerList(); public slots: void addServer(); void delServer(); void editServer(); + void acceptOnClick(QListBoxItem*); protected: Config *m_config; QListBox *m_list; }; #endif /* __IRCSERVERLIST_H */ diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index 2a34c0b..5ca7a29 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,384 +1,391 @@ #include <qtextstream.h> #include <qwhatsthis.h> #include "ircservertab.h" bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { - return (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); + return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) || + (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); } 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); QWhatsThis::add(m_textview, tr("Server messages")); m_layout->add(m_textview); m_field = new IRCHistoryLineEdit(this); connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); 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))); connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); settingsChanged(); + + m_field->setFocus(); + m_field->setActiveWindow(); + } void IRCServerTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); } void IRCServerTab::appendText(QString text) { /* not using append because it creates layout problems */ - QString txt = m_textview->text() + text + "\n"; + QString txt = m_textview->text() + IRCTab::appendTimestamp( text ); + + + 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; } /* QString *IRCServerTab::mynick() { return (*m_server->nick()); } */ 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); //JOIN if (command == "JOIN" || command == "J") { 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>"); } } //KICK else if (command == "KICK"){ QString nickname; stream >> nickname; if (nickname.length() > 0) { if (line.length() > 7 + nickname.length()) { QString text = line.right(line.length()-nickname.length()-7); IRCPerson person; person.setNick(nickname); m_session->kick(((IRCChannelTab *)tab)->channel(), &person, text); } else { IRCPerson person; person.setNick(nickname); m_session->kick(((IRCChannelTab *)tab)->channel(), &person); } } } else if (command == "OP"){ QString nickname; stream >> nickname; if (nickname.length() > 0) { QString text = line.right(line.length()-nickname.length()-5); IRCPerson person; person.setNick(nickname); m_session->op(((IRCChannelTab *)tab)->channel(), &person); } } //SEND MODES else if (command == "MODE"){ QString text = line.right(line.length()-6); if (text.length() > 0) { m_session->mode(text); } else { tab->appendText("<font color=\"" + m_errorColor + "\">/mode channel {[+|-]|o|p|s|i|t|n|b|v} [limit] [user] [ban mask]<br>/mode nickname {[+|-]|i|w|s|o}</font><br>"); } } //SEND RAW MESSAGE TO SERVER, COMPLETELY UNCHECKED - anything in the RFC...or really anything you want else if (command == "RAW"){ QString text = line.right(line.length()-5); if (text.length() > 0) { m_session->raw(text); } } else if (command == "SUSPEND"){ QString text = line.right(line.length()-9); if (text.upper() == "ON") { QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } else if (text.upper() == "OFF"){ QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; } else { tab->appendText("<font color=\"" + m_errorColor + "\">Line: "+ line +"</font><br>Text: "+text); } } else if (command == "QUIT"){ QString text = line.right(line.length()-6); if (text.length() > 0) { m_session->quit(text); } else { m_session->quit(); } } //SEND ACTION 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>"); } } } //SEND PRIVMSG 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(); if (text.startsWith("/") && !text.startsWith("//")) { /* Command mode */ executeCommand(this, text); } m_field->clear(); } void IRCServerTab::doConnect() { m_session->beginSession(); } void IRCServerTab::remove() { /* Close requested */ if (m_session->isSessionActive()) { /* While there is a running session */ m_close = TRUE; m_session->endSession(); } else { /* Session has previously been closed */ m_channelTabs.first(); while (m_channelTabs.current() != 0) { - m_mainWindow->killTab(m_channelTabs.current()); + m_mainWindow->killTab(m_channelTabs.current(), true); } m_queryTabs.first(); while (m_queryTabs.current() != 0) { - m_mainWindow->killTab(m_queryTabs.current()); + m_mainWindow->killTab(m_queryTabs.current(), true); } m_mainWindow->killTab(this); } } IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { if (it.current()->channel() == channel) return it.current(); } return 0; } IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) { QListIterator<IRCQueryTab> it(m_queryTabs); for (; it.current(); ++it) { if (it.current()->person()->nick() == person->nick()) return it.current(); } return 0; } void IRCServerTab::display(IRCOutput output) { /* All messages to be displayed inside the GUI get here */ switch (output.type()) { case OUTPUT_CONNCLOSE: if (m_close) { m_channelTabs.first(); while (m_channelTabs.current() != 0) { - m_mainWindow->killTab(m_channelTabs.current()); + m_mainWindow->killTab(m_channelTabs.current(), true); } m_queryTabs.first(); while (m_queryTabs.current() != 0) { - m_mainWindow->killTab(m_queryTabs.current()); + m_mainWindow->killTab(m_queryTabs.current(), true); } m_mainWindow->killTab(this); } else { appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); } } break; case OUTPUT_SELFJOIN: { IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); m_channelTabs.append(channeltab); m_mainWindow->addTab(channeltab); } break; case OUTPUT_CHANPRIVMSG: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+IRCOutput::toHTML(((IRCChannelPerson *)output.getParam(1))->person->nick())+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage()+"</font><br>"); } break; case OUTPUT_QUERYACTION: case OUTPUT_QUERYPRIVMSG: { IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); if (!queryTab) { queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); m_queryTabs.append(queryTab); m_mainWindow->addTab(queryTab); } queryTab->display(output); } break; case OUTPUT_SELFPART: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); if (channelTab) - m_mainWindow->killTab(channelTab); + m_mainWindow->killTab(channelTab, true); } break; case OUTPUT_SELFKICK: { appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); if (channelTab) - m_mainWindow->killTab(channelTab); + m_mainWindow->killTab(channelTab, true); } break; case OUTPUT_CHANACTION: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); } break; case OUTPUT_TOPIC: { IRCChannel *channel = (IRCChannel *) output.getParam(0); if (channel) { IRCChannelTab *channelTab = getTabForChannel(channel); if (channelTab) { channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); return; } } appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); } break; case OUTPUT_QUIT: { QString nick = ((IRCPerson *)output.getParam(0))->nick(); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { if (it.current()->list()->hasPerson(nick)) { it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); it.current()->list()->update(); } } } break; /* case OUTPUT_NICKCHANGE: { //WAS HERE QString nick = ((IRCPerson *)output.getParam(0))->nick(); QListIterator<IRCChannelTab> it(m_channelTabs); for (; it.current(); ++it) { if (it.current()->list()->hasPerson(nick)) { it.current()->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); it.current()->list()->update(); } } } break; */ case OUTPUT_OTHERJOIN: case OUTPUT_OTHERKICK: case OUTPUT_CHANPERSONMODE: case OUTPUT_OTHERPART: { IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); channelTab->appendText("<font color=\"" + m_notificationColor + "\">"+output.htmlMessage()+"</font><br>"); channelTab->list()->update(); } break; case OUTPUT_CTCP: appendText("<font color=\"" + m_notificationColor + "\">" + output.htmlMessage() + "</font><br>"); break; case OUTPUT_ERROR: appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); break; default: appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() + "</font><br>"); break; } } diff --git a/noncore/net/opieirc/ircsettings.cpp b/noncore/net/opieirc/ircsettings.cpp index 1fba030..7a1dd6c 100644 --- a/noncore/net/opieirc/ircsettings.cpp +++ b/noncore/net/opieirc/ircsettings.cpp @@ -1,128 +1,144 @@ #include "ircsettings.h" #include "irctab.h" #include "ircmisc.h" /* OPIE */ #include <opie2/ocolorbutton.h> #include <opie2/otabwidget.h> #include <opie2/okeyconfigwidget.h> #include <qpe/qpeapplication.h> /* QT */ #include <qvalidator.h> #include <qwhatsthis.h> +#include <qcheckbox.h> using namespace Opie; using namespace Opie::Ui; IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { setCaption(tr("Settings") ); m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); QHBoxLayout *l = new QHBoxLayout(this, 2, 2); OTabWidget *tw = new OTabWidget(this); l->addWidget(tw); /* General Configuration */ QWidget *genwidget = new QWidget(tw); - QGridLayout *layout = new QGridLayout(genwidget, 1, 2, 5, 0); + QGridLayout *layout = new QGridLayout(genwidget, 1, 4, 5, 0); QLabel *label = new QLabel(tr("Lines displayed :"), genwidget); layout->addWidget(label, 0, 0); m_lines = new QLineEdit(m_config->readEntry("Lines", "100"), genwidget); QWhatsThis::add(m_lines, tr("Amount of lines to be displayed in chats before old lines get deleted - this is necessary to restrain memory consumption. Set to 0 if you don't need this")); QIntValidator *validator = new QIntValidator(this); validator->setTop(10000); validator->setBottom(0); m_lines->setValidator(validator); layout->addWidget(m_lines, 0, 1); + + /* + * include timestamp + */ + m_displayTime = new QCheckBox( tr("Display time in chat log"), genwidget ); + m_displayTime->setChecked( m_config->readBoolEntry("DisplayTime", false) ); + layout->addMultiCellWidget(m_displayTime, 1, 1, 0, 4 ); + + // add a spacer + layout->addItem( new QSpacerItem(1,1, QSizePolicy::Minimum, + QSizePolicy::MinimumExpanding), + 2, 0 ); + tw->addTab(genwidget, "opieirc/settings", tr("General")); /* Color configuration */ QScrollView *view = new QScrollView(this); view->setResizePolicy(QScrollView::AutoOneFit); view->setFrameStyle( QFrame::NoFrame ); QWidget *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 OColorButton(widget, m_config->readEntry("BackgroundColor", "#FFFFFF")); QWhatsThis::add(m_background, tr("Background color to be used in chats")); layout->addWidget(m_background, 0, 1); label = new QLabel(tr("Normal text color :"), widget); layout->addWidget(label, 1, 0); m_text = new OColorButton(widget, m_config->readEntry("TextColor", "#000000")); QWhatsThis::add(m_text, tr("Text color to be used in chats")); layout->addWidget(m_text, 1, 1); label = new QLabel(tr("Error color :"), widget); layout->addWidget(label, 2, 0); m_error = new OColorButton(widget, m_config->readEntry("ErrorColor", "#FF0000")); QWhatsThis::add(m_error, tr("Text color to be used to display errors")); layout->addWidget(m_error, 2, 1); label = new QLabel(tr("Text written by yourself :"), widget); layout->addWidget(label, 3, 0); m_self = new OColorButton(widget, m_config->readEntry("SelfColor", "#CC0000")); QWhatsThis::add(m_self, tr("Text color to be used to identify text written by yourself")); layout->addWidget(m_self, 3, 1); label = new QLabel(tr("Text written by others :"), widget); layout->addWidget(label, 4, 0); m_other = new OColorButton(widget, m_config->readEntry("OtherColor", "#0000BB")); QWhatsThis::add(m_other, tr("Text color to be used to identify text written by others")); layout->addWidget(m_other, 4, 1); label = new QLabel(tr("Text written by the server :"), widget); layout->addWidget(label, 5, 0); m_server = new OColorButton(widget, m_config->readEntry("ServerColor", "#0000FF")); QWhatsThis::add(m_server, tr("Text color to be used to identify text written by the server")); layout->addWidget(m_server, 5, 1); label = new QLabel(tr("Notifications :"), widget); layout->addWidget(label, 6, 0); m_notification = new OColorButton(widget, m_config->readEntry("NotificationColor", "#AAE300")); QWhatsThis::add(m_notification, tr("Text color to be used to display notifications")); layout->addWidget(m_notification, 6, 1); tw->addTab(view, "opieirc/colors", tr("Colors")); /* * IRC EditLine KeyConfiguration */ m_keyConf = new Opie::Ui::OKeyConfigWidget(tw, "KEyConfig GUI" ); m_keyConf->setChangeMode( OKeyConfigWidget::Queue ); m_keyConf->insert( tr("Keyboard Shortcuts"), IRCHistoryLineEdit::keyConfigInstance() ); m_keyConf->load(); tw->addTab(m_keyConf, "SettingsIcon", tr("Keyboard Shortcuts") ); tw->setCurrentTab( genwidget ); QPEApplication::showDialog( this ); } void IRCSettings::accept() { IRCTab::m_backgroundColor = m_background->color().name(); IRCTab::m_textColor = m_text->color().name(); IRCTab::m_errorColor = m_error->color().name(); IRCTab::m_selfColor = m_self->color().name(); IRCTab::m_otherColor = m_other->color().name(); IRCTab::m_serverColor = m_server->color().name(); IRCTab::m_notificationColor = m_notification->color().name(); IRCTab::m_maxLines = m_lines->text().toInt(); m_keyConf->save(); m_config->writeEntry("BackgroundColor", IRCTab::m_backgroundColor); m_config->writeEntry("TextColor", IRCTab::m_textColor); m_config->writeEntry("ErrorColor", IRCTab::m_errorColor); m_config->writeEntry("SelfColor", IRCTab::m_selfColor); m_config->writeEntry("OtherColor", IRCTab::m_otherColor); m_config->writeEntry("ServerColor", IRCTab::m_serverColor); m_config->writeEntry("NotificationColor", IRCTab::m_notificationColor); m_config->writeEntry("Lines", m_lines->text()); + m_config->writeEntry("DisplayTime", m_displayTime->isChecked() ); + IRCTab::setUseTimeStamps(m_displayTime->isChecked()); IRCHistoryLineEdit::keyConfigInstance()->save(); QDialog::accept(); } IRCSettings::~IRCSettings() { delete m_config; } diff --git a/noncore/net/opieirc/ircsettings.h b/noncore/net/opieirc/ircsettings.h index a032aff..b51d535 100644 --- a/noncore/net/opieirc/ircsettings.h +++ b/noncore/net/opieirc/ircsettings.h @@ -1,55 +1,57 @@ /* 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> namespace Opie { class OColorButton; namespace Ui { class OKeyConfigWidget; } } +class QCheckBox; class IRCSettings : public QDialog { Q_OBJECT public: IRCSettings(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); ~IRCSettings(); protected slots: void accept(); protected: Config *m_config; Opie::OColorButton *m_background; Opie::OColorButton *m_text; Opie::OColorButton *m_error; Opie::OColorButton *m_self; Opie::OColorButton *m_server; Opie::OColorButton *m_other; Opie::OColorButton *m_notification; Opie::Ui::OKeyConfigWidget *m_keyConf; QLineEdit *m_lines; + QCheckBox *m_displayTime; }; #endif /* __IRCSETTINGS_H */ diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp index 2b3ecd4..fbbf303 100644 --- a/noncore/net/opieirc/irctab.cpp +++ b/noncore/net/opieirc/irctab.cpp @@ -1,50 +1,66 @@ #include "irctab.h" #include "mainwindow.h" #include <opie2/okeyconfigmanager.h> #include <qpe/resource.h> #include <qpushbutton.h> #include <qwhatsthis.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; + +static bool g_useTime = false; + +void IRCTab::setUseTimeStamps( bool b ) { + g_useTime = b; +} + +// ## FIXME use TimeString later for AM/PM Setting +QString IRCTab::appendTimestamp( const QString& text ) { + return g_useTime ? + "[" +QTime::currentTime().toString()+"]" + text + "\n" : + text + "\n"; + +} + + 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); QWhatsThis::add(m_description, tr("Description of the tab's content")); descLayout->addWidget(m_description); descLayout->setStretchFactor(m_description, 5); QPushButton *close = new QPushButton(this); QWhatsThis::add(close, tr("Close this tab")); 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; } void IRCTab::showEvent( QShowEvent *ev ) { topLevelWidget()->setCaption( MainWindow::appCaption() + " " + title() ); QWidget::showEvent( ev ); emit editFocus(); } diff --git a/noncore/net/opieirc/irctab.h b/noncore/net/opieirc/irctab.h index 6c29ea5..d17c530 100644 --- a/noncore/net/opieirc/irctab.h +++ b/noncore/net/opieirc/irctab.h @@ -1,76 +1,80 @@ /* 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(); + + static void setUseTimeStamps(bool b); + static QString appendTimestamp(const QString& tex); + virtual QString title() = 0; virtual IRCSession *session() = 0; virtual void appendText(QString text) = 0; signals: void changed(IRCTab *); void ping(const QString& ); void nextTab(); void prevTab(); void closeTab(); void editFocus(); public slots: virtual void remove() = 0; virtual void settingsChanged() = 0; protected: void showEvent( QShowEvent* ); 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/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index 2e674c5..2562f33 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -1,129 +1,135 @@ #include <qmenubar.h> #include <qpe/resource.h> #include <qwhatsthis.h> #include "mainwindow.h" #include "ircservertab.h" #include "ircserverlist.h" #include "ircsettings.h" QString MainWindow::appCaption() { return QObject::tr("Opie IRC"); } MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { setCaption(tr("IRC Client")); m_tabWidget = new IRCTabWidget(this); QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); connect(m_tabWidget, SIGNAL(currentChanged(QWidget*)), this, SLOT(selected(QWidget*))); setCentralWidget(m_tabWidget); setToolBarsMovable(FALSE); QMenuBar *menuBar = new QMenuBar(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->setWhatsThis(tr("Create a new connection to an IRC server")); a->addTo(irc); a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); connect(a, SIGNAL(activated()), this, SLOT(settings())); a->addTo(irc); loadSettings(); } /*IRCTabWidget MainWindow::getTabWidget(){ return m_tabWidget; } */ 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); + IRCTab::setUseTimeStamps( config.readBoolEntry("DisplayTime", false ) ); } void MainWindow::selected(QWidget *) { m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); emit updateScroll(); } void MainWindow::addTab(IRCTab *tab) { connect(tab, SIGNAL(changed(IRCTab*)), this, SLOT(changeEvent(IRCTab*))); connect(tab, SIGNAL(ping (const QString&)), this, SLOT(slotPing(const QString&))); connect(tab, SIGNAL(nextTab()), this, SLOT(slotNextTab())); connect(tab, SIGNAL(prevTab()), this, SLOT(slotPrevTab())); - connect(tab, SIGNAL(closeTab()), this, SLOT(slotCloseTab())); 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); } -void MainWindow::killTab(IRCTab *tab) { - m_tabWidget->removePage(tab); - m_tabs.remove(tab); +void MainWindow::killTab(IRCTab *tab, bool imediate) { + m_toDelete.append( tab ); - /* there might be nicer ways to do this .. */ - delete tab; + if ( imediate ) + slotKillTabsLater(); + else + QTimer::singleShot(0, this, SLOT(slotKillTabsLater()) ); +} + +void MainWindow::slotKillTabsLater() { + for ( QListIterator<IRCTab> it(m_toDelete); it.current(); ++it ) { + m_tabWidget->removePage( it.current() ); + m_tabs.remove( it.current() ); + } + + m_toDelete.setAutoDelete( true ); + m_toDelete.clear(); + m_toDelete.setAutoDelete( false ); } 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(); } } } void MainWindow::slotNextTab() { int i = m_tabWidget->currentPageIndex (); m_tabWidget->setCurrentPage ( i+1 ); int j = m_tabWidget->currentPageIndex (); if ( i == j ) m_tabWidget->setCurrentPage ( 1 ); } void MainWindow::slotPrevTab() { int i = m_tabWidget->currentPageIndex (); if ( i > 1 ) m_tabWidget->setCurrentPage ( i-1 ); } -void MainWindow::slotCloseTab() { - IRCTab *tab = (IRCTab *) m_tabWidget->currentPage (); - if ( tab ) - killTab ( tab ); -} - -void MainWindow::slotPing( const QString& channel ) { +void MainWindow::slotPing( const QString& /*channel*/ ) { raise(); } diff --git a/noncore/net/opieirc/mainwindow.h b/noncore/net/opieirc/mainwindow.h index 945fc71..abf205d 100644 --- a/noncore/net/opieirc/mainwindow.h +++ b/noncore/net/opieirc/mainwindow.h @@ -1,60 +1,61 @@ /* 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 __MAINWINDOW_H #define __MAINWINDOW_H #include <qmainwindow.h> #include <qaction.h> #include <qlist.h> #include "mainwindow.h" #include "ircmisc.h" #include "irctab.h" class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0); // IRCTabWidget getTabWidget(); void addTab(IRCTab *tab); - void killTab(IRCTab *tab); + void killTab(IRCTab *tab, bool now = false); static QString appName() { return QString::fromLatin1("opieirc"); } static QString appCaption(); signals: void updateScroll(); protected slots: void newConnection(); void settings(); void selected(QWidget *); void changeEvent(IRCTab *); void slotNextTab(); void slotPrevTab(); - void slotCloseTab(); void slotPing(const QString&); + void slotKillTabsLater(); protected: void loadSettings(); protected: IRCTabWidget *m_tabWidget; QList<IRCTab> m_tabs; + QList<IRCTab> m_toDelete; }; #endif /* __MAINWINDOW_H */ |