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

List:       kde-commits
Subject:    playground/pim/krss/resource
From:       Dmitry Ivanov <vonami () gmail ! com>
Date:       2008-06-28 19:42:28
Message-ID: 1214682148.312922.25548.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 825606 by divanov:

- add a custom RssItemSync'er: update items if their hash values don't match
- use RssItemSync'er and incremental retrieval in the resource


 M  +1 -0      CMakeLists.txt  
 A             rssitemsync.cpp   [License: GPL (v2+)]
 A             rssitemsync.h   [License: GPL (v2+)]
 M  +33 -17    rssresource.cpp  
 M  +1 -0      rssresource.h  


--- trunk/playground/pim/krss/resource/CMakeLists.txt #825605:825606
@@ -6,6 +6,7 @@
     ../libkrss/tagscollectionattribute.cpp
     ../libkrss/subscriptionlabelscollectionattribute.cpp
     ../libkrss/feedpropertiescollectionattribute.cpp
+    rssitemsync.cpp
 )
 
 qt4_add_dbus_adaptor(rssresource_SRCS ../libkrss/org.kde.krss.xml rssresource.h \
                RssResource )
--- trunk/playground/pim/krss/resource/rssresource.cpp #825605:825606
@@ -17,6 +17,7 @@
 
 #include "krssadaptor.h"
 #include "rssresource.h"
+#include "rssitemsync.h"
 #include "../libkrss/tagscollectionattribute.h"
 #include "../libkrss/subscriptionlabelscollectionattribute.h"
 #include "../libkrss/feedpropertiescollectionattribute.h"
@@ -42,12 +43,19 @@
 using namespace Akonadi;
 
 // helper functions
+
+// from akregator/src/utils.cpp
+static inline int calcHash( const QString &str )
+{
+        const QByteArray array = str.toAscii();
+        return qChecksum( array.constData(), array.size() );
+}
+
 static inline KFeed::Item convertToKFeedItem( const Syndication::ItemPtr &syndItem )
 {
                 KFeed::Item kfeedItem;
 
                 kfeedItem.setStatus( KFeed::New );
-                //kfeedItem.setHash()                        // do i need to calc \
                the hash value?
                 kfeedItem.setIdIsHash( syndItem->id().startsWith("hash:") );
                 //kfeedItem.setSourceFeedId(currentCollection().remoteId().toInt()); \
// kfeed supports only integer ids  kfeedItem.setTitle( syndItem->title() );
@@ -72,6 +80,7 @@
                 kfeedItem.setCommentPostUri( syndItem->commentPostUri() );
 
                 // Authors
+                QString authors;  // for hash
                 QList<KFeed::Person> kfeedPersons;
                 Q_FOREACH( const Syndication::PersonPtr &pers, syndItem->authors() ) \
{  if ( !pers->isNull() ) {
@@ -113,6 +122,9 @@
                 kfeedItem.setCategories( kfeedCategories );
 
                 // TODO: custom properties
+
+                kfeedItem.setHash( calcHash( syndItem->title() + \
syndItem->description() + syndItem->content() + syndItem->link() + +                  \
authors ) );  return kfeedItem;
 }
 
@@ -356,23 +368,12 @@
 {
         kDebug() << "Retrieving items for" << col.name();
 
-        if ( !col.isValid() ) {
-                kDebug() << "Collection is not valid";
-                return;
-        }
-
-        if ( col.contentMimeTypes().contains( Collection::mimeType() ) ) {
-                kDebug() << "Collection" << col.name() << "is a folder";
-                return;
-        }
-
         if ( col.hasAttribute( "FeedProperties" ) ) {
                 fetchFeedContent( \
col.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() );  }
         else {
                 kDebug() << "Collection doesn't have \'FeedProperties\' attribute \
                set";
-                Item::List itemList;
-                itemsRetrieved( itemList );
+                itemsRetrievedIncremental( Akonadi::Item::List(), \
Akonadi::Item::List() );  }
 }
 
@@ -534,6 +535,17 @@
         QDBusConnection::sessionBus().send( m_replyMessage );
 }
 
+void RssResource::slotItemSyncDone( KJob *job )
+{
+        kDebug() << "ItemSync done";
+        if ( job->error() ) {
+                kWarning() << "Failed to sync collection";
+                kWarning() << job->errorString();
+        }
+
+        itemsRetrievalDone();
+}
+
 void RssResource::fetchFeedContent( const QString &url )
 {
         Syndication::Loader *loader = Syndication::Loader::create( this, SLOT( \
feedContentFetched( Syndication::Loader*, @@ -590,23 +602,27 @@
 
         kDebug() << "Status:" << status;
 
-        Item::List itemList;
         if ( status != Syndication::Success ) {
                 kDebug() << "Failed to load feed from"
                         << \
                currentCollection().attribute<FeedPropertiesCollectionAttribute>()->xmlUrl();
                
-                itemsRetrieved( itemList );
+                itemsRetrievedIncremental( Akonadi::Item::List(), \
Akonadi::Item::List() );  return;
         }
 
+        Akonadi::Item::List items;
         Q_FOREACH( const Syndication::ItemPtr &it, feed->items() ) {
                 Item item;
                 item.setRemoteId( it->id() );
                 item.setMimeType( "application/rss+xml" );
                 item.setPayload<KFeed::Item>( convertToKFeedItem( it ) );
-                itemList.append( item );
+                items.append( item );
         }
 
-        itemsRetrieved( itemList );
+        ItemSync *syncer = new RssItemSync( currentCollection() );
+        connect( syncer, SIGNAL( percent( KJob*, unsigned long ) ), this, SLOT( \
slotPercent( KJob*, unsigned long ) ) ); +        connect( syncer, SIGNAL( result( \
KJob* ) ), this, SLOT( slotItemSyncDone( KJob* ) ) ); +
+        syncer->setIncrementalSyncItems( items, Akonadi::Item::List() );
 }
 
 void RssResource::importOpml( const QString &path, const QString &defaultTag )
--- trunk/playground/pim/krss/resource/rssresource.h #825605:825606
@@ -72,6 +72,7 @@
         void slotCollectionDeleted( KJob *job );
         void slotSubscriptionDone( KJob *job );
         void slotTaggingDone( KJob *job );
+        void slotItemSyncDone( KJob *job );
         void feedPropertiesFetched( Syndication::Loader *loader, \
                Syndication::FeedPtr feed, Syndication::ErrorCode status );
         void feedContentFetched( Syndication::Loader *loader, Syndication::FeedPtr \
feed, Syndication::ErrorCode status );  


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

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