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

List:       kde-commits
Subject:    KDE/kdepim/akonadi/agents
From:       Volker Krause <vkrause () kde ! org>
Date:       2009-09-16 12:38:22
Message-ID: 1253104702.062837.23195.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1024357 by vkrause:

Factor out the initial fetching code and make it fully async and a bit more clever.


 M  +1 -0      nepomuk_calendar_feeder/CMakeLists.txt  
 M  +6 -47     nepomuk_calendar_feeder/nepomukcalendarfeeder.cpp  
 M  +0 -8      nepomuk_calendar_feeder/nepomukcalendarfeeder.h  
 M  +3 -65     nepomuk_contact_feeder/nepomukcontactfeeder.cpp  
 M  +0 -9      nepomuk_contact_feeder/nepomukcontactfeeder.h  
 M  +3 -3      nepomuk_email_feeder/nepomukemailfeeder.cpp  
 M  +68 -0     nepomukfeeder/nepomukfeederagent.cpp  
 M  +22 -0     nepomukfeeder/nepomukfeederagent.h  


--- trunk/KDE/kdepim/akonadi/agents/nepomuk_calendar_feeder/CMakeLists.txt \
#1024356:1024357 @@ -19,6 +19,7 @@
   ${NEPOMUK_LIBRARIES}
   ${SOPRANO_LIBRARIES}
   ${KDE4_KDECORE_LIBS}
+  akonadi-kcal
   )
 
 install(TARGETS akonadi_nepomuk_calendar_feeder ${INSTALL_TARGETS_DEFAULT_ARGS})
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_calendar_feeder/nepomukcalendarfeeder.cpp \
#1024356:1024357 @@ -29,6 +29,7 @@
 #include <akonadi/itemfetchjob.h>
 #include <akonadi/collectionfetchjob.h>
 #include <akonadi/mimetypechecker.h>
+#include <kcal/kcalmimetypevisitor.h>
 
 #include <nepomuk/resource.h>
 #include <nepomuk/resourcemanager.h>
@@ -87,16 +88,13 @@
   : NepomukFeederAgent( id ),
     mForceUpdate( false )
 {
+  addSupportedMimeType( KCalMimeTypeVisitor::eventMimeType() );
+  addSupportedMimeType( KCalMimeTypeVisitor::todoMimeType() );
+  addSupportedMimeType( KCalMimeTypeVisitor::journalMimeType() );
+  addSupportedMimeType( KCalMimeTypeVisitor::freeBusyMimeType() );
+
   changeRecorder()->itemFetchScope().fetchFullPayload();
-  changeRecorder()->setMimeTypeMonitored( "text/calendar" );
-  changeRecorder()->setChangeRecordingEnabled( false );
 
-  // do the initial scan to make sure all items have been fed to nepomuk
-  QTimer::singleShot( 0, this, SLOT( slotInitialItemScan() ) );
-
-  // The line below is not necessary anymore once AgentBase also exports scriptable \
                slots
-  QDBusConnection::sessionBus().registerObject( "/nepomukcalendarfeeder", this, \
                QDBusConnection::ExportScriptableSlots );
-
   mNrlModel = new Soprano::NRLModel( \
Nepomuk::ResourceManager::instance()->mainModel() );  }
 
@@ -105,45 +103,6 @@
   delete mNrlModel;
 }
 
-void NepomukCalendarFeeder::slotInitialItemScan()
-{
-  kDebug();
-  updateAll( false );
-}
-
-void NepomukCalendarFeeder::updateAll( bool force )
-{
-  mForceUpdate = force;
-
-  CollectionFetchJob *collectionFetch = new CollectionFetchJob( Collection::root(), \
                CollectionFetchJob::Recursive );
-  if ( collectionFetch->exec() ) {
-    Collection::List collections = collectionFetch->collections();
-
-    MimeTypeChecker calendarFilter;
-    calendarFilter.addWantedMimeType( "text/calendar" );
-    foreach ( const Collection &collection, collections ) {
-      if ( calendarFilter.isWantedCollection( collection ) ) {
-        ItemFetchJob *itemFetch = new ItemFetchJob( collection );
-        itemFetch->fetchScope().fetchFullPayload();
-        connect( itemFetch, SIGNAL( itemsReceived( Akonadi::Item::List ) ),
-                 this, SLOT( slotItemsReceivedForInitialScan( Akonadi::Item::List ) \
                ) );
-      }
-    }
-  }
-}
-
-void NepomukCalendarFeeder::slotItemsReceivedForInitialScan( const \
                Akonadi::Item::List& items )
