[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepimlibs/akregator_port] krss: port global unread count
From: Frank Osterfeld <frank.osterfeld () kdemail ! net>
Date: 2012-03-31 15:16:21
Message-ID: 20120331151621.E5663A60DF () git ! kde ! org
[Download RAW message or body]
Git commit d12f6d81d73a21e9717642c08ae9b69eadceadd5 by Frank Osterfeld.
Committed on 04/10/2009 at 15:28.
Pushed by osterfeld into branch 'akregator_port'.
port global unread count
svn path=/branches/work/akonadi-ports/kdepim/; revision=1031237
M +51 -2 krss/feedlist.cpp
M +8 -2 krss/feedlist.h
M +15 -3 krss/feedlist_p.h
http://commits.kde.org/kdepimlibs/d12f6d81d73a21e9717642c08ae9b69eadceadd5
diff --git a/krss/feedlist.cpp b/krss/feedlist.cpp
index 3b40fc4..8302511 100644
--- a/krss/feedlist.cpp
+++ b/krss/feedlist.cpp
@@ -80,6 +80,43 @@ void FeedListPrivate::appendFeedCollection( const FeedCollection& collection,
q, SIGNAL( feedChanged( const KRss::Feed::Id& ) ) );
QObject::connect( feed.get(), SIGNAL( removed( const KRss::Feed::Id& ) ),
q, SLOT( slotFeedRemoved( const KRss::Feed::Id& ) ) );
+ emitItemCounts();
+}
+
+void FeedListPrivate::emitItemCounts()
+{
+ if ( !m_emitItemCountTimer.isActive() )
+ m_emitItemCountTimer.start();
+}
+
+void FeedListPrivate::slotEmitItemCountsDelayed()
+{
+ int total = 0;
+ int unread = 0;
+ QHash<Feed::Id, shared_ptr<Feed> >::ConstIterator it = m_feeds.constBegin();
+ const QHash<Feed::Id, shared_ptr<Feed> >::ConstIterator end = m_feeds.constEnd();
+
+ while ( it != end ) {
+ total += it.value()->total();
+ unread += it.value()->unread();
+ ++it;
+ }
+ m_totalCount = total;
+ m_unreadCount = unread;
+ emit q->unreadCountChanged( unread );
+ emit q->totalCountChanged( total );
+}
+
+void FeedListPrivate::slotUnreadCountChanged( const Feed::Id& id, int count )
+{
+ emit q->unreadCountChanged( id, count );
+ emitItemCounts();
+}
+
+void FeedListPrivate::slotTotalCountChanged( const Feed::Id& id, int count )
+{
+ emit q->totalCountChanged( id, count );
+ emitItemCounts();
}
void FeedListPrivate::slotFeedAdded( const QString& resourceId, const KRss::Feed::Id& id )
@@ -97,8 +134,10 @@ void FeedListPrivate::slotFeedAdded( const QString& resourceId, const KRss::Feed
void FeedListPrivate::slotFeedRemoved( const KRss::Feed::Id& id )
{
- Q_UNUSED( id )
- //TODO: implement
+ // TODO handle races (removed before collection loaded
+ m_feeds.value( id )->disconnect( q );
+ m_feeds.remove( id );
+ emitItemCounts();
}
void FeedListPrivate::slotCollectionLoadDone( KJob *job )
@@ -131,6 +170,16 @@ FeedList::~FeedList()
delete d;
}
+int FeedList::unreadCount() const
+{
+ return d->m_unreadCount;
+}
+
+int FeedList::totalCount() const
+{
+ return d->m_totalCount;
+}
+
QList<shared_ptr<Feed> > FeedList::feeds() const
{
return d->m_feeds.values();
diff --git a/krss/feedlist.h b/krss/feedlist.h
index 984e8eb..accccae 100644
--- a/krss/feedlist.h
+++ b/krss/feedlist.h
@@ -64,14 +64,18 @@ public:
QList<boost::shared_ptr<Feed> > feedByTitle( const QString& title ) const;
QList<boost::shared_ptr<const Feed> > constFeedByTitle( const QString& title ) const;
+ int unreadCount() const;
+ int totalCount() const;
+
Q_SIGNALS:
void feedAdded( const KRss::Feed::Id& id );
void feedChanged( const KRss::Feed::Id& id );
void feedRemoved( const KRss::Feed::Id& id );
void totalCountChanged( const KRss::Feed::Id& id, int count );
+ void totalCountChanged( int count );
void unreadCountChanged( const KRss::Feed::Id& id, int count );
-
+ void unreadCountChanged( int count );
void fetchStarted( const KRss::Feed::Id& id );
void fetchPercent( const KRss::Feed::Id& id, uint percent );
void fetchFinished( const KRss::Feed::Id& id );
@@ -83,11 +87,13 @@ private:
Q_DISABLE_COPY( FeedList )
Q_PRIVATE_SLOT( d, void slotFeedAdded( const QString& resourceId, const KRss::Feed::Id& id ) )
Q_PRIVATE_SLOT( d, void slotFeedRemoved( const KRss::Feed::Id& id ) )
+ Q_PRIVATE_SLOT( d, void slotTotalCountChanged( const KRss::Feed::Id&, int ) )
+ Q_PRIVATE_SLOT( d, void slotUnreadCountChanged( const KRss::Feed::Id&, int ) )
Q_PRIVATE_SLOT( d, void slotCollectionLoadDone( KJob *job ) )
+ Q_PRIVATE_SLOT( d, void slotEmitItemCountsDelayed() )
};
-
class KRSS_EXPORT RetrieveFeedListJob : public KJob
{
Q_OBJECT
diff --git a/krss/feedlist_p.h b/krss/feedlist_p.h
index 1826e34..5cf8fde 100644
--- a/krss/feedlist_p.h
+++ b/krss/feedlist_p.h
@@ -25,6 +25,7 @@
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QHash>
+#include <QtCore/QTimer>
#include <boost/shared_ptr.hpp>
class KJob;
@@ -39,22 +40,33 @@ class FeedListPrivate
{
public:
explicit FeedListPrivate( FeedList *qq )
- : q( qq ) {}
+ : q( qq ), m_totalCount( 0 ), m_unreadCount( 0 ) {
+ m_emitItemCountTimer.setSingleShot( true );
+ m_emitItemCountTimer.setInterval( 400 );
+ q->connect( &m_emitItemCountTimer, SIGNAL(timeout()), q, SLOT(slotEmitItemCountsDelayed()) );
+ }
void appendResourceCollections( const QList<Akonadi::Collection>& collections,
const boost::shared_ptr<Resource>& resource );
void appendFeedCollection( const FeedCollection& feedCollection,
const boost::shared_ptr<Resource>& resource );
- void slotFeedAdded( const QString& resourceId, const KRss::Feed::Id& id );
- void slotFeedRemoved( const KRss::Feed::Id& id );
+ void slotFeedAdded( const QString& resourceId, const Feed::Id& id );
+ void slotFeedRemoved( const Feed::Id& id );
+ void slotUnreadCountChanged( const Feed::Id& id, int count );
+ void slotTotalCountChanged( const Feed::Id& id, int count );
void slotCollectionLoadDone( KJob *job );
+ void emitItemCounts();
+ void slotEmitItemCountsDelayed();
public:
FeedList * const q;
QHash<Feed::Id, boost::shared_ptr<Feed> > m_feeds;
QHash<QString, boost::shared_ptr<Resource> > m_resources;
QHash<const KJob*, QString> m_pendingJobs;
+ int m_totalCount;
+ int m_unreadCount;
+ QTimer m_emitItemCountTimer;
};
} // namespace KRss
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic