[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-17 19:07:11
Message-ID: 1213729631.119489.10109.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 821551 by divanov:

- return the remoteId in addFeed(); it will be used for
  the other D-Bus calls
- disable collectionAdded(), it's broken and probably won't
  be of any use anymore


 M  +48 -23    rssresource.cpp  
 M  +7 -2      rssresource.h  


--- trunk/playground/pim/krss/resource/rssresource.cpp #821550:821551
@@ -25,6 +25,7 @@
 #include <kfeed/enclosure.h>
 #include <kfeed/category.h>
 #include <akonadi/collectionfetchjob.h>
+#include <akonadi/collectioncreatejob.h>
 #include <akonadi/attributefactory.h>
 #include <akonadi/changerecorder.h>
 
@@ -55,7 +56,7 @@
         listCollections();
 }
 
-void RssResource::addFeed( const QString &xmlUrl, const QString &subscriptionLabel )
+QString RssResource::addFeed( const QString &xmlUrl, const QString \
&subscriptionLabel )  {
         Akonadi::Collection col;
         col.setName( xmlUrl );
@@ -65,12 +66,19 @@
         col.attribute<FeedPropertiesCollectionAttribute>( \
                Akonadi::Collection::AddIfMissing )->setXmlUrl( xmlUrl );
         col.attribute<SubscriptionLabelsCollectionAttribute>( \
Akonadi::Collection::AddIfMissing )->addSubscriptionLabel( subscriptionLabel );  
+        // send the reply later
+        setDelayedReply( true );
+        m_replyMessage = QDBusContext::message().createReply();
+
         // load feed properties
         m_changedCollections << col;
         fetchFeedProperties( xmlUrl );
+
+        return QString();
 }
 
-void RssResource::collectionAdded( const Akonadi::Collection &collection, const \
Akonadi::Collection &parent ) +// to be removed
+/*void RssResource::collectionAdded( const Akonadi::Collection &collection, const \
Akonadi::Collection &parent )  {
         // col.name() contains the XmlUrl of the added feed
         if ( m_collections.contains( collection.name() ) ) {
@@ -88,7 +96,7 @@
         // load feed properties
         m_changedCollections << copy;
         fetchFeedProperties( copy.name() );
-}
+}*/
 
 bool RssResource::retrieveItem(const Akonadi::Item &item, const QSet<QByteArray> \
&parts)  {
@@ -139,24 +147,19 @@
         QHashIterator<QString, Akonadi::Collection> itold(m_collections);
         while ( itold.hasNext() ) {
                 itold.next();
-                kDebug() << "XmlUrl:" << itold.key() << ", name:" << \
itold.value().name(); +                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 ) {
-                if ( col.parent() == Akonadi::Collection::root().id() ) {
-                        m_collections[ col.remoteId() ] = col;
-                }
-                else {
-                        m_collections[ \
                col.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() ] = col;
-                }
+                m_collections[ col.remoteId() ] = col;
         }
 
         // process removed collections
         Q_FOREACH( const Akonadi::Collection &col, m_removedCollections ) {
-                m_collections.remove( \
col.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() ); +                \
m_collections.remove( col.remoteId() );  }
 
         // cleanup
@@ -167,7 +170,7 @@
         QHashIterator<QString, Akonadi::Collection> itnew(m_collections);
         while ( itnew.hasNext() ) {
                 itnew.next();
-                kDebug() << "XmlUrl:" << itnew.key() << ", name:" << \
itnew.value().name(); +                kDebug() << "Remote id:" << itnew.key() << ", \
name:" << itnew.value().name();  }
 }
 
@@ -218,21 +221,43 @@
                 if ( col.parent() == Collection::root().id() ) {
                         kDebug() << "Found root collection:" << col.name();
                         m_rootCollection = col;
-                        m_collections[ col.remoteId() ] = col;
                 }
-                else {
-                        m_collections[ \
                col.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() ] = col;
-                }
+                m_collections[ col.remoteId() ] = col;
         }
 
         kDebug() << "Collections:";
         QHashIterator<QString, Akonadi::Collection> it(m_collections);
         while ( it.hasNext() ) {
                 it.next();
-                kDebug() << "XmlUrl:" << it.key() << ", name:" << it.value().name();
+                kDebug() << "Remote id:" << it.key() << ", name:" << \
it.value().name() << ", id:" << it.value().id();  }
 }
 
+void RssResource::slotCollectionCreated( KJob *job )
+{
+        kDebug() << "CollectionCreateJob done";
+        if ( job->error() ) {
+                kWarning() << "Failed to create a new collection";
+                kWarning() << job->errorString();
+                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 );
+}
+
 void RssResource::fetchFeedContent( const QString &url )
 {
         Syndication::Loader *loader = Syndication::Loader::create( this, SLOT( \
feedContentFetched( Syndication::Loader*, @@ -259,10 +284,7 @@
 
         if ( ( status == Syndication::InvalidXml ) && (m_fetchTries < 3 ) && ( \
loader->discoveredFeedURL().isValid() ) ) {  kDebug() << "Refetching by discovered \
                feed url";
-                // move the feed within m_collections by its new url
-                QString oldUrl = m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->xmlUrl();  QString newUrl = \
                loader->discoveredFeedURL().url();
-                m_collections[ newUrl ] = m_collections.take( oldUrl );
                 m_changedCollections[ 0 ].setName( newUrl );
                 m_changedCollections[ 0 \
].attribute<FeedPropertiesCollectionAttribute>()->setXmlUrl( newUrl );  \
m_fetchTries++; @@ -272,15 +294,18 @@
 
         if ( status == Syndication::Success ) {
                 // set the corresponding collection attributes
-                m_changedCollections[ 0 ].setName( feed->title() );
+                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() \
);  }
 
-        // sync the collection tree
         m_fetchTries = 0;
-        synchronizeCollectionTree();
+
+        // commit the new collection
+        Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob( \
m_changedCollections[ 0 ] ); +        connect( job, SIGNAL( result( KJob* ) ),
+                 this, SLOT( slotCollectionCreated( KJob* ) ) );
 }
 
 void RssResource::feedContentFetched( Syndication::Loader *loader, \
                Syndication::FeedPtr feed, Syndication::ErrorCode status )
--- trunk/playground/pim/krss/resource/rssresource.h #821550:821551
@@ -36,13 +36,15 @@
 
 protected:
 
-        void collectionAdded( const Akonadi::Collection &collection, const \
Akonadi::Collection &parent ); +        //void collectionAdded( const \
Akonadi::Collection &collection, const Akonadi::Collection &parent );  
 public Q_SLOTS:
 
         void configure(WId windowId);
-        void addFeed( const QString &xmlUrl, const QString &subscriptionLabel );
 
+        // D-Bus interface
+        QString addFeed( const QString &xmlUrl, const QString &subscriptionLabel );
+
 protected Q_SLOTS:
 
         void retrieveCollections();
@@ -52,6 +54,7 @@
 private Q_SLOTS:
 
         void slotListingDone( KJob *job );
+        void slotCollectionCreated( KJob *job );
         void feedPropertiesFetched( Syndication::Loader *loader, \
                Syndication::FeedPtr feed, Syndication::ErrorCode status );
         void feedContentFetched( Syndication::Loader *loader, Syndication::FeedPtr \
feed, Syndication::ErrorCode status );  
@@ -77,6 +80,8 @@
         QList<Akonadi::Collection> m_changedCollections;
         QList<Akonadi::Collection> m_removedCollections;
         QXmlStreamReader m_reader;
+
+        QDBusMessage m_replyMessage;
 };
 
 #endif /* AKONADI_RSS_RESOURCE */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic