[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/pim/krss/resource
From: Dmitry Ivanov <vonami () gmail ! com>
Date: 2008-06-18 18:43:44
Message-ID: 1213814624.520087.24695.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 821874 by divanov:
Create all collections without the assistance of CollectionSync
M +70 -60 rssresource.cpp
M +5 -2 rssresource.h
--- trunk/playground/pim/krss/resource/rssresource.cpp #821873:821874
@@ -73,7 +73,7 @@
m_replyMessage = QDBusContext::message().createReply();
// load feed properties
- m_changedCollections << col;
+ m_currentCollection = col;
fetchFeedProperties( xmlUrl );
return QString();
@@ -207,55 +207,17 @@
root.setName( "RSS subscriptions" );
root.setContentMimeTypes( QStringList( Collection::mimeType() ) );
- m_rootCollection = root;
- m_changedCollections << root;
+ loadOpml( path );
- loadOpml( path );
- synchronize();
+ Akonadi::CollectionCreateJob *job = new \
Akonadi::CollectionCreateJob( root ); + connect( job, SIGNAL( result( \
KJob* ) ), + this, SLOT( slotRootCollectionCreated( KJob* ) ) \
); }
}
void RssResource::retrieveCollections()
{
- kDebug() << "Changed collections:";
- Q_FOREACH( const Akonadi::Collection &col, m_changedCollections ) {
- kDebug() << "Name:" << col.name() << "RemoteId:" << col.remoteId() \
<< "Local id:" << col.id();
- }
-
- kDebug() << "Removed collections:";
- Q_FOREACH( const Akonadi::Collection &col, m_removedCollections ) {
- kDebug() << "Name:" << col.name();
- }
-
- kDebug() << "Old collections:";
- QHashIterator<QString, Akonadi::Collection> itold(m_collections);
- while ( itold.hasNext() ) {
- itold.next();
- kDebug() << "Remote id:" << itold.key() << ", name:" << \
itold.value().name();
- }
-
- collectionsRetrievedIncremental( m_changedCollections, m_removedCollections \
);
-
- // process changed collections
- Q_FOREACH( const Akonadi::Collection &col, m_changedCollections ) {
- m_collections[ col.remoteId() ] = col;
- }
-
- // process removed collections
- Q_FOREACH( const Akonadi::Collection &col, m_removedCollections ) {
- m_collections.remove( col.remoteId() );
- }
-
- // cleanup
- m_changedCollections.clear();
- m_removedCollections.clear();
-
- kDebug() << "New collections:";
- QHashIterator<QString, Akonadi::Collection> itnew(m_collections);
- while ( itnew.hasNext() ) {
- itnew.next();
- kDebug() << "Remote id:" << itnew.key() << ", name:" << \
itnew.value().name();
- }
+ collectionsRetrieved( m_collections.values() );
}
void RssResource::retrieveItems(const Akonadi::Collection &col)
@@ -317,6 +279,62 @@
}
}
+void RssResource::slotRootCollectionCreated( KJob *job )
+{
+ kDebug() << "Root collection creation done";
+ if ( job->error() ) {
+ kWarning() << "Failed to create the root collection";
+ kWarning() << job->errorString();
+ return;
+ }
+
+ m_rootCollection = static_cast<Akonadi::CollectionCreateJob*>( job \
)->collection(); + m_collections[ m_rootCollection.remoteId() ] = \
m_rootCollection; + kDebug() << "Got id:" << m_rootCollection.id();
+
+ if ( !m_pendingCollections.isEmpty() ) {
+ Akonadi::Collection col = m_pendingCollections.top();
+ kDebug() << "Import new collection:" << col.name();
+ col.setParent( m_rootCollection );
+ Akonadi::CollectionCreateJob *job = new \
Akonadi::CollectionCreateJob( col ); + connect( job, SIGNAL( result( \
KJob* ) ), + this, SLOT( slotCollectionImported( KJob* ) ) );
+ }
+ else {
+ kDebug() << "No pending collections: synchronizing the tree";
+ synchronize();
+ }
+}
+
+void RssResource::slotCollectionImported( KJob *job )
+{
+ kDebug() << "Collection import done";
+ if ( job->error() ) {
+ kWarning() << "Failed to create the a new collection";
+ kWarning() << job->errorString();
+ m_pendingCollections.pop();
+ return;
+ }
+
+ Akonadi::Collection col = static_cast<Akonadi::CollectionCreateJob*>( job \
)->collection(); + m_collections[ col.remoteId() ] = col;
+ m_pendingCollections.pop();
+ kDebug() << "Got id:" << col.id();
+
+ if ( !m_pendingCollections.isEmpty() ) {
+ Akonadi::Collection col = m_pendingCollections.top();
+ kDebug() << "Import new collection:" << col.remoteId() << ", name:" \
<< col.name(); + col.setParent( m_rootCollection );
+ Akonadi::CollectionCreateJob *job = new \
Akonadi::CollectionCreateJob( col ); + connect( job, SIGNAL( result( \
KJob* ) ), + this, SLOT( slotCollectionImported( KJob* ) ) );
+ }
+ else {
+ kDebug() << "No pending collections: synchronizing the tree";
+ synchronize();
+ }
+}
+
void RssResource::slotCollectionCreated( KJob *job )
{
kDebug() << "CollectionCreateJob done";
@@ -326,17 +344,9 @@
return;
}
- m_changedCollections.clear();
Akonadi::Collection col = static_cast<Akonadi::CollectionCreateJob*>( job \
)->collection(); m_collections[ col.remoteId() ] = col;
- kDebug() << "Collections:";
- QHashIterator<QString, Akonadi::Collection> it(m_collections);
- while ( it.hasNext() ) {
- it.next();
- kDebug() << "Remote id:" << it.key() << ", name:" << \
it.value().name() << ", id:" << it.value().id();
- }
-
// return the remote id to the caller
m_replyMessage << col.remoteId();
QDBusConnection::sessionBus().send( m_replyMessage );
@@ -401,8 +411,8 @@
if ( ( status == Syndication::InvalidXml ) && (m_fetchTries < 3 ) && ( \
loader->discoveredFeedURL().isValid() ) ) { kDebug() << "Refetching by discovered \
feed url"; QString newUrl = loader->discoveredFeedURL().url();
- m_changedCollections[ 0 ].setName( newUrl );
- m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setXmlUrl( newUrl ); + \
m_currentCollection.setName( newUrl ); + \
m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setXmlUrl( newUrl \
); m_fetchTries++;
fetchFeedProperties( newUrl );
return;
@@ -410,16 +420,16 @@
if ( status == Syndication::Success ) {
// set the corresponding collection attributes
- m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setName( \
feed->title() );
- m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setHtmlUrl( \
feed->link() );
- m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setFeedType( "rss" \
);
- m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setDescription( feed->description() \
); + m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setName( \
feed->title() ); + \
m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setHtmlUrl( \
feed->link() ); + \
m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setFeedType( \
"rss" ); + \
m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setDescription( \
feed->description() ); }
m_fetchTries = 0;
// commit the new collection
- Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob( \
m_changedCollections[ 0 ] ); + Akonadi::CollectionCreateJob *job = new \
Akonadi::CollectionCreateJob( m_currentCollection ); connect( job, SIGNAL( result( \
KJob* ) ), this, SLOT( slotCollectionCreated( KJob* ) ) );
}
@@ -675,7 +685,7 @@
kDebug() << "Setting tags:" << tags;
TagsCollectionAttribute *feedTags = new TagsCollectionAttribute( \
tags ); col.addAttribute( feedTags );
- m_changedCollections << col;
+ m_pendingCollections.push( col );
}
while ( !m_reader.atEnd() ) {
--- trunk/playground/pim/krss/resource/rssresource.h #821873:821874
@@ -22,6 +22,7 @@
#include <syndication/syndication.h>
#include <akonadi/resourcebase.h>
+#include <QStack>
#include <QHash>
#include <QXmlStreamReader>
@@ -59,6 +60,8 @@
private Q_SLOTS:
void slotListingDone( KJob *job );
+ void slotRootCollectionCreated( KJob *job );
+ void slotCollectionImported( KJob *job );
void slotCollectionCreated( KJob *job );
void slotCollectionDeleted( KJob *job );
void slotSubscriptionDone( KJob *job );
@@ -84,8 +87,8 @@
Akonadi::Collection m_rootCollection;
QHash<QString, Akonadi::Collection> m_collections;
- QList<Akonadi::Collection> m_changedCollections;
- QList<Akonadi::Collection> m_removedCollections;
+ QStack<Akonadi::Collection> m_pendingCollections;
+ Akonadi::Collection m_currentCollection;
QXmlStreamReader m_reader;
QDBusMessage m_replyMessage;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic