diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index 135705d65..6f85822de 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -138,7 +138,9 @@ Database::impl() QThread* thread = QThread::currentThread(); if ( !m_implHash.contains( thread ) ) { - DatabaseImpl* impl = m_impl->clone(); + QPair< QString, QString > args = m_impl->cloneArgs(); + DatabaseImpl* impl = new DatabaseImpl( args.first, args.second ); + impl->setFuzzyIndex( m_impl->fuzzyIndex() ); m_implHash.insert( thread, impl ); } diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index bd8c8dd5a..ed7078f57 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -85,12 +85,12 @@ DatabaseImpl::DatabaseImpl( const QString& dbname ) } -DatabaseImpl::DatabaseImpl( const QString& dbname, bool internal ) +DatabaseImpl::DatabaseImpl( const QString &dbname, const QString &dbid ) : QObject( (QObject*) QThread::currentThread() ) { - Q_UNUSED( internal ); openDatabase( dbname, false ); init(); + m_dbid = dbid; } @@ -142,15 +142,12 @@ DatabaseImpl::database() } -DatabaseImpl* -DatabaseImpl::clone() const +QPair< QString, QString > +DatabaseImpl::cloneArgs() const { QMutexLocker lock( &m_mutex ); - - DatabaseImpl* impl = new DatabaseImpl( m_db.databaseName(), true ); - impl->setDatabaseID( m_dbid ); - impl->setFuzzyIndex( m_fuzzyIndex ); - return impl; + QPair< QString, QString > args( m_db.databaseName(), m_dbid ); + return args; } diff --git a/src/libtomahawk/database/DatabaseImpl.h b/src/libtomahawk/database/DatabaseImpl.h index c5fa87688..828110ef6 100644 --- a/src/libtomahawk/database/DatabaseImpl.h +++ b/src/libtomahawk/database/DatabaseImpl.h @@ -48,7 +48,7 @@ public: DatabaseImpl( const QString& dbname ); ~DatabaseImpl(); - DatabaseImpl* clone() const; + QPair< QString, QString > cloneArgs() const; TomahawkSqlQuery newquery(); QSqlDatabase& database(); @@ -82,9 +82,9 @@ signals: void indexReady(); private: - DatabaseImpl( const QString& dbname, bool internal ); + DatabaseImpl( const QString &dbname, const QString &dbid ); + FuzzyIndex* fuzzyIndex() const { return m_fuzzyIndex; } void setFuzzyIndex( FuzzyIndex* fi ) { m_fuzzyIndex = fi; } - void setDatabaseID( const QString& dbid ) { m_dbid = dbid; } void init(); bool openDatabase( const QString& dbname, bool checkSchema = true ); @@ -101,6 +101,8 @@ private: QString m_dbid; FuzzyIndex* m_fuzzyIndex; mutable QMutex m_mutex; + + friend class Database; }; #endif // DATABASEIMPL_H