Diffstat (limited to 'noncore/net/opieirc/ircoutput.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircoutput.cpp | 45 |
1 files changed, 40 insertions, 5 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,7 +1,17 @@ | |||
1 | #include <qtopia/stringutil.h> | ||
2 | |||
1 | #include "ircoutput.h" | 3 | #include "ircoutput.h" |
2 | 4 | ||
5 | |||
6 | IRCOutputEscapeSecuences IRCOutput::m_escapeSecuences[] = { | ||
7 | { '', "<b>", "</b>"}, | ||
8 | { '', "<u>", "</u>"}, | ||
9 | { 0, 0, 0}, | ||
10 | }; | ||
11 | |||
3 | IRCOutput::IRCOutput(IRCOutputType type, QString message) { | 12 | IRCOutput::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 | ||
@@ -14,12 +24,36 @@ QString IRCOutput::message() { | |||
14 | } | 24 | } |
15 | 25 | ||
26 | void IRCOutput::setType(IRCOutputType type) { | ||
27 | m_type = type; | ||
28 | } | ||
29 | |||
30 | void IRCOutput::setMessage(const QString &message) { | ||
31 | m_message = message; | ||
32 | } | ||
33 | |||
16 | QString IRCOutput::htmlMessage() { | 34 | QString IRCOutput::htmlMessage() { |
17 | return toHTML(m_message); | 35 | return toHTML(m_message); |
18 | } | 36 | } |
19 | 37 | ||
20 | QString IRCOutput::toHTML(QString message) { | 38 | QString IRCOutput::toHTML(const QString &message) { |
21 | QString htmlMessage =message.replace(QRegExp("&"), "&"); | 39 | QString htmlMessage = Qtopia::escapeString(message); |
22 | htmlMessage = htmlMessage.replace(QRegExp(">"), ">"); | 40 | |
23 | htmlMessage = htmlMessage.replace(QRegExp("<"), "<"); | 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 | } |
@@ -32,2 +66,3 @@ void *IRCOutput::getParam(int index) { | |||
32 | return m_parameters.at(index); | 66 | return m_parameters.at(index); |
33 | } | 67 | } |
68 | |||