mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +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;
|
||||
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
|
||||
foreach( const result_ptr& rp, newresults )
|
||||
@@ -258,7 +258,7 @@ Query::onResultStatusChanged()
|
||||
Q_D( Query );
|
||||
QMutexLocker lock( &d->mutex );
|
||||
if ( !d->results.isEmpty() )
|
||||
qStableSort( d->results.begin(), d->results.end(), std::bind( &Query::resultSorter, this, std::placeholders::_1, std::placeholders::_2 ) );
|
||||
sortResults();
|
||||
}
|
||||
|
||||
checkResults();
|
||||
@@ -273,6 +273,11 @@ Query::removeResult( const Tomahawk::result_ptr& result )
|
||||
Q_D( Query );
|
||||
QMutexLocker lock( &d->mutex );
|
||||
d->results.removeAll( result );
|
||||
if ( d->preferredResult == result )
|
||||
{
|
||||
d->preferredResult.clear();
|
||||
}
|
||||
sortResults();
|
||||
}
|
||||
|
||||
emit resultsRemoved( result );
|
||||
@@ -396,6 +401,15 @@ Query::id() const
|
||||
bool
|
||||
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 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
|
||||
Query::setCurrentResolver( Tomahawk::Resolver* resolver )
|
||||
{
|
||||
@@ -734,3 +772,11 @@ Query::setWeakRef( QWeakPointer<Query> weakRef )
|
||||
Q_D( Query );
|
||||
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
|
||||
bool resultSorter( const result_ptr& left, const result_ptr& right );
|
||||
result_ptr preferredResult() const;
|
||||
void setPreferredResult( const result_ptr& result );
|
||||
|
||||
signals:
|
||||
void resultsAdded( const QList<Tomahawk::result_ptr>& );
|
||||
@@ -158,6 +160,7 @@ private:
|
||||
void setCurrentResolver( Tomahawk::Resolver* resolver );
|
||||
void clearResults();
|
||||
void checkResults();
|
||||
void sortResults();
|
||||
};
|
||||
|
||||
} //ns
|
||||
|
@@ -39,6 +39,7 @@ private:
|
||||
QList< Tomahawk::artist_ptr > artists;
|
||||
QList< Tomahawk::album_ptr > albums;
|
||||
QList< Tomahawk::result_ptr > results;
|
||||
Tomahawk::result_ptr preferredResult;
|
||||
|
||||
float score;
|
||||
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( 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() ) );
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ TrackDetailView::onResultsChanged()
|
||||
resolverIcon->setFixedWidth( 12 );
|
||||
resolverIcon->setPixmap( result->sourceIcon( TomahawkUtils::RoundedCorners, QSize( 12, 12 ) ) );
|
||||
|
||||
QLabel* resolverLabel = new ClickableLabel( this );
|
||||
ClickableLabel* resolverLabel = new ClickableLabel( this );
|
||||
resolverLabel->setFont( f );
|
||||
resolverLabel->setStyleSheet( "QLabel { color: rgba( 0, 0, 0, 50% ) }" );
|
||||
resolverLabel->setText( QString( "%1 - %2" ).arg( result->track()->track() ).arg( result->track()->artist() ) );
|
||||
@@ -403,8 +403,8 @@ TrackDetailView::onResultsChanged()
|
||||
;
|
||||
resolverLabel->setFixedWidth( width() - 32 - 4 );
|
||||
|
||||
NewClosure( resolverLabel, SIGNAL( clicked() ), const_cast< AudioEngine* >( AudioEngine::instance() ),
|
||||
SLOT( playItem( Tomahawk::playlistinterface_ptr, Tomahawk::result_ptr, Tomahawk::query_ptr ) ),
|
||||
NewClosure( resolverLabel, SIGNAL( clicked() ), const_cast< TrackDetailView* >( this ),
|
||||
SLOT( onResultClicked( Tomahawk::playlistinterface_ptr, Tomahawk::result_ptr, Tomahawk::query_ptr ) ),
|
||||
m_playlistInterface, result, m_query )->setAutoDelete( false );
|
||||
|
||||
QWidget* hbox = new QWidget;
|
||||
@@ -441,3 +441,11 @@ TrackDetailView::setBuyButtonVisible( bool 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 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:
|
||||
void setSocialActions();
|
||||
|
||||
|
Reference in New Issue
Block a user