[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-07-05 18:22:26
Message-ID: 1215282146.835805.17666.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 828404 by divanov:
Wrap the addFeed() D-Bus call in AddFeedJob.
M +1 -0 CMakeLists.txt
A addfeedjob.cpp [License: GPL (v2+)]
A addfeedjob.h [License: GPL (v2+)]
M +21 -53 rssresource.cpp
M +1 -7 rssresource.h
--- trunk/playground/pim/krss/resource/CMakeLists.txt #828403:828404
@@ -9,6 +9,7 @@
rssitemsync.cpp
../libkrss/flagsmodifyjob.cpp
syncfeedjob.cpp
+ addfeedjob.cpp
)
qt4_add_dbus_adaptor(rssresource_SRCS ../libkrss/org.kde.krss.xml rssresource.h \
RssResource )
--- trunk/playground/pim/krss/resource/rssresource.cpp #828403:828404
@@ -21,6 +21,7 @@
#include "../libkrss/subscriptionlabelscollectionattribute.h"
#include "../libkrss/feedpropertiescollectionattribute.h"
#include "syncfeedjob.h"
+#include "addfeedjob.h"
#include <akonadi/collectionfetchjob.h>
#include <akonadi/collectioncreatejob.h>
@@ -52,7 +53,7 @@
// member functions
RssResource::RssResource( const QString &id )
- :ResourceBase( id ), m_fetchTries( 0 )
+ :ResourceBase( id )
{
AttributeFactory::registerAttribute<TagsCollectionAttribute>();
AttributeFactory::registerAttribute<SubscriptionLabelsCollectionAttribute>();
@@ -75,16 +76,19 @@
col.setContentMimeTypes( QStringList( "application/rss+xml" ) );
col.setRemoteId( KRandom::randomString( 10 ) );
col.setName( xmlUrl + '_' + col.remoteId() );
- col.attribute<FeedPropertiesCollectionAttribute>( \
Akonadi::Collection::AddIfMissing )->setXmlUrl( xmlUrl );
- col.attribute<SubscriptionLabelsCollectionAttribute>( \
Akonadi::Collection::AddIfMissing )->addSubscriptionLabel( subscriptionLabel ); + \
col.attribute<FeedPropertiesCollectionAttribute>( Akonadi::Collection::AddIfMissing \
)-> + setXmlUrl( xmlUrl );
+ col.attribute<SubscriptionLabelsCollectionAttribute>( \
Akonadi::Collection::AddIfMissing )-> + \
addSubscriptionLabel( subscriptionLabel );
+ AddFeedJob *job = new AddFeedJob( col );
+ connect( job, SIGNAL( result( KJob* ) ), this, SLOT( feedCreationDone( KJob* \
) ) ); +
// send the reply later
setDelayedReply( true );
- m_replyMessage = QDBusContext::message().createReply();
+ job->setReplyMessage( QDBusContext::message().createReply() );
- // load feed properties
- m_currentCollection = col;
- fetchFeedProperties( xmlUrl );
+ job->start();
return QString();
}
@@ -402,21 +406,25 @@
}
}
-void RssResource::slotCollectionCreated( KJob *job )
+void RssResource::feedCreationDone( KJob *job )
{
- kDebug() << "CollectionCreateJob done";
+ kDebug() << "Feed creation done";
+
+ QString remoteId;
if ( job->error() ) {
- kWarning() << "Failed to create a new collection";
+ kWarning() << "Failed to create a new feed";
kWarning() << job->errorString();
return;
}
- Akonadi::Collection col = static_cast<Akonadi::CollectionCreateJob*>( job \
)->collection(); + Akonadi::Collection col = static_cast<AddFeedJob*>( job \
)->collection(); m_collections[ col.remoteId() ] = col;
+ remoteId = col.remoteId();
// return the remote id to the caller
- m_replyMessage << col.remoteId();
- QDBusConnection::sessionBus().send( m_replyMessage );
+ QDBusMessage replyMessage = static_cast<AddFeedJob*>( job )->replyMessage();
+ replyMessage << remoteId;
+ QDBusConnection::sessionBus().send( replyMessage );
}
void RssResource::slotCollectionDeleted( KJob *job )
@@ -469,46 +477,6 @@
QDBusConnection::sessionBus().send( m_replyMessage );
}
-void RssResource::fetchFeedProperties( const QString &url )
-{
- Syndication::Loader *loader = Syndication::Loader::create( this, SLOT( \
feedPropertiesFetched( Syndication::Loader*,
- \
Syndication::FeedPtr,
- \
Syndication::ErrorCode ) ) );
-
- kDebug() << "Url:" << url;
- loader->loadFrom( url );
-}
-
-void RssResource::feedPropertiesFetched( Syndication::Loader *loader, \
Syndication::FeedPtr feed, Syndication::ErrorCode status )
-{
- kDebug() << "Status:" << status;
-
- if ( ( status == Syndication::InvalidXml ) && (m_fetchTries < 3 ) && ( \
loader->discoveredFeedURL().isValid() ) ) {
- kDebug() << "Refetching by discovered feed url";
- QString newUrl = loader->discoveredFeedURL().url();
- m_currentCollection.setName( newUrl + '_' + \
m_currentCollection.remoteId() );
- m_currentCollection.attribute<FeedPropertiesCollectionAttribute>()->setXmlUrl( \
newUrl );
- m_fetchTries++;
- fetchFeedProperties( newUrl );
- return;
- }
-
- if ( status == Syndication::Success ) {
- // set the corresponding collection attributes
- 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_currentCollection );
- connect( job, SIGNAL( result( KJob* ) ),
- this, SLOT( slotCollectionCreated( KJob* ) ) );
-}
-
void RssResource::importOpml( const QString &path, const QString &defaultTag )
{
// load the opml to m_pendingCollections
--- trunk/playground/pim/krss/resource/rssresource.h #828403:828404
@@ -18,8 +18,6 @@
#ifndef KRSS_RSSRESOURCE
#define KRSS_RSSRESOURCE
-#include <kfeed/item.h>
-#include <syndication/syndication.h>
#include <akonadi/resourcebase.h>
#include <QStack>
@@ -68,18 +66,16 @@
void slotListingDone( KJob *job );
void slotRootCollectionCreated( KJob *job );
void slotCollectionImported( KJob *job );
- void slotCollectionCreated( KJob *job );
void slotCollectionDeleted( KJob *job );
void slotSubscriptionDone( KJob *job );
void slotTaggingDone( KJob *job );
+ void feedCreationDone( KJob *job );
void blockedFeedSyncDone( KJob *job );
void parallelFeedSyncDone( KJob *job );
- void feedPropertiesFetched( Syndication::Loader *loader, \
Syndication::FeedPtr feed, Syndication::ErrorCode status );
private:
void listCollections();
- void fetchFeedProperties( const QString &url );
void loadOpml( const QString &path, const QString &defaultTag );
void readUnknownElement();
@@ -91,8 +87,6 @@
private:
- int m_fetchTries;
-
Akonadi::Collection m_rootCollection;
QHash<QString, Akonadi::Collection> m_collections;
QStack<Akonadi::Collection> m_pendingCollections;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic