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

List:       kde-commits
Subject:    playground/pim/krss
From:       Frank Osterfeld <frank.osterfeld () kdemail ! net>
Date:       2009-06-20 19:35:45
Message-ID: 1245526545.019792.8110.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 984464 by osterfeld:

add virtual methods for common stuff to TreeNode, to reduce the need for visitors


 M  +1 -3      krssreader/mainwidget.cpp  
 M  +82 -1     libkrss/treenode.cpp  
 M  +21 -0     libkrss/treenode.h  
 M  +0 -53     libkrss/treenodevisitor.cpp  
 M  +0 -18     libkrss/treenodevisitor.h  


--- trunk/playground/pim/krss/krssreader/mainwidget.cpp #984463:984464
@@ -246,9 +246,7 @@
     Akonadi::ItemFetchScope fetchScope;
     fetchScope.fetchPayloadPart( Item::HeadersPart );
     fetchScope.fetchAllAttributes();
-    auto_ptr<CreateItemListJobVisitor> visitor( new CreateItemListJobVisitor( m_feedList, fetchScope) );
-    m_currentNode->accept( visitor.get() );
-    CompositeItemListJob * const job = visitor->compositeItemListJob();
+    ItemListJob * const job = m_currentNode->createItemListJob( m_feedList );
     connect( job, SIGNAL(finished(KJob*)), this, SLOT(itemListingDone(KJob*)) );
     job->start();
 }
--- trunk/playground/pim/krss/libkrss/treenode.cpp #984463:984464
@@ -17,11 +17,12 @@
 
 #include "treenode.h"
 #include "feed.h"
+#include "feedlist.h"
 #include "itemlistjob.h"
 #include "treenodevisitor.h"
 
 using namespace KRss;
-using boost::shared_ptr;
+using namespace boost;
 
 TreeNode::~TreeNode()
 {
@@ -104,7 +105,29 @@
     d->m_tagNodes.clear();
 }
 
+ItemListJob* RootNode::createItemListJob( const shared_ptr<FeedList>& feedList ) const {
+    //TODO: return All Feeds list job
+    return 0;
+}
 
+QString RootNode::title( const shared_ptr<const FeedList>& feedList ) const {
+    return QString();
+}
+
+int RootNode::unreadCount( const shared_ptr<const FeedList>& feedList ) const {
+    int unread = 0;
+    //TODO: return sum of all feeds, or all feeds tag node (but not sum of all tag nodes!)
+    return unread;
+}
+
+int RootNode::totalCount( const shared_ptr<const FeedList>& feedList ) const {
+    int total = 0;
+    //TODO: return sum of all feeds, or all feeds tag node (but not sum of all tag nodes!)
+    return total;
+}
+
+
+
 class TagNode::Private
 {
 public:
@@ -218,7 +241,35 @@
     d->m_feedNodes.clear();
 }
 
+ItemListJob* TagNode::createItemListJob( const shared_ptr<FeedList>& feedList ) const {
+    CompositeItemListJob* job = new CompositeItemListJob;
+    Q_FOREACH( const shared_ptr<const FeedNode>& feedNode, feedNodes() ) {
+        ItemListJob* const sj = feedNode->createItemListJob( feedList );
+        if ( sj )
+            job->addSubJob( sj );
+    }
+    return job;
+}
 
+QString TagNode::title( const shared_ptr<const FeedList>& ) const {
+    return d->m_tag.label();
+}
+
+int TagNode::unreadCount( const shared_ptr<const FeedList>& feedList ) const {
+    int sum = 0;
+    Q_FOREACH( const shared_ptr<const FeedNode>& feedNode, feedNodes() )
+            sum += feedNode->unreadCount( feedList );
+    return sum;
+}
+
+int TagNode::totalCount( const shared_ptr<const FeedList>& feedList ) const {
+    int sum = 0;
+    Q_FOREACH( const shared_ptr<const FeedNode>& feedNode, feedNodes() )
+            sum += feedNode->totalCount( feedList );
+    return sum;
+}
+
+
 class FeedNode::Private
 {
 public:
@@ -227,6 +278,15 @@
 
     const shared_ptr<TagNode> m_parent;
     Feed::Id m_id;
+
+    shared_ptr<const Feed> feed( const shared_ptr<const FeedList>& fl ) const {
+        return fl ? fl->constFeedById( m_id ) : shared_ptr<const Feed>();
+    }
+
+    const shared_ptr<Feed> feed( const shared_ptr<FeedList>& fl ) const {
+        return fl ? fl->feedById( m_id ) : shared_ptr<Feed>();
+    }
+
 };
 
 FeedNode::FeedNode( const shared_ptr<TagNode>& parent )
@@ -281,3 +341,24 @@
     Q_ASSERT_X( false, "FeedNode::row", "This feed node was not found among the parent's child nodes" );
     return 0;
 }
+
+
+ItemListJob* FeedNode::createItemListJob( const shared_ptr<FeedList>& feedList ) const {
+    const shared_ptr<Feed> f = d->feed( feedList );
+    return f ? f->itemListJob() : 0;
+}
+
+QString FeedNode::title( const shared_ptr<const FeedList>& feedList ) const {
+    const shared_ptr<const Feed> f = d->feed( feedList );
+    return f ? f->title() : QString();
+}
+
+int FeedNode::unreadCount( const shared_ptr<const FeedList>& feedList ) const {
+    const shared_ptr<const Feed> f = d->feed( feedList );
+    return f ? f->unread() : 0;
+}
+
+int FeedNode::totalCount( const shared_ptr<const FeedList>& feedList ) const {
+    const shared_ptr<const Feed> f = d->feed( feedList );
+    return f ? f->total() : 0;
+}
--- trunk/playground/pim/krss/libkrss/treenode.h #984463:984464
@@ -35,6 +35,7 @@
 namespace KRss {
 
 class Feed;
+class FeedList;
 class ItemListJob;
 class RootNode;
 class TagNode;
@@ -54,6 +55,11 @@
 
     virtual Tier tier() const = 0;
     virtual void accept( TreeNodeVisitor *visitor ) = 0;
+
+    virtual ItemListJob* createItemListJob( const boost::shared_ptr<FeedList>& feedList ) const = 0;
+    virtual QString title( const boost::shared_ptr<const FeedList>& feedList ) const = 0;
+    virtual int unreadCount( const boost::shared_ptr<const FeedList>& feedList ) const = 0;
+    virtual int totalCount( const boost::shared_ptr<const FeedList>& feedList ) const = 0;
 };
 
 class KRSS_EXPORT RootNode : public TreeNode, public boost::enable_shared_from_this<RootNode>
@@ -75,6 +81,11 @@
     void removeTagNodeAt( int row );
     void removeTagNodes();
 
+
+    /* reimp */ ItemListJob* createItemListJob( const boost::shared_ptr<FeedList>& feedList ) const;
+    /* reimp */ QString title( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int unreadCount( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int totalCount( const boost::shared_ptr<const FeedList>& feedList ) const;
 private:
     class Private;
     Private * const d;
@@ -105,6 +116,11 @@
     void removeFeedNodeAt( int row );
     void removeFeedNodes();
 
+    /* reimp */ ItemListJob* createItemListJob( const boost::shared_ptr<FeedList>& feedList ) const;
+    /* reimp */ QString title( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int unreadCount( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int totalCount( const boost::shared_ptr<const FeedList>& feedList ) const;
+
 private:
     class Private;
     Private * const d;
@@ -126,6 +142,11 @@
     boost::shared_ptr<const TagNode> parent() const;
     int row() const;
 
+    /* reimp */ ItemListJob* createItemListJob( const boost::shared_ptr<FeedList>& feedList ) const;
+    /* reimp */ QString title( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int unreadCount( const boost::shared_ptr<const FeedList>& feedList ) const;
+    /* reimp */ int totalCount( const boost::shared_ptr<const FeedList>& feedList ) const;
+
 private:
     class Private;
     Private * const d;
--- trunk/playground/pim/krss/libkrss/treenodevisitor.cpp #984463:984464
@@ -75,59 +75,6 @@
     d->m_itemListing->connectToFeed( d->m_feedList->constFeedById( feedNode->feedId() ) );
 }
 
-
-class CreateItemListJobVisitor::Private
-{
-public:
-    explicit Private( const boost::shared_ptr<const FeedList>& feedList,
-                      const Akonadi::ItemFetchScope& fetchScope )
-        : m_feedList( feedList), m_fetchScope( fetchScope ), m_job( new CompositeItemListJob )
-    {
-        m_job->setFetchScope( m_fetchScope );
-    }
-
-    const boost::shared_ptr<const FeedList> m_feedList;
-    const Akonadi::ItemFetchScope m_fetchScope;
-    CompositeItemListJob * const m_job;
-};
-
-CreateItemListJobVisitor::CreateItemListJobVisitor( const boost::shared_ptr<const FeedList>& feedList,
-                                                    const Akonadi::ItemFetchScope& fetchScope )
-    : d( new Private( feedList, fetchScope ) )
-{
-}
-
-CreateItemListJobVisitor::~CreateItemListJobVisitor()
-{
-    delete d;
-}
-
-CompositeItemListJob* CreateItemListJobVisitor::compositeItemListJob() const
-{
-    return d->m_job;
-}
-
-void CreateItemListJobVisitor::visit( const shared_ptr<RootNode>& rootNode )
-{
-    const QList<shared_ptr<TagNode> > tagNodes = rootNode->tagNodes();
-    Q_FOREACH( const shared_ptr<TagNode>& tagNode, tagNodes ) {
-        tagNode->accept( this );
-    }
-}
-
-void CreateItemListJobVisitor::visit( const shared_ptr<TagNode>& tagNode )
-{
-    const QList<shared_ptr<FeedNode> > feedNodes = tagNode->feedNodes();
-    Q_FOREACH( const shared_ptr<FeedNode>& feedNode, feedNodes ) {
-        feedNode->accept( this );
-    }
-}
-
-void CreateItemListJobVisitor::visit( const shared_ptr<FeedNode>& feedNode )
-{
-    d->m_job->addSubJob( d->m_feedList->feedById( feedNode->feedId() )->itemListJob() );
-}
-
 class CreateStatusModifyJobVisitor::Private
 {
 public:
--- trunk/playground/pim/krss/libkrss/treenodevisitor.h #984463:984464
@@ -63,24 +63,6 @@
     Private * const d;
 };
 
-class KRSS_EXPORT CreateItemListJobVisitor : public TreeNodeVisitor
-{
-public:
-    explicit CreateItemListJobVisitor( const boost::shared_ptr<const FeedList>& feedList,
-                                       const Akonadi::ItemFetchScope& fetchScope );
-    ~CreateItemListJobVisitor();
-
-    CompositeItemListJob* compositeItemListJob() const;
-
-    void visit( const boost::shared_ptr<RootNode>& rootNode );
-    void visit( const boost::shared_ptr<TagNode>& tagNode );
-    void visit( const boost::shared_ptr<FeedNode>& feedNode );
-
-private:
-    class Private;
-    Private * const d;
-};
-
 class KRSS_EXPORT CreateStatusModifyJobVisitor : public TreeNodeVisitor
 {
 public:
[prev in list] [next in list] [prev in thread] [next in thread] 

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