extragear/multimedia/amarok/src/collection/nepomukcollection

Daniel Winter dw at danielwinter.de
Tue Jul 1 16:38:46 CEST 2008


SVN commit 826823 by danielw:

Now using model from Nepomuk ResourceManager as the QLocalSocket bug is fixed in Soprano (Sebastian++). Easier code, faster. Needs recent Soprano (should not affect Amarok if it is too old, but Nepomuk Collection will not work correct)

CCMAIL: strueg at mandriva.com
CCMAIL: amarok-devel at kde.org

 M  +11 -30    NepomukCollection.cpp  
 M  +2 -5      NepomukCollection.h  
 M  +8 -18     NepomukQueryMaker.cpp  
 M  +1 -3      NepomukQueryMaker.h  


--- trunk/extragear/multimedia/amarok/src/collection/nepomukcollection/NepomukCollection.cpp #826822:826823
@@ -34,6 +34,7 @@
 #include <Nepomuk/Resource>
 #include <Nepomuk/ResourceManager>
 #include <Soprano/Model>
+#include <Soprano/PluginManager>
 #include <Soprano/QueryResultIterator>
 #include <Soprano/Vocabulary/NAO>
 #include <Soprano/Vocabulary/Xesam>
@@ -46,34 +47,24 @@
 void
 NepomukCollectionFactory::init()
 {
-    Soprano::Client::DBusClient* client = new Soprano::Client::DBusClient( "org.kde.NepomukStorage" );
-
-    // TODO: use QLocalSocket 
-    //if ( Nepomuk::ResourceManager::instance()->init() == 0 )
-    if (client->isValid())
+    if ( Nepomuk::ResourceManager::instance()->init() == 0 )
     {
-        Soprano::Model* model = (Soprano::Model*)client->createModel( "main" );
-        Nepomuk::ResourceManager::instance()->setOverrideMainModel( model );
+        Soprano::Model* model = Nepomuk::ResourceManager::instance()->mainModel();
+
         // find out if Nepomuk is fast enough
         // (if sesame2 is used or not, it makes no sense to use it with redland
         // doesn't work and is terrible slow, slows down amarok start when 
         // songs in playlist)
-         
-        QTime t;
-        t.start();
-        Nepomuk::Resource::Resource( "file://home/" ).exists();
-        int elapsed = t.elapsed();
-        debug() << "Nepomuk Resource.exists() took " << elapsed <<  " ms" << endl;
         
         Collection* collection;
-        if ( elapsed < 50 )
+        if (  Soprano::PluginManager::instance()->discoverBackendByName("sesame2") != 0 )
         {
-            collection = new NepomukCollection( client, model, true );
+            collection = new NepomukCollection( model, true );
             debug() << "fast  enough full nepomuk collection enabled" << endl;
         }
         else
         {
-            collection = new NepomukCollection( client, model, false );
+            collection = new NepomukCollection( model, false );
             debug() << "too slow, trackForUrl() disabled" << endl;
         }
         emit newCollection( collection );
@@ -81,15 +72,13 @@
     else
     {
         warning() << "Nepomuk is not running, can not init Nepomuk Collection" << endl;
-        delete client;
     }
 }
 
 // NepomukCollection
 
-NepomukCollection::NepomukCollection(Soprano::Client::DBusClient *client, Soprano::Model* model, bool isFast )
+NepomukCollection::NepomukCollection( Soprano::Model* model, bool isFast )
     :   Collection() 
-    ,   m_client( client )
     ,   m_model( model )
     ,   m_isFast( isFast )
 {
@@ -99,13 +88,12 @@
 NepomukCollection::~NepomukCollection()
 {
     delete m_model;
-    delete m_client;
 }
 
 QueryMaker*
 NepomukCollection::queryMaker()
 {
-	return new NepomukQueryMaker(this, m_client, m_model);
+	return new NepomukQueryMaker(this, m_model);
 }
 
 QString
@@ -139,12 +127,11 @@
         return Meta::TrackPtr();
     
     DEBUG_BLOCK
-    Nepomuk::ResourceManager::instance()->setOverrideMainModel( m_model );
     if ( Nepomuk::Resource::Resource( url ).exists() )
     {
         debug() << "Track: " << url.prettyUrl() << " is in NepomukCollection" << endl;
         
-        NepomukQueryMaker qm( this, m_client, m_model );
+        NepomukQueryMaker qm( this, m_model );
         qm.startTrackQuery();
         qm.addMatch( url );
         QString query = qm.buildQuery();
@@ -152,6 +139,7 @@
         Soprano::QueryResultIterator it
                               = m_model->executeQuery( query, 
                                                      Soprano::Query::QueryLanguageSparql );
+        
         // assuming that there is only one result, should never be more, if so giving
         // the first is the best to do anyway
         if ( it.next() )
@@ -165,13 +153,6 @@
 }
 
 void
-NepomukCollection::lostDBusConnection()
-{
-    debug() << "removing NepomukCollection, lost dbus connection" << endl;
-    emit remove();
-}
-
-void 
 NepomukCollection::initHashMaps()
 {
     // this "v =" works around a linker error 
--- trunk/extragear/multimedia/amarok/src/collection/nepomukcollection/NepomukCollection.h #826822:826823
@@ -26,7 +26,6 @@
 #include <QStringList>
 #include <QHash>
 
-#include <Soprano/Client/DBusClient>
 #include <Soprano/Model>
 
 class KUrl;
@@ -44,7 +43,7 @@
 class NepomukCollection : public Collection
 {
 public:
-    NepomukCollection( Soprano::Client::DBusClient*, Soprano::Model* model, bool isFast );
+    NepomukCollection( Soprano::Model* model, bool isFast );
     virtual ~NepomukCollection();
     
     virtual QueryMaker* queryMaker();
@@ -56,8 +55,7 @@
     virtual Meta::TrackPtr trackForUrl( const KUrl &url );
     
     // only for nepomuk collection plugin
-    virtual void lostDBusConnection();
-    
+
     QString getNameForValue( const qint64 ) const;
     QString getUrlForValue( const qint64 ) const;
     const QStringList& getAllNamesAndUrls( void ) const;
@@ -66,7 +64,6 @@
     
     void initHashMaps();
     
-    Soprano::Client::DBusClient *m_client;
     Soprano::Model *m_model;
     QHash< qint64, QString > m_nameForValue;
     QHash< qint64, QString > m_urlForValue;
--- trunk/extragear/multimedia/amarok/src/collection/nepomukcollection/NepomukQueryMaker.cpp #826822:826823
@@ -36,9 +36,7 @@
 #include <Nepomuk/Resource>
 #include <Nepomuk/ResourceManager>
 #include <Nepomuk/Variant>
-#include <Soprano/Client/DBusClient>
 #include <Soprano/Model>
-#include <Soprano/Util/MutexModel>
 #include <Soprano/QueryResultIterator>
 #include <Soprano/Vocabulary/RDF>
 #include <Soprano/Vocabulary/Xesam>
@@ -80,14 +78,13 @@
 
 
 NepomukQueryMaker::NepomukQueryMaker(NepomukCollection *collection
-            , Soprano::Client::DBusClient *client, Soprano::Model* model)
+            , Soprano::Model* model)
     : QueryMaker() 
     , m_collection(collection)
     , m_model( model )
 
 {
     worker = 0;
-    this->client = client;
     reset();
 }
 
@@ -318,10 +315,10 @@
 QueryMaker*
 NepomukQueryMaker::addFilter( qint64 value, const QString &filter, bool matchBegin, bool matchEnd )
 {
-    debug() << "addFilter()" << endl;
-    debug() << "filter against: " << m_collection->getNameForValue( value ) << endl;
-    debug() << "filter: " << filter << endl;
-    debug() << "matchbegin, match end " << matchBegin << matchEnd << endl;
+    debug() << queryType << " addFilter()" << endl;
+    debug() << queryType << "filter against: " << m_collection->getNameForValue( value ) << endl;
+    debug() <<  queryType <<  "filter: " << filter << endl;
+    debug() <<  queryType << "matchbegin, match end " << matchBegin << matchEnd << endl;
 	Q_UNUSED( value )
 	Q_UNUSED( filter )
 	Q_UNUSED( matchBegin )
@@ -416,21 +413,21 @@
 QueryMaker*
 NepomukQueryMaker::beginAnd()
 {
-    debug() << "beginAnd()" << endl;
+    debug() <<  queryType <<  "beginAnd()" << endl;
     return this;
 }
 
 QueryMaker*
 NepomukQueryMaker::beginOr()
 {
-    debug() << "beginOr()" << endl;
+    debug() <<  queryType <<  "beginOr()" << endl;
     return this;
 }
 
 QueryMaker*
 NepomukQueryMaker::endAndOr()
 {
-    debug() << "endAndOr()" << endl;
+    debug() <<  queryType << "endAndOr()" << endl;
     return this;
 }
 
@@ -533,13 +530,6 @@
     DEBUG_BLOCK
     if ( query.isEmpty() )
         return;
-    
-    if (!client->isValid())
-    {
-        m_collection->lostDBusConnection();
-        return;
-    }
-    
     switch ( queryType )
     {
         case ARTIST:
--- trunk/extragear/multimedia/amarok/src/collection/nepomukcollection/NepomukQueryMaker.h #826822:826823
@@ -24,7 +24,6 @@
 #include <QString>
 
 #include <threadweaver/Job.h>
-#include <Soprano/Client/DBusClient>
 #include <Soprano/Model>
 
 class Kurl;
@@ -36,7 +35,7 @@
     Q_OBJECT
     
 	public:
-	    NepomukQueryMaker(NepomukCollection *collection, Soprano::Client::DBusClient *client, Soprano::Model* model);
+	    NepomukQueryMaker(NepomukCollection *collection, Soprano::Model* model);
 	    virtual ~NepomukQueryMaker();
 	
 	    virtual QueryMaker* reset();
@@ -102,7 +101,6 @@
         bool resultAsDataPtrs;
         NepomukWorkerThread *worker;
         NepomukCollection *m_collection;
-        Soprano::Client::DBusClient *client;
         Soprano::Model *m_model;
         QString queryOrderBy;
         int queryLimit;


More information about the Amarok-devel mailing list