From 8558cdfc8e1ab59fca65752a2c1944ee324b687e Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 19 Jun 2012 00:43:08 +0200 Subject: [PATCH] Revert usage of boost::threads to speed up id loading. Our MinGW boost package is broken. Revert "Set future on artist/album immediately after creating promise" This reverts commit 9d9fae75b549862810d0330729d7878e24a9d8e9. Revert "Remove duplicate function, and fix copy link from sidebar track page" This reverts commit 1fe28714cbd1117df496fea5760c365badddb725. Revert "Catch by const ref and assert to check hypothesis" This reverts commit a8f0053fc8b68cfff0ff6a7ec383c4ba43e539b9. Revert "Reimplement QApplication::notify() to print out something about the exception if we can" This reverts commit 7b8136a36e5bc4b005708470a47a1805cf74314f. Revert "Catch boost::unitialized_future if it is thrown" This reverts commit c1d678e2b19076115ca740f639a8c81a41b04481. Revert "Another boost/thread.hpp include rather than specific boost headers" This reverts commit ee8d3e6a921bebdcda913c5d5155c3f4511b68e0. Revert "One include to (hopefully) rule them all" This reverts commit 52752cd2348b308fcf8bacb9acb59cbf5e56b07b. Revert "Add another boost include" This reverts commit 7bec03560a286e481455f93d3a66f411af5989c8. Revert "Try some more includes" This reverts commit e56f2f7ee0e8836637f620171c805907252b4a91. Revert "Remove old code" This reverts commit 69b56e08364b9fad24e28f63a0d937cf4db2855b. Revert "Fix oversight in queue draining" This reverts commit 8c48af423cf88f3ec86c9903c8032cac2c2863b9. Revert "Safer locking of id() to prevent deadlocks" This reverts commit 3f2906d4d114e763d72a86cfb2809a9819c1f898. Revert "Cleanup fixes" This reverts commit cd3eeb29519bcfabef67ea95d8561864e935c4ca. Revert "Experimental asynchronous artist and album id loading" This reverts commit 75eb35397da87e245dc49eb30d3fb1c106fc132a. Conflicts: src/libtomahawk/CMakeLists.txt --- CMakeLists.txt | 2 +- src/TomahawkApp.cpp | 21 --- src/TomahawkApp.h | 3 - src/libtomahawk/Album.cpp | 109 +----------- src/libtomahawk/Album.h | 20 +-- src/libtomahawk/Artist.cpp | 107 ++---------- src/libtomahawk/Artist.h | 22 +-- src/libtomahawk/CMakeLists.txt | 2 - src/libtomahawk/GlobalActionManager.cpp | 14 ++ src/libtomahawk/GlobalActionManager.h | 4 +- src/libtomahawk/database/Database.cpp | 5 - src/libtomahawk/database/Database.h | 2 - src/libtomahawk/database/DatabaseImpl.cpp | 2 +- src/libtomahawk/database/DatabaseWorker.cpp | 2 +- src/libtomahawk/database/IdThreadWorker.cpp | 180 -------------------- src/libtomahawk/database/IdThreadWorker.h | 56 ------ src/sourcetree/items/TemporaryPageItem.cpp | 2 +- 17 files changed, 45 insertions(+), 508 deletions(-) delete mode 100644 src/libtomahawk/database/IdThreadWorker.cpp delete mode 100644 src/libtomahawk/database/IdThreadWorker.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a0a7b291f..a9e25574d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,7 +115,7 @@ macro_log_feature(TAGLIB_FOUND "TagLib" "Audio Meta-Data Library" "http://develo include( CheckTagLibFileName ) check_taglib_filename( COMPLEX_TAGLIB_FILENAME ) -macro_optional_find_package( Boost COMPONENTS thread ) +macro_optional_find_package(Boost) macro_log_feature(Boost_FOUND "Boost" "Provides free peer-reviewed portable C++ source libraries" "http://www.boost.org" TRUE "" "") #FIXME: give useful explaination macro_optional_find_package(QCA2) diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index ec7dc8ea3..f3ac2a95c 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -707,27 +707,6 @@ TomahawkApp::loadUrl( const QString& url ) } -bool -TomahawkApp::notify( QObject *receiver, QEvent *e ) -{ - try - { - return TOMAHAWK_APPLICATION::notify( receiver, e ); - } - catch ( const std::exception& e ) - { - qWarning( "TomahawkApp::notify caught a std exception in a Qt event handler: " ); - qFatal( e.what() ); - } - catch ( ... ) - { - qFatal( "TomahawkApp::notify caught a non-std-exception from a Qt event handler. Aborting." ); - } - - return false; -} - - void TomahawkApp::instanceStarted( KDSingleApplicationGuard::Instance instance ) { diff --git a/src/TomahawkApp.h b/src/TomahawkApp.h index 74cfffc11..417bc3094 100644 --- a/src/TomahawkApp.h +++ b/src/TomahawkApp.h @@ -99,9 +99,6 @@ public: bool isTomahawkLoaded() const { return m_loaded; } - // reimplemented from QApplication/QCoreApplication - virtual bool notify( QObject* receiver, QEvent* e ); - signals: void tomahawkLoaded(); diff --git a/src/libtomahawk/Album.cpp b/src/libtomahawk/Album.cpp index 18627a518..a639042c7 100644 --- a/src/libtomahawk/Album.cpp +++ b/src/libtomahawk/Album.cpp @@ -23,22 +23,13 @@ #include "AlbumPlaylistInterface.h" #include "database/Database.h" #include "database/DatabaseImpl.h" -#include "database/IdThreadWorker.h" #include "Query.h" #include "Source.h" #include "utils/Logger.h" -#include - using namespace Tomahawk; -QHash< QString, album_ptr > Album::s_albumsByName = QHash< QString, album_ptr >(); -QHash< unsigned int, album_ptr > Album::s_albumsById = QHash< unsigned int, album_ptr >(); - -static QMutex s_nameCacheMutex; -static QMutex s_idCacheMutex; -static QReadWriteLock s_idMutex; Album::~Album() { @@ -49,12 +40,6 @@ Album::~Album() #endif } -inline QString -albumCacheKey( const Tomahawk::artist_ptr& artist, const QString& albumName ) -{ - return QString( "%1\t\t%2" ).arg( artist->name() ).arg( albumName ); -} - album_ptr Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate ) @@ -62,22 +47,11 @@ Album::get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCr if ( !Database::instance() || !Database::instance()->impl() ) return album_ptr(); - QMutexLocker l( &s_nameCacheMutex ); + int albid = Database::instance()->impl()->albumId( artist->id(), name, autoCreate ); + if ( albid < 1 && autoCreate ) + return album_ptr(); - const QString key = albumCacheKey( artist, name ); - if ( s_albumsByName.contains( key ) ) - { - return s_albumsByName[ key ]; - } - -// qDebug() << "LOOKING UP ALBUM:" << artist->name() << name; - album_ptr album = album_ptr( new Album( name, artist ) ); - album->setWeakRef( album.toWeakRef() ); - album->loadId( autoCreate ); - - s_albumsByName[ key ] = album; - - return album; + return Album::get( albid, name, artist ); } @@ -87,17 +61,17 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar static QHash< unsigned int, album_ptr > s_albums; static QMutex s_mutex; - QMutexLocker lock( &s_idCacheMutex ); - if ( s_albumsById.contains( id ) ) + QMutexLocker lock( &s_mutex ); + if ( s_albums.contains( id ) ) { - return s_albumsById.value( id ); + return s_albums.value( id ); } album_ptr a = album_ptr( new Album( id, name, artist ), &QObject::deleteLater ); a->setWeakRef( a.toWeakRef() ); if ( id > 0 ) - s_albumsById.insert( id, a ); + s_albums.insert( id, a ); return a; } @@ -105,7 +79,6 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ) : QObject() - , m_waitingForId( false ) , m_id( id ) , m_name( name ) , m_artist( artist ) @@ -119,20 +92,6 @@ Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& } -Album::Album( const QString& name, const Tomahawk::artist_ptr& artist ) - : QObject() - , m_waitingForId( true ) - , m_name( name ) - , m_artist( artist ) - , m_coverLoaded( false ) - , m_coverLoading( false ) -#ifndef ENABLE_HEADLESS - , m_cover( 0 ) -#endif -{ - m_sortname = DatabaseImpl::sortname( name ); -} - void Album::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ) { @@ -147,56 +106,6 @@ Album::artist() const } -void -Album::loadId( bool autoCreate ) -{ - Q_ASSERT( m_waitingForId ); - IdThreadWorker::getAlbumId( m_ownRef.toStrongRef(), autoCreate ); -} - - -void -Album::setIdFuture( boost::unique_future< unsigned int > future ) -{ - m_idFuture = boost::move( future ); -} - - -unsigned int -Album::id() const -{ - s_idMutex.lockForRead(); - const bool waiting = m_waitingForId; - unsigned int finalId = m_id; - s_idMutex.unlock(); - - if ( waiting ) - { - try - { - finalId = m_idFuture.get(); - - s_idMutex.lockForWrite(); - m_id = finalId; - m_waitingForId = false; - - if ( m_id > 0 ) - s_albumsById[ m_id ] = m_ownRef.toStrongRef(); - s_idMutex.unlock(); - } - catch( const boost::future_uninitialized& e ) - { - qWarning() << "Caught boost::future_uninitialized when trying to get artist id from future, WTF?"; - qWarning() << "Potential race condition, do we have an ID?" << m_id << "and waiting?" << m_waitingForId << e.what(); - - Q_ASSERT( !m_waitingForId ); - } - } - - return finalId; -} - - #ifndef ENABLE_HEADLESS QPixmap Album::cover( const QSize& size, bool forceLoad ) const @@ -330,4 +239,4 @@ Album::infoid() const m_uuid = uuid(); return m_uuid; -} +} \ No newline at end of file diff --git a/src/libtomahawk/Album.h b/src/libtomahawk/Album.h index 1dc51d5f7..89c6ad09f 100644 --- a/src/libtomahawk/Album.h +++ b/src/libtomahawk/Album.h @@ -28,16 +28,12 @@ #include #endif -#include - #include "Typedefs.h" #include "PlaylistInterface.h" #include "DllMacro.h" #include "Collection.h" #include "infosystem/InfoSystem.h" -class IdThreadWorker; - namespace Tomahawk { @@ -49,11 +45,10 @@ public: static album_ptr get( const Tomahawk::artist_ptr& artist, const QString& name, bool autoCreate = false ); static album_ptr get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ); - Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ); - Album( const QString& name, const Tomahawk::artist_ptr& artist ); + explicit Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist ); virtual ~Album(); - unsigned int id() const; + unsigned int id() const { return m_id; } QString name() const { return m_name; } QString sortname() const { return m_sortname; } @@ -69,7 +64,6 @@ public: QWeakPointer< Tomahawk::Album > weakRef() { return m_ownRef; } void setWeakRef( QWeakPointer< Tomahawk::Album > weakRef ) { m_ownRef = weakRef; } - void loadId( bool autoCreate ); signals: void tracksAdded( const QList& tracks, Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void updated(); @@ -84,11 +78,8 @@ private slots: private: Q_DISABLE_COPY( Album ) QString infoid() const; - void setIdFuture( boost::unique_future< unsigned int > future ); - mutable bool m_waitingForId; - mutable boost::unique_future< unsigned int > m_idFuture; - mutable unsigned int m_id; + unsigned int m_id; QString m_name; QString m_sortname; @@ -107,11 +98,6 @@ private: QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface; QWeakPointer< Tomahawk::Album > m_ownRef; - - static QHash< QString, album_ptr > s_albumsByName; - static QHash< unsigned int, album_ptr > s_albumsById; - - friend class ::IdThreadWorker; }; } // ns diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 58e3942c5..fbd30f477 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -25,21 +25,12 @@ #include "database/DatabaseImpl.h" #include "database/DatabaseCommand_AllAlbums.h" #include "database/DatabaseCommand_TrackStats.h" -#include "database/IdThreadWorker.h" #include "Source.h" #include "utils/Logger.h" -#include - using namespace Tomahawk; -QHash< QString, artist_ptr > Artist::s_artistsByName = QHash< QString, artist_ptr >(); -QHash< unsigned int, artist_ptr > Artist::s_artistsById = QHash< unsigned int, artist_ptr >(); - -static QMutex s_nameCacheMutex; -static QMutex s_idCacheMutex; -static QReadWriteLock s_idMutex; Artist::~Artist() { @@ -54,40 +45,34 @@ Artist::~Artist() artist_ptr Artist::get( const QString& name, bool autoCreate ) { - if ( name.isEmpty() ) - return artist_ptr(); - - QMutexLocker lock( &s_nameCacheMutex ); - if ( s_artistsByName.contains( name ) ) - return s_artistsByName.value( name ); - if ( !Database::instance() || !Database::instance()->impl() ) return artist_ptr(); - artist_ptr artist = artist_ptr( new Artist( name ), &QObject::deleteLater ); - artist->setWeakRef( artist.toWeakRef() ); - artist->loadId( autoCreate ); + int artid = Database::instance()->impl()->artistId( name, autoCreate ); + if ( artid < 1 && autoCreate ) + return artist_ptr(); - s_artistsByName[ name ] = artist; - - return artist; + return Artist::get( artid, name ); } artist_ptr Artist::get( unsigned int id, const QString& name ) { - QMutexLocker lock( &s_idCacheMutex ); - if ( s_artistsById.contains( id ) ) + static QHash< unsigned int, artist_ptr > s_artists; + static QMutex s_mutex; + + QMutexLocker lock( &s_mutex ); + if ( s_artists.contains( id ) ) { - return s_artistsById.value( id ); + return s_artists.value( id ); } artist_ptr a = artist_ptr( new Artist( id, name ), &QObject::deleteLater ); a->setWeakRef( a.toWeakRef() ); if ( id > 0 ) - s_artistsById.insert( id, a ); + s_artists.insert( id, a ); return a; } @@ -95,7 +80,6 @@ Artist::get( unsigned int id, const QString& name ) Artist::Artist( unsigned int id, const QString& name ) : QObject() - , m_waitingForFuture( false ) , m_id( id ) , m_name( name ) , m_coverLoaded( false ) @@ -111,24 +95,6 @@ Artist::Artist( unsigned int id, const QString& name ) } -Artist::Artist( const QString& name ) - : QObject() - , m_waitingForFuture( true ) - , m_id( 0 ) - , m_name( name ) - , m_coverLoaded( false ) - , m_coverLoading( false ) - , m_simArtistsLoaded( false ) - , m_biographyLoaded( false ) - , m_infoJobs( 0 ) -#ifndef ENABLE_HEADLESS - , m_cover( 0 ) -#endif -{ - m_sortname = DatabaseImpl::sortname( name, true ); -} - - void Artist::onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ) { @@ -226,57 +192,6 @@ Artist::similarArtists() const } -void -Artist::loadId( bool autoCreate ) -{ - Q_ASSERT( m_waitingForFuture ); - - IdThreadWorker::getArtistId( m_ownRef.toStrongRef(), autoCreate ); -} - - -void -Artist::setIdFuture( boost::unique_future< unsigned int > future ) -{ - m_idFuture = boost::move(future); -} - - -unsigned int -Artist::id() const -{ - s_idMutex.lockForRead(); - const bool waiting = m_waitingForFuture; - unsigned int finalid = m_id; - s_idMutex.unlock(); - - if ( waiting ) - { - try - { - finalid = m_idFuture.get(); - - s_idMutex.lockForWrite(); - m_id = finalid; - m_waitingForFuture = false; - - if ( m_id > 0 ) - s_artistsById[ m_id ] = m_ownRef.toStrongRef(); - s_idMutex.unlock(); - } - catch( const boost::future_uninitialized& e ) - { - qWarning() << "Caught boost::future_uninitialized when trying to get artist id from future, WTF?"; - qWarning() << "Potential race condition, do we have an ID?" << m_id << "and waiting?" << m_waitingForFuture << e.what(); - - Q_ASSERT( !m_waitingForFuture ); - } - } - - return m_id; -} - - QString Artist::biography() const { diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index d9d39fd3d..3eef077a1 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -31,10 +31,6 @@ #include "DllMacro.h" #include "Query.h" -#include - -class IdThreadWorker; - namespace Tomahawk { @@ -46,11 +42,10 @@ public: static artist_ptr get( const QString& name, bool autoCreate = false ); static artist_ptr get( unsigned int id, const QString& name ); - Artist( unsigned int id, const QString& name ); - explicit Artist( const QString& name ); + explicit Artist( unsigned int id, const QString& name ); virtual ~Artist(); - unsigned int id() const; + unsigned int id() const { return m_id; } QString name() const { return m_name; } QString sortname() const { return m_sortname; } @@ -77,7 +72,6 @@ public: QWeakPointer< Tomahawk::Artist > weakRef() { return m_ownRef; } void setWeakRef( QWeakPointer< Tomahawk::Artist > weakRef ) { m_ownRef = weakRef; } - void loadId( bool autoCreate ); signals: void tracksAdded( const QList& tracks, Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void albumsAdded( const QList& albums, Tomahawk::ModelMode mode ); @@ -99,12 +93,7 @@ private: Artist(); QString infoid() const; - void setIdFuture( boost::unique_future< unsigned int > future ); - - mutable bool m_waitingForFuture; - mutable boost::unique_future< unsigned int > m_idFuture; - mutable unsigned int m_id; - + unsigned int m_id; QString m_name; QString m_sortname; @@ -134,11 +123,6 @@ private: QHash< Tomahawk::ModelMode, QHash< Tomahawk::collection_ptr, Tomahawk::playlistinterface_ptr > > m_playlistInterface; QWeakPointer< Tomahawk::Artist > m_ownRef; - - static QHash< QString, artist_ptr > s_artistsByName; - static QHash< unsigned int, artist_ptr > s_artistsById; - - friend class ::IdThreadWorker; }; } // ns diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index fc42ea208..2069a6a6c 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -256,7 +256,6 @@ set( libSources database/DatabaseCommand_SetTrackAttributes.cpp database/Database.cpp database/TomahawkSqlQuery.cpp - database/IdThreadWorker.cpp infosystem/InfoSystem.cpp infosystem/InfoSystemCache.cpp @@ -455,7 +454,6 @@ TARGET_LINK_LIBRARIES( tomahawklib ${OS_SPECIFIC_LINK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${LINK_LIBRARIES} - ${Boost_LIBRARIES} ${SQLITE_LIBRARIES} ) diff --git a/src/libtomahawk/GlobalActionManager.cpp b/src/libtomahawk/GlobalActionManager.cpp index a7553202c..ec1756b49 100644 --- a/src/libtomahawk/GlobalActionManager.cpp +++ b/src/libtomahawk/GlobalActionManager.cpp @@ -97,6 +97,20 @@ GlobalActionManager::openLinkFromQuery( const query_ptr& query ) const } +QUrl +GlobalActionManager::copyOpenLink( const query_ptr& query ) const +{ + const QUrl link = openLinkFromQuery( query ); + + QClipboard* cb = QApplication::clipboard(); + QByteArray data = link.toEncoded(); + data.replace( "'", "%27" ); // QUrl doesn't encode ', which it doesn't have to. Some apps don't like ' though, and want %27. Both are valid. + cb->setText( data ); + + return link; +} + + QUrl GlobalActionManager::copyOpenLink( const artist_ptr& artist ) const { diff --git a/src/libtomahawk/GlobalActionManager.h b/src/libtomahawk/GlobalActionManager.h index c04290d15..9c43503f4 100644 --- a/src/libtomahawk/GlobalActionManager.h +++ b/src/libtomahawk/GlobalActionManager.h @@ -46,6 +46,7 @@ public: QUrl copyOpenLink( const Tomahawk::artist_ptr& artist ) const; QUrl copyOpenLink( const Tomahawk::album_ptr& album ) const; + QUrl copyOpenLink( const Tomahawk::query_ptr& query ) const; QUrl openLink( const QString& title, const QString& artist, const QString& album ) const; @@ -60,10 +61,7 @@ public slots: /// Takes a spotify link and performs the default open action on it bool openRdioLink( const QString& link ); - /// Creates a link from the requested data and copies it to the clipboard void copyToClipboard( const Tomahawk::query_ptr& query ); - - QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist ); void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename ); diff --git a/src/libtomahawk/database/Database.cpp b/src/libtomahawk/database/Database.cpp index 9f835a839..eea51aca0 100644 --- a/src/libtomahawk/database/Database.cpp +++ b/src/libtomahawk/database/Database.cpp @@ -22,7 +22,6 @@ #include "DatabaseCommand.h" #include "DatabaseImpl.h" #include "DatabaseWorker.h" -#include "IdThreadWorker.h" #include "utils/Logger.h" #include "Source.h" @@ -44,7 +43,6 @@ Database::Database( const QString& dbname, QObject* parent ) , m_ready( false ) , m_impl( new DatabaseImpl( dbname, this ) ) , m_workerRW( new DatabaseWorker( this, true ) ) - , m_idWorker( new IdThreadWorker( this ) ) { s_instance = this; @@ -60,7 +58,6 @@ Database::Database( const QString& dbname, QObject* parent ) connect( m_impl, SIGNAL( indexReady() ), SLOT( setIsReadyTrue() ) ); m_workerRW->start(); - m_idWorker->start(); } @@ -70,8 +67,6 @@ Database::~Database() qDeleteAll( m_workers ); delete m_workerRW; - m_idWorker->stop(); - delete m_idWorker; delete m_impl; } diff --git a/src/libtomahawk/database/Database.h b/src/libtomahawk/database/Database.h index 307a3ddd8..7bf05a09e 100644 --- a/src/libtomahawk/database/Database.h +++ b/src/libtomahawk/database/Database.h @@ -31,7 +31,6 @@ class DatabaseImpl; class DatabaseWorker; -class IdThreadWorker; /* This class is really a firewall/pimpl - the public functions of LibraryImpl @@ -80,7 +79,6 @@ private: DatabaseImpl* m_impl; DatabaseWorker* m_workerRW; QList m_workers; - IdThreadWorker* m_idWorker; bool m_indexReady; int m_maxConcurrentThreads; diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index c3e331911..09a533841 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -45,7 +45,7 @@ #define CURRENT_SCHEMA_VERSION 28 DatabaseImpl::DatabaseImpl( const QString& dbname, Database* parent ) - : QObject( parent ) + : QObject( (QObject*) parent ) , m_parent( parent ) { QTime t; diff --git a/src/libtomahawk/database/DatabaseWorker.cpp b/src/libtomahawk/database/DatabaseWorker.cpp index 944fcb334..186012437 100644 --- a/src/libtomahawk/database/DatabaseWorker.cpp +++ b/src/libtomahawk/database/DatabaseWorker.cpp @@ -69,7 +69,7 @@ void DatabaseWorker::run() { m_dbimpl = m_db->impl()->clone(); - tDebug() << "New db connection with name:" << m_dbimpl->database().connectionName() << "this thread:" << thread() << "Parent of dbcon:" << m_dbimpl->parent()->thread(); + tDebug() << "New db connection with name:" << m_dbimpl->database().connectionName(); exec(); qDebug() << Q_FUNC_INFO << "DatabaseWorker finishing..."; } diff --git a/src/libtomahawk/database/IdThreadWorker.cpp b/src/libtomahawk/database/IdThreadWorker.cpp deleted file mode 100644 index 1d264f576..000000000 --- a/src/libtomahawk/database/IdThreadWorker.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012 Leo Franchi - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ - -#include "IdThreadWorker.h" - -#include "Artist.h" -#include "Album.h" -#include "Database.h" -#include "DatabaseImpl.h" -#include "Source.h" - -#define ID_THREAD_DEBUG 0 - -using namespace Tomahawk; - -namespace { - enum QueryType { - ArtistType, - AlbumType - }; -} - - -static QWaitCondition s_waitCond; -static QMutex s_mutex; - -struct QueueItem -{ - boost::promise< unsigned int > promise; - artist_ptr artist; - album_ptr album; - QueryType type; - bool create; -}; - -// TODO Q_GLOBAL_STATIC -QQueue< QueueItem* > IdThreadWorker::s_workQueue = QQueue< QueueItem* >(); - -IdThreadWorker::IdThreadWorker( Database* db ) - : QThread() - , m_db( db ) - , m_stop( false ) -{ - moveToThread( this ); -} - - -IdThreadWorker::~IdThreadWorker() -{ - wait(); -} - - -void -IdThreadWorker::stop() -{ - { - QMutexLocker l( &s_mutex ); - m_stop = true; - } - - s_waitCond.wakeOne(); -} - - -QueueItem* -internalGet( const artist_ptr& artist, const album_ptr& album, bool autoCreate, QueryType type ) -{ - QueueItem* item = new QueueItem; - item->artist = artist; - item->album = album; - item->type = type; - item->create = autoCreate; - - return item; -} - - -void -IdThreadWorker::getArtistId( const artist_ptr& artist, bool autoCreate ) -{ - QueueItem* item = internalGet( artist, album_ptr(), autoCreate, ArtistType ); - artist->setIdFuture( item->promise.get_future() ); - -#if ID_THREAD_DEBUG - qDebug() << "QUEUEING ARTIST:" << artist->name(); -#endif - - s_mutex.lock(); - s_workQueue.enqueue( item ); - s_mutex.unlock(); - s_waitCond.wakeOne(); -#if ID_THREAD_DEBUG - qDebug() << "DONE WOKE UP THREAD:" << artist->name(); -#endif -} - - -void -IdThreadWorker::getAlbumId( const album_ptr& album, bool autoCreate ) -{ - QueueItem* item = internalGet( artist_ptr(), album, autoCreate, AlbumType ); - album->setIdFuture( item->promise.get_future() ); - -#if ID_THREAD_DEBUG - qDebug() << "QUEUEING ALUBM:" << album->artist()->name() << album->name(); -#endif - s_mutex.lock(); - s_workQueue.enqueue( item ); - s_mutex.unlock(); - s_waitCond.wakeOne(); -#if ID_THREAD_DEBUG - qDebug() << "DONE WOKE UP THREAD:" << album->artist()->name() << album->name(); -#endif -} - - -void -IdThreadWorker::run() -{ - m_impl = m_db->impl()->clone(); - - while ( !m_stop ) - { - s_mutex.lock(); -#if ID_THREAD_DEBUG - qDebug() << "IdWorkerThread waiting on condition..."; -#endif - s_waitCond.wait( &s_mutex ); -#if ID_THREAD_DEBUG - qDebug() << "IdWorkerThread WOKEN UP"; -#endif - - while ( !s_workQueue.isEmpty() ) - { - QueueItem* item = s_workQueue.dequeue(); - s_mutex.unlock(); - -#if ID_THREAD_DEBUG - qDebug() << "WITH CONTENTS:" << (item->type == ArtistType ? item->artist->name() : item->album->artist()->name() + " _ " + item->album->name()); -#endif - if ( item->type == ArtistType ) - { - unsigned int id = m_impl->artistId( item->artist->name(), item->create ); - item->promise.set_value( id ); - - item->artist->id(); - delete item; - } - else if ( item->type == AlbumType ) - { - unsigned int artistId = m_impl->artistId( item->album->artist()->name(), item->create ); - unsigned int albumId = m_impl->albumId( artistId, item->album->name(), item->create ); - item->promise.set_value( albumId ); - - item->album->id(); - delete item; - } - - s_mutex.lock(); - } - - s_mutex.unlock(); - } -} diff --git a/src/libtomahawk/database/IdThreadWorker.h b/src/libtomahawk/database/IdThreadWorker.h deleted file mode 100644 index b3d18d69e..000000000 --- a/src/libtomahawk/database/IdThreadWorker.h +++ /dev/null @@ -1,56 +0,0 @@ -/* === This file is part of Tomahawk Player - === - * - * Copyright 2012 Leo Franchi - * - * Tomahawk is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Tomahawk is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Tomahawk. If not, see . - */ -#ifndef IDTHREADWORKER_H -#define IDTHREADWORKER_H - -#include "DllMacro.h" -#include "Typedefs.h" - -#include -#include -#include -#include - -#include - -class QueueItem; -class Database; -class DatabaseImpl; - -class DLLEXPORT IdThreadWorker : public QThread -{ - Q_OBJECT -public: - explicit IdThreadWorker( Database* db ); - virtual ~IdThreadWorker(); - - void run(); - void stop(); - - static void getArtistId( const Tomahawk::artist_ptr& artist, bool autoCreate = false ); - static void getAlbumId( const Tomahawk::album_ptr& album, bool autoCreate = false ); - -private: - Database* m_db; - DatabaseImpl* m_impl; - bool m_stop; - - static QQueue< QueueItem* > s_workQueue; -}; - -#endif // IDTHREADWORKER_H diff --git a/src/sourcetree/items/TemporaryPageItem.cpp b/src/sourcetree/items/TemporaryPageItem.cpp index 25bd2413c..8b9ea3a04 100644 --- a/src/sourcetree/items/TemporaryPageItem.cpp +++ b/src/sourcetree/items/TemporaryPageItem.cpp @@ -165,7 +165,7 @@ TemporaryPageItem::linkActionTriggered( QAction* action ) { TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page ); Q_ASSERT( tPage ); - GlobalActionManager::instance()->copyToClipboard( tPage->query() ); + GlobalActionManager::instance()->copyOpenLink( tPage->query() ); break; }