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

List:       kde-commits
Subject:    playground/pim/krss
From:       Dmitry Ivanov <vonami () gmail ! com>
Date:       2009-04-07 19:54:11
Message-ID: 1239134051.713740.4482.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 950785 by divanov:

Apparently, the content of an RSS item can be empty:
 - I'm subscribed to a feed whose items have only the title
 - when importing items from Akreagtor, deleted items
   has no content at all

So, make the serializer more reliable wrt splitting an item
into parts by providing explicit headersLoaded and
contentLoaded properties in RssItem class instead of guessing
what is loaded.


 M  +30 -3     libkrss/rssitem.cpp  
 M  +5 -0      libkrss/rssitem.h  
 M  +6 -0      libkrss/rssitemserializer.cpp  
 M  +5 -10     plugin/akonadi_serializer_rss.cpp  
 M  +2 -0      resources/libkrssresource/itemimportreader.cpp  
 M  +2 -0      resources/libkrssresource/util.cpp  


--- trunk/playground/pim/krss/libkrss/rssitem.cpp #950784:950785
@@ -38,7 +38,8 @@
 class RssItem::Private : public QSharedData
 {
 public:
-    Private() : hash( 0 ), guidIsHash( false ), commentsCount( -1 ), feedId( -1 )
+    Private() : hash( 0 ), guidIsHash( false ), commentsCount( -1 ), feedId( -1 ),
+        headersLoaded( false ), contentLoaded( false )
     {}
 
     Private( const Private& other );
@@ -67,7 +68,9 @@
             && commentsFeed == other.commentsFeed
             && commentPostUri == other.commentPostUri
             && customProperties == other.customProperties
-            && feedId == other.feedId;
+            && feedId == other.feedId
+            && headersLoaded == other.headersLoaded
+            && contentLoaded == other.contentLoaded;
     }
 
     int hash;
@@ -89,6 +92,8 @@
     QString commentPostUri;
     QHash<QString, QString> customProperties;
     int feedId;
+    bool headersLoaded;
+    bool contentLoaded;
 };
 
 RssItem::Private::Private( const Private& other )
@@ -110,7 +115,9 @@
     commentsLink( other.commentsLink ),
     commentPostUri( other.commentPostUri ),
     customProperties( other.customProperties ),
-    feedId( other.feedId )
+    feedId( other.feedId ),
+    headersLoaded( other.headersLoaded ),
+    contentLoaded( other.contentLoaded )
 {
 }
 
@@ -148,6 +155,26 @@
 {
 }
 
+bool RssItem::headersLoaded() const
+{
+    return d->headersLoaded;
+}
+
+void RssItem::setHeadersLoaded( bool headersLoaded )
+{
+    d->headersLoaded = headersLoaded;
+}
+
+bool RssItem::contentLoaded() const
+{
+    return d->contentLoaded;
+}
+
+void RssItem::setContentLoaded( bool contentLoaded )
+{
+    d->contentLoaded = contentLoaded;
+}
+
 QString RssItem::title() const
 {
     return d->title;
--- trunk/playground/pim/krss/libkrss/rssitem.h #950784:950785
@@ -51,6 +51,11 @@
     bool operator==( const RssItem& other ) const;
     bool operator!=( const RssItem& other ) const;
 
+    bool headersLoaded() const;
+    void setHeadersLoaded( bool headersLoaded );
+    bool contentLoaded() const;
+    void setContentLoaded( bool contentLoaded );
+
     int hash() const;
     void setHash( int hash );
     bool guidIsHash() const;
--- trunk/playground/pim/krss/libkrss/rssitemserializer.cpp #950784:950785
@@ -405,6 +405,12 @@
     const bool readHeaders = ( part == Full || part == Headers );
     const bool readContent = ( part == Full || part == Content );
 
+    if ( readHeaders )
+        item.setHeadersLoaded( true );
+
+    if ( readContent )
+        item.setContentLoaded( true );
+
     while ( !reader.atEnd() )
     {
         reader.readNext();
--- trunk/playground/pim/krss/plugin/akonadi_serializer_rss.cpp #950784:950785
@@ -91,22 +91,17 @@
     if ( item.hasPayload<RssItem>() ) {
         const RssItem rssItem = item.payload<RssItem>();
 
-        bool hasHeaders = false;
-        bool hasContent = false;
-
-        // if guid or hash is not empty we are sure the headers are loaded
-        if ( !rssItem.guid().isEmpty() || !rssItem.link().isEmpty() ) {
-            partIdentifiers << KRss::Item::HeadersPart;
-            hasHeaders = true;
+        if ( rssItem.headersLoaded() ) {
+            partIdentifiers << KRss::Item::HeadersPart ;
         }
 
-        if ( !rssItem.description().isEmpty() || !rssItem.content().isEmpty() ) {
+        if ( rssItem.contentLoaded() ) {
             partIdentifiers << KRss::Item::ContentPart;
-            hasContent = true;
         }
 
-        if ( hasHeaders && hasContent )
+        if ( rssItem.headersLoaded() && rssItem.contentLoaded() ) {
             partIdentifiers << Akonadi::Item::FullPayload;
+        }
     }
 
     return partIdentifiers;
--- trunk/playground/pim/krss/resources/libkrssresource/itemimportreader.cpp #950784:950785
@@ -195,6 +195,8 @@
 
     Akonadi::Item::Flags flags;
     KRss::RssItem item;
+    item.setHeadersLoaded( true );
+    item.setContentLoaded( true );
 
     while ( !reader.atEnd() && !el.entry.isNextIn( reader ) )
     {
--- trunk/playground/pim/krss/resources/libkrssresource/util.cpp #950784:950785
@@ -50,6 +50,8 @@
 KRss::RssItem KRssResource::fromSyndicationItem( const Syndication::ItemPtr& syndItem )
 {
     KRss::RssItem rssItem;
+    rssItem.setHeadersLoaded( true );
+    rssItem.setContentLoaded( true );
 
     rssItem.setGuidIsHash( syndItem->id().startsWith( "hash:" ) );
     //rssItem.setSourceFeedId(currentCollection().remoteId().toInt());
[prev in list] [next in list] [prev in thread] [next in thread] 

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