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

List:       kde-commits
Subject:    [kdepim-runtime/akregator_port] krsslocal: polished version after failed attempts to remove errors
From:       Alessandro Cosentino <cosenal () gmail ! com>
Date:       2012-03-31 15:16:46
Message-ID: 20120331151646.6F9B3A6106 () git ! kde ! org
[Download RAW message or body]

Git commit 4d252402ffbdb59effebbbfa9bd7a1deeb68887f by Alessandro Cosentino.
Committed on 29/08/2011 at 15:56.
Pushed by osterfeld into branch 'akregator_port'.

polished version after failed attempts to remove errors

M  +54   -28   krsslocal/krsslocalresource.cpp
M  +9    -6    krsslocal/krsslocalresource.h
M  +1    -1    krsslocal/util.cpp

http://commits.kde.org/kdepim-runtime/4d252402ffbdb59effebbbfa9bd7a1deeb68887f

diff --git a/krsslocal/krsslocalresource.cpp b/krsslocal/krsslocalresource.cpp
index 76a602e..3daed0b 100644
--- a/krsslocal/krsslocalresource.cpp
+++ b/krsslocal/krsslocalresource.cpp
@@ -13,12 +13,12 @@
 #include <QtXml/QXmlStreamReader>
 #include <QMessageBox>
 #include <akonadi/entitydisplayattribute.h>
+#include <Akonadi/ItemFetchJob>
+#include <Akonadi/ItemFetchScope>
+#include <Akonadi/ChangeRecorder>
 #include <krss/rssitem.h>
 #include <krssresource/krssresource_export.h>
 
-#define CACHE_TIMEOUT 1
-#define INTERVAL_CHECK_TIME 1  
-
 using namespace Akonadi;
 using namespace KRssResource;
 using namespace boost;
@@ -32,12 +32,23 @@ KRssLocalResource::KRssLocalResource( const QString &id )
    
   policy.setCacheTimeout( CACHE_TIMEOUT );
   policy.setIntervalCheckTime( INTERVAL_CHECK_TIME );
+  
+  /*
+  changeRecorder()->fetchCollection( true );
+  changeRecorder()->itemFetchScope().fetchFullPayload( false );
+  changeRecorder()->itemFetchScope().fetchAllAttributes( true );
+  */
 }
 
 KRssLocalResource::~KRssLocalResource()
 {
 }
 
+QString KRssLocalResource::mimeType()
+{
+  return QLatin1String("application/rss+xml");
+}
+
 void KRssLocalResource::retrieveCollections()
 {
   // TODO: this method is called when Akonadi wants to have all the
@@ -127,18 +138,18 @@ Collection::List KRssLocalResource::buildCollectionTree( \
QList<shared_ptr<const  
 void KRssLocalResource::retrieveItems( const Akonadi::Collection &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.
-  // 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 );
-
+// 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.
+// 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 );
+      
 }
 
 void KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, \
Syndication::FeedPtr feed,  @@ -152,21 +163,34 @@ void \
KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, Syndica  return;
      }
 
-     QString title = feed->title();
-     const QList<Syndication::ItemPtr> syndItems = feed->items();
+     m_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;
+     foreach ( const Syndication::ItemPtr& syndItem, m_syndItems ) {
+	  Akonadi::Item item( mimeType() );
+	  item.setRemoteId( syndItem->id() );
+	  item.setPayload<KRss::RssItem>( fromSyndicationItem( syndItem ) );
+	  item.setFlag( KRss::RssItem::flagNew() );
+	  /*	  
+	  Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection );
+	  connect( job, SIGNAL( result( KJob* ) ), SLOT( jobFinished( KJob* ) ) );
+	  job->start();
+	  */
+	  items << item;
      }
-     
-     itemsRetrieved( items );
 
+     itemsRetrieved( items );
+ 
 }
+/*
+bool KRssLocalResource::jobFinished(KJob* job)
+{
+    if ( job->error() ) {
+      qDebug() << "Error occurred";
+      return false;
+    }
+   
+
+}  */  
 
 bool KRssLocalResource::retrieveItem( const Akonadi::Item &item, const \
QSet<QByteArray> &parts )  {
@@ -178,7 +202,7 @@ bool KRssLocalResource::retrieveItem( const Akonadi::Item &item, \
const QSet<QByt  // to provide all in one go
 
   
-  return true;
+  return false;
 }
 
 void KRssLocalResource::aboutToQuit()
@@ -214,7 +238,7 @@ void KRssLocalResource::configure( WId windowId )
 
 void KRssLocalResource::itemAdded( const Akonadi::Item &item, const \
Akonadi::Collection &collection )  {
-  Q_UNUSED( item );
+  //Q_UNUSED( item );
   Q_UNUSED( collection );
 
   // TODO: this method is called when somebody else, e.g. a client application,
@@ -222,6 +246,8 @@ void KRssLocalResource::itemAdded( const Akonadi::Item &item, \
const Akonadi::Col  
   // NOTE: There is an equivalent method for collections, but it isn't part
   // of this template code to keep it simple
+  
+  changeCommitted( item );
 }
 
 void KRssLocalResource::itemChanged( const Akonadi::Item &item, const \
                QSet<QByteArray> &parts )
diff --git a/krsslocal/krsslocalresource.h b/krsslocal/krsslocalresource.h
index d28a888..8c5210e 100644
--- a/krsslocal/krsslocalresource.h
+++ b/krsslocal/krsslocalresource.h
@@ -18,7 +18,8 @@ class KRssLocalResource : public Akonadi::ResourceBase,
     ~KRssLocalResource();
     Akonadi::Collection::List buildCollectionTree( QList<boost::shared_ptr<const \
KRssResource::ParsedNode> > listOfNodes,   Akonadi::Collection::List &list, \
                Akonadi::Collection &parent);
-    
+    QString mimeType();
+
   public Q_SLOTS:
     virtual void configure( WId windowId );
 
@@ -27,8 +28,9 @@ class KRssLocalResource : public Akonadi::ResourceBase,
     void retrieveItems( const Akonadi::Collection &col );
     bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
     void slotLoadingComplete(Syndication::Loader* loader, Syndication::FeedPtr feed, \
                
-					    Syndication::ErrorCode status);
-        
+			Syndication::ErrorCode status );
+//   bool jobFinished( KJob *job );
+    
   protected:
     virtual void aboutToQuit();
 
@@ -38,10 +40,11 @@ class KRssLocalResource : public Akonadi::ResourceBase,
     
     void fetchFeed( const Akonadi::Collection &feed );
     
-  private:
-    QTimer timer;
+  private:    
     Akonadi::CachePolicy policy;
-       
+    QList<Syndication::ItemPtr> m_syndItems;
+    static const int CACHE_TIMEOUT = -1, INTERVAL_CHECK_TIME = 5;
+    
 };
 
 #endif
diff --git a/krsslocal/util.cpp b/krsslocal/util.cpp
index 734e498..49cace7 100644
--- a/krsslocal/util.cpp
+++ b/krsslocal/util.cpp
@@ -46,7 +46,7 @@ static inline int calcHash( const QString& str )
     return qChecksum( array.constData(), array.size() );
 }
 
-KRss::RssItem KRssResource::fromSyndicationItem( const Syndication::ItemPtr& \
syndItem ) +static KRss::RssItem KRssResource::fromSyndicationItem( const \
Syndication::ItemPtr& syndItem )  {
     KRss::RssItem rssItem;
     rssItem.setHeadersLoaded( true );


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

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