mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Merge pull request #490 from tomahawk-player/preferred-result
Enable setting a preferred result on a query
This commit is contained in:
@@ -194,7 +194,7 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
d->results << newresults;
|
d->results << newresults;
|
||||||
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
|
sortResults();
|
||||||
|
|
||||||
// hook up signals, and check solved status
|
// hook up signals, and check solved status
|
||||||
foreach( const result_ptr& rp, newresults )
|
foreach( const result_ptr& rp, newresults )
|
||||||
@@ -258,7 +258,7 @@ Query::onResultStatusChanged()
|
|||||||
Q_D( Query );
|
Q_D( Query );
|
||||||
QMutexLocker lock( &d->mutex );
|
QMutexLocker lock( &d->mutex );
|
||||||
if ( !d->results.isEmpty() )
|
if ( !d->results.isEmpty() )
|
||||||
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
|
sortResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
checkResults();
|
checkResults();
|
||||||
@@ -273,6 +273,11 @@ Query::removeResult( const Tomahawk::result_ptr& result )
|
|||||||
Q_D( Query );
|
Q_D( Query );
|
||||||
QMutexLocker lock( &d->mutex );
|
QMutexLocker lock( &d->mutex );
|
||||||
d->results.removeAll( result );
|
d->results.removeAll( result );
|
||||||
|
if ( d->preferredResult == result )
|
||||||
|
{
|
||||||
|
d->preferredResult.clear();
|
||||||
|
}
|
||||||
|
sortResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit resultsRemoved( result );
|
emit resultsRemoved( result );
|
||||||
@@ -396,6 +401,15 @@ Query::id() const
|
|||||||
bool
|
bool
|
||||||
Query::resultSorter( const result_ptr& left, const result_ptr& right )
|
Query::resultSorter( const result_ptr& left, const result_ptr& right )
|
||||||
{
|
{
|
||||||
|
Q_D( Query );
|
||||||
|
if ( !d->preferredResult.isNull() )
|
||||||
|
{
|
||||||
|
if ( d->preferredResult == left )
|
||||||
|
return true;
|
||||||
|
if ( d->preferredResult == right )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const float ls = left->isOnline() ? howSimilar( left ) : 0.0;
|
const float ls = left->isOnline() ? howSimilar( left ) : 0.0;
|
||||||
const float rs = right->isOnline() ? howSimilar( right ) : 0.0;
|
const float rs = right->isOnline() ? howSimilar( right ) : 0.0;
|
||||||
|
|
||||||
@@ -427,6 +441,30 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
result_ptr
|
||||||
|
Query::preferredResult() const
|
||||||
|
{
|
||||||
|
Q_D( const Query );
|
||||||
|
return d->preferredResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::setPreferredResult( const result_ptr& result )
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Q_D( Query );
|
||||||
|
QMutexLocker lock( &d->mutex );
|
||||||
|
|
||||||
|
Q_ASSERT( d->results.contains( result ) );
|
||||||
|
d->preferredResult = result;
|
||||||
|
sortResults();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit resultsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Query::setCurrentResolver( Tomahawk::Resolver* resolver )
|
Query::setCurrentResolver( Tomahawk::Resolver* resolver )
|
||||||
{
|
{
|
||||||
@@ -734,3 +772,11 @@ Query::setWeakRef( QWeakPointer<Query> weakRef )
|
|||||||
Q_D( Query );
|
Q_D( Query );
|
||||||
d->ownRef = weakRef;
|
d->ownRef = weakRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Query::sortResults()
|
||||||
|
{
|
||||||
|
Q_D( Query );
|
||||||
|
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
|
||||||
|
}
|
||||||
|
@@ -112,6 +112,8 @@ public:
|
|||||||
|
|
||||||
/// sorter for list of results
|
/// sorter for list of results
|
||||||
bool resultSorter( const result_ptr& left, const result_ptr& right );
|
bool resultSorter( const result_ptr& left, const result_ptr& right );
|
||||||
|
result_ptr preferredResult() const;
|
||||||
|
void setPreferredResult( const result_ptr& result );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void resultsAdded( const QList<Tomahawk::result_ptr>& );
|
void resultsAdded( const QList<Tomahawk::result_ptr>& );
|
||||||
@@ -158,6 +160,7 @@ private:
|
|||||||
void setCurrentResolver( Tomahawk::Resolver* resolver );
|
void setCurrentResolver( Tomahawk::Resolver* resolver );
|
||||||
void clearResults();
|
void clearResults();
|
||||||
void checkResults();
|
void checkResults();
|
||||||
|
void sortResults();
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
@@ -39,6 +39,7 @@ private:
|
|||||||
QList< Tomahawk::artist_ptr > artists;
|
QList< Tomahawk::artist_ptr > artists;
|
||||||
QList< Tomahawk::album_ptr > albums;
|
QList< Tomahawk::album_ptr > albums;
|
||||||
QList< Tomahawk::result_ptr > results;
|
QList< Tomahawk::result_ptr > results;
|
||||||
|
Tomahawk::result_ptr preferredResult;
|
||||||
|
|
||||||
float score;
|
float score;
|
||||||
bool solved;
|
bool solved;
|
||||||
|
@@ -198,7 +198,7 @@ TrackDetailView::setQuery( const Tomahawk::query_ptr& query )
|
|||||||
|
|
||||||
connect( m_query->track().data(), SIGNAL( updated() ), SLOT( onCoverUpdated() ) );
|
connect( m_query->track().data(), SIGNAL( updated() ), SLOT( onCoverUpdated() ) );
|
||||||
connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), SLOT( onSocialActionsLoaded() ) );
|
connect( m_query->track().data(), SIGNAL( socialActionsLoaded() ), SLOT( onSocialActionsLoaded() ) );
|
||||||
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ) );
|
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onResultsChanged() ), Qt::QueuedConnection );
|
||||||
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onAlbumUpdated() ) );
|
connect( m_query.data(), SIGNAL( resultsChanged() ), SLOT( onAlbumUpdated() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ TrackDetailView::onResultsChanged()
|
|||||||
resolverIcon->setFixedWidth( 12 );
|
resolverIcon->setFixedWidth( 12 );
|
||||||
resolverIcon->setPixmap( result->sourceIcon( TomahawkUtils::RoundedCorners, QSize( 12, 12 ) ) );
|
resolverIcon->setPixmap( result->sourceIcon( TomahawkUtils::RoundedCorners, QSize( 12, 12 ) ) );
|
||||||
|
|
||||||
QLabel* resolverLabel = new ClickableLabel( this );
|
ClickableLabel* resolverLabel = new ClickableLabel( this );
|
||||||
resolverLabel->setFont( f );
|
resolverLabel->setFont( f );
|
||||||
resolverLabel->setStyleSheet( "QLabel { color: rgba( 0, 0, 0, 50% ) }" );
|
resolverLabel->setStyleSheet( "QLabel { color: rgba( 0, 0, 0, 50% ) }" );
|
||||||
resolverLabel->setText( QString( "%1 - %2" ).arg( result->track()->track() ).arg( result->track()->artist() ) );
|
resolverLabel->setText( QString( "%1 - %2" ).arg( result->track()->track() ).arg( result->track()->artist() ) );
|
||||||
@@ -403,8 +403,8 @@ TrackDetailView::onResultsChanged()
|
|||||||
;
|
;
|
||||||
resolverLabel->setFixedWidth( width() - 32 - 4 );
|
resolverLabel->setFixedWidth( width() - 32 - 4 );
|
||||||
|
|
||||||
NewClosure( resolverLabel, SIGNAL( clicked() ), const_cast< AudioEngine* >( AudioEngine::instance() ),
|
NewClosure( resolverLabel, SIGNAL( clicked() ), const_cast< TrackDetailView* >( this ),
|
||||||
SLOT( playItem( Tomahawk::playlistinterface_ptr, Tomahawk::result_ptr, Tomahawk::query_ptr ) ),
|
SLOT( onResultClicked( Tomahawk::playlistinterface_ptr, Tomahawk::result_ptr, Tomahawk::query_ptr ) ),
|
||||||
m_playlistInterface, result, m_query )->setAutoDelete( false );
|
m_playlistInterface, result, m_query )->setAutoDelete( false );
|
||||||
|
|
||||||
QWidget* hbox = new QWidget;
|
QWidget* hbox = new QWidget;
|
||||||
@@ -441,3 +441,11 @@ TrackDetailView::setBuyButtonVisible( bool visible )
|
|||||||
{
|
{
|
||||||
m_buyButtonVisible = visible;
|
m_buyButtonVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackDetailView::onResultClicked( const Tomahawk::playlistinterface_ptr& playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery )
|
||||||
|
{
|
||||||
|
fromQuery->setPreferredResult( result );
|
||||||
|
AudioEngine::instance()->playItem( playlist, result, fromQuery );
|
||||||
|
}
|
||||||
|
@@ -64,6 +64,8 @@ private slots:
|
|||||||
void onBuyButtonClicked();
|
void onBuyButtonClicked();
|
||||||
void onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState );
|
void onDownloadManagerStateChanged( DownloadManager::DownloadManagerState newState, DownloadManager::DownloadManagerState oldState );
|
||||||
|
|
||||||
|
void onResultClicked( const Tomahawk::playlistinterface_ptr& playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setSocialActions();
|
void setSocialActions();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user