-{
-  kDebug() << items.count();
-  foreach( const Item &item, items ) {
-    // only update the item if it does not exist
-    if ( mForceUpdate ||
-         !Nepomuk::ResourceManager::instance()->mainModel()->containsAnyStatement( \
                item.url(), Soprano::Node(), Soprano::Node() ) ) {
-      updateItem( item );
-    }
-  }
-}
-
 void NepomukCalendarFeeder::updateItem( const Akonadi::Item &item )
 {
   if ( !item.hasPayload<IncidencePtr>() ) {
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_calendar_feeder/nepomukcalendarfeeder.h \
#1024356:1024357 @@ -41,19 +41,11 @@
 class NepomukCalendarFeeder : public NepomukFeederAgent
 {
   Q_OBJECT
-  Q_CLASSINFO( "D-Bus Interface", "org.kde.akonadi.NepomukCalendarFeeder" )
 
   public:
     NepomukCalendarFeeder( const QString &id );
     ~NepomukCalendarFeeder();
 
-  public Q_SLOTS:
-    Q_SCRIPTABLE void updateAll( bool force = false );
-
-  private Q_SLOTS:
-    void slotInitialItemScan();
-    void slotItemsReceivedForInitialScan( const Akonadi::Item::List& items );
-
   private:
     void updateItem( const Akonadi::Item &item );
     void updateEventItem( const Akonadi::Item &item, KCal::Event*, const QUrl& );
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_contact_feeder/nepomukcontactfeeder.cpp \
#1024356:1024357 @@ -73,17 +73,11 @@
   : NepomukFeederAgent( id ),
     mForceUpdate( false )
 {
+  addSupportedMimeType( KABC::Addressee::mimeType() );
+  addSupportedMimeType( KABC::ContactGroup::mimeType() );
+
   changeRecorder()->itemFetchScope().fetchFullPayload();
-  changeRecorder()->setMimeTypeMonitored( KABC::Addressee::mimeType() );
-  changeRecorder()->setMimeTypeMonitored( KABC::ContactGroup::mimeType() );
-  changeRecorder()->setChangeRecordingEnabled( false );
 
-  // do the initial scan to make sure all items have been fed to nepomuk
-  QTimer::singleShot( 0, this, SLOT( slotInitialItemScan() ) );
-
-  // The line below is not necessary anymore once AgentBase also exports scriptable \
                slots
-  QDBusConnection::sessionBus().registerObject( "/nepomukcontactfeeder", this, \
                QDBusConnection::ExportScriptableSlots );
-
   mNrlModel = new Soprano::NRLModel( \
Nepomuk::ResourceManager::instance()->mainModel() );  }
 
@@ -92,62 +86,6 @@
   delete mNrlModel;
 }
 
-void NepomukContactFeeder::slotInitialItemScan()
-{
-  kDebug();
-  updateAll( false );
-}
-
-void NepomukContactFeeder::updateAll( bool force )
-{
-  mForceUpdate = force;
-
-  CollectionFetchJob *collectionFetch = new CollectionFetchJob( Collection::root(), \
                CollectionFetchJob::Recursive );
-  if ( collectionFetch->exec() ) {
-    Collection::List collections = collectionFetch->collections();
-
-    MimeTypeChecker contactFilter;
-    contactFilter.addWantedMimeType( KABC::Addressee::mimeType() );
-    contactFilter.addWantedMimeType( KABC::ContactGroup::mimeType() );
-    foreach( const Collection &collection, collections) {
-      kDebug() << "checking collection" << collection.name();
-      if ( contactFilter.isWantedCollection( collection ) ) {
-        kDebug() << "fetching items from collection" << collection.name();
-        ItemFetchJob *itemFetch = new ItemFetchJob( collection );
-        itemFetch->fetchScope().fetchFullPayload();
-        connect( itemFetch, SIGNAL( itemsReceived( Akonadi::Item::List ) ),
-                 this, SLOT( slotItemsReceivedForInitialScan( Akonadi::Item::List ) \
                ) );
-      }
-    }
-  }
-}
-
-void NepomukContactFeeder::slotItemsReceivedForInitialScan( const \
                Akonadi::Item::List& items )
-{
-  kDebug() << items.count();
-  foreach( const Item &item, items ) {
-    // only update the item if it does not exist
-    if ( mForceUpdate ||
-         !Nepomuk::ResourceManager::instance()->mainModel()->containsAnyStatement( \
                item.url(), Soprano::Node(), Soprano::Node() ) ) {
-      // FIXME: the idea is that we only fetch the full payload for items that need \
                updating
-      //        However, the code below always returns an empty list!
-//       ItemFetchJob *itemFetch = new ItemFetchJob( item );
-//       itemFetch->fetchScope().fetchFullPayload();
-//       if ( itemFetch->exec() ) {
-//         Akonadi::Item::List fullItems = itemFetch->items();
-//         if ( fullItems.isEmpty() ) {
-//           kDebug() << "Failed to get full payload for item" << item.url();
-//         }
-//         else {
-//           updateItem( itemFetch->items().first() );
-//         }
-//       }
-      updateItem( item );
-    }
-  }
-  kDebug() << "done";
-}
-
 namespace {
   inline QStringList listFromString( const QString& s ) {
     if ( s.isEmpty() )
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_contact_feeder/nepomukcontactfeeder.h \
#1024356:1024357 @@ -35,19 +35,10 @@
 class NepomukContactFeeder : public NepomukFeederAgent
 {
   Q_OBJECT
-  Q_CLASSINFO( "D-Bus Interface", "org.kde.akonadi.NepomukContactFeeder" )
-
   public:
     NepomukContactFeeder( const QString &id );
     ~NepomukContactFeeder();
 
-  public Q_SLOTS:
-    Q_SCRIPTABLE void updateAll( bool force = false );
-
-  private Q_SLOTS:
-    void slotInitialItemScan();
-    void slotItemsReceivedForInitialScan( const Akonadi::Item::List& items );
-
   private:
     void updateItem( const Akonadi::Item &item );
     void updateContactItem( const Akonadi::Item &item, const QUrl& );
--- trunk/KDE/kdepim/akonadi/agents/nepomuk_email_feeder/nepomukemailfeeder.cpp \
#1024356:1024357 @@ -54,10 +54,10 @@
 Akonadi::NepomukEMailFeeder::NepomukEMailFeeder( const QString &id ) :
   NepomukFeederAgent( id )
 {
+  addSupportedMimeType( "message/rfc822" );
+  addSupportedMimeType( "message/news" );
+
   changeRecorder()->itemFetchScope().fetchPayloadPart( MessagePart::Envelope );
-  changeRecorder()->setMimeTypeMonitored( "message/rfc822" );
-  changeRecorder()->setMimeTypeMonitored( "message/news" );
-  changeRecorder()->setChangeRecordingEnabled( false );
 
   mNrlModel = new Soprano::NRLModel( \
Nepomuk::ResourceManager::instance()->mainModel() );  }
--- trunk/KDE/kdepim/akonadi/agents/nepomukfeeder/nepomukfeederagent.cpp \
#1024356:1024357 @@ -22,6 +22,12 @@
 #include "nepomukfeederagent.h"
 
 #include <akonadi/item.h>
+#include <akonadi/changerecorder.h>
+#include <akonadi/collectionfetchjob.h>
+#include <akonadi/collectionfetchscope.h>
+#include <akonadi/mimetypechecker.h>
+#include <akonadi/itemfetchjob.h>
+#include <akonadi/itemfetchscope.h>
 
 #include <nepomuk/resource.h>
 #include <nepomuk/resourcemanager.h>
@@ -32,10 +38,20 @@
 #include <Soprano/NodeIterator>
 #include <Soprano/QueryResultIterator>
 
+#include <QtCore/QTimer>
+
+#include <boost/bind.hpp>
+
+using namespace Akonadi;
+
 NepomukFeederAgent::NepomukFeederAgent(const QString& id) : AgentBase(id)
 {
   // initialize Nepomuk
   Nepomuk::ResourceManager::instance()->init();
+
+ changeRecorder()->setChangeRecordingEnabled( false );
+
+ QTimer::singleShot( 0, this, SLOT(updateAll()) );
 }
 
 NepomukFeederAgent::~NepomukFeederAgent()
@@ -74,4 +90,56 @@
   removeItemFromNepomuk( item );
 }
 
+void NepomukFeederAgent::addSupportedMimeType( const QString &mimeType )
+{
+  mSupportedMimeTypes.append( mimeType );
+  changeRecorder()->setMimeTypeMonitored( mimeType );
+  mMimeTypeChecker.setWantedMimeTypes( mSupportedMimeTypes );
+}
+
+void NepomukFeederAgent::updateAll()
+{
+  CollectionFetchJob *collectionFetch = new CollectionFetchJob( Collection::root(), \
CollectionFetchJob::Recursive, this ); +  \
collectionFetch->fetchScope().setContentMimeTypes( mSupportedMimeTypes ); +  connect( \
collectionFetch, SIGNAL(collectionsReceived(Akonadi::Collection::List)), \
SLOT(collectionsReceived(Akonadi::Collection::List)) ); +}
+
+void NepomukFeederAgent::collectionsReceived(const Akonadi::Collection::List& \
collections) +{
+  mMimeTypeChecker.setWantedMimeTypes( mSupportedMimeTypes );
+  foreach( const Collection &collection, collections ) {
+    kDebug() << "checking collection" << collection.name();
+    if ( mMimeTypeChecker.isWantedCollection( collection ) ) {
+      kDebug() << "fetching items from collection" << collection.name();
+      ItemFetchJob *itemFetch = new ItemFetchJob( collection, this );
+      connect( itemFetch, SIGNAL(itemsReceived( Akonadi::Item::List)), \
SLOT(itemHeadersReceived(Akonadi::Item::List)) ); +    }
+  }
+}
+
+void NepomukFeederAgent::itemHeadersReceived(const Akonadi::Item::List& items)
+{
+  kDebug() << items.count();
+  Akonadi::Item::List itemsToUpdate;
+  foreach( const Item &item, items ) {
+    if ( !mMimeTypeChecker.isWantedItem( item ) )
+      continue;
+    // update item if it does not exist
+    if ( !Nepomuk::ResourceManager::instance()->mainModel()->containsAnyStatement( \
item.url(), Soprano::Node(), Soprano::Node() ) ) +      itemsToUpdate.append( item );
+  }
+
+  ItemFetchJob *itemFetch = new ItemFetchJob( items, this );
+  itemFetch->setFetchScope( changeRecorder()->itemFetchScope() );
+  connect( itemFetch, SIGNAL(itemsReceived(Akonadi::Item::List)), \
SLOT(itemsReceived(Akonadi::Item::List)) ); +  kDebug() << "done";
+}
+
+void NepomukFeederAgent::itemsReceived(const Akonadi::Item::List& items)
+{
+  kDebug() << items.size();
+  std::for_each( items.constBegin(), items.constEnd(), boost::bind( \
&NepomukFeederAgent::updateItem, this, _1 ) ); +}
+
+
 #include "nepomukfeederagent.moc"
--- trunk/KDE/kdepim/akonadi/agents/nepomukfeeder/nepomukfeederagent.h \
#1024356:1024357 @@ -23,7 +23,12 @@
 #define NEPOMUKFEEDERAGENT_H
 
 #include <akonadi/agentbase.h>
+#include <akonadi/collection.h>
+#include <akonadi/item.h>
+#include <akonadi/mimetypechecker.h>
 
+#include <QStringList>
+
 namespace Akonadi
 {
   class Item;
@@ -38,15 +43,32 @@
     NepomukFeederAgent(const QString& id);
     ~NepomukFeederAgent();
 
+    /** Remove all references to the given item from Nepomuk. */
     static void removeItemFromNepomuk( const Akonadi::Item &item );
 
+    /** Add a supported mimetype. */
+    void addSupportedMimeType( const QString &mimeType );
+
     /** Reimplement to do the actual work. */
     virtual void updateItem( const Akonadi::Item &item ) = 0;
 
+  public slots:
+    /** Trigger a complete update of all items. */
+    void updateAll();
+
   protected:
     void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection \
                );
     void itemChanged( const Akonadi::Item &item, const QSet<QByteArray> \
&partIdentifiers );  void itemRemoved(const Akonadi::Item &item);
+
+  private slots:
+    void collectionsReceived( const Akonadi::Collection::List &collections );
+    void itemHeadersReceived( const Akonadi::Item::List &items );
+    void itemsReceived( const Akonadi::Item::List &items );
+
+  private:
+    QStringList mSupportedMimeTypes;
+    Akonadi::MimeTypeChecker mMimeTypeChecker;
 };
 
 #endif


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

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