From kde-commits Mon Feb 20 21:25:55 2012 From: Frank Osterfeld Date: Mon, 20 Feb 2012 21:25:55 +0000 To: kde-commits Subject: [kdepim/akregator_port] krsslocal: if fetching a feed where the collection has not title set, apply Message-Id: <20120220212555.CD0E8A60F6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=132977322000671 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 #include #include +#include #include #include #include @@ -40,6 +41,7 @@ #include #include = + 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 =3D Syndication::Loader::create(); - connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, Synd= ication::FeedPtr, Syndication::ErrorCode ) ), - this, SLOT( slotLoadingComplete( Syndication::Loader*, Syndication::Feed= Ptr, Syndication::ErrorCode ) ) ); - KUrl xmlUrl( collection.remoteId() ); = - loader->loadFrom( xmlUrl ); - = + Syndication::Loader * const loader =3D Syndication::Loader::create(); + connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, Syndic= ation::FeedPtr, Syndication::ErrorCode ) ), + this, SLOT( slotLoadingComplete( Syndication::Loader*, Syndica= tion::FeedPtr, Syndication::ErrorCode ) ) ); + const KRss::FeedCollection fc( collection ); + const KUrl xmlUrl =3D fc.xmlUrl(); + m_collectionByLoader.insert( loader, collection ); + loader->loadFrom( xmlUrl ); } = void KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, S= yndication::FeedPtr feed, = Syndication::ErrorCode status) { - Q_UNUSED(loader); - = - if (status !=3D Syndication::Success) { - kWarning() << "Error while parsing xml file"; - itemsRetrievalDone(); - return; - } - - QList syndItems =3D feed->items(); - Akonadi::Item::List items; - foreach ( const Syndication::ItemPtr& syndItem, syndItems ) { - Akonadi::Item item( mimeType() ); - item.setRemoteId( syndItem->id() ); - item.setPayload( Util::fromSyndicationItem( syndItem ) ); - item.setFlag( KRss::RssItem::flagNew() ); - items << item; - } - - itemsRetrieved( items ); + const Collection c =3D m_collectionByLoader.take( loader ); + + if (status !=3D 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 =3D new Akonadi::CollectionModif= yJob( fc ); + job->start(); + } + QList syndItems =3D feed->items(); + Akonadi::Item::List items; + foreach ( const Syndication::ItemPtr& syndItem, syndItems ) { + Akonadi::Item item( mimeType() ); + item.setRemoteId( syndItem->id() ); + item.setPayload( Util::fromSyndicationItem( syndIte= m ) ); + 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 #include #include +#include #include "opmlparser.h" = class KRssLocalResource : public Akonadi::ResourceBase, @@ -63,6 +64,7 @@ class KRssLocalResource : public Akonadi::ResourceBase, = private: = Akonadi::CachePolicy policy; + QHash m_collectionByLoader; QTimer *writeBackTimer; static const int CacheTimeout =3D -1, IntervalCheckTime =3D 5; = static const int WriteBackTimeout =3D 30000; // in milliseconds