1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 23:39:42 +01:00

* Fixed album position & ordering for InfoSystem views.

This commit is contained in:
Christian Muehlhaeuser 2011-11-08 15:30:13 +01:00
parent 0c136e6815
commit 14639337d4
4 changed files with 48 additions and 13 deletions

View File

@ -300,10 +300,16 @@ TreeModel::data( const QModelIndex& index, int role ) const
else if ( !entry->result().isNull() )
{
const result_ptr& result = entry->result();
unsigned int albumpos = 0;
if ( !entry->query().isNull() )
albumpos = entry->query()->albumpos();
if ( albumpos == 0 )
albumpos = result->albumpos();
switch( index.column() )
{
case Name:
return QString( "%1%2" ).arg( result->albumpos() > 0 ? QString( "%1. ").arg( result->albumpos() ) : QString() )
return QString( "%1%2" ).arg( albumpos > 0 ? QString( "%1. ").arg( albumpos ) : QString() )
.arg( result->track() );
case Duration:
@ -331,9 +337,21 @@ TreeModel::data( const QModelIndex& index, int role ) const
return QVariant();
}
}
else if ( !entry->query().isNull() && index.column() == Name )
else if ( !entry->query().isNull() )
{
return entry->query()->track();
const query_ptr& query = entry->query();
switch( index.column() )
{
case Name:
return QString( "%1%2" ).arg( query->albumpos() > 0 ? QString( "%1. ").arg( query->albumpos() ) : QString() )
.arg( query->track() );
case AlbumPosition:
return entry->query()->albumpos();
default:
return QVariant();
}
}
return QVariant();
@ -889,16 +907,17 @@ TreeModel::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QV
m_receivedInfoData.insert( requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >() );
QStringList tracks = returnedData[ "tracks" ].toStringList();
QList<query_ptr> ql;
Tomahawk::InfoSystem::InfoStringHash inputInfo;
inputInfo = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >();
unsigned int trackNo = 1;
foreach ( const QString& trackName, tracks )
{
query_ptr query = Query::get( inputInfo[ "artist" ], trackName, inputInfo[ "album" ], uuid() );
query->setAlbumPos( trackNo++ );
ql << query;
}
onTracksAdded( ql, requestData.customData[ "rows" ] );

View File

@ -264,22 +264,33 @@ TreeProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) co
if ( !p2 )
return false;
if ( !p1->result().isNull() && p2->result().isNull() )
/* if ( !p1->result().isNull() && p2->result().isNull() )
return true;
if ( p1->result().isNull() && !p2->result().isNull() )
return false;
return false;*/
unsigned int albumpos1 = 0;
unsigned int albumpos2 = 0;
if ( !p1->query().isNull() )
albumpos1 = p1->query()->albumpos();
if ( !p2->query().isNull() )
albumpos2 = p2->query()->albumpos();
if ( albumpos1 == 0 && !p1->result().isNull() )
albumpos1 = p1->result()->albumpos();
if ( albumpos2 == 0 && !p2->result().isNull() )
albumpos2 = p2->result()->albumpos();
const QString& lefts = textForItem( p1 );
const QString& rights = textForItem( p2 );
if ( !p1->result().isNull() )
{
if ( p1->result()->albumpos() != p2->result()->albumpos() )
return p1->result()->albumpos() < p2->result()->albumpos();
tDebug() << lefts << albumpos1;
tDebug() << rights << albumpos2;
if ( lefts == rights )
return (qint64)&p1 < (qint64)&p2;
}
if ( albumpos1 != albumpos2 )
return albumpos1 < albumpos2;
if ( lefts == rights )
return (qint64)&p1 < (qint64)&p2;
return QString::localeAwareCompare( lefts, rights ) < 0;
}

View File

@ -122,6 +122,7 @@ Query::init()
m_solved = false;
m_playable = false;
m_duration = -1;
m_albumpos = 0;
updateSortNames();
}

View File

@ -86,6 +86,7 @@ public:
void setTrack( const QString& track ) { m_track = track; updateSortNames(); }
void setResultHint( const QString& resultHint ) { m_resultHint = resultHint; }
void setDuration( int duration ) { m_duration = duration; }
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
QVariant toVariant() const;
QString toString() const;
@ -97,7 +98,9 @@ public:
QString artist() const { return m_artist; }
QString album() const { return m_album; }
QString track() const { return m_track; }
int duration() const { return m_duration; }
unsigned int albumpos() const { return m_albumpos; }
void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
@ -154,6 +157,7 @@ private:
QString m_fullTextQuery;
int m_duration;
unsigned int m_albumpos;
QString m_resultHint;
QPair< Tomahawk::source_ptr, unsigned int > m_playedBy;