Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Pimp My Code #3

  • Loading branch information...
commit 7e4b431652c1288539bc01709d7f870c12e4d394 1 parent b1ef8ea
Paweł Wiejacha authored
2  src/chatviewfactory.cpp
@@ -12,6 +12,8 @@ ChatView * ChatViewFactory::createChatView(bool isGroupChat, QString jid,
12 12
                                            HTMLThemeManager* themeManager,
13 13
                                            IconServer* iconServer) {
14 14
 
  15
+    Q_UNUSED(jid); //jid could be used to select jid-based theme.
  16
+
15 17
     bool useHTMLView;
16 18
     
17 19
     if (isGroupChat) {
6  src/defaulthtmltextformatter.cpp
@@ -9,7 +9,6 @@ QString DefaultHTMLTextFormatter::format(const QString& input, const QDomNode& p
9 9
     
10 10
     //remove /me from first text node
11 11
     if(textNodeNumber_ == 0 && removeEmoteString_ && output.startsWith("/me ")) {         
12  
-        qDebug() << "DOM transform: removed /me ";
13 12
         output = output.mid(4);
14 13
     }
15 14
 
@@ -23,16 +22,15 @@ QString DefaultHTMLTextFormatter::format(const QString& input, const QDomNode& p
23 22
         output = TextUtil::legacyFormat(output);
24 23
     }
25 24
 
26  
-    //TODO ? 14 it would be nice to have html template that handles highlighting
  25
+    //TODO ? 14 it would be nice to have customizable highlighting
27 26
     if (doHighlighting_) {
28 27
         output = "<strong>" + output + "</strong>";
29 28
     }
30 29
 
31  
-//    qDebug() << "!!! tf messageText1.5 0" << output;
32  
-
33 30
     if (!input.trimmed().isEmpty()) { //skip nodes that contains only whitespaces
34 31
         textNodeNumber_++;
35 32
     }
  33
+    
36 34
     return output;
37 35
 }
38 36
 
8  src/defaulthtmltextformatter.h
@@ -89,8 +89,16 @@ class DefaultHTMLTextFormatter : public HTMLTextFormatter {
89 89
 protected:
90 90
     bool doEmoticonify_;
91 91
     bool doLinkify_;
  92
+
  93
+    /** 'Legacy Formtting' changes *txt* to </b>*txt*</b> */
92 94
     bool doLegacyFormatting_;
93 95
     bool doHighlighting_;
  96
+
  97
+    /** 
  98
+     * It should be true for HTMLChatView and false for PlainTextChatView.
  99
+     * 
  100
+     * We use \<icon\> in PlainText ChatView and \<img src="icon://"\> in Webkit-based one.
  101
+     */
94 102
     bool useImgTagInEmoticonify_;
95 103
 
96 104
     /** This property holds whether '/me' substring should be deleted from the first text node*/
4  src/emotechatevent.cpp
@@ -7,10 +7,10 @@ QString EmoteChatEvent::getRightTemplateAndFillItWithData(const ChatTheme& theme
7 7
 
8 8
 
9 9
 void EmoteChatEvent::setMessage(QString message) {
10  
-    _message = message;
  10
+    message_ = message;
11 11
 }
12 12
 
13 13
 
14 14
 QString EmoteChatEvent::message() const {
15  
-    return _message;
  15
+    return message_;
16 16
 }
13  src/emotechatevent.h
... ...
@@ -1,7 +1,6 @@
1 1
 #ifndef _EMOTECHATEVENT_H
2 2
 #define	_EMOTECHATEVENT_H
3 3
 
4  
-#include <Qt>
5 4
 #include <QString>
6 5
 
7 6
 #include "chattheme.h"
@@ -10,23 +9,21 @@
10 9
 class ChatTheme;
11 10
 class AstractChatEvent;
12 11
 
13  
-
14  
-/** Emote (/me is reading...) ChatEvent */
  12
+/** Emote or Action Message (/me is reading...) ChatEvent */
15 13
 class EmoteChatEvent : public ChatEvent, public UserChatData {
16 14
 
17 15
 public:
18  
-    /** eg 'is reading' */
  16
+
  17
+    /** Emote message, for example 'is reading' */
19 18
     QString message() const;
20 19
     void setMessage(QString message);
21 20
 
  21
+    //reimplemented
22 22
     QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const;
23 23
 
24 24
 private:
25  
-    QString _message;
26  
-    QString _nick;
27  
-    bool isLocal_;
  25
+    QString message_;
28 26
 };
29 27
 
30 28
 
31 29
 #endif
32  
-
9  src/eventview.cpp
@@ -7,16 +7,16 @@
7 7
 
8 8
 
9 9
 EventView::EventView(QWidget* parent, IconServer* iconServer) : WebView(parent, iconServer) {
10  
-    
  10
+
11 11
     connect(page(), SIGNAL(linkClicked(const QUrl&)), this, SLOT(onLinkClicked(const QUrl&)));
12  
-    
  12
+
13 13
     connect(this, SIGNAL(loadFinished(bool)), this, SLOT(loadAndBindJS(bool)));
14 14
     connect(&jsNotifier, SIGNAL(onAddToWhiteListRequested(const QString&)), SLOT(onAddToWhiteListRequested(const QString&)));
15 15
 }
16 16
 
17 17
 
18 18
 void EventView::displayText(const QString& xhtmlText) {
19  
-    QString xhtml("<html><body style=\"background-color:#008030\">%1</body></html>");
  19
+    QString xhtml("<html><body>%1</body></html>");
20 20
     setHtml(xhtml.arg(xhtmlText));
21 21
 }
22 22
 
@@ -30,9 +30,10 @@ void EventView::onLinkClicked(const QUrl& url) {
30 30
     emit openURL(url.toString());
31 31
 }
32 32
 
  33
+
33 34
 void EventView::loadAndBindJS(bool ok) {
34 35
     if (!ok) {
35  
-        qDebug() << "WARNING: EventView::onEmptyDocumentLoaded() - load failed"; //NOTE: see HTMLChatView note
  36
+        qDebug() << "WARNING: EventView::onEmptyDocumentLoaded() - load failed"; //NOTE: see note in HTMLChatView.cpp
36 37
         return;
37 38
     }
38 39
 
6  src/eventview.h
@@ -8,16 +8,14 @@
8 8
 /**
9 9
  * Webkit-based event viewer (used in EventDlg).
10 10
  * 
11  
- * It offers better XHTML(-IM) rendering.
12  
- * It's a WebPage with disabled JavaScript
13  
- * It also has icon:// URL support
  11
+ * It offers better XHTML(-IM) rendering and has icon:// URL support
14 12
  */
15 13
 class EventView : public WebView {
16 14
 
17 15
     Q_OBJECT
18 16
 
19 17
 public:
20  
-    /** IconServer will be used to display iconx:// */
  18
+    /** IconServer will be used to display icon:// URLs */
21 19
     EventView(QWidget* parent, IconServer* iconServer);
22 20
 
23 21
     /** 
16  src/filetransferchatevent.cpp
... ...
@@ -1,15 +1,21 @@
1 1
 #include "filetransferchatevent.h"
2 2
 
3 3
 
4  
-FileTransferChatEvent::FileTransferChatEvent() 
5  
-    :type(Initiated) {
6  
-    
  4
+FileTransferChatEvent::FileTransferChatEvent() : type(Initiated) {
  5
+
7 6
 }
  7
+
  8
+
8 9
 QString FileTransferChatEvent::fileName() const {
9  
-    return _fileName;
  10
+    return fileName_;
10 11
 }
11 12
 
12 13
 
13 14
 void FileTransferChatEvent::setFileName(QString fileName) {
14  
-    _fileName = fileName;
  15
+    fileName_ = fileName;
  16
+}
  17
+
  18
+
  19
+QString FileTransferChatEvent::getRightTemplateAndFillItWithData(const ChatTheme& theme) const {
  20
+    return theme.createFileTransferEventPart(this);
15 21
 }
24  src/filetransferchatevent.h
... ...
@@ -1,17 +1,16 @@
1 1
 #ifndef HAVE_FILE_TRANSFER_CHAT_EVENT
2 2
 #define HAVE_FILE_TRANSFER_CHAT_EVENT
3 3
 
4  
-#include <Qt>
5 4
 #include <QString>
6 5
 
7 6
 #include "chatevent.h"
8 7
 #include "chattheme.h"
9 8
 
10  
-class ChatTheme;
11  
-class AstractChatEvent;
12  
-
13  
-
14  
-/** FileTransfer (init/abort/finished) ChatEvent */
  9
+/**
  10
+ * FileTransfer ChatEvent
  11
+ * 
  12
+ * Displayed when user receives/aborts File Transfer.  
  13
+ */
15 14
 class FileTransferChatEvent : public ChatEvent {
16 15
 
17 16
 public:
@@ -24,6 +23,11 @@ class FileTransferChatEvent : public ChatEvent {
24 23
         Finished,
25 24
     };
26 25
 
  26
+    /**
  27
+     * Constructor.
  28
+     *
  29
+     * type = Initiated.
  30
+     */
27 31
     FileTransferChatEvent();
28 32
 
29 33
     /** Type of FileTransferEvent */
@@ -35,13 +39,11 @@ class FileTransferChatEvent : public ChatEvent {
35 39
     /** Sets fileName */
36 40
     void setFileName(QString fileName);
37 41
 
38  
-
39  
-    QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const {
40  
-        return theme.createFileTransferEventPart(this);
41  
-    }
  42
+    //reimplemented
  43
+    QString getRightTemplateAndFillItWithData(const ChatTheme& theme) const;
42 44
 
43 45
 private:
44  
-    QString _fileName; //need accessors
  46
+    QString fileName_; 
45 47
 };
46 48
 
47 49
 #endif
2  src/finddialog.h
@@ -4,7 +4,7 @@
4 4
 #include <QDialog>
5 5
 #include <QLineEdit>
6 6
 
7  
-/** Dialog for text searching */
  7
+/** Text searching dialog */
8 8
 class FindDialog : public QDialog {
9 9
 
10 10
     Q_OBJECT
20  src/htmlchatpart.cpp
@@ -11,8 +11,14 @@ HTMLChatPart::HTMLChatPart(const QString _content)
11 11
 }
12 12
 
13 13
 
14  
-QString HTMLChatPart::toString() {
15  
-    return content;
  14
+HTMLChatPart::HTMLChatPart() {
  15
+};
  16
+
  17
+
  18
+QString HTMLChatPart::toString() const {
  19
+//    QString ret = content;
  20
+//    ret.replace("\\%", "%").replace("\\\\", "\\");
  21
+    return ret;
16 22
 }
17 23
 
18 24
 
@@ -27,7 +33,7 @@ void HTMLChatPart::replaceMessageBody(QString value) {
27 33
 
28 34
 
29 35
 QString HTMLChatPart::escapeString(QString string) {
30  
-    return string.replace('"', "\"");
  36
+    return string; //replace('\\', "\\\\").replace('%', "\\%");
31 37
 }
32 38
 
33 39
 
@@ -41,12 +47,6 @@ void HTMLChatPart::replaceTimeKeyword(QString keyword, QDateTime time) {
41 47
 }
42 48
 
43 49
 
44  
-
45  
-// These colors are used for coloring nicknames. I tried to use
46  
-// colors both visible on light and dark background.
47  
-// [it's Kopete color list]
48  
-
49  
-
50 50
 void HTMLChatPart::replaceSenderColorKeyword(const QColor& userColor) {
51 51
 
52 52
     QRegExp colorPattern("%senderColor(?:\\{([^}]*)\\})?%");
@@ -78,7 +78,7 @@ QString HTMLChatPart::formatTime(QString format, const QDateTime& time) {
78 78
 
79 79
 
80 80
 QString HTMLChatPart::createShortTime(const QDateTime& time) {
81  
-	return time.toString("hh:mm");
  81
+    return time.toString("hh:mm");
82 82
 }
83 83
 
84 84
 
46  src/htmlchatpart.h
@@ -7,17 +7,21 @@
7 7
 #include <QColor> 
8 8
 
9 9
 
10  
-/** Part (string) of HTMLChat document (eg. newly created message/event)
  10
+/** 
  11
+ * Part (string) of HTMLChat document (eg. newly created message/event).
11 12
  *
12  
- * 	+ method to escape and replace %keywords% with corresponding values
  13
+ * Main methods: replaceAndEscapeKeyword(key, value), toString().
  14
+ *
  15
+ *  Usage:
  16
+ *
  17
+ *   HTMLChatPart part = fileTransferEventTemplate.createFreshHTMLPart();
  18
+ *   part.replaceAndEscapeKeyword("%status%", statusStr);
13 19
  */
14 20
 class HTMLChatPart {
15 21
 
16 22
 public:
17 23
 
18  
-
19  
-    HTMLChatPart() {
20  
-    };
  24
+    HTMLChatPart();
21 25
 
22 26
     /** Creates HTMLChatPart with body = content*/
23 27
     HTMLChatPart(const QString _content);
@@ -25,14 +29,13 @@ class HTMLChatPart {
25 29
     /** Replaces occurence of %keyword% with escaped value */
26 30
     void replaceAndEscapeKeyword(QString keyword, QString value);
27 31
 
28  
-    /** Replaces occurence of %message% with escaped value;
29  
-     *  We need this method because user input must be validated by CSS validator  
30  
-     *  written in JS.
  32
+    /* 
  33
+     * "Replaces" occurence of %message% with escaped value;
  34
+     *
  35
+     * \param value is stored (messageBody()) and is replaced in JavaScript code after 
  36
+     * CSS validation/transformermation.
31 37
      */
32  
-    void replaceMessageBody(QString value); 
33  
-
34  
-    /** Replaces %keyword% with value */
35  
-    void replaceKeyword(QString keyword, QString value);
  38
+    void replaceMessageBody(QString value);
36 39
 
37 40
     /** Replaces time keyword %keyword{format}% with formatted time */
38 41
     void replaceTimeKeyword(QString keyword, QDateTime time);
@@ -40,14 +43,13 @@ class HTMLChatPart {
40 43
     /** Replaces time keyword %senderColor% with color computed using userHash */
41 44
     void replaceSenderColorKeyword(const QColor& userColor);
42 45
 
43  
-    /** Escapes string */
44  
-    static QString escapeString(QString string); //TODO 47 unused
45  
-
46  
-    /** Creates "short time" string (%shortTime%) */
  46
+    /** Creates 'short time' string (%shortTime%) */
47 47
     static QString createShortTime(const QDateTime& time);
48 48
 
49  
-    /** Converts part to string */
50  
-    QString toString();
  49
+    /** 
  50
+     * Converts part to string.
  51
+     */
  52
+    QString toString() const;
51 53
 
52 54
     /** Returns value of %message% */
53 55
     QString messageBody() const;
@@ -56,13 +58,15 @@ class HTMLChatPart {
56 58
     /** Part body */
57 59
     QString content;
58 60
 
59  
-    /** Message body (%message%) */ 
  61
+    /** Message body (%message%) */
60 62
     QString _messageBody;
61 63
 
62 64
     /** Returns formated time, eg for %timeOpened{X}% */
63 65
     QString formatTime(QString format, const QDateTime& time);
64  
-
65  
-
  66
+    
  67
+    /** Escapes string (% escaping) */ 
  68
+    QString escapeString(QString string); //TODO!!!
  69
+    
66 70
 };
67 71
 
68 72
 #endif
4  src/htmlchatview.js
@@ -95,7 +95,7 @@ function psi_dfs(element) {
95 95
 
96 96
 /** Replaces %message% keyword with CSS-validated messageBody */
97 97
 function psi_setMessageBody(messagePart, messageBody) {
98  
-    return messagePart.replace("%message%", psi_validateCSS(messageBody));
  98
+    return messagePart.replace(/%message%/g, psi_validateCSS(messageBody));
99 99
 }
100 100
 
101 101
 
@@ -279,4 +279,4 @@ function psi_unban(url) {
279 279
     catch(e) {
280 280
         alert('Webkit JavaScript [unban] exception:' + e);
281 281
     }
282  
-}
  282
+}
12  src/htmltextformatter.h
@@ -7,7 +7,13 @@
7 7
 
8 8
 /**
9 9
  * Abstract TextFormatter is used when MessageValidator encounters text node in DOM tree.
10  
- * You can iconify/linkify/etc message body here .
  10
+ *
  11
+ * You can iconify, linkify, etc. message body here.
  12
+ *
  13
+ * Everytime MessageValidator encounters text node T it wil replace T with ::format(T).
  14
+ *
  15
+ * TextFormatter and MessageValidator can be easily modified to format other DOM nodes, 
  16
+ * for example, formatNode(<p>text</p>) = [text, <br/>]
11 17
  */
12 18
 class HTMLTextFormatter {
13 19
 
@@ -15,11 +21,11 @@ class HTMLTextFormatter {
15 21
 
16 22
 
17 23
     /**
18  
-     * Formats xhtml-im text node and return formated xml fragment (QString)
  24
+     * Formats XHTML-IM text node and returns formated xml fragment (QString).
19 25
      *
20 26
      * formats \param input which is a text child of \param parenteElement 
21 27
      * 
22  
-     * Some may wonder why QString is returned (eg. "<b>text</b>") not QDomNode, 
  28
+     * Some may wonder why QString is returned (eg. "<b>text</b>") instead of QDomNodeList - 
23 29
      * it's a long story (performance issues, missing spaces, unclean code).
24 30
      */
25 31
     virtual QString format(const QString& input, const QDomNode& parentElement) = 0;
24  src/htmlthememanager.cpp
@@ -2,43 +2,43 @@
2 2
 #include "applicationinfo.h"
3 3
 
4 4
 
5  
-HTMLThemeManager::HTMLThemeManager(const QString& themesDir_) : themesDir(themesDir_){
  5
+HTMLThemeManager::HTMLThemeManager(const QString& themesDir_) : themesDir(themesDir_) {
6 6
 
7  
-    _themeList = new HTMLChatThemeList();
8  
-    _themeList->readThemes(QDir(themesDir));
  7
+    themeList_ = new HTMLChatThemeList();
  8
+    themeList_->readThemes(QDir(themesDir));
9 9
 }
10 10
 
11 11
 
12 12
 HTMLThemeManager::~HTMLThemeManager() {
13  
-    delete _themeList;
  13
+    delete themeList_;
14 14
 }
15 15
 
16 16
 
17 17
 const HTMLChatThemeList* HTMLThemeManager::themeList() const {
18  
-    return _themeList;
  18
+    return themeList_;
19 19
 }
20 20
 
21 21
 
22 22
 HTMLChatTheme HTMLThemeManager::getTheme(const QString& themeName, const QString& variant) {
23 23
 
24  
-    QString path = _themeList->themePath(themeName);
  24
+    QString path = themeList_->themePath(themeName);
25 25
 
26  
-    if (path.isEmpty()) { //theme not found, but filesystem could be changed since last check
27  
-        _themeList->readThemes(QDir(themesDir));
28  
-        path = _themeList->themePath(themeName);
  26
+    if (path.isEmpty()) { //theme not found, but filesystem could have been changed since last check
  27
+        themeList_->readThemes(QDir(themesDir));
  28
+        path = themeList_->themePath(themeName);
29 29
     }
30 30
 
31 31
     if (!path.isEmpty()) { //theme found
32 32
         QPair<QString, QString> key(path, variant);
33 33
 
34  
-        if (_themeCache.contains(key)) {
35  
-            return _themeCache[key];
  34
+        if (themeCache.contains(key)) {
  35
+            return themeCache[key];
36 36
         }
37 37
 
38 38
         //cache miss
39 39
         HTMLChatTheme theme(path);
40 40
         theme.setCurrentVariant(variant);
41  
-        _themeCache.insert(key, theme);
  41
+        themeCache.insert(key, theme);
42 42
         return theme;
43 43
     }
44 44
 
22  src/htmlthememanager.h
@@ -9,34 +9,40 @@
9 9
 #include "htmlchattheme.h"
10 10
 
11 11
 
12  
-/** Keeps HTML theme list, and caches loaded themes */
  12
+/**
  13
+ * Stores HTMLThemeList and caches loaded (from filesystem) themes.
  14
+ */
13 15
 class HTMLThemeManager {
14 16
 
15 17
 public:
16 18
     /**
17  
-     * Fils theme list with themes located in themesDir dir. 
  19
+     * Fills the theme list with themes located in themesDir dir. 
18 20
      */
19 21
     HTMLThemeManager(const QString& themesDir);
20 22
     ~HTMLThemeManager();
21 23
 
22  
-    /** Returns theme list. Used in PsiOptions */
  24
+    /** 
  25
+     * Returns theme list. 
  26
+     * 
  27
+     * It is used in PsiOptions 
  28
+     */
23 29
     const HTMLChatThemeList* themeList() const;
24 30
 
25 31
     /** 
26 32
      * Returns theme and loads it from filesystem if needed.
27  
-     * use theme.isValid() after this call
  33
+     *
  34
+     * Use theme.isValid() after this call.
28 35
      */
29 36
     HTMLChatTheme getTheme(const QString& themeName, const QString& variant);
  37
+    
30 38
 private:
31  
-    HTMLChatThemeList * _themeList;
  39
+    HTMLChatThemeList * themeList_;
32 40
 
33 41
     /** Loaded themes [(path,variant) -> theme] */
34  
-    QHash< QPair<QString, QString>, HTMLChatTheme> _themeCache;
  42
+    QHash< QPair<QString, QString>, HTMLChatTheme> themeCache;
35 43
 
36 44
     /** A path to dir with themes */
37 45
     QString themesDir;
38  
-
39  
-
40 46
 };
41 47
 
42 48
 #endif
22  src/iconreply.cpp
... ...
@@ -1,7 +1,6 @@
1  
-#include "iconreply.h"
2  
-
3 1
 #include <QFile>
4 2
 
  3
+#include "iconreply.h"
5 4
 
6 5
 IconReply::IconReply(const QUrl& url, const IconServer* iconSever) : QNetworkReply() {
7 6
     setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
@@ -14,6 +13,7 @@ IconReply::IconReply(const QUrl& url, const IconServer* iconSever) : QNetworkRep
14 13
     QTimer::singleShot(0, this, SLOT(dataReady()));
15 14
 }
16 15
 
  16
+
17 17
 IconReply::IconReply() {
18 18
     setOpenMode(QIODevice::ReadOnly | QIODevice::Unbuffered);
19 19
     setUrl(QUrl());
@@ -22,56 +22,50 @@ IconReply::IconReply() {
22 22
 
23 23
     qDebug() << "access denied IR::IconReply()" << iconBuffer.bytesAvailable();
24 24
     QTimer::singleShot(0, this, SLOT(dataReady()));
25  
-    
26 25
 }
27 26
 
  27
+
28 28
 void IconReply::abort() {
29 29
     qDebug() << "IR::abort()";
30 30
 }
31 31
 
32 32
 
33 33
 void IconReply::close() {
34  
-    qDebug() << "IR::close()";
35 34
 }
36 35
 
37 36
 
38 37
 qint64 IconReply::bytesAvailable() const {
39  
-    qDebug() << "IR::bytesAvailable()" << iconBuffer.bytesAvailable();
40 38
     return iconBuffer.bytesAvailable();
41  
-
42 39
 }
43 40
 
44 41
 
45 42
 qint64 IconReply::readData(char *data, qint64 len) {
46  
-    qDebug() << "IR::readData()" << len << iconBuffer.bytesAvailable();
47 43
     return iconBuffer.read(data, len);
48 44
 }
49 45
 
50 46
 
51 47
 void IconReply::setReadBufferSize(qint64 size) {
52 48
     Q_UNUSED(size);
53  
-    qDebug() << "IR::setReadBufferSize()";
54 49
     Q_ASSERT(0); //should never happened
55 50
 }
56 51
 
57 52
 
58 53
 IconReply::~IconReply() {
59  
-    qDebug() << "IR::~IconReply()";
  54
+    qDebug() << "@@@@ MEM WEBKIT: ----" << "IconReply::~IconReply()";
60 55
 }
61 56
 
62 57
 
63 58
 void IconReply::dataReady() {
64  
-    qDebug() << "IR::dataReady()";
65 59
 
66 60
     qint64 totalSize = iconBuffer.bytesAvailable();
67  
-    
  61
+
68 62
     if (!totalSize) { //not in IconServer or (internet) access denied
69 63
         setError(QNetworkReply::ContentAccessDenied, "Access Denied");
70 64
         emit error(QNetworkReply::ContentAccessDenied);
71 65
         emit finished();
72  
-        return; 
  66
+        return;
73 67
     }
74  
-    
  68
+
75 69
     emit downloadProgress(0, totalSize);
76 70
     emit downloadProgress(totalSize, totalSize);
77 71
     emit readyRead();
@@ -81,12 +75,10 @@ void IconReply::dataReady() {
81 75
 
82 76
 bool IconReply::open(OpenMode mode) {
83 77
     Q_UNUSED(mode);
84  
-    qDebug() << "IR::open()";
85 78
     Q_ASSERT(0); //should never happened
86 79
 }
87 80
 
88 81
 
89 82
 qint64 IconReply::size() const {
90  
-    qDebug() << "IR::size()";
91 83
     return bytesAvailable(); //well, should never happended too
92 84
 }
28  src/iconreply.h
... ...
@@ -1,7 +1,6 @@
1 1
 #ifndef HAVE_RESOURCE_REPLY
2 2
 #define HAVE_RESOURCE_REPLY
3 3
 
4  
-#include <Qt>
5 4
 #include <QNetworkReply>
6 5
 #include <QDebug>
7 6
 #include <QTimer>
@@ -11,7 +10,18 @@
11 10
 
12 11
 
13 12
 /** 
14  
- * "Network" reply that returns icon (e.g .png file contents) n) from IconSever.
  13
+ * "Network" reply that "downloads" icon from IconServer. 
  14
+ * 
  15
+ * It's (another) bridge between C++ part of Psi and Webkit-based ChatView.
  16
+ * 
  17
+ * NOTE: Although it's *Icon*Reply and there's *Icon*Server you can download any data from
  18
+ * NOTE: IconServer using icon:// URL. Name ResouceReply would be a little confusing, I think.
  19
+ *
  20
+ * BTW, QWebkit doesn't cache data:// URI
  21
+ *
  22
+ * NOTE: Webkit IconReplies are cached. You may set QNetworkRequest::LastModifiedHeader HTTP header, 
  23
+ * NOTE: or QNetworkRequest::AlwaysNetwork to force download from the iconServer.
  24
+ * 
15 25
  * Used by QWebkit ( icon:// URLs )
16 26
  */
17 27
 class IconReply : public QNetworkReply {
@@ -21,7 +31,7 @@ class IconReply : public QNetworkReply {
21 31
 public:
22 32
     /** URL of icon, eg icon://smile.png; icon will be "downloaded" from \param iconServer */
23 33
     IconReply(const QUrl& url, const IconServer* iconServer);
24  
-    
  34
+
25 35
     /** Construct IconReply that fails with ContentAccessDenied error */
26 36
     IconReply();
27 37
     ~IconReply();
@@ -36,9 +46,17 @@ class IconReply : public QNetworkReply {
36 46
     qint64 size() const;
37 47
 
38 48
 
39  
-    private 
  49
+    private
40 50
 slots:
41  
-    /** We cannot emit finish() in constructor/before QNetworkAccessManager::createRequest() returns [Qt bug] */
  51
+
  52
+    /**
  53
+     * Emits finished().
  54
+     * 
  55
+     * We cannot emit finished() in constructor.
  56
+     *
  57
+     * To be precise QNetworkAccessManager::createRequest() must return before we emit finished()
  58
+     * It's Qt bug.
  59
+     */
42 60
     void dataReady();
43 61
 
44 62
 private:
6  src/iconserver.cpp
... ...
@@ -1,6 +1,7 @@
1  
-#include "iconserver.h"
2 1
 #include <QDebug>
3 2
 
  3
+#include "iconserver.h"
  4
+
4 5
 class IconServer;
5 6
 
6 7
 
@@ -16,7 +17,6 @@ void IconServer::registerIcon(const QString& name, QByteArray data) {
16 17
 QByteArray IconServer::getIcon(const QString& name) const {
17 18
     dataMutex.lock();
18 19
 
19  
-//    qDebug() << "IconServer :: getIcon()" << name;
20 20
     QByteArray data = dict[name];
21 21
 
22 22
     dataMutex.unlock();
@@ -36,7 +36,6 @@ QByteArray IconServer::pixmapToPng(const QPixmap& pixmap) {
36 36
 
37 37
 void IconServer::unregisterAll(const QStringList& names) {
38 38
     dataMutex.lock();
39  
-//    qDebug() << "   ---| runregisterAll()" << names;
40 39
 
41 40
     foreach(QString name, names) {
42 41
         dict.remove(name);
@@ -48,7 +47,6 @@ void IconServer::unregisterAll(const QStringList& names) {
48 47
 
49 48
 void IconServer::registerAll(QStringList names, const QList<const QPixmap*>& icons) { //qt moc cannot handle const list<pair>& 
50 49
     dataMutex.lock();
51  
-//    qDebug() << "+++   | registerAll()" << names;
52 50
 
53 51
     Q_ASSERT(icons.size() == names.size());
54 52
 
42  src/iconserver.h
@@ -13,16 +13,18 @@
13 13
 
14 14
 /**
15 15
  * Conains icons and avatars for Webkit use.
16  
- * It has similar to IconsetFactory+AvatarFactory functionality.
17  
- * When webkit encounter for example \<img src="icon://smile.png"\> it will call * 
  16
+ *
  17
+ * It has similar to the IconsetFactory + AvatarFactory functionality.
  18
+ *
  19
+ * When webkit encounter for example \<img src="icon://smile.png"\> it will call  
18 20
  * IconServer::getIcon("smile.png") 
19 21
  *
20  
- * You have to registerIcon() before webkit could use it
  22
+ * You have to registerIcon() before webkit could use it. 
  23
+ * You can register any data (e.g. you can "download" HTML using icon:// URL).
21 24
  *
22  
- * You have to delete this object afer all Webkit (ChatDialogs) instances deletion
  25
+ * You have to delete this object afer all Webkit (ChatDialogs) instances are deleted.
23 26
  * 
24  
- * dataMutex is mutable
25  
- *
  27
+ * NOTE: dataMutex is mutable
26 28
  */
27 29
 class IconServer : public QObject {
28 30
 
@@ -30,14 +32,22 @@ class IconServer : public QObject {
30 32
 public:
31 33
 
32 34
     IconServer() : QObject() {}
  35
+    
33 36
     /**
34 37
      * Registers icon.
35  
-     * name => data. \param data should contain image data eg. BMP, PNG 
36  
-     * It will replace old icon
  38
+     *
  39
+     * name => data. \param data should contain image data eg. BMP, PNG *
  40
+     * It will replace old icon.
  41
+     *
  42
+     * NOTE: dataMutex is modified 
37 43
      */
38 44
     void registerIcon(const QString& name, QByteArray data);
39 45
 
40  
-    /** Returns image data or empty QByteArray if \param name was't registered; dataMutex is modified */
  46
+    /** 
  47
+     * Returns image data or empty QByteArray if \param name was't registered.
  48
+     *
  49
+     * NOTE: dataMutex is modified 
  50
+     */
41 51
     QByteArray getIcon(const QString& name) const;
42 52
 
43 53
     /** Converts QPixmap to QByteArray using PNG format */
@@ -45,10 +55,18 @@ class IconServer : public QObject {
45 55
 
46 56
     public 
47 57
 slots:
48  
-    /** Unregisters all icons from (icon)names */
  58
+    /** 
  59
+     * Unregisters all icons from (icon)names 
  60
+     *
  61
+     * NOTE: dataMutex is modified 
  62
+     */
49 63
     void unregisterAll(const QStringList& names);
50 64
 
51  
-    /** Registers all icons (key => value) from icons */
  65
+    /**
  66
+     * Registers all icons (name => icon) 
  67
+     *
  68
+     * NOTE: dataMutex is modified 
  69
+     */
52 70
     void registerAll(QStringList names, const QList<const QPixmap*>& icons); //qt moc cannot handle const list<pair>& 
53 71
 
54 72
 
@@ -60,6 +78,4 @@ class IconServer : public QObject {
60 78
     mutable QMutex dataMutex;
61 79
 };
62 80
 
63  
-
64 81
 #endif	
65  
-
8  src/imagedownloaddialog.cpp
@@ -12,16 +12,20 @@ ImageDownloadDialog::ImageDownloadDialog(QWidget* parent) : QDialog(parent), dow
12 12
     connect(manager, SIGNAL(finished(QNetworkReply*)),
13 13
             this, SLOT(replyFinished(QNetworkReply*)));
14 14
 
  15
+    //layout
15 16
     setAttribute(Qt::WA_DeleteOnClose);
16 17
     setWindowTitle(tr("Insert image"));
17 18
     QVBoxLayout *vb = new QVBoxLayout(this, 4);
18 19
     QHBoxLayout *hb = new QHBoxLayout(vb);
19 20
     QLabel *l = new QLabel(tr("URL:"), this);
20 21
     hb->addWidget(l);
  22
+
  23
+    //URL input
21 24
     urlEdit = new QLineEdit(this);
22 25
     hb->addWidget(urlEdit);
23 26
     vb->addStretch(1);
24 27
 
  28
+    //separator
25 29
     QFrame *Line1 = new QFrame(this);
26 30
     Line1->setFrameShape(QFrame::HLine);
27 31
     Line1->setFrameShadow(QFrame::Sunken);
@@ -31,10 +35,12 @@ ImageDownloadDialog::ImageDownloadDialog(QWidget* parent) : QDialog(parent), dow
31 35
     hb = new QHBoxLayout(vb);
32 36
     hb->addStretch(1);
33 37
 
  38
+    //downloading label
34 39
     downloadingLabel = new QLabel(tr("Downloading..."), this);
35 40
     hb->addWidget(downloadingLabel);
36 41
     downloadingLabel->setVisible(false);
37 42
 
  43
+    //buttons
38 44
     QPushButton *cancelButton = new QPushButton(tr("&Cancel"), this);
39 45
     connect(cancelButton, SIGNAL(clicked()), SLOT(cancel()));
40 46
     hb->addWidget(cancelButton);
@@ -53,7 +59,7 @@ ImageDownloadDialog::ImageDownloadDialog(QWidget* parent) : QDialog(parent), dow
53 59
 
54 60
 
55 61
 ImageDownloadDialog::~ImageDownloadDialog() {
56  
-    qDebug() << "img dlg";
  62
+    qDebug() << "@@@@ MEM WEBKIT: ----" << "ImageDownloadDialog::~ImageDownloadDialog()";
57 63
 }
58 64
 
59 65
 
10  src/imagedownloaddialog.h
@@ -8,7 +8,11 @@
8 8
 #include <QImage>
9 9
 #include <QLabel>
10 10
 
11  
-
  11
+/**
  12
+ * Dialog used for downloading images over HTTP.
  13
+ *
  14
+ * User provides image's URL and when download id finished finished() signal is emmited. 
  15
+ */
12 16
 class ImageDownloadDialog : public QDialog {
13 17
 
14 18
     Q_OBJECT
@@ -17,7 +21,7 @@ class ImageDownloadDialog : public QDialog {
17 21
     /**
18 22
      * Constructor.
19 23
      *
20  
-     * DeleteOnClose is set.
  24
+     * NOTE: DeleteOnClose is set.
21 25
      */
22 26
     ImageDownloadDialog(QWidget* parent);
23 27
     ~ImageDownloadDialog();
@@ -40,6 +44,7 @@ class ImageDownloadDialog : public QDialog {
40 44
 
41 45
     private
42 46
 slots:
  47
+        
43 48
     /** Closes dialog and aborts downloading file (if needed) */
44 49
     void cancel();
45 50
 
@@ -71,4 +76,3 @@ class ImageDownloadDialog : public QDialog {
71 76
 
72 77
 
73 78
 #endif
74  
-
3  src/networkaccessmanager.cpp
@@ -58,6 +58,7 @@ QNetworkReply * NetworkAccessManager::createRequest(Operation op, const QNetwork
58 58
 
59 59
 void NetworkAccessManager::callFinished() {
60 60
     QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
  61
+    
61 62
     if (reply) {
62 63
         emit finished(reply);
63 64
     }
@@ -72,5 +73,3 @@ void NetworkAccessManager::addUrlToWhiteList(const QString& url) {
72 73
 
73 74
     whiteListMutex.unlock();
74 75
 }
75  
-
76  
-
13  src/networkaccessmanager.h
@@ -4,6 +4,7 @@
4 4
 #include <QNetworkAccessManager>
5 5
 #include <QStringList>
6 6
 #include <QMutex>
  7
+
7 8
 #include "iconserver.h"
8 9
 
9 10
 
@@ -15,6 +16,7 @@ class NetworkAccessManager : public QNetworkAccessManager {
15 16
 public:
16 17
     /** 
17 18
      * Constructor. 
  19
+     *
18 20
      * \param iconServer will be used to serve icon:// urls 
19 21
      */
20 22
     NetworkAccessManager(QObject *parent, IconServer* iconServer);
@@ -25,7 +27,12 @@ class NetworkAccessManager : public QNetworkAccessManager {
25 27
 
26 28
     private
27 29
 slots:
28  
-    /** Called by QNetworkReply::finish(); reemits finish(reply) */
  30
+        
  31
+    /** 
  32
+     * Called by QNetworkReply::finish(). 
  33
+     * 
  34
+     * Emitts finish(reply) 
  35
+     */
29 36
     void callFinished();
30 37
 
31 38
 protected:
@@ -42,7 +49,9 @@ class NetworkAccessManager : public QNetworkAccessManager {
42 49
     QStringList whiteList;
43 50
 
44 51
     /** 
45  
-     * Mutal exclusion for whitList. WhiteList can be accessed by Webkit (createRequest()) 
  52
+     * Mutal exclusion for whitList. 
  53
+     * 
  54
+     * WhiteList can be accessed by Webkit (createRequest()) 
46 55
      * and Psi (addUrlToWhiteList()) simultaneously)
47 56
      */
48 57
     QMutex whiteListMutex;
48  src/unittest/htmlchatview/htmlchatviewtest.cpp
@@ -7,6 +7,7 @@
7 7
 
8 8
 CPPUNIT_TEST_SUITE_REGISTRATION(HTMLChatViewTest);
9 9
 
  10
+
10 11
 void HTMLChatViewTest::onlyFooterAndHeader() {
11 12
     prepareTest("testingTheme/");
12 13
     checkResultBody(
@@ -287,6 +288,53 @@ void HTMLChatViewTest::defaultIcons() {
287 288
 }
288 289
 
289 290
 
  291
+void HTMLChatViewTest::keywordEscaping() {
  292
+    prepareTest("testingTheme/");
  293
+
  294
+    QDateTime time;
  295
+    time.setTime_t(24 * 60 * 60 * 35);
  296
+
  297
+    MessageChatEvent * ce = new MessageChatEvent();
  298
+
  299
+    ce->setBody("ABCDEFGHIJ1234567890");
  300
+
  301
+    ce->setTimeStamp(time);
  302
+    ce->setNick("se%service%nu");
  303
+    ce->setService("Jab%userIconPath%ber");
  304
+    ce->setConsecutive(false);
  305
+    ce->setJid("senu@ja%message%bber.pl");
  306
+    ce->setLocal(true);
  307
+    ce->setUserIconPath("outgoing"); //
  308
+    ce->setUserStatusIcon("myicon.png");
  309
+    ce->setUserColor("#123456");
  310
+
  311
+    view->appendMessage(ce);
  312
+
  313
+    waitUntil(&helper.append);
  314
+
  315
+    checkResultBody(
  316
+                    "<div><b style=\"color: green\">header</b></div><hr>"
  317
+                    "<div id=\"Chat\">"
  318
+
  319
+                    "<div class=\"combine\"><div class=\"ctime\">1970-02-05 - 01:00</div>"
  320
+                    "Outgoing/buddy_icon.png - myicon.png - ltr - senu@jabber.pl - senu - " //
  321
+                    "Jabber - senu@jabber.pl - Outgoing/buddy_icon.png :: " //
  322
+
  323
+                    "message"
  324
+
  325
+                    " || message outgoing <span style=\"color: #194978\">COLOR</span>"
  326
+                    "</div>"
  327
+
  328
+                    "<div id=\"insert\"></div>"
  329
+
  330
+                    "</div>"
  331
+                    "<hr>"
  332
+                    "<div><b style=\"color: red\">footer</b></div>"
  333
+                    );
  334
+
  335
+}
  336
+
  337
+
290 338
 void HTMLChatViewTest::prepareTest(QString themePath) {
291 339
 
292 340
     QApplication app();
9  src/unittest/htmlchatview/htmlchatviewtest.h
@@ -7,7 +7,7 @@
7 7
 #include <cppunit/TestFixture.h>
8 8
 #include <cppunit/extensions/HelperMacros.h>
9 9
 
10  
-#include "../../htmlChatView.h"
  10
+#include "../../htmlchatview.h"
11 11
 #include "../../iconserver.h"
12 12
 
13 13
 
@@ -36,8 +36,10 @@ class HTMLChatViewTest : public CPPUNIT_NS::TestCase {
36 36
     CPPUNIT_TEST(clearMessages);
37 37
     CPPUNIT_TEST(emoteEvent);
38 38
     CPPUNIT_TEST(themeChanged);
39  
-
  39
+    
  40
+    CPPUNIT_TEST(keywordEscaping);
40 41
     CPPUNIT_TEST(javaScriptCSSValidatorIntegration);
  42
+    
41 43
     CPPUNIT_TEST(defaultIcons);
42 44
 
43 45
     CPPUNIT_TEST(noActionTemplate);
@@ -68,6 +70,9 @@ class HTMLChatViewTest : public CPPUNIT_NS::TestCase {
68 70
 	/** Checks if HTMLChatView uses JavaScript CSS Validator */
69 71
     void defaultIcons();
70 72
 
  73
+    /** Keyword values with %% have to be escaped */
  74
+    void keywordEscaping();
  75
+
71 76
     void prepareTest(QString themePath);
72 77
 
73 78
     /** We check only \body contents; Deletes form and view */

0 notes on commit 7e4b431

Please sign in to comment.
Something went wrong with that request. Please try again.