Skip to content

Commit 39a40ce

Browse files
committed
* Use proper sort order for Top Hits & Related Artists.
1 parent fdb13a1 commit 39a40ce

File tree

6 files changed

+73
-47
lines changed

6 files changed

+73
-47
lines changed

src/libtomahawk/infosystem/infoplugins/generic/lastfmplugin.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,26 @@ LastFmPlugin::similarArtistsReturned()
489489
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
490490

491491
QMap< int, QString > similarArtists = lastfm::Artist::getSimilar( reply );
492+
493+
QStringList sortedArtists;
494+
QStringList sortedScores;
492495
QStringList al;
493496
QStringList sl;
494497

495-
foreach ( const QString& a, similarArtists.values() )
496-
al << a;
498+
foreach ( const QString& artist, similarArtists.values() )
499+
al << artist;
500+
foreach ( int score, similarArtists.keys() )
501+
sl << QString::number( score );
502+
503+
for ( int i = al.count() - 1; i >= 0; i-- )
504+
{
505+
sortedArtists << al.at( i );
506+
sortedScores << sl.at( i );
507+
}
497508

498509
QVariantMap returnedData;
499-
returnedData["artists"] = al;
500-
returnedData["score"] = sl;
510+
returnedData["artists"] = sortedArtists;
511+
returnedData["score"] = sortedScores;
501512

502513
Tomahawk::InfoSystem::InfoRequestData requestData = reply->property( "requestData" ).value< Tomahawk::InfoSystem::InfoRequestData >();
503514

@@ -682,25 +693,25 @@ LastFmPlugin::artistImagesReturned()
682693
void
683694
LastFmPlugin::settingsChanged()
684695
{
685-
if( !m_scrobbler && TomahawkSettings::instance()->scrobblingEnabled() )
696+
if ( !m_scrobbler && TomahawkSettings::instance()->scrobblingEnabled() )
686697
{ // can simply create the scrobbler
687698
lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername();
688699
m_pw = TomahawkSettings::instance()->lastFmPassword();
689700

690701
createScrobbler();
691702
}
692-
else if( m_scrobbler && !TomahawkSettings::instance()->scrobblingEnabled() )
703+
else if ( m_scrobbler && !TomahawkSettings::instance()->scrobblingEnabled() )
693704
{
694705
delete m_scrobbler;
695706
m_scrobbler = 0;
696707
}
697-
else if( TomahawkSettings::instance()->lastFmUsername() != lastfm::ws::Username ||
708+
else if ( TomahawkSettings::instance()->lastFmUsername() != lastfm::ws::Username ||
698709
TomahawkSettings::instance()->lastFmPassword() != m_pw )
699710
{
700711
lastfm::ws::Username = TomahawkSettings::instance()->lastFmUsername();
701712
m_pw = TomahawkSettings::instance()->lastFmPassword();
702713
// credentials have changed, have to re-create scrobbler for them to take effect
703-
if( m_scrobbler )
714+
if ( m_scrobbler )
704715
{
705716
delete m_scrobbler;
706717
m_scrobbler = 0;
@@ -715,17 +726,17 @@ void
715726
LastFmPlugin::onAuthenticated()
716727
{
717728
QNetworkReply* authJob = dynamic_cast<QNetworkReply*>( sender() );
718-
if( !authJob )
729+
if ( !authJob )
719730
{
720731
tLog() << Q_FUNC_INFO << "Help! No longer got a last.fm auth job!";
721732
return;
722733
}
723734

724-
if( authJob->error() == QNetworkReply::NoError )
735+
if ( authJob->error() == QNetworkReply::NoError )
725736
{
726737
lastfm::XmlQuery lfm = lastfm::XmlQuery( authJob->readAll() );
727738

728-
if( lfm.children( "error" ).size() > 0 )
739+
if ( lfm.children( "error" ).size() > 0 )
729740
{
730741
tLog() << "Error from authenticating with Last.fm service:" << lfm.text();
731742
TomahawkSettings::instance()->setLastFmSessionKey( QByteArray() );
@@ -737,7 +748,7 @@ LastFmPlugin::onAuthenticated()
737748
TomahawkSettings::instance()->setLastFmSessionKey( lastfm::ws::SessionKey.toLatin1() );
738749

739750
// qDebug() << "Got session key from last.fm";
740-
if( TomahawkSettings::instance()->scrobblingEnabled() )
751+
if ( TomahawkSettings::instance()->scrobblingEnabled() )
741752
m_scrobbler = new lastfm::Audioscrobbler( "thk" );
742753
}
743754
}
@@ -753,7 +764,7 @@ LastFmPlugin::onAuthenticated()
753764
void
754765
LastFmPlugin::createScrobbler()
755766
{
756-
if( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one
767+
if ( TomahawkSettings::instance()->lastFmSessionKey().isEmpty() ) // no session key, so get one
757768
{
758769
qDebug() << "LastFmPlugin::createScrobbler Session key is empty";
759770
QString authToken = TomahawkUtils::md5( ( lastfm::ws::Username.toLower() + TomahawkUtils::md5( m_pw.toUtf8() ) ).toUtf8() );
@@ -780,14 +791,15 @@ QList<lastfm::Track>
780791
LastFmPlugin::parseTrackList( QNetworkReply* reply )
781792
{
782793
QList<lastfm::Track> tracks;
783-
try {
794+
try
795+
{
784796
lastfm::XmlQuery lfm = reply->readAll();
785797
foreach ( lastfm::XmlQuery xq, lfm.children( "track" ) )
786798
{
787799
tracks.append( lastfm::Track( xq ) );
788800
}
789801
}
790-
catch( lastfm::ws::ParseError& e )
802+
catch ( lastfm::ws::ParseError& e )
791803
{
792804
qWarning() << e.what();
793805
}

src/libtomahawk/playlist/trackview.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ TrackView::setTrackModel( TrackModel* model )
132132
m_proxyModel->setSourceTrackModel( m_model );
133133
}
134134

135-
if ( m_model && m_model->metaObject()->indexOfSignal( "itemSizeChanged(QModelIndex)" ) > -1 )
136-
connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) );
137-
138135
connect( m_model, SIGNAL( loadingStarted() ), m_loadingSpinner, SLOT( fadeIn() ) );
139136
connect( m_model, SIGNAL( loadingFinished() ), m_loadingSpinner, SLOT( fadeOut() ) );
140137

src/libtomahawk/playlist/treemodel.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ TreeModel::data( const QModelIndex& index, int role ) const
272272
{
273273
const result_ptr& result = entry->result();
274274
unsigned int discnumber = 0;
275-
if( !entry->query().isNull() )
275+
if ( !entry->query().isNull() )
276276
discnumber = entry->query()->discnumber();
277-
if( discnumber == 0 )
277+
if ( discnumber == 0 )
278278
discnumber = result->discnumber();
279279

280280
unsigned int albumpos = 0;
@@ -294,18 +294,14 @@ TreeModel::data( const QModelIndex& index, int role ) const
294294
return TomahawkUtils::timeToString( result->duration() );
295295

296296
case Bitrate:
297-
if ( result->bitrate() == 0 )
298-
return QString();
299-
else
297+
if ( result->bitrate() > 0 )
300298
return result->bitrate();
301299

302300
case Age:
303301
return TomahawkUtils::ageToString( QDateTime::fromTime_t( result->modificationTime() ) );
304302

305303
case Year:
306-
if ( result->year() == 0 )
307-
return QString();
308-
else
304+
if ( result->year() != 0 )
309305
return result->year();
310306

311307
case Filesize:
@@ -318,7 +314,8 @@ TreeModel::data( const QModelIndex& index, int role ) const
318314
return result->albumpos();
319315

320316
case Composer:
321-
return result->composer()->name();
317+
if ( !result->composer().isNull() )
318+
return result->composer()->name();
322319

323320
default:
324321
return QVariant();

src/libtomahawk/playlist/treeproxymodel.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ TreeProxyModel::TreeProxyModel( QObject* parent )
4141
setSourceTreeModel( 0 );
4242
}
4343

44+
4445
QPersistentModelIndex
4546
TreeProxyModel::currentIndex() const
4647
{
@@ -109,6 +110,7 @@ TreeProxyModel::onModelReset()
109110
m_albumsFilter.clear();
110111
}
111112

113+
112114
void
113115
TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
114116
{
@@ -142,6 +144,7 @@ TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
142144
}
143145
}
144146

147+
145148
void
146149
TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
147150
{
@@ -288,25 +291,25 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co
288291
unsigned int albumpos2 = 0;
289292
unsigned int discnumber1 = 0;
290293
unsigned int discnumber2 = 0;
291-
if( !p1->query().isNull() )
294+
if ( !p1->query().isNull() )
292295
{
293296
albumpos1 = p1->query()->albumpos();
294297
discnumber1 = p1->query()->discnumber();
295298
}
296-
if( !p2->query().isNull() )
299+
if ( !p2->query().isNull() )
297300
{
298301
albumpos2 = p2->query()->albumpos();
299302
discnumber2 = p2->query()->discnumber();
300303
}
301304

302-
if( albumpos1 == 0 && !p1->result().isNull() )
305+
if ( albumpos1 == 0 && !p1->result().isNull() )
303306
albumpos1 = p1->result()->albumpos();
304-
if( discnumber1 == 0 && !p1->result().isNull() )
307+
if ( discnumber1 == 0 && !p1->result().isNull() )
305308
discnumber1 = p1->result()->discnumber();
306309

307-
if( albumpos2 == 0 && !p2->result().isNull() )
310+
if ( albumpos2 == 0 && !p2->result().isNull() )
308311
albumpos2 = p2->result()->albumpos();
309-
if( discnumber2 == 0 && !p2->result().isNull() )
312+
if ( discnumber2 == 0 && !p2->result().isNull() )
310313
discnumber2 = p2->result()->discnumber();
311314

312315
const QString& lefts = textForItem( p1 );

src/libtomahawk/viewmanager.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,16 @@ ViewManager::createPageForPlaylist( const playlist_ptr& pl )
140140
return view;
141141
}
142142

143+
143144
playlist_ptr
144145
ViewManager::playlistForPage( ViewPage* page ) const
145146
{
146147
playlist_ptr p;
147148
if ( dynamic_cast< PlaylistView* >( page ) && dynamic_cast< PlaylistView* >( page )->playlistModel() &&
148149
!dynamic_cast< PlaylistView* >( page )->playlistModel()->playlist().isNull() )
150+
{
149151
p = dynamic_cast< PlaylistView* >( page )->playlistModel()->playlist();
152+
}
150153
else if ( dynamic_cast< DynamicWidget* >( page ) )
151154
p = dynamic_cast< DynamicWidget* >( page )->playlist();
152155

@@ -484,20 +487,23 @@ ViewManager::historyBack()
484487
delete oldPage;
485488
}
486489

490+
487491
void
488492
ViewManager::removeFromHistory ( ViewPage* p )
489493
{
490494
if ( currentPage() == p )
491495
{
492496
historyBack();
493-
} else
497+
}
498+
else
494499
{
495500
m_pageHistory.removeAll( p );
496501
delete p;
497502
}
498503

499504
}
500505

506+
501507
void
502508
ViewManager::setFilter( const QString& filter )
503509
{
@@ -645,16 +651,16 @@ ViewManager::updateView()
645651
if ( currentPlaylistInterface() )
646652
{
647653
connect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
648-
SIGNAL( numTracksChanged( unsigned int ) ) );
654+
SIGNAL( numTracksChanged( unsigned int ) ) );
649655

650656
connect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ),
651-
SIGNAL( numShownChanged( unsigned int ) ) );
657+
SIGNAL( numShownChanged( unsigned int ) ) );
652658

653659
connect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ),
654-
SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
660+
SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) );
655661

656662
connect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ),
657-
SIGNAL( shuffleModeChanged( bool ) ) );
663+
SIGNAL( shuffleModeChanged( bool ) ) );
658664

659665
m_infobar->setFilter( currentPlaylistInterface()->filter() );
660666
}
@@ -717,12 +723,17 @@ ViewManager::loadCurrentPlaylistSettings()
717723
{
718724
TomahawkSettings* s = TomahawkSettings::instance();
719725
Tomahawk::playlist_ptr pl = playlistForInterface( currentPlaylistInterface() );
720-
if ( !pl.isNull() ) {
726+
727+
if ( !pl.isNull() )
728+
{
721729
currentPlaylistInterface()->setShuffled( s->shuffleState( pl->guid() ));
722730
currentPlaylistInterface()->setRepeatMode( s->repeatMode( pl->guid() ));
723-
} else {
731+
}
732+
else
733+
{
724734
Tomahawk::dynplaylist_ptr dynPl = dynamicPlaylistForInterface( currentPlaylistInterface() );
725-
if ( !dynPl.isNull() ) {
735+
if ( !dynPl.isNull() )
736+
{
726737
currentPlaylistInterface()->setShuffled( s->shuffleState( dynPl->guid() ));
727738
}
728739
}
@@ -783,8 +794,7 @@ ViewManager::setShuffled( bool enabled )
783794

784795

785796
void
786-
ViewManager::createPlaylist( const Tomahawk::source_ptr& src,
787-
const QVariant& contents )
797+
ViewManager::createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents )
788798
{
789799
Tomahawk::playlist_ptr p = Tomahawk::playlist_ptr( new Tomahawk::Playlist( src ) );
790800
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
@@ -793,8 +803,7 @@ ViewManager::createPlaylist( const Tomahawk::source_ptr& src,
793803

794804

795805
void
796-
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
797-
const QVariant& contents )
806+
ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents )
798807
{
799808
Tomahawk::dynplaylist_ptr p = Tomahawk::dynplaylist_ptr( new Tomahawk::DynamicPlaylist( src, contents.toMap().value( "type", QString() ).toString() ) );
800809
QJson::QObjectHelper::qvariant2qobject( contents.toMap(), p.data() );
@@ -838,6 +847,7 @@ ViewManager::pageForInterface( Tomahawk::playlistinterface_ptr interface ) const
838847
return 0;
839848
}
840849

850+
841851
Tomahawk::playlistinterface_ptr
842852
ViewManager::currentPlaylistInterface() const
843853
{
@@ -854,6 +864,7 @@ ViewManager::currentPage() const
854864
return m_pageHistory.isEmpty() ? 0 : m_pageHistory.front();
855865
}
856866

867+
857868
Tomahawk::playlist_ptr
858869
ViewManager::playlistForInterface( Tomahawk::playlistinterface_ptr interface ) const
859870
{

src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ui_ArtistInfoWidget.h"
2222

2323
#include "audio/audioengine.h"
24+
#include "playlist/trackheader.h"
2425
#include "playlist/treemodel.h"
2526
#include "playlist/playlistmodel.h"
2627
#include "playlist/treeproxymodel.h"
@@ -68,10 +69,13 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget*
6869
m_relatedModel = new TreeModel( ui->relatedArtists );
6970
m_relatedModel->setColumnStyle( TreeModel::TrackOnly );
7071
ui->relatedArtists->setTreeModel( m_relatedModel );
72+
ui->relatedArtists->setSortingEnabled( false );
73+
ui->relatedArtists->proxyModel()->sort( -1 );
7174

7275
m_topHitsModel = new PlaylistModel( ui->topHits );
7376
m_topHitsModel->setStyle( TrackModel::Short );
7477
ui->topHits->setTrackModel( m_topHitsModel );
78+
ui->topHits->setSortingEnabled( false );
7579

7680
m_pixmap = QPixmap( RESPATH "images/no-album-no-case.png" ).scaledToWidth( 48, Qt::SmoothTransformation );
7781

@@ -252,15 +256,17 @@ ArtistInfoWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestD
252256
{
253257
const QStringList tracks = returnedData["tracks"].toStringList();
254258

259+
QList< query_ptr > queries;
255260
int i = 0;
256261
foreach ( const QString& track, tracks )
257262
{
258-
query_ptr query = Query::get( m_artist->name(), track, QString(), uuid() );
259-
m_topHitsModel->append( query );
263+
queries << Query::get( m_artist->name(), track, QString(), uuid() );
260264

261265
if ( ++i == 15 )
262266
break;
263267
}
268+
269+
m_topHitsModel->append( queries );
264270
break;
265271
}
266272

0 commit comments

Comments
 (0)