Permalink
Browse files

Pimp My Code #3

  • Loading branch information...
1 parent b1ef8ea commit 7e4b431652c1288539bc01709d7f870c12e4d394 @senu committed Aug 17, 2008
View
@@ -12,6 +12,8 @@ ChatView * ChatViewFactory::createChatView(bool isGroupChat, QString jid,
HTMLThemeManager* themeManager,
IconServer* iconServer) {
+ Q_UNUSED(jid); //jid could be used to select jid-based theme.
+
bool useHTMLView;
if (isGroupChat) {
@@ -9,7 +9,6 @@ QString DefaultHTMLTextFormatter::format(const QString& input, const QDomNode& p
//remove /me from first text node
if(textNodeNumber_ == 0 && removeEmoteString_ && output.startsWith("/me ")) {
- qDebug() << "DOM transform: removed /me ";
output = output.mid(4);
}
@@ -23,16 +22,15 @@ QString DefaultHTMLTextFormatter::format(const QString& input, const QDomNode& p
output = TextUtil::legacyFormat(output);
}
- //TODO ? 14 it would be nice to have html template that handles highlighting
+ //TODO ? 14 it would be nice to have customizable highlighting
if (doHighlighting_) {
output = "<strong>" + output + "</strong>";
}
-// qDebug() << "!!! tf messageText1.5 0" << output;
-
if (!input.trimmed().isEmpty()) { //skip nodes that contains only whitespaces
textNodeNumber_++;
}
+
return output;
}
@@ -89,8 +89,16 @@ class DefaultHTMLTextFormatter : public HTMLTextFormatter {
protected:
bool doEmoticonify_;
bool doLinkify_;
+
+ /** 'Legacy Formtting' changes *txt* to </b>*txt*</b> */
bool doLegacyFormatting_;
bool doHighlighting_;
+
+ /**
+ * It should be true for HTMLChatView and false for PlainTextChatView.
+ *
+ * We use \<icon\> in PlainText ChatView and \<img src="icon://"\> in Webkit-based one.
+ */
bool useImgTagInEmoticonify_;
/** This property holds whether '/me' substring should be deleted from the first text node*/
View
@@ -7,10 +7,10 @@ QString EmoteChatEvent::getRightTemplateAndFillItWithData(const ChatTheme& theme
void EmoteChatEvent::setMessage(QString message) {
- _message = message;
+ message_ = message;
}
QString EmoteChatEvent::message() const {
- return _message;
+ return message_;
}
View
@@ -1,7 +1,6 @@
#ifndef _EMOTECHATEVENT_H
#define _EMOTECHATEVENT_H
-#include <Qt>
#include <QString>
#include "chattheme.h"
@@ -10,23 +9,21 @@
class ChatTheme;
class AstractChatEvent;
-
-/** Emote (/me is reading...) ChatEvent */
+/** Emote or Action Message (/me is reading...) ChatEvent */
class EmoteChatEvent : public ChatEvent, public UserChatData {
public:
- /** eg 'is reading' */
+
+ /** Emote message, for example 'is reading' */
QString message() const;
void setMessage(QString message);
+ //reimplemented
QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const;
private:
- QString _message;
- QString _nick;
- bool isLocal_;
+ QString message_;
};
#endif
-
View
@@ -7,16 +7,16 @@
EventView::EventView(QWidget* parent, IconServer* iconServer) : WebView(parent, iconServer) {
-
+
connect(page(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(onLinkClicked(const QUrl&)));
-
+
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadAndBindJS(bool)));
connect(&jsNotifier, SIGNAL(onAddToWhiteListRequested(const QString&)), SLOT(onAddToWhiteListRequested(const QString&)));
}
void EventView::displayText(const QString& xhtmlText) {
- QString xhtml("<html><body style=\"background-color:#008030\">%1</body></html>");
+ QString xhtml("<html><body>%1</body></html>");
setHtml(xhtml.arg(xhtmlText));
}
@@ -30,9 +30,10 @@ void EventView::onLinkClicked(const QUrl& url) {
emit openURL(url.toString());
}
+
void EventView::loadAndBindJS(bool ok) {
if (!ok) {
- qDebug() << "WARNING: EventView::onEmptyDocumentLoaded() - load failed"; //NOTE: see HTMLChatView note
+ qDebug() << "WARNING: EventView::onEmptyDocumentLoaded() - load failed"; //NOTE: see note in HTMLChatView.cpp
return;
}
View
@@ -8,16 +8,14 @@
/**
* Webkit-based event viewer (used in EventDlg).
*
- * It offers better XHTML(-IM) rendering.
- * It's a WebPage with disabled JavaScript
- * It also has icon:// URL support
+ * It offers better XHTML(-IM) rendering and has icon:// URL support
*/
class EventView : public WebView {
Q_OBJECT
public:
- /** IconServer will be used to display iconx:// */
+ /** IconServer will be used to display icon:// URLs */
EventView(QWidget* parent, IconServer* iconServer);
/**
@@ -1,15 +1,21 @@
#include "filetransferchatevent.h"
-FileTransferChatEvent::FileTransferChatEvent()
- :type(Initiated) {
-
+FileTransferChatEvent::FileTransferChatEvent() : type(Initiated) {
+
}
+
+
QString FileTransferChatEvent::fileName() const {
- return _fileName;
+ return fileName_;
}
void FileTransferChatEvent::setFileName(QString fileName) {
- _fileName = fileName;
+ fileName_ = fileName;
+}
+
+
+QString FileTransferChatEvent::getRightTemplateAndFillItWithData(const ChatTheme& theme) const {
+ return theme.createFileTransferEventPart(this);
}
@@ -1,17 +1,16 @@
#ifndef HAVE_FILE_TRANSFER_CHAT_EVENT
#define HAVE_FILE_TRANSFER_CHAT_EVENT
-#include <Qt>
#include <QString>
#include "chatevent.h"
#include "chattheme.h"
-class ChatTheme;
-class AstractChatEvent;
-
-
-/** FileTransfer (init/abort/finished) ChatEvent */
+/**
+ * FileTransfer ChatEvent
+ *
+ * Displayed when user receives/aborts File Transfer.
+ */
class FileTransferChatEvent : public ChatEvent {
public:
@@ -24,6 +23,11 @@ class FileTransferChatEvent : public ChatEvent {
Finished,
};
+ /**
+ * Constructor.
+ *
+ * type = Initiated.
+ */
FileTransferChatEvent();
/** Type of FileTransferEvent */
@@ -35,13 +39,11 @@ class FileTransferChatEvent : public ChatEvent {
/** Sets fileName */
void setFileName(QString fileName);
-
- QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const {
- return theme.createFileTransferEventPart(this);
- }
+ //reimplemented
+ QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const;
private:
- QString _fileName; //need accessors
+ QString fileName_;
};
#endif
View
@@ -4,7 +4,7 @@
#include <QDialog>
#include <QLineEdit>
-/** Dialog for text searching */
+/** Text searching dialog */
class FindDialog : public QDialog {
Q_OBJECT
View
@@ -11,8 +11,14 @@ HTMLChatPart::HTMLChatPart(const QString _content)
}
-QString HTMLChatPart::toString() {
- return content;
+HTMLChatPart::HTMLChatPart() {
+};
+
+
+QString HTMLChatPart::toString() const {
+// QString ret = content;
+// ret.replace("\\%", "%").replace("\\\\", "\\");
+ return ret;
}
@@ -27,7 +33,7 @@ void HTMLChatPart::replaceMessageBody(QString value) {
QString HTMLChatPart::escapeString(QString string) {
- return string.replace('"', "\"");
+ return string; //replace('\\', "\\\\").replace('%', "\\%");
}
@@ -41,12 +47,6 @@ void HTMLChatPart::replaceTimeKeyword(QString keyword, QDateTime time) {
}
-
-// These colors are used for coloring nicknames. I tried to use
-// colors both visible on light and dark background.
-// [it's Kopete color list]
-
-
void HTMLChatPart::replaceSenderColorKeyword(const QColor& userColor) {
QRegExp colorPattern("%senderColor(?:\\{([^}]*)\\})?%");
@@ -78,7 +78,7 @@ QString HTMLChatPart::formatTime(QString format, const QDateTime& time) {
QString HTMLChatPart::createShortTime(const QDateTime& time) {
- return time.toString("hh:mm");
+ return time.toString("hh:mm");
}
View
@@ -7,47 +7,49 @@
#include <QColor>
-/** Part (string) of HTMLChat document (eg. newly created message/event)
+/**
+ * Part (string) of HTMLChat document (eg. newly created message/event).
*
- * + method to escape and replace %keywords% with corresponding values
+ * Main methods: replaceAndEscapeKeyword(key, value), toString().
+ *
+ * Usage:
+ *
+ * HTMLChatPart part = fileTransferEventTemplate.createFreshHTMLPart();
+ * part.replaceAndEscapeKeyword("%status%", statusStr);
*/
class HTMLChatPart {
public:
-
- HTMLChatPart() {
- };
+ HTMLChatPart();
/** Creates HTMLChatPart with body = content*/
HTMLChatPart(const QString _content);
/** Replaces occurence of %keyword% with escaped value */
void replaceAndEscapeKeyword(QString keyword, QString value);
- /** Replaces occurence of %message% with escaped value;
- * We need this method because user input must be validated by CSS validator
- * written in JS.
+ /*
+ * "Replaces" occurence of %message% with escaped value;
+ *
+ * \param value is stored (messageBody()) and is replaced in JavaScript code after
+ * CSS validation/transformermation.
*/
- void replaceMessageBody(QString value);
-
- /** Replaces %keyword% with value */
- void replaceKeyword(QString keyword, QString value);
+ void replaceMessageBody(QString value);
/** Replaces time keyword %keyword{format}% with formatted time */
void replaceTimeKeyword(QString keyword, QDateTime time);
/** Replaces time keyword %senderColor% with color computed using userHash */
void replaceSenderColorKeyword(const QColor& userColor);
- /** Escapes string */
- static QString escapeString(QString string); //TODO 47 unused
-
- /** Creates "short time" string (%shortTime%) */
+ /** Creates 'short time' string (%shortTime%) */
static QString createShortTime(const QDateTime& time);
- /** Converts part to string */
- QString toString();
+ /**
+ * Converts part to string.
+ */
+ QString toString() const;
/** Returns value of %message% */
QString messageBody() const;
@@ -56,13 +58,15 @@ class HTMLChatPart {
/** Part body */
QString content;
- /** Message body (%message%) */
+ /** Message body (%message%) */
QString _messageBody;
/** Returns formated time, eg for %timeOpened{X}% */
QString formatTime(QString format, const QDateTime& time);
-
-
+
+ /** Escapes string (% escaping) */
+ QString escapeString(QString string); //TODO!!!
+
};
#endif
View
@@ -95,7 +95,7 @@ function psi_dfs(element) {
/** Replaces %message% keyword with CSS-validated messageBody */
function psi_setMessageBody(messagePart, messageBody) {
- return messagePart.replace("%message%", psi_validateCSS(messageBody));
+ return messagePart.replace(/%message%/g, psi_validateCSS(messageBody));
}
@@ -279,4 +279,4 @@ function psi_unban(url) {
catch(e) {
alert('Webkit JavaScript [unban] exception:' + e);
}
-}
+}
Oops, something went wrong.

0 comments on commit 7e4b431

Please sign in to comment.