summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircservertab.cpp
Unidiff
Diffstat (limited to 'noncore/net/opieirc/ircservertab.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircservertab.cpp25
1 files changed, 16 insertions, 9 deletions
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,19 +1,20 @@
1#include <qtextstream.h> 1#include <qtextstream.h>
2#include <qwhatsthis.h> 2#include <qwhatsthis.h>
3#include "ircservertab.h" 3#include "ircservertab.h"
4 4
5 5
6bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) { 6bool IRCServerTab::containsPing( const QString& text, IRCServerTab* tab ) {
7 return (text.find("ping") != -1 && text.find( tab->server()->nick() != -1)); 7 return (text.contains(IRCMessageParser::tr("Received a CTCP PING from "))) ||
8 (text.find("ping") != -1 && text.find( tab->server()->nick() != -1));
8} 9}
9 10
10 11
11IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { 12IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
12 m_server = server; 13 m_server = server;
13 m_session = new IRCSession(&m_server); 14 m_session = new IRCSession(&m_server);
14 m_mainWindow = mainWindow; 15 m_mainWindow = mainWindow;
15 m_close = FALSE; 16 m_close = FALSE;
16 m_lines = 0; 17 m_lines = 0;
17 m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>"); 18 m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>");
18 m_textview = new QTextView(this); 19 m_textview = new QTextView(this);
19 m_textview->setHScrollBarMode(QScrollView::AlwaysOff); 20 m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
@@ -21,38 +22,44 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa
21 m_textview->setTextFormat(RichText); 22 m_textview->setTextFormat(RichText);
22 QWhatsThis::add(m_textview, tr("Server messages")); 23 QWhatsThis::add(m_textview, tr("Server messages"));
23 m_layout->add(m_textview); 24 m_layout->add(m_textview);
24 m_field = new IRCHistoryLineEdit(this); 25 m_field = new IRCHistoryLineEdit(this);
25 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab())); 26 connect(m_field, SIGNAL(nextTab()), this, SIGNAL(nextTab()));
26 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab())); 27 connect(m_field, SIGNAL(prevTab()), this, SIGNAL(prevTab()));
27 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab())); 28 connect(m_field, SIGNAL(closeTab()), this, SIGNAL(closeTab()));
28 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus())); 29 connect(this, SIGNAL(editFocus()), m_field, SLOT(setEditFocus()));
29 30
30 QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help")); 31 QWhatsThis::add(m_field, tr("Type commands here. A list of available commands can be found inside the OpieIRC help"));
31 m_layout->add(m_field); 32 m_layout->add(m_field);
32 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); 33 connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
33 m_field->setFocus();
34 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput))); 34 connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
35 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling())); 35 connect(m_mainWindow, SIGNAL(updateScroll()), this, SLOT(scrolling()));
36 settingsChanged(); 36 settingsChanged();
37
38 m_field->setFocus();
39 m_field->setActiveWindow();
40
37} 41}
38 42
39void IRCServerTab::scrolling(){ 43void IRCServerTab::scrolling(){
40 m_textview->ensureVisible(0, m_textview->contentsHeight()); 44 m_textview->ensureVisible(0, m_textview->contentsHeight());
41} 45}
42 46
43 47
44void IRCServerTab::appendText(QString text) { 48void IRCServerTab::appendText(QString text) {
45 /* not using append because it creates layout problems */ 49 /* not using append because it creates layout problems */
46 QString txt = m_textview->text() + text + "\n"; 50 QString txt = m_textview->text() + IRCTab::appendTimestamp( text );
51
52
53
47 if (m_maxLines > 0 && m_lines >= m_maxLines) { 54 if (m_maxLines > 0 && m_lines >= m_maxLines) {
48 int firstBreak = txt.find('\n'); 55 int firstBreak = txt.find('\n');
49 if (firstBreak != -1) { 56 if (firstBreak != -1) {
50 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); 57 txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1));
51 } 58 }
52 } else { 59 } else {
53 m_lines++; 60 m_lines++;
54 } 61 }
55 m_textview->setText(txt); 62 m_textview->setText(txt);
56 m_textview->ensureVisible(0, m_textview->contentsHeight()); 63 m_textview->ensureVisible(0, m_textview->contentsHeight());
57 emit changed(this); 64 emit changed(this);
58} 65}
@@ -225,29 +232,29 @@ void IRCServerTab::doConnect() {
225} 232}
226 233
227void IRCServerTab::remove() { 234void IRCServerTab::remove() {
228 /* Close requested */ 235 /* Close requested */
229 if (m_session->isSessionActive()) { 236 if (m_session->isSessionActive()) {
230 /* While there is a running session */ 237 /* While there is a running session */
231 m_close = TRUE; 238 m_close = TRUE;
232 m_session->endSession(); 239 m_session->endSession();
233 } else { 240 } else {
234 /* Session has previously been closed */ 241 /* Session has previously been closed */
235 m_channelTabs.first(); 242 m_channelTabs.first();
236 while (m_channelTabs.current() != 0) { 243 while (m_channelTabs.current() != 0) {
237 m_mainWindow->killTab(m_channelTabs.current()); 244 m_mainWindow->killTab(m_channelTabs.current(), true);
238 } 245 }
239 m_queryTabs.first(); 246 m_queryTabs.first();
240 while (m_queryTabs.current() != 0) { 247 while (m_queryTabs.current() != 0) {
241 m_mainWindow->killTab(m_queryTabs.current()); 248 m_mainWindow->killTab(m_queryTabs.current(), true);
242 } 249 }
243 m_mainWindow->killTab(this); 250 m_mainWindow->killTab(this);
244 } 251 }
245} 252}
246 253
247IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) { 254IRCChannelTab *IRCServerTab::getTabForChannel(IRCChannel *channel) {
248 QListIterator<IRCChannelTab> it(m_channelTabs); 255 QListIterator<IRCChannelTab> it(m_channelTabs);
249 256
250 for (; it.current(); ++it) { 257 for (; it.current(); ++it) {
251 if (it.current()->channel() == channel) 258 if (it.current()->channel() == channel)
252 return it.current(); 259 return it.current();
253 } 260 }
@@ -263,29 +270,29 @@ IRCQueryTab *IRCServerTab::getTabForQuery(IRCPerson *person) {
263 } 270 }
264 return 0; 271 return 0;
265} 272}
266 273
267void IRCServerTab::display(IRCOutput output) { 274void IRCServerTab::display(IRCOutput output) {
268 275
269 /* All messages to be displayed inside the GUI get here */ 276 /* All messages to be displayed inside the GUI get here */
270 switch (output.type()) { 277 switch (output.type()) {
271 case OUTPUT_CONNCLOSE: 278 case OUTPUT_CONNCLOSE:
272 if (m_close) { 279 if (m_close) {
273 m_channelTabs.first(); 280 m_channelTabs.first();
274 while (m_channelTabs.current() != 0) { 281 while (m_channelTabs.current() != 0) {
275 m_mainWindow->killTab(m_channelTabs.current()); 282 m_mainWindow->killTab(m_channelTabs.current(), true);
276 } 283 }
277 m_queryTabs.first(); 284 m_queryTabs.first();
278 while (m_queryTabs.current() != 0) { 285 while (m_queryTabs.current() != 0) {
279 m_mainWindow->killTab(m_queryTabs.current()); 286 m_mainWindow->killTab(m_queryTabs.current(), true);
280 } 287 }
281 m_mainWindow->killTab(this); 288 m_mainWindow->killTab(this);
282 } else { 289 } else {
283 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>"); 290 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() +"</font><br>");
284 QListIterator<IRCChannelTab> it(m_channelTabs); 291 QListIterator<IRCChannelTab> it(m_channelTabs);
285 for (; it.current(); ++it) { 292 for (; it.current(); ++it) {
286 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>"); 293 it.current()->appendText("<font color=\"" + m_serverColor + "\">" + output.htmlMessage() +"</font><br>");
287 } 294 }
288 } 295 }
289 break; 296 break;
290 case OUTPUT_SELFJOIN: { 297 case OUTPUT_SELFJOIN: {
291 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 298 IRCChannelTab *channeltab = new IRCChannelTab((IRCChannel *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
@@ -303,32 +310,32 @@ void IRCServerTab::display(IRCOutput output) {
303 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0)); 310 IRCQueryTab *queryTab = getTabForQuery((IRCPerson *)output.getParam(0));
304 if (!queryTab) { 311 if (!queryTab) {
305 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent()); 312 queryTab = new IRCQueryTab((IRCPerson *)output.getParam(0), this, m_mainWindow, (QWidget *)parent());
306 m_queryTabs.append(queryTab); 313 m_queryTabs.append(queryTab);
307 m_mainWindow->addTab(queryTab); 314 m_mainWindow->addTab(queryTab);
308 } 315 }
309 queryTab->display(output); 316 queryTab->display(output);
310 } 317 }
311 break; 318 break;
312 case OUTPUT_SELFPART: { 319 case OUTPUT_SELFPART: {
313 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 320 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
314 if (channelTab) 321 if (channelTab)
315 m_mainWindow->killTab(channelTab); 322 m_mainWindow->killTab(channelTab, true);
316 } 323 }
317 break; 324 break;
318 case OUTPUT_SELFKICK: { 325 case OUTPUT_SELFKICK: {
319 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>"); 326 appendText("<font color=\"" + m_errorColor + "\">" + output.htmlMessage() + "</font><br>");
320 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 327 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
321 if (channelTab) 328 if (channelTab)
322 m_mainWindow->killTab(channelTab); 329 m_mainWindow->killTab(channelTab, true);
323 } 330 }
324 break; 331 break;
325 case OUTPUT_CHANACTION: { 332 case OUTPUT_CHANACTION: {
326 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0)); 333 IRCChannelTab *channelTab = getTabForChannel((IRCChannel *)output.getParam(0));
327 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>"); 334 channelTab->appendText("<font color=\"" + m_otherColor + "\">"+output.htmlMessage()+"</font><br>");
328 } 335 }
329 break; 336 break;
330 case OUTPUT_TOPIC: { 337 case OUTPUT_TOPIC: {
331 IRCChannel *channel = (IRCChannel *) output.getParam(0); 338 IRCChannel *channel = (IRCChannel *) output.getParam(0);
332 if (channel) { 339 if (channel) {
333 IRCChannelTab *channelTab = getTabForChannel(channel); 340 IRCChannelTab *channelTab = getTabForChannel(channel);
334 if (channelTab) { 341 if (channelTab) {