Diffstat (limited to 'noncore/net/opieirc/ircoutput.cpp') (more/less context) (ignore 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,33 +1,68 @@ | |||
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 | ||
8 | IRCOutputType IRCOutput::type() { | 18 | IRCOutputType IRCOutput::type() { |
9 | return m_type; | 19 | return m_type; |
10 | } | 20 | } |
11 | 21 | ||
12 | QString IRCOutput::message() { | 22 | QString IRCOutput::message() { |
13 | return m_message; | 23 | return m_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 | } |
26 | 60 | ||
27 | void IRCOutput::addParam(void *data) { | 61 | void IRCOutput::addParam(void *data) { |
28 | m_parameters.append(data); | 62 | m_parameters.append(data); |
29 | } | 63 | } |
30 | 64 | ||
31 | void *IRCOutput::getParam(int index) { | 65 | void *IRCOutput::getParam(int index) { |
32 | return m_parameters.at(index); | 66 | return m_parameters.at(index); |
33 | } | 67 | } |
68 | |||