[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepimlibs/akregator_port] krss: Port author listing in formatted article
From: Frank Osterfeld <frank.osterfeld () kdab ! com>
Date: 2012-03-31 15:16:24
Message-ID: 20120331151624.AA830A612C () git ! kde ! org
[Download RAW message or body]
Git commit 20f59466923fe3bf1fd0ed5aa4eac85795591c3e by Frank Osterfeld.
Committed on 04/03/2012 at 19:41.
Pushed by osterfeld into branch 'akregator_port'.
Port author listing in formatted article
M +37 -0 krss/item.cpp
M +2 -0 krss/item.h
http://commits.kde.org/kdepimlibs/20f59466923fe3bf1fd0ed5aa4eac85795591c3e
diff --git a/krss/item.cpp b/krss/item.cpp
index 7bd9077..3672942 100644
--- a/krss/item.cpp
+++ b/krss/item.cpp
@@ -30,6 +30,9 @@
#include <syndication/tools.h>
#include <KDateTime>
+#include <KLocalizedString>
+
+#include <QTextDocument>
#include <algorithm>
@@ -203,6 +206,40 @@ QList<Person> Item::authors() const
return d->akonadiItem.payload<RssItem>().authors();
}
+static QString authorAsHtml( const Person& p ) {
+ const QString name = Qt::escape( p.name() );
+ const QString email = Qt::escape( p.email() );
+
+ if (!email.isEmpty()) {
+ if (!name.isEmpty())
+ return QString::fromLatin1("<a href=\"mailto:%1\">%2</a>").arg( email, name );
+ else
+ return QString::fromLatin1("<a href=\"mailto:%1\">%1</a>").arg( email );
+ }
+
+ const QString uri = Qt::escape( p.uri() );
+ if (!name.isEmpty()) {
+ if (!uri.isEmpty())
+ return QString::fromLatin1("<a href=\"%1\">%2</a>").arg( uri, name );
+ else
+ return Qt::escape( name );
+ }
+
+ if ( !uri.isEmpty() )
+ return QString::fromLatin1( "<a href=\"%1\">%1</a>" ).arg( uri );
+ return QString();
+
+}
+
+QString Item::authorsAsHtml() const
+{
+ const QList<Person> authors = d->akonadiItem.payload<RssItem>().authors();
+ QStringList formatted;
+ Q_FOREACH( const Person& i, authors )
+ formatted += authorAsHtml( i );
+ return formatted.join( i18nc("separator for listing multiple authors", ", ") );
+}
+
void Item::setAuthors( const QList<Person>& authors )
{
RssItem payload = d->akonadiItem.payload<RssItem>();
diff --git a/krss/item.h b/krss/item.h
index 86b55fa..7027607 100644
--- a/krss/item.h
+++ b/krss/item.h
@@ -192,6 +192,8 @@ public:
QList<Person> authors() const;
void setAuthors( const QList<Person>& authors );
+ QString authorsAsHtml() const;
+
/**
* returns the language used in the item's content
*
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic