-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 16 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmessageparser.cpp | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 19 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 8 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 9 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 11 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.h | 2 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.cpp | 7 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.h | 10 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 37 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.h | 7 |
11 files changed, 124 insertions, 4 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp index 667e977..b6e3954 100644 --- a/noncore/net/opieirc/ircchanneltab.cpp +++ b/noncore/net/opieirc/ircchanneltab.cpp @@ -14,64 +14,80 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW 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); 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(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())); 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"; 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 ) { + 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("//")) { diff --git a/noncore/net/opieirc/ircmessageparser.cpp b/noncore/net/opieirc/ircmessageparser.cpp index 400ff41..90280d7 100644 --- a/noncore/net/opieirc/ircmessageparser.cpp +++ b/noncore/net/opieirc/ircmessageparser.cpp @@ -162,25 +162,25 @@ void IRCMessageParser::parseLiteralPart(IRCMessage *message) { 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() == message->param(0)) { + 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) == '+') { diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp index 6d93a34..df6f874 100644 --- a/noncore/net/opieirc/ircmisc.cpp +++ b/noncore/net/opieirc/ircmisc.cpp @@ -57,30 +57,43 @@ void IRCHistoryLineEdit::keyPressEvent(QKeyEvent *event) { } 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; - } else if (key == Key_Tab) { - odebug << "got tab" << oendl; + } else if (key == Key_N && event->state() == Qt::ControlButton) { + emit nextTab(); + return; + } else if ( ( key == Key_Y || key == Key_Z ) && event->state() == Qt::ControlButton) { + emit closeTab(); + return; + } else if (key == Key_P && event->state() == Qt::ControlButton) { + emit prevTab(); return; } + 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) { - odebug << "tab!" << oendl; + 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 b4a5b06..c42dcbd 100644 --- a/noncore/net/opieirc/ircmisc.h +++ b/noncore/net/opieirc/ircmisc.h @@ -52,20 +52,28 @@ protected: 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: 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 a113b04..1fddc6d 100644 --- a/noncore/net/opieirc/ircquerytab.cpp +++ b/noncore/net/opieirc/ircquerytab.cpp @@ -7,24 +7,29 @@ IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow 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())); + + 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(); } void IRCQueryTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); @@ -35,24 +40,28 @@ 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()) { diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp index d1aab40..2a34c0b 100644 --- a/noncore/net/opieirc/ircservertab.cpp +++ b/noncore/net/opieirc/ircservertab.cpp @@ -1,30 +1,41 @@ #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)); +} + + 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(); } void IRCServerTab::scrolling(){ m_textview->ensureVisible(0, m_textview->contentsHeight()); } diff --git a/noncore/net/opieirc/ircservertab.h b/noncore/net/opieirc/ircservertab.h index 48200d7..69543fc 100644 --- a/noncore/net/opieirc/ircservertab.h +++ b/noncore/net/opieirc/ircservertab.h @@ -24,24 +24,26 @@ #include <qpe/qcopenvelope_qws.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: + static bool containsPing(const QString& text, IRCServerTab *tab); + /* 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(); // QString *mynick(); /* Remove tabs from the internal tab lists */ void removeChannelTab(IRCChannelTab *tab); diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp index 3351c3b..8e1dc16 100644 --- a/noncore/net/opieirc/irctab.cpp +++ b/noncore/net/opieirc/irctab.cpp @@ -1,16 +1,17 @@ #include <qpe/resource.h> #include <qpushbutton.h> #include <qwhatsthis.h> #include "irctab.h" +#include "mainwindow.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); @@ -27,12 +28,18 @@ IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, na 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 7a2d0a2..6c29ea5 100644 --- a/noncore/net/opieirc/irctab.h +++ b/noncore/net/opieirc/irctab.h @@ -34,27 +34,37 @@ 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 *); + 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; diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index 0923a11..1143213 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -1,21 +1,26 @@ #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())); @@ -43,24 +48,29 @@ void MainWindow::loadSettings() { 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); 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) { @@ -80,12 +90,39 @@ void MainWindow::newConnection() { } 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 ) { + raise(); +} + diff --git a/noncore/net/opieirc/mainwindow.h b/noncore/net/opieirc/mainwindow.h index 0f60855..945fc71 100644 --- a/noncore/net/opieirc/mainwindow.h +++ b/noncore/net/opieirc/mainwindow.h @@ -27,27 +27,34 @@ #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); 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&); + protected: void loadSettings(); protected: IRCTabWidget *m_tabWidget; QList<IRCTab> m_tabs; }; #endif /* __MAINWINDOW_H */ |