[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim/akregator_port] krsslocal: if fetching a feed where the collection has not title set, apply
From: Frank Osterfeld <frank.osterfeld () kdab ! com>
Date: 2012-02-20 21:25:55
Message-ID: 20120220212555.CD0E8A60F6 () git ! kde ! org
[Download RAW message or body]
Git commit f582a377a6fb72e8677822d821f8c470940691e6 by Frank Osterfeld.
Committed on 17/09/2011 at 18:37.
Pushed by cgiboudeaux into branch 'akregator_port'.
if fetching a feed where the collection has not title set, apply the
feed properties for title, description and htmlUrl.
M +37 -25 krsslocal/krsslocalresource.cpp
M +2 -0 krsslocal/krsslocalresource.h
http://commits.kde.org/kdepim/f582a377a6fb72e8677822d821f8c470940691e6
diff --git a/krsslocal/krsslocalresource.cpp \
b/krsslocal/krsslocalresource.cpp index b91766a..298629c 100644
--- a/krsslocal/krsslocalresource.cpp
+++ b/krsslocal/krsslocalresource.cpp
@@ -33,6 +33,7 @@
#include <Akonadi/ItemFetchScope>
#include <Akonadi/ChangeRecorder>
#include <Akonadi/Collection>
+#include <Akonadi/CollectionModifyJob>
#include <Akonadi/CollectionFetchJob>
#include <Akonadi/CollectionFetchScope>
#include <krss/rssitem.h>
@@ -40,6 +41,7 @@
#include <krss/resourcemanager.h>
#include <krss/feedcollection.h>
+
using namespace Akonadi;
using namespace KRssResource;
using namespace boost;
@@ -185,36 +187,46 @@ void KRssLocalResource::retrieveItems( const \
Akonadi::Collection &collection ) // Depending on how your resource \
accesses the data, there are several // different ways to tell Akonadi \
when you are done.
- Syndication::Loader * const loader = Syndication::Loader::create();
- connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode ) ),
- this, SLOT( slotLoadingComplete( Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode ) ) );
- KUrl xmlUrl( collection.remoteId() );
- loader->loadFrom( xmlUrl );
-
+ Syndication::Loader * const loader = Syndication::Loader::create();
+ connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode ) ), + this, SLOT( \
slotLoadingComplete( Syndication::Loader*, Syndication::FeedPtr, \
Syndication::ErrorCode ) ) ); + const KRss::FeedCollection fc( \
collection ); + const KUrl xmlUrl = fc.xmlUrl();
+ m_collectionByLoader.insert( loader, collection );
+ loader->loadFrom( xmlUrl );
}
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;
- }
-
- QList<Syndication::ItemPtr> syndItems = feed->items();
- Akonadi::Item::List items;
- foreach ( const Syndication::ItemPtr& syndItem, syndItems ) {
- Akonadi::Item item( mimeType() );
- item.setRemoteId( syndItem->id() );
- item.setPayload<KRss::RssItem>( Util::fromSyndicationItem( syndItem ) \
);
- item.setFlag( KRss::RssItem::flagNew() );
- items << item;
- }
-
- itemsRetrieved( items );
+ const Collection c = m_collectionByLoader.take( loader );
+
+ if (status != Syndication::Success) {
+ kWarning() << "Error while parsing xml file";
+ //TODO report error to user?
+ itemsRetrievalDone();
+ return;
+ }
+ KRss::FeedCollection fc( c );
+ if ( fc.title().isEmpty() ) {
+ fc.setTitle( feed->title() );
+ fc.setName( feed->title() );
+ fc.setDescription( feed->description() );
+ fc.setHtmlUrl( feed->link() );
+ Akonadi::CollectionModifyJob* job = new \
Akonadi::CollectionModifyJob( fc ); + job->start();
+ }
+ QList<Syndication::ItemPtr> syndItems = feed->items();
+ Akonadi::Item::List items;
+ foreach ( const Syndication::ItemPtr& syndItem, syndItems ) {
+ Akonadi::Item item( mimeType() );
+ item.setRemoteId( syndItem->id() );
+ item.setPayload<KRss::RssItem>( Util::fromSyndicationItem( \
syndItem ) ); + item.setFlag( KRss::RssItem::flagNew() );
+ items << item;
+ }
+
+ itemsRetrieved( items );
}
diff --git a/krsslocal/krsslocalresource.h b/krsslocal/krsslocalresource.h
index 6102544..bf94585 100644
--- a/krsslocal/krsslocalresource.h
+++ b/krsslocal/krsslocalresource.h
@@ -23,6 +23,7 @@
#include <boost/shared_ptr.hpp>
#include <Syndication/Syndication>
#include <QTimer>
+#include <QHash>
#include "opmlparser.h"
class KRssLocalResource : public Akonadi::ResourceBase,
@@ -63,6 +64,7 @@ class KRssLocalResource : public Akonadi::ResourceBase,
private:
Akonadi::CachePolicy policy;
+ QHash<Syndication::Loader*, Akonadi::Collection> m_collectionByLoader;
QTimer *writeBackTimer;
static const int CacheTimeout = -1, IntervalCheckTime = 5;
static const int WriteBackTimeout = 30000; // in milliseconds
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic