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