[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim/akregator_port] krsslocal: Writing back to opml handled by a timer
From: Alessandro Cosentino <cosenal () gmail ! com>
Date: 2012-02-20 21:25:55
Message-ID: 20120220212555.9CE4AA60EB () git ! kde ! org
[Download RAW message or body]
Git commit 0458c3ef8a34271d2cff7faf57d849c2b2c3a9c0 by Alessandro Cosentino.
Committed on 03/09/2011 at 23:58.
Pushed by cgiboudeaux into branch 'akregator_port'.
Writing back to opml handled by a timer
M +32 -12 krsslocal/krsslocalresource.cpp
M +9 -3 krsslocal/krsslocalresource.h
http://commits.kde.org/kdepim/0458c3ef8a34271d2cff7faf57d849c2b2c3a9c0
diff --git a/krsslocal/krsslocalresource.cpp b/krsslocal/krsslocalresource.cpp
index e2895ee..9be5cfb 100644
--- a/krsslocal/krsslocalresource.cpp
+++ b/krsslocal/krsslocalresource.cpp
@@ -45,6 +45,14 @@ KRssLocalResource::KRssLocalResource( const QString &id )
changeRecorder()->itemFetchScope().fetchFullPayload( false );
//changeRecorder()->itemFetchScope().fetchAllAttributes( true );
+ //This timer handles the situation in which at least one collection is changed
+ //and the modifications must be written back on the opml file.
+ //
+ writeBackTimer = new QTimer(this);
+ writeBackTimer->setSingleShot( true );
+ connect(writeBackTimer, SIGNAL(timeout()), this, SIGNAL(quitOrTimeout()));
+ connect(this, SIGNAL(quitOrTimeout()), this, SLOT(fetchCollections()));
+
}
KRssLocalResource::~KRssLocalResource()
@@ -56,11 +64,14 @@ QString KRssLocalResource::mimeType()
return QLatin1String("application/rss+xml");
}
+// this method is called when Akonadi wants to have all the
+// collections your resource provides.
+// Be sure to set the remote ID and the content MIME types
void KRssLocalResource::retrieveCollections()
{
- // TODO: this method is called when Akonadi wants to have all the
- // collections your resource provides.
- // Be sure to set the remote ID and the content MIME types
+
+ //it forces previous changes of the Collections to be written back
+ fetchCollections();
const QString path = Settings::self()->path();
@@ -171,9 +182,9 @@ void KRssLocalResource::slotLoadingComplete(Syndication::Loader* \
loader, Syndica return;
}
- m_syndItems = feed->items();
+ QList<Syndication::ItemPtr> syndItems = feed->items();
Akonadi::Item::List items;
- foreach ( const Syndication::ItemPtr& syndItem, m_syndItems ) {
+ foreach ( const Syndication::ItemPtr& syndItem, syndItems ) {
Akonadi::Item item( mimeType() );
item.setRemoteId( syndItem->id() );
item.setPayload<KRss::RssItem>( Util::fromSyndicationItem( syndItem ) );
@@ -201,6 +212,12 @@ void KRssLocalResource::aboutToQuit()
{
// TODO: any cleanup you need to do while there is still an active
// event loop. The resource will terminate after this method returns
+
+ if (writeBackTimer->isActive()) {
+ writeBackTimer->stop();
+ emit quitOrTimeout();
+ }
+
}
void KRssLocalResource::configure( WId windowId )
@@ -250,16 +267,20 @@ void KRssLocalResource::itemChanged( const Akonadi::Item &item, \
const QSet<QByte }
void KRssLocalResource::collectionChanged(const Akonadi::Collection& collection)
-{
- using namespace Akonadi;
-
+{
Q_UNUSED( collection );
+ if (!writeBackTimer->isActive()) {
+ writeBackTimer->start(WRITE_BACK_TIMEOUT);
+ }
+
+}
+
+void KRssLocalResource::fetchCollections() {
// fetching all collections containing rss feeds recursively, starting at the root \
collection CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), \
CollectionFetchJob::Recursive, this ); job->fetchScope().setContentMimeTypes( \
QStringList() << mimeType() ); connect( job, SIGNAL( result( KJob* ) ), SLOT( \
fetchCollectionsFinished( KJob* ) ) );
-
}
void KRssLocalResource::fetchCollectionsFinished(KJob *job) {
@@ -273,9 +294,9 @@ void KRssLocalResource::fetchCollectionsFinished(KJob *job) {
const Collection::List collections = fetchJob->collections();
- const QString path = Settings::self()->path();
-
+ const QString path = Settings::self()->path();
writeFeedsToOpml( path, collections );
+
}
void KRssLocalResource::writeFeedsToOpml(const QString &path, const \
QList<Akonadi::Collection>& feeds) @@ -296,7 +317,6 @@ void \
KRssLocalResource::writeFeedsToOpml(const QString &path, const QList<Akonad }
-
AKONADI_RESOURCE_MAIN( KRssLocalResource )
#include "krsslocalresource.moc"
diff --git a/krsslocal/krsslocalresource.h b/krsslocal/krsslocalresource.h
index aa123f2..b3f2b0b 100644
--- a/krsslocal/krsslocalresource.h
+++ b/krsslocal/krsslocalresource.h
@@ -6,6 +6,7 @@
#include <boost/shared_ptr.hpp>
#include <krssresource/opmlparser.h>
#include <Syndication/Syndication>
+#include <QTimer>
class KRssLocalResource : public Akonadi::ResourceBase,
public Akonadi::AgentBase::Observer
@@ -21,7 +22,9 @@ class KRssLocalResource : public Akonadi::ResourceBase,
void writeFeedsToOpml(const QString &path, const QList<Akonadi::Collection>& \
feeds);
public Q_SLOTS:
- virtual void configure( WId windowId );
+ virtual void configure( WId windowId );
+ signals:
+ void quitOrTimeout();
protected Q_SLOTS:
void retrieveCollections();
@@ -29,6 +32,7 @@ class KRssLocalResource : public Akonadi::ResourceBase,
bool retrieveItem( const Akonadi::Item &item, const QSet<QByteArray> &parts );
void slotLoadingComplete(Syndication::Loader* loader, Syndication::FeedPtr feed, \
Syndication::ErrorCode status );
+ void fetchCollections();
void fetchCollectionsFinished( KJob *job );
@@ -42,8 +46,10 @@ class KRssLocalResource : public Akonadi::ResourceBase,
private:
Akonadi::CachePolicy policy;
- QList<Syndication::ItemPtr> m_syndItems;
- static const int CACHE_TIMEOUT = -1, INTERVAL_CHECK_TIME = 5;
+ //QList<Syndication::ItemPtr> m_syndItems;
+ QTimer *writeBackTimer;
+ static const int CACHE_TIMEOUT = -1, INTERVAL_CHECK_TIME = 5;
+ static const int WRITE_BACK_TIMEOUT = 30000; // in milliseconds
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic