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

List:       kde-commits
Subject:    [kdepim-runtime/akregator_port] krsslocal: implemented retrievePayload and moved static methods from
From:       Alessandro Cosentino <cosenal () gmail ! com>
Date:       2012-03-31 15:16:46
Message-ID: 20120331151646.68CEBA6102 () git ! kde ! org
[Download RAW message or body]

Git commit 6f9b8b24bb491d0fe7977148ce728a90c6dcefb4 by Alessandro Cosentino.
Committed on 24/08/2011 at 22:50.
Pushed by osterfeld into branch 'akregator_port'.

implemented retrievePayload and moved static methods from KRss

M  +34   -31   krsslocal/krsslocalresource.cpp
A  +146  -0    krsslocal/util.cpp     [License: GPL (v2+)]
A  +39   -0    krsslocal/util.h     [License: GPL (v2+)]

http://commits.kde.org/kdepim-runtime/6f9b8b24bb491d0fe7977148ce728a90c6dcefb4

diff --git a/krsslocal/krsslocalresource.cpp b/krsslocal/krsslocalresource.cpp
index d4fffa4..76a602e 100644
--- a/krsslocal/krsslocalresource.cpp
+++ b/krsslocal/krsslocalresource.cpp
@@ -2,6 +2,7 @@
 
 #include "settings.h"
 #include "settingsadaptor.h"
+#include "util.h"
 
 #include <QtDBus/QDBusConnection>
 
@@ -12,6 +13,8 @@
 #include <QtXml/QXmlStreamReader>
 #include <QMessageBox>
 #include <akonadi/entitydisplayattribute.h>
+#include <krss/rssitem.h>
+#include <krssresource/krssresource_export.h>
 
 #define CACHE_TIMEOUT 1
 #define INTERVAL_CHECK_TIME 1  
@@ -123,10 +126,7 @@ Collection::List KRssLocalResource::buildCollectionTree( \
QList<shared_ptr<const  }
 
 void KRssLocalResource::retrieveItems( const Akonadi::Collection &collection )
-{
-  
-  //Q_UNUSED(collection);
-  
+{   
   // TODO: this method is called when Akonadi wants to know about all the
   // items in the given collection. You can but don't have to provide all the
   // data for each item, remote ID and MIME type are enough at this stage.
@@ -141,15 +141,43 @@ void KRssLocalResource::retrieveItems( const \
Akonadi::Collection &collection )  
 }
 
+void KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, \
Syndication::FeedPtr feed,  +					    Syndication::ErrorCode status)
+{
+     Q_UNUSED(loader);
+     
+     if (status != Syndication::Success) {
+	    kWarning() << "Error while parsing xml file";
+	    itemsRetrievalDone();
+	    return;
+     }
+
+     QString title = feed->title();
+     const QList<Syndication::ItemPtr> syndItems = feed->items();
+     Akonadi::Item::List items;
+     Q_FOREACH( const Syndication::ItemPtr& syndItem, syndItems ) {
+            kWarning() << syndItem->title();
+	    Akonadi::Item item( QLatin1String("application/rss+xml") );
+	    item.setRemoteId( syndItem->id() );
+	    item.setPayload<KRss::RssItem>( fromSyndicationItem( syndItem ) );
+            item.setFlag( KRss::RssItem::flagNew() );
+	    items << item;
+     }
+     
+     itemsRetrieved( items );
+
+}
+
 bool KRssLocalResource::retrieveItem( const Akonadi::Item &item, const \
QSet<QByteArray> &parts )  {
-  Q_UNUSED( item );
   Q_UNUSED( parts );
-
+  Q_UNUSED( item );
+  
   // TODO: this method is called when Akonadi wants more data for a given item.
   // You can only provide the parts that have been requested but you are allowed
   // to provide all in one go
 
+  
   return true;
 }
 
@@ -219,31 +247,6 @@ void KRssLocalResource::itemRemoved( const Akonadi::Item &item )
   // of this template code to keep it simple
 }
 
-void KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, \
                Syndication::FeedPtr feed, 
-					    Syndication::ErrorCode status)
-{
-     Q_UNUSED(loader);
-     
-     if (status != Syndication::Success) {
-	    kWarning() << "Error while parsing xml file";
-	    itemsRetrievalDone();
-	    return;
-     }
-
-     QString title = feed->title();
-     const QList<Syndication::ItemPtr> syndItems = feed->items();
-     Akonadi::Item::List items;
-     Q_FOREACH( const Syndication::ItemPtr& syndItem, syndItems ) {
-            kWarning() << syndItem->title();
-	    Akonadi::Item item( QLatin1String("application/rss+xml") );
-	    item.setRemoteId( syndItem->id() );
-            items << item;
-     }
-     
-     itemsRetrieved( items );
-
-}
-
 AKONADI_RESOURCE_MAIN( KRssLocalResource )
 
 #include "krsslocalresource.moc"
diff --git a/krsslocal/util.cpp b/krsslocal/util.cpp
new file mode 100644
index 0000000..734e498
--- /dev/null
+++ b/krsslocal/util.cpp
@@ -0,0 +1,146 @@
+/*
+    Copyright (C) 2009    Dmitry Ivanov <vonami@gmail.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "util.h"
+
+#include <krss/item.h>
+#include <krss/rssitem.h>
+#include <krss/person.h>
+#include <krss/category.h>
+#include <krss/enclosure.h>
+//#include <krss/feedcollection.h>
+
+#include <Akonadi/Collection>
+#include <Syndication/Person>
+#include <Syndication/Enclosure>
+#include <Syndication/Category>
+#include <KDateTime>
+#include <QtCore/QString>
+#include <QtCore/QByteArray>
+
+#include <KDebug>
+#include <QtCore/QMultiMap>
+#include <QtCore/QMapIterator>
+#include <QtXml/QDomElement>
+
+namespace Util
+{
+// from akregator/src/utils.cpp
+static inline int calcHash( const QString& str )
+{
+    const QByteArray array = str.toAscii();
+    return qChecksum( array.constData(), array.size() );
+}
+
+KRss::RssItem KRssResource::fromSyndicationItem( const Syndication::ItemPtr& \
syndItem ) +{
+    KRss::RssItem rssItem;
+    rssItem.setHeadersLoaded( true );
+    rssItem.setContentLoaded( true );
+
+    rssItem.setGuidIsHash( syndItem->id().startsWith( QLatin1String("hash:") ) );
+    //rssItem.setSourceFeedId(currentCollection().remoteId().toInt());
+    rssItem.setTitle( syndItem->title() );
+    rssItem.setLink( syndItem->link() );
+    rssItem.setDescription( syndItem->description() );
+    rssItem.setContent( syndItem->content() );
+    KDateTime dt;
+    if ( syndItem->datePublished() > 0 ) {
+        dt.setTime_t( syndItem->datePublished() );
+        rssItem.setDatePublished( dt );
+    }
+    else {
+        rssItem.setDatePublished( KDateTime::currentLocalDateTime() );
+    }
+    dt.setTime_t( syndItem->dateUpdated() );
+    rssItem.setDateUpdated( dt );
+    rssItem.setGuid( syndItem->id() );
+    rssItem.setLanguage( syndItem->language() );
+    rssItem.setCommentsCount( syndItem->commentsCount() );
+    rssItem.setCommentsLink( syndItem->commentsLink() );
+    rssItem.setCommentsFeed( syndItem->commentsFeed() );
+    rssItem.setCommentPostUri( syndItem->commentPostUri() );
+
+    // Authors
+    QList<KRss::Person> authors;
+    const QList<Syndication::PersonPtr> syndAuthors = syndItem->authors();
+    Q_FOREACH( const Syndication::PersonPtr& syndAuthor, syndAuthors ) {
+        if ( !syndAuthor->isNull() ) {
+            KRss::Person author;
+            author.setName( syndAuthor->name() );
+            author.setUri( syndAuthor->uri() );
+            author.setEmail( syndAuthor->email() );
+            authors.append( author );
+        }
+    }
+    rssItem.setAuthors( authors );
+
+    // Enclosures
+    QList<KRss::Enclosure> enclosures;
+    const QList<Syndication::EnclosurePtr> syndEnclosures = syndItem->enclosures();
+    Q_FOREACH( const Syndication::EnclosurePtr& syncEnclosure, syndEnclosures ) {
+        if ( !syncEnclosure->isNull() ) {
+            KRss::Enclosure enclosure;
+            enclosure.setUrl( syncEnclosure->url() );
+            enclosure.setTitle( syncEnclosure->title());
+            enclosure.setType( syncEnclosure->type() );
+            enclosure.setLength( syncEnclosure->length() );
+            enclosure.setDuration( syncEnclosure->duration() );
+            enclosures.append( enclosure );
+        }
+    }
+    rssItem.setEnclosures( enclosures );
+
+    // Categories
+    QList<KRss::Category> categories;
+    const QList<Syndication::CategoryPtr> syndCategories = syndItem->categories();
+    Q_FOREACH( const Syndication::CategoryPtr& syndCategory, syndCategories ) {
+        if ( !syndCategory->isNull() ) {
+            KRss::Category category;
+            category.setTerm( syndCategory->term() );
+            category.setScheme( syndCategory->scheme() );
+            category.setLabel( syndCategory->label() );
+            categories.append( category );
+        }
+    }
+    rssItem.setCategories( categories );
+
+    // Additional properties
+    // it's a multi map but we store only the most recently inserted value
+    const QMultiMap<QString, QDomElement> syndProperties = \
syndItem->additionalProperties(); +    QMapIterator<QString, QDomElement> it( \
syndProperties ); +    while ( it.hasNext() ) {
+        it.next();
+        rssItem.setCustomProperty( it.key(), it.value().text() );
+    }
+
+    rssItem.setHash( calcHash( syndItem->title() + syndItem->description() +
+                               syndItem->content() + syndItem->link() ) );
+    return rssItem;
+}
+
+/*
+QString KRssResource::generateCollectionName( const Akonadi::Collection& collection \
) +{
+    if ( static_cast<KRss::FeedCollection>( collection ).title().isEmpty() ) {
+        return collection.remoteId();
+    }
+
+    return static_cast<KRss::FeedCollection>( collection ).title() + QLatin1Char( \
'-' ) + collection.remoteId(); +}*/
+
+}
\ No newline at end of file
diff --git a/krsslocal/util.h b/krsslocal/util.h
new file mode 100644
index 0000000..c275e37
--- /dev/null
+++ b/krsslocal/util.h
@@ -0,0 +1,39 @@
+/*
+    Copyright (C) 2009    Dmitry Ivanov <vonami@gmail.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef KRSSRESOURCE_UTIL_H
+#define KRSSRESOURCE_UTIL_H
+
+#include <Syndication/Item>
+
+namespace KRss {
+class RssItem;
+}
+
+namespace Akonadi {
+class Collection;
+}
+
+namespace KRssResource
+{
+
+KRss::RssItem fromSyndicationItem( const Syndication::ItemPtr& syndItem );
+//QString generateCollectionName( const Akonadi::Collection& collection );
+
+} // namespace KRssResource
+
+#endif // KRSSRESOURCE_UTIL_H


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

Configure | About | News | Add a list | Sponsored by KoreLogic