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; }