summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircoutput.cpp45
-rw-r--r--noncore/net/opieirc/ircoutput.h19
2 files changed, 55 insertions, 9 deletions
diff --git a/noncore/net/opieirc/ircoutput.cpp b/noncore/net/opieirc/ircoutput.cpp
index 4822fc4..d2c730f 100644
--- a/noncore/net/opieirc/ircoutput.cpp
+++ b/noncore/net/opieirc/ircoutput.cpp
@@ -1,33 +1,68 @@
1#include <qtopia/stringutil.h>
2
1#include "ircoutput.h" 3#include "ircoutput.h"
2 4
5
6IRCOutputEscapeSecuences IRCOutput::m_escapeSecuences[] = {
7 { '', "<b>", "</b>"},
8 { '', "<u>", "</u>"},
9 { 0, 0, 0},
10};
11
3IRCOutput::IRCOutput(IRCOutputType type, QString message) { 12IRCOutput::IRCOutput(IRCOutputType type, QString message) {
4 m_type = type; 13 m_type = type;
5 m_message = message; 14 /* Filter color, bold and underline escape sequences, since they aren't implemented yet */
15 m_message = message.replace(QRegExp("[1-9]*,*[1-9]*"), "");
6} 16}
7 17
8IRCOutputType IRCOutput::type() { 18IRCOutputType IRCOutput::type() {
9 return m_type; 19 return m_type;
10} 20}
11 21
12QString IRCOutput::message() { 22QString IRCOutput::message() {
13 return m_message; 23 return m_message;
14} 24}
15 25
26void IRCOutput::setType(IRCOutputType type) {
27 m_type = type;
28}
29
30void IRCOutput::setMessage(const QString &message) {
31 m_message = message;
32}
33
16QString IRCOutput::htmlMessage() { 34QString IRCOutput::htmlMessage() {
17 return toHTML(m_message); 35 return toHTML(m_message);
18} 36}
19 37
20QString IRCOutput::toHTML(QString message) { 38QString IRCOutput::toHTML(const QString &message) {
21 QString htmlMessage =message.replace(QRegExp("&"), "&amp;"); 39 QString htmlMessage = Qtopia::escapeString(message);
22 htmlMessage = htmlMessage.replace(QRegExp(">"), "&gt;"); 40
23 htmlMessage = htmlMessage.replace(QRegExp("<"), "&lt;"); 41 for(int i=0; m_escapeSecuences[i].escape != 0;++i) {
42 int pos = 0;
43 bool isOpen = false;
44 while( (pos = htmlMessage.find(m_escapeSecuences[i].escape, pos)) != -1) {
45 htmlMessage.remove(pos, 1);
46 if(isOpen)
47 htmlMessage.insert(pos, m_escapeSecuences[i].close);
48 else
49 htmlMessage.insert(pos, m_escapeSecuences[i].open);
50
51 isOpen = !isOpen;
52 }
53 if(isOpen)
54 htmlMessage.append(m_escapeSecuences[i].close);
55 }
56
57 htmlMessage = htmlMessage.replace(QRegExp("\n"), "<br>");
24 return htmlMessage; 58 return htmlMessage;
25} 59}
26 60
27void IRCOutput::addParam(void *data) { 61void IRCOutput::addParam(void *data) {
28 m_parameters.append(data); 62 m_parameters.append(data);
29} 63}
30 64
31void *IRCOutput::getParam(int index) { 65void *IRCOutput::getParam(int index) {
32 return m_parameters.at(index); 66 return m_parameters.at(index);
33} 67}
68
diff --git a/noncore/net/opieirc/ircoutput.h b/noncore/net/opieirc/ircoutput.h
index 9c0b8bb..934dbda 100644
--- a/noncore/net/opieirc/ircoutput.h
+++ b/noncore/net/opieirc/ircoutput.h
@@ -1,75 +1,86 @@
1/* 1/*
2 OpieIRC - An embedded IRC client 2 OpieIRC - An embedded IRC client
3 Copyright (C) 2002 Wenzel Jakob 3 Copyright (C) 2002 Wenzel Jakob
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18
19*/ 19*/
20 20
21#ifndef __IRCOUTPUT_H 21#ifndef __IRCOUTPUT_H
22#define __IRCOUTPUT_H 22#define __IRCOUTPUT_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qlist.h> 25#include <qlist.h>
26#include "ircchannel.h" 26#include "ircchannel.h"
27 27
28/* Types of possible IRC output */ 28/* Types of possible IRC output */
29enum IRCOutputType { 29enum IRCOutputType {
30 OUTPUT_ERROR = -1, /* parameters : none */ 30 OUTPUT_ERROR = -1, /* parameters : none */
31 OUTPUT_SERVERMESSAGE = 0, /* parameters : none */ 31 OUTPUT_SERVERMESSAGE = 0, /* parameters : none */
32 OUTPUT_CLIENTMESSAGE = 1, /* parameters : none */ 32 OUTPUT_CLIENTMESSAGE = 1, /* parameters : none */
33 OUTPUT_CHANPRIVMSG = 2, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ 33 OUTPUT_CHANPRIVMSG = 2, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */
34 OUTPUT_QUERYPRIVMSG = 3, /* parameters : person (IRCPerson) */ 34 OUTPUT_QUERYPRIVMSG = 3, /* parameters : person (IRCPerson) */
35 OUTPUT_NICKCHANGE = 4, /* parameters : person (IRCPerson) */ 35 OUTPUT_NICKCHANGE = 4, /* parameters : person (IRCPerson) */
36 OUTPUT_SELFJOIN = 5, /* parameters : channel (IRCChannel) */ 36 OUTPUT_SELFJOIN = 5, /* parameters : channel (IRCChannel) */
37 OUTPUT_OTHERJOIN = 6, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ 37 OUTPUT_OTHERJOIN = 6, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */
38 OUTPUT_SELFPART = 7, /* parameters : channel (IRCChannel) */ 38 OUTPUT_SELFPART = 7, /* parameters : channel (IRCChannel) */
39 OUTPUT_OTHERPART = 8, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */ 39 OUTPUT_OTHERPART = 8, /* parameters : channel (IRCChannel), person (IRCChannelPerson) */
40 OUTPUT_QUIT = 9, /* parameters : person (IRCPerson) */ 40 OUTPUT_QUIT = 9, /* parameters : person (IRCPerson) */
41 OUTPUT_CONNCLOSE = 10, /* parameters : none */ 41 OUTPUT_CONNCLOSE = 10, /* parameters : none */
42 OUTPUT_CTCP = 11, /* parameters : none */ 42 OUTPUT_CTCP = 11, /* parameters : none */
43 OUTPUT_SELFKICK = 12, /* parameters : channel (IRCChannel) */ 43 OUTPUT_SELFKICK = 12, /* parameters : channel (IRCChannel) */
44 OUTPUT_OTHERKICK = 13, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ 44 OUTPUT_OTHERKICK = 13, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */
45 OUTPUT_CHANACTION = 14, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */ 45 OUTPUT_CHANACTION = 14, /* parameters : channel (IRCChannel) person (IRCChannelPerson) */
46 OUTPUT_QUERYACTION = 15, /* parameters : person (IRCPerson) */ 46 OUTPUT_QUERYACTION = 15, /* parameters : person (IRCPerson) */
47 OUTPUT_CHANPERSONMODE = 16, /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */ 47 OUTPUT_CHANPERSONMODE = 16, /* parameters : channel (IRCCHannel) person (IRCChannelPerson) */
48 OUTPUT_TOPIC = 17 /* parameters : channel (IRCChannel) */ 48 OUTPUT_TOPIC = 17, /* parameters : channel (IRCChannel) */
49 OUTPUT_TITLE = 18 /* parameters : channel (IRCChannel) */
50};
51
52typedef struct IRCOutputEscapeSecuences {
53 char escape;
54 char *open;
55 char *close;
49}; 56};
50 57
51/* The IRCOutput class is used as a kind of message which is sent by the 58/* The IRCOutput class is used as a kind of message which is sent by the
52 IRC parser to inform the GUI of changes. This could for example be a 59 IRC parser to inform the GUI of changes. This could for example be a
53 channel message or a nickname change */ 60 channel message or a nickname change */
54 61
55class IRCOutput { 62class IRCOutput {
56public: 63public:
57 IRCOutput(IRCOutputType type, QString message); 64 IRCOutput(IRCOutputType type = OUTPUT_SERVERMESSAGE, QString message = QString::null);
58 /* Used to add a parameter to this IRCOutput. Parameters are dependent 65 /* Used to add a parameter to this IRCOutput. Parameters are dependent
59 on which IRCOutputType we are using (see above) */ 66 on which IRCOutputType we are using (see above) */
60 void addParam(void *data); 67 void addParam(void *data);
61 68
62 IRCOutputType type(); 69 IRCOutputType type();
63 QString message(); 70 QString message();
64 /* Return the message with all HTML code escaped (for example &lt; instead of '<') */ 71 /* Return the message with all HTML code escaped (for example &lt; instead of '<') */
65 QString htmlMessage(); 72 QString htmlMessage();
66 73
67 static QString toHTML(QString message); 74 void setType(IRCOutputType);
75 void setMessage(const QString &message);
76
77 static QString toHTML(const QString &message);
68 void *getParam(int index); 78 void *getParam(int index);
69protected: 79protected:
70 IRCOutputType m_type; 80 IRCOutputType m_type;
71 QString m_message; 81 QString m_message;
72 QList<void> m_parameters; 82 QList<void> m_parameters;
83 static IRCOutputEscapeSecuences m_escapeSecuences[];
73}; 84};
74 85
75#endif 86#endif