[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/pim/krss/resources/libkrssresource
From: Dmitry Ivanov <vonami () gmail ! com>
Date: 2009-06-14 8:53:48
Message-ID: 1244969628.212474.23282.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 981729 by divanov:
Propagate the fetch-related signals
M +21 -3 rssresourcebase.cpp
M +10 -6 rssresourcebase.h
M +20 -2 rssresourcebasejobs.cpp
--- trunk/playground/pim/krss/resources/libkrssresource/rssresourcebase.cpp #981728:981729
@@ -57,7 +57,7 @@
explicit Private() {};
QHash<KJob*, KRss::FeedCollection> m_feedsInProcess;
- QHash<KRss::FeedCollection::Id, FeedFetchJob*> m_fetchJobs;
+ QHash<const KJob*, KRss::Feed::Id> m_fetchJobs;
QHash<KJob*, QDBusMessage> m_replies;
};
@@ -172,8 +172,12 @@
job->setResourceId( identifier() );
job->setBackendJob( backendJob );
job->setSynchronizeFlags( flagsSynchronizable() );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFeedFetched( KJob* ) ) );
+ connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFetchResult( KJob* ) ) );
+ connect( job, SIGNAL( percent( KJob*, unsigned long) ),
+ this, SLOT( slotFetchPercent( KJob*, unsigned long ) ) );
+ d->m_fetchJobs.insert( job, id );
job->start();
+ emit fetchStarted( id );
return;
}
@@ -488,14 +492,28 @@
itemsRetrievalDone();
}
-void RssResourceBase::slotFeedFetched( KJob * job )
+void RssResourceBase::slotFetchResult( KJob * job )
{
+ Q_ASSERT( d->m_fetchJobs.contains( job ) );
+ const KRss::Feed::Id id = d->m_fetchJobs.take( job );
+
if ( job->error() ) {
kWarning() << "Failed to fetch the feed";
kWarning() << job->errorString();
+ ( job->error() == KJob::KilledJobError ? emit fetchAborted( id ) :
+ emit fetchFailed( id, job->errorString() ) );
+ return;
}
+
+ emit fetchFinished( id );
}
+void RssResourceBase::slotFetchPercent( KJob *job, unsigned long percentage )
+{
+ Q_ASSERT( d->m_fetchJobs.contains( job ) );
+ emit fetchPercent( d->m_fetchJobs.value( job ), percentage );
+}
+
void RssResourceBase::slotOpmlImported( KJob *job )
{
if ( job->error() ) {
--- trunk/playground/pim/krss/resources/libkrssresource/rssresourcebase.h #981728:981729
@@ -73,11 +73,14 @@
Q_SIGNALS:
// D-Bus interface
- void fetchStarted( const KRss::Feed::Id& id );
- void fetchPercent( const KRss::Feed::Id& id, uint percentage );
- void fetchFinished( const KRss::Feed::Id& id );
- void fetchFailed( const KRss::Feed::Id& id, const QString& errorMessage );
- void fetchAborted( const KRss::Feed::Id& id );
+ // NOTE: 'qlonglong' means here 'const KRss::Feed::Id&'
+ // needed for QDBusAbstractAdaptor::autoRelaySignals to work
+ // (the signatures must match)
+ void fetchStarted( qlonglong id );
+ void fetchPercent( qlonglong id , uint percentage );
+ void fetchFinished( qlonglong id );
+ void fetchFailed( qlonglong id, const QString& errorMessage );
+ void fetchAborted( qlonglong id );
protected Q_SLOTS:
void retrieveCollections();
@@ -94,7 +97,8 @@
void slotFeedDeleted( KJob *job );
void slotSubscriptionsRetrieved( KJob *job );
void slotItemsRetrieved( KJob *job );
- void slotFeedFetched( KJob *job );
+ void slotFetchResult( KJob *job );
+ void slotFetchPercent( KJob *job, unsigned long percentage );
void slotOpmlImported( KJob *job );
void slotOpmlExported( KJob *job );
void slotItemsImported( KJob *job );
--- trunk/playground/pim/krss/resources/libkrssresource/rssresourcebasejobs.cpp #981728:981729
@@ -31,6 +31,7 @@
#include <KLocale>
#include <KDebug>
#include <boost/bind.hpp>
+#include <numeric>
//todo:
// - overloaded ctors
@@ -551,12 +552,15 @@
public:
explicit Private( const KRss::FeedCollection& collection, FeedCollectionFetchJob * qq )
: m_collection( collection ), m_id( KRss::Feed::Id() ), haveOnlyId( false ),
- m_synchronizeFlags( false ), m_backendJob( 0 ), q( qq ) {}
+ m_synchronizeFlags( false ), m_backendJob( 0 ),
+ m_percentages( QVector<uint>( 3, 0 ) ), q( qq ) {}
explicit Private( const KRss::Feed::Id& id, FeedCollectionFetchJob * qq )
- : m_id( id ), haveOnlyId( true ), m_synchronizeFlags( false ), m_backendJob( 0 ), q( qq ) {}
+ : m_id( id ), haveOnlyId( true ), m_synchronizeFlags( false ), m_backendJob( 0 ),
+ m_percentages( QVector<uint>( 3, 0 ) ), q( qq ) {}
bool clearNewFlag( Akonadi::Item& item );
+ void updatePercent();
void doStart();
void slotAkonadiCollectionRetrieved( KJob *job );
void slotOldItemsMarked( KJob* );
@@ -569,6 +573,7 @@
QString m_resourceId;
bool m_synchronizeFlags;
KRssResource::FeedFetchJob *m_backendJob;
+ QVector<uint> m_percentages;
FeedCollectionFetchJob * const q;
};
@@ -583,6 +588,13 @@
return false;
}
+void FeedCollectionFetchJob::Private::updatePercent()
+{
+ const uint p = qBound( 0, qRound( std::accumulate( m_percentages.begin(), m_percentages.end(), 0u )
+ / static_cast<double>( m_percentages.size() ) ), 100 );
+ q->setPercent( p );
+}
+
void FeedCollectionFetchJob::Private::doStart()
{
if ( haveOnlyId ) {
@@ -631,6 +643,8 @@
return;
}
+ m_percentages.insert( 0, 100 );
+ updatePercent();
Q_ASSERT( m_backendJob );
m_backendJob->setFeed( m_collection );
connect( m_backendJob, SIGNAL( result( KJob* ) ), q, SLOT( slotFeedFetched( KJob* ) ) );
@@ -647,6 +661,8 @@
return;
}
+ m_percentages.insert( 1, 100 );
+ updatePercent();
const FeedFetchJob * const fjob = qobject_cast<const FeedFetchJob*>( job );
Q_ASSERT( fjob );
const QList<Akonadi::Item> items = fjob->items();
@@ -668,6 +684,8 @@
return;
}
+ m_percentages.insert( 2, 100 );
+ updatePercent();
q->emitResult();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic