[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdepim/akregator_port] /: Port author listing in formatted article
From:       Frank Osterfeld <frank.osterfeld () kdab ! com>
Date:       2012-03-04 19:20:26
Message-ID: 20120304192026.35C9CA60BB () git ! kde ! org
[Download RAW message or body]

Git commit 9087c46b430b5b031ec7190468c50e1024d60649 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  +2    -10   akregator2/src/articleformatter.cpp
M  +37   -0    krss/krss/item.cpp
M  +2    -0    krss/krss/item.h

http://commits.kde.org/kdepim/9087c46b430b5b031ec7190468c50e1024d60649

diff --git a/akregator2/src/articleformatter.cpp \
b/akregator2/src/articleformatter.cpp index 1c5f46e..1c464b9 100644
--- a/akregator2/src/articleformatter.cpp
+++ b/akregator2/src/articleformatter.cpp
@@ -211,8 +211,7 @@ QString DefaultNormalViewFormatter::formatItem( const KRss::Item& \
                item, IconOpti
         text += KGlobal::locale()->formatDateTime(item.dateUpdated(), \
KLocale::FancyLongDate) +"</span>\n"; // TODO: might need RTL?  }
 
-#ifdef KRSS_PORT_DISABLED
-    const QString author = item.authorAsHtml();
+    const QString author = item.authorsAsHtml();
     if (!author.isEmpty())
     {
         text += QString("<br/><span class=\"header\" \
dir=\"%1\">").arg(Utils::directionOf(i18n("Author"))); @@ -220,9 +219,6 @@ QString \
DefaultNormalViewFormatter::formatItem( const KRss::Item& item, IconOpti  text += \
"</span><span class=\"headertext\">";  text += author+"</span>\n"; // TODO: might \
need RTL?  }
-#else
-    kWarning() << "Code temporarily disabled (Akonadi port)";
-#endif //KRSS_PORT_DISABLED
 
     if (!enc.isEmpty())
     {
@@ -393,8 +389,7 @@ QString DefaultCombinedViewFormatter::formatItem( const \
                KRss::Item& item, IconOp
         text += KGlobal::locale()->formatDateTime(item.datePublished(), \
KLocale::FancyLongDate) + "</span>\n"; // TODO: might need RTL?  }
 
-#ifdef KRSS_PORT_DISABLED
-    const QString author = item.authorAsHtml();
+    const QString author = item.authorsAsHtml();
     if (!author.isEmpty())
     {
         text += QString("<br/><span class=\"header\" \
dir=\"%1\">").arg(Utils::directionOf(i18n("Author"))); @@ -402,9 +397,6 @@ QString \
DefaultCombinedViewFormatter::formatItem( const KRss::Item& item, IconOp  text += \
"</span><span class=\"headertext\">";  text += author+"</span>\n"; // TODO: might \
need RTL?  }
-#else
-    kWarning() << "Code temporarily disabled (Akonadi port)";
-#endif //KRSS_PORT_DISABLED
     if (!enc.isEmpty())
     {
         text += QString("<br/><span class=\"header\" \
                dir=\"%1\">").arg(Utils::directionOf(i18n("Enclosure")));
diff --git a/krss/krss/item.cpp b/krss/krss/item.cpp
index 7bd9077..3672942 100644
--- a/krss/krss/item.cpp
+++ b/krss/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/krss/item.h b/krss/krss/item.h
index 86b55fa..7027607 100644
--- a/krss/krss/item.h
+++ b/krss/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