[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/runtime/knotify
From: Sjors Gielen <dazjorz () dazjorz ! com>
Date: 2010-09-10 23:17:53
Message-ID: 20100910231753.C4B1DAC888 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1173950 by sgielen:
Reviewboard (svn) entry 5229
This patch adds a HtmlEntityResolver class and makes the XML stripper use it to \
resolve additional entities. The which would have caused an XML error, is now \
turned into a regular space, fixing the problem. (Any HTML entities unknown to \
KCharset cause a warning and are replaced with an empty character.)
M +21 -0 notifybypopup.cpp
M +10 -0 notifybypopup.h
--- trunk/KDE/kdebase/runtime/knotify/notifybypopup.cpp #1173949:1173950
@@ -29,6 +29,7 @@
#include <kdialog.h>
#include <khbox.h>
#include <kvbox.h>
+#include <kcharsets.h>
#include <QBuffer>
#include <QImage>
@@ -533,6 +534,8 @@
QString NotifyByPopup::stripHtml( const QString &text )
{
QXmlStreamReader r( "<elem>" + text + "</elem>" );
+ HtmlEntityResolver resolver;
+ r.setEntityResolver( &resolver );
QString result;
while( !r.atEnd() ) {
r.readNext();
@@ -560,4 +563,22 @@
return result;
}
+QString NotifyByPopup::HtmlEntityResolver::resolveUndeclaredEntity(
+ const QString &name )
+{
+ QString result =
+ QXmlStreamEntityResolver::resolveUndeclaredEntity(name);
+ if( !result.isEmpty() )
+ return result;
+
+ QChar ent = KCharsets::fromEntity( '&' + name );
+ if( ent.isNull() ) {
+ kWarning(300) << "Notification to send to backend which does "
+ "not support HTML, contains invalid entity: "
+ << name;
+ ent = ' ';
+ }
+ return QString(ent);
+}
+
#include "notifybypopup.moc"
--- trunk/KDE/kdebase/runtime/knotify/notifybypopup.h #1173949:1173950
@@ -26,6 +26,7 @@
#include <QMap>
#include <QHash>
#include <QStringList>
+#include <QXmlStreamEntityResolver>
class KPassivePopup;
@@ -113,6 +114,15 @@
* Maps knotify notification IDs to DBus notifications IDs
*/
QHash<int,uint> m_idMap;
+
+ /**
+ * A class for resolving HTML entities in XML documents (used
+ * during HTML stripping)
+ */
+ class HtmlEntityResolver : public QXmlStreamEntityResolver
+ {
+ QString resolveUndeclaredEntity( const QString &name );
};
+};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic