mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-18 23:09:42 +01:00
* Use proper sort order for Top Hits & Related Artists.
This commit is contained in:
parent
fdb13a1f78
commit
39a40ce372
@ -489,15 +489,26 @@ LastFmPlugin::similarArtistsReturned()
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
|
||||
|
||||
QMap< int, QString > similarArtists = lastfm::Artist::getSimilar( reply );
|
||||
|
||||
QStringList sortedArtists;
|
||||
QStringList sortedScores;
|
||||
QStringList al;
|
||||
QStringList sl;
|
||||
|
||||
foreach ( const QString& a, similarArtists.values() )
|
||||
al << a;
|
||||
foreach ( const QString& artist, similarArtists.values() )
|
||||
al << artist;
|
||||
foreach ( int score, similarArtists.keys() )
|
||||
sl << QString::number( score );
|
||||
|
||||
for ( int i = al.count() - 1; i >= 0; i-- )
|
||||
{
|
||||
sortedArtists << al.at( i );
|
||||
sortedScores << sl.at( i );
|
||||
}
|
||||
|
||||
QVariantMap returnedData;
|
||||
returnedData["artists"] = al;
|
||||
returnedData["score"] = sl;
|
||||
returnedData["artists"] = sortedArtists;
|
||||
returnedData["score"] = sortedScores;
|
||||
|
||||
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
|
||||
|
||||
@ -682,25 +693,25 @@ LastFmPlugin::artistImagesReturned()
|
||||
void
|
||||
LastFmPlugin::settingsChanged()
|
||||
{
|
||||
if( !m_scrobbler && TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
if ( !m_scrobbler && TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
{ // can simply create the scrobbler
|
||||
lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername();
|
||||
m_pw = TomahawkSettings::instance()->lastFmPassword();
|
||||
|
||||
createScrobbler();
|
||||
}
|
||||
else if( m_scrobbler && !TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
else if ( m_scrobbler && !TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
{
|
||||
delete m_scrobbler;
|
||||
m_scrobbler = 0;
|
||||
}
|
||||
else if( TomahawkSettings::instance()->lastFmUsername() != lastfm::ws::Username ||
|
||||
else if ( TomahawkSettings::instance()->lastFmUsername() != lastfm::ws::Username ||
|
||||
TomahawkSettings::instance()->lastFmPassword() != m_pw )
|
||||
{
|
||||
lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername();
|
||||
m_pw = TomahawkSettings::instance()->lastFmPassword();
|
||||
// credentials have changed, have to re-create scrobbler for them to take effect
|
||||
if( m_scrobbler )
|
||||
if ( m_scrobbler )
|
||||
{
|
||||
delete m_scrobbler;
|
||||
m_scrobbler = 0;
|
||||
@ -715,17 +726,17 @@ void
|
||||
LastFmPlugin::onAuthenticated()
|
||||
{
|
||||
QNetworkReply* authJob = dynamic_cast<QNetworkReply*>( sender() );
|
||||
if( !authJob )
|
||||
if ( !authJob )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO << "Help! No longer got a last.fm auth job!";
|
||||
return;
|
||||
}
|
||||
|
||||
if( authJob->error() == QNetworkReply::NoError )
|
||||
if ( authJob->error() == QNetworkReply::NoError )
|
||||
{
|
||||
lastfm::XmlQuery lfm = lastfm::XmlQuery( authJob->readAll() );
|
||||
|
||||
if( lfm.children( "error" ).size() > 0 )
|
||||
if ( lfm.children( "error" ).size() > 0 )
|
||||
{
|
||||
tLog() << "Error from authenticating with Last.fm service:" << lfm.text();
|
||||
TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() );
|
||||
@ -737,7 +748,7 @@ LastFmPlugin::onAuthenticated()
|
||||
TomahawkSettings::instance()->setLastFmSessionKey( lastfm::ws::SessionKey.toLatin1() );
|
||||
|
||||
// qDebug() << "Got session key from last.fm";
|
||||
if( TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
if ( TomahawkSettings::instance()->scrobblingEnabled() )
|
||||
m_scrobbler = new lastfm::Audioscrobbler( "thk" );
|
||||
}
|
||||
}
|
||||
@ -753,7 +764,7 @@ LastFmPlugin::onAuthenticated()
|
||||
void
|
||||
LastFmPlugin::createScrobbler()
|
||||
{
|
||||
if( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one
|
||||
if ( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one
|
||||
{
|
||||
qDebug() << "LastFmPlugin::createScrobbler Session key is empty";
|
||||
QString authToken = TomahawkUtils::md5( ( lastfm::ws::Username.toLower() + TomahawkUtils::md5( m_pw.toUtf8() ) ).toUtf8() );
|
||||
@ -780,14 +791,15 @@ QList<lastfm::Track>
|
||||
LastFmPlugin::parseTrackList( QNetworkReply* reply )
|
||||
{
|
||||
QList<lastfm::Track> tracks;
|
||||
try {
|
||||
try
|
||||
{
|
||||
lastfm::XmlQuery lfm = reply->readAll();
|
||||
foreach ( lastfm::XmlQuery xq, lfm.children( "track" ) )
|
||||
{
|
||||
tracks.append( lastfm::Track( xq ) );
|
||||
}
|
||||
}
|
||||
catch( lastfm::ws::ParseError& e )
|
||||
catch ( lastfm::ws::ParseError& e )
|
||||
{
|
||||
qWarning() << e.what();
|
||||
}
|
||||
|
@ -132,9 +132,6 @@ TrackView::setTrackModel( TrackModel* model )
|
||||
m_proxyModel->setSourceTrackModel( m_model );
|
||||
}
|
||||
|
||||
if ( m_model && m_model->metaObject()->indexOfSignal( "itemSizeChanged(QModelIndex)" ) > -1 )
|
||||
connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) );
|
||||
|
||||
connect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
|
||||
connect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
|
||||
|
||||
|
@ -272,9 +272,9 @@ TreeModel::data( const QModelIndex& index, int role ) const
|
||||
{
|
||||
const result_ptr& result = entry->result();
|
||||
unsigned int discnumber = 0;
|
||||
if( !entry->query().isNull() )
|
||||
if ( !entry->query().isNull() )
|
||||
discnumber = entry->query()->discnumber();
|
||||
if( discnumber == 0 )
|
||||
if ( discnumber == 0 )
|
||||
discnumber = result->discnumber();
|
||||
|
||||
unsigned int albumpos = 0;
|
||||
@ -294,18 +294,14 @@ TreeModel::data( const QModelIndex& index, int role ) const
|
||||
return TomahawkUtils::timeToString( result->duration() );
|
||||
|
||||
case Bitrate:
|
||||
if ( result->bitrate() == 0 )
|
||||
return QString();
|
||||
else
|
||||
if ( result->bitrate() > 0 )
|
||||
return result->bitrate();
|
||||
|
||||
case Age:
|
||||
return TomahawkUtils::ageToString( QDateTime::fromTime_t( result->modificationTime() ) );
|
||||
|
||||
case Year:
|
||||
if ( result->year() == 0 )
|
||||
return QString();
|
||||
else
|
||||
if ( result->year() != 0 )
|
||||
return result->year();
|
||||
|
||||
case Filesize:
|
||||
@ -318,7 +314,8 @@ TreeModel::data( const QModelIndex& index, int role ) const
|
||||
return result->albumpos();
|
||||
|
||||
case Composer:
|
||||
return result->composer()->name();
|
||||
if ( !result->composer().isNull() )
|
||||
return result->composer()->name();
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
|
@ -41,6 +41,7 @@ TreeProxyModel::TreeProxyModel( QObject* parent )
|
||||
setSourceTreeModel( 0 );
|
||||
}
|
||||
|
||||
|
||||
QPersistentModelIndex
|
||||
TreeProxyModel::currentIndex() const
|
||||
{
|
||||
@ -109,6 +110,7 @@ TreeProxyModel::onModelReset()
|
||||
m_albumsFilter.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
|
||||
{
|
||||
@ -142,6 +144,7 @@ TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
|
||||
{
|
||||
@ -288,25 +291,25 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co
|
||||
unsigned int albumpos2 = 0;
|
||||
unsigned int discnumber1 = 0;
|
||||
unsigned int discnumber2 = 0;
|
||||
if( !p1->query().isNull() )
|
||||
if ( !p1->query().isNull() )
|
||||
{
|
||||
albumpos1 = p1->query()->albumpos();
|
||||
discnumber1 = p1->query()->discnumber();
|
||||
}
|
||||
if( !p2->query().isNull() )
|
||||
if ( !p2->query().isNull() )
|
||||
{
|
||||
albumpos2 = p2->query()->albumpos();
|
||||
discnumber2 = p2->query()->discnumber();
|
||||
}
|
||||
|
||||
if( albumpos1 == 0 && !p1->result().isNull() )
|
||||
if ( albumpos1 == 0 && !p1->result().isNull() )
|
||||
albumpos1 = p1->result()->albumpos();
|
||||
if( discnumber1 == 0 && !p1->result().isNull() )
|
||||
if ( discnumber1 == 0 && !p1->result().isNull() )
|
||||
discnumber1 = p1->result()->discnumber();
|
||||
|
||||
if( albumpos2 == 0 && !p2->result().isNull() )
|
||||
if ( albumpos2 == 0 && !p2->result().isNull() )
|
||||
albumpos2 = p2->result()->albumpos();
|
||||
if( discnumber2 == 0 && !p2->result().isNull() )
|
||||
if ( discnumber2 == 0 && !p2->result().isNull() )
|
||||
discnumber2 = p2->result()->discnumber();
|
||||
|
||||
const QString& lefts = textForItem( p1 );
|
||||
|
@ -140,13 +140,16 @@ ViewManager::createPageForPlaylist( const playlist_ptr& pl )
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
playlist_ptr
|
||||
ViewManager::playlistForPage( ViewPage* page ) const
|
||||
{
|
||||
playlist_ptr p;
|
||||
if ( dynamic_cast< PlaylistView* >( page ) && dynamic_cast< PlaylistView* >( page )->playlistModel() &&
|
||||
!dynamic_cast< PlaylistView* >( page )->playlistModel()->playlist().isNull() )
|
||||
{
|
||||
p = dynamic_cast< PlaylistView* >( page )->playlistModel()->playlist();
|
||||
}
|
||||
else if ( dynamic_cast< DynamicWidget* >( page ) )
|
||||
p = dynamic_cast< DynamicWidget* >( page )->playlist();
|
||||
|
||||
@ -484,13 +487,15 @@ ViewManager::historyBack()
|
||||
delete oldPage;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::removeFromHistory ( ViewPage* p )
|
||||
{
|
||||
if ( currentPage() == p )
|
||||
{
|
||||
historyBack();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pageHistory.removeAll( p );
|
||||
delete p;
|
||||
@ -498,6 +503,7 @@ ViewManager::removeFromHistory ( ViewPage* p )
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::setFilter( const QString& filter )
|
||||
{
|
||||
@ -645,16 +651,16 @@ ViewManager::updateView()
|
||||
if ( currentPlaylistInterface() )
|
||||
{
|
||||
connect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
|
||||
SIGNAL( numTracksChanged( unsigned int ) ) );
|
||||
SIGNAL( numTracksChanged( unsigned int ) ) );
|
||||
|
||||
connect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ),
|
||||
SIGNAL( numShownChanged( unsigned int ) ) );
|
||||
SIGNAL( numShownChanged( unsigned int ) ) );
|
||||
|
||||
connect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
|
||||
SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
|
||||
SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
|
||||
|
||||
connect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ),
|
||||
SIGNAL( shuffleModeChanged( bool ) ) );
|
||||
SIGNAL( shuffleModeChanged( bool ) ) );
|
||||
|
||||
m_infobar->setFilter( currentPlaylistInterface()->filter() );
|
||||
}
|
||||
@ -717,12 +723,17 @@ ViewManager::loadCurrentPlaylistSettings()
|
||||
{
|
||||
TomahawkSettings* s = TomahawkSettings::instance();
|
||||
Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() );
|
||||
if ( !pl.isNull() ) {
|
||||
|
||||
if ( !pl.isNull() )
|
||||
{
|
||||
currentPlaylistInterface()->setShuffled( s->shuffleState( pl->guid() ));
|
||||
currentPlaylistInterface()->setRepeatMode( s->repeatMode( pl->guid() ));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() );
|
||||
if ( !dynPl.isNull() ) {
|
||||
if ( !dynPl.isNull() )
|
||||
{
|
||||
currentPlaylistInterface()->setShuffled( s->shuffleState( dynPl->guid() ));
|
||||
}
|
||||
}
|
||||
@ -783,8 +794,7 @@ ViewManager::setShuffled( bool enabled )
|
||||
|
||||
|
||||
void
|
||||
ViewManager::createPlaylist( const Tomahawk::source_ptr& src,
|
||||
const QVariant& contents )
|
||||
ViewManager::createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents )
|
||||
{
|
||||
Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) );
|
||||
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
|
||||
@ -793,8 +803,7 @@ ViewManager::createPlaylist( const Tomahawk::source_ptr& src,
|
||||
|
||||
|
||||
void
|
||||
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
|
||||
const QVariant& contents )
|
||||
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents )
|
||||
{
|
||||
Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) );
|
||||
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
|
||||
@ -838,6 +847,7 @@ ViewManager::pageForInterface( Tomahawk::playlistinterface_ptr interface ) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::playlistinterface_ptr
|
||||
ViewManager::currentPlaylistInterface() const
|
||||
{
|
||||
@ -854,6 +864,7 @@ ViewManager::currentPage() const
|
||||
return m_pageHistory.isEmpty() ? 0 : m_pageHistory.front();
|
||||
}
|
||||
|
||||
|
||||
Tomahawk::playlist_ptr
|
||||
ViewManager::playlistForInterface( Tomahawk::playlistinterface_ptr interface ) const
|
||||
{
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ui_ArtistInfoWidget.h"
|
||||
|
||||
#include "audio/audioengine.h"
|
||||
#include "playlist/trackheader.h"
|
||||
#include "playlist/treemodel.h"
|
||||
#include "playlist/playlistmodel.h"
|
||||
#include "playlist/treeproxymodel.h"
|
||||
@ -68,10 +69,13 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
|
||||
m_relatedModel = new TreeModel( ui->relatedArtists );
|
||||
m_relatedModel->setColumnStyle( TreeModel::TrackOnly );
|
||||
ui->relatedArtists->setTreeModel( m_relatedModel );
|
||||
ui->relatedArtists->setSortingEnabled( false );
|
||||
ui->relatedArtists->proxyModel()->sort( -1 );
|
||||
|
||||
m_topHitsModel = new PlaylistModel( ui->topHits );
|
||||
m_topHitsModel->setStyle( TrackModel::Short );
|
||||
ui->topHits->setTrackModel( m_topHitsModel );
|
||||
ui->topHits->setSortingEnabled( false );
|
||||
|
||||
m_pixmap = QPixmap( RESPATH "images/no-album-no-case.png" ).scaledToWidth( 48, Qt::SmoothTransformation );
|
||||
|
||||
@ -252,15 +256,17 @@ ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD
|
||||
{
|
||||
const QStringList tracks = returnedData["tracks"].toStringList();
|
||||
|
||||
QList< query_ptr > queries;
|
||||
int i = 0;
|
||||
foreach ( const QString& track, tracks )
|
||||
{
|
||||
query_ptr query = Query::get( m_artist->name(), track, QString(), uuid() );
|
||||
m_topHitsModel->append( query );
|
||||
queries << Query::get( m_artist->name(), track, QString(), uuid() );
|
||||
|
||||
if ( ++i == 15 )
|
||||
break;
|
||||
}
|
||||
|
||||
m_topHitsModel->append( queries );
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user