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

Merge remote branch 'origin/master' into proxyrefactor

This commit is contained in:
Jeff Mitchell 2011-11-08 10:15:18 -05:00
commit d3f4046396
6 changed files with 77 additions and 50 deletions

View File

@ -16,5 +16,5 @@ INCLUDE( ${QT_USE_FILE} )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/src ../../libtomahawk )
ADD_DEFINITIONS( ${QT_DEFINITIONS} )
ADD_EXECUTABLE( CrashReporter ${crashreporter_SOURCES} ${crashreporter_HEADERS_MOC} ${crashreporter_UI_HEADERS} ${crashreporter_RC_RCC} )
ADD_EXECUTABLE( CrashReporter WIN32 ${crashreporter_SOURCES} ${crashreporter_HEADERS_MOC} ${crashreporter_UI_HEADERS} ${crashreporter_RC_RCC} )
TARGET_LINK_LIBRARIES( CrashReporter ${QT_LIBRARIES} tomahawklib )

View File

@ -110,7 +110,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly )
qDebug() << Q_FUNC_INFO;
QModelIndex idx = index( 0, 0 );
if( rowCount() )
if ( rowCount() )
{
if ( m_shuffled )
{
@ -123,12 +123,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly )
idx = currentIndex();
// random mode is disabled
if ( m_repeatMode == PlaylistInterface::RepeatOne )
{
// repeat one track
idx = index( idx.row(), 0 );
}
else
if ( m_repeatMode != PlaylistInterface::RepeatOne )
{
// keep progressing through the playlist normally
idx = index( idx.row() + itemsAway, 0 );
@ -152,7 +147,7 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly )
}
// Try to find the next available PlaylistItem (with results)
if ( idx.isValid() ) do
while ( idx.isValid() )
{
TrackModelItem* item = itemFromIndex( mapToSource( idx ) );
if ( item && item->query()->playable() )
@ -165,7 +160,6 @@ TrackProxyModel::siblingItem( int itemsAway, bool readOnly )
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 );
}
while ( idx.isValid() );
if ( !readOnly )
setCurrentIndex( QModelIndex() );

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

@ -192,18 +192,18 @@ TreeProxyModel::filterFinished()
bool
TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
TreeModelItem* pi = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
Q_ASSERT( pi );
TreeModelItem* item = sourceModel()->itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
Q_ASSERT( item );
if ( m_model->mode() == Tomahawk::DatabaseMode && !pi->result().isNull() )
if ( m_model->mode() == Tomahawk::DatabaseMode && !item->result().isNull() )
{
QList< Tomahawk::result_ptr > rl = m_cache.values( sourceParent );
foreach ( const Tomahawk::result_ptr& result, rl )
foreach ( const Tomahawk::result_ptr& cachedResult, rl )
{
if ( result->track() == pi->result()->track() &&
( result->albumpos() == pi->result()->albumpos() || result->albumpos() == 0 ) )
if ( cachedResult->track() == item->result()->track() &&
( cachedResult->albumpos() == item->result()->albumpos() || cachedResult->albumpos() == 0 ) )
{
return ( result.data() == pi->result().data() );
return ( cachedResult.data() == item->result().data() );
}
}
@ -214,13 +214,13 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
TreeModelItem* ti = sourceModel()->itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
if ( ti->name() == pi->name() &&
( ti->result()->albumpos() == pi->result()->albumpos() || ti->result()->albumpos() == 0 ) )
if ( ti->name() == item->name() &&
( ti->result()->albumpos() == item->result()->albumpos() || ti->result()->albumpos() == 0 || item->result()->albumpos() == 0 ) )
{
if ( !pi->result()->isOnline() && ti->result()->isOnline() )
if ( !item->result()->isOnline() && ti->result()->isOnline() )
return false;
if ( !pi->result()->collection()->source()->isLocal() && ti->result()->collection()->source()->isLocal() )
if ( !item->result()->collection()->source()->isLocal() && ti->result()->collection()->source()->isLocal() )
return false;
}
}
@ -229,26 +229,26 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
bool accepted = false;
if ( m_filter.isEmpty() )
accepted = true;
else if ( !pi->artist().isNull() )
accepted = m_artistsFilter.contains( pi->artist() );
else if ( !pi->album().isNull() )
accepted = m_albumsFilter.contains( pi->album()->id() );
else if ( !item->artist().isNull() )
accepted = m_artistsFilter.contains( item->artist() );
else if ( !item->album().isNull() )
accepted = m_albumsFilter.contains( item->album()->id() );
if ( !accepted )
{
QStringList sl = m_filter.split( " ", QString::SkipEmptyParts );
foreach( const QString& s, sl )
{
if ( !pi->name().contains( s, Qt::CaseInsensitive ) &&
!pi->albumName().contains( s, Qt::CaseInsensitive ) &&
!pi->artistName().contains( s, Qt::CaseInsensitive ) )
if ( !item->name().contains( s, Qt::CaseInsensitive ) &&
!item->albumName().contains( s, Qt::CaseInsensitive ) &&
!item->artistName().contains( s, Qt::CaseInsensitive ) )
{
return false;
}
}
}
m_cache.insertMulti( sourceParent, pi->result() );
m_cache.insertMulti( sourceParent, item->result() );
return true;
}
@ -264,22 +264,30 @@ 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();
if ( albumpos1 != albumpos2 )
return albumpos1 < albumpos2;
if ( lefts == rights )
return (qint64)&p1 < (qint64)&p2;
}
if ( lefts == rights )
return (qint64)&p1 < (qint64)&p2;
return QString::localeAwareCompare( lefts, rights ) < 0;
}
@ -334,11 +342,14 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly )
return Tomahawk::result_ptr();
if ( m_shuffled )
{
idx = index( qrand() % rowCount( idx.parent() ), 0, idx.parent() );
else if ( m_repeatMode == PlaylistInterface::RepeatOne )
idx = index( idx.row(), 0, idx.parent() );
}
else
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
{
if ( m_repeatMode != PlaylistInterface::RepeatOne )
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll )
{
@ -355,11 +366,8 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly )
}
// Try to find the next available PlaylistItem (with results)
if ( idx.isValid() ) do
while ( idx.isValid() )
{
if ( !idx.isValid() )
break;
TreeModelItem* item = itemFromIndex( mapToSource( idx ) );
if ( item && !item->result().isNull() && item->result()->isOnline() )
{
@ -368,8 +376,9 @@ TreeProxyModel::siblingItem( int itemsAway, bool readOnly )
setCurrentIndex( idx );
return item->result();
}
idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() );
}
while ( idx.isValid() );
if ( !readOnly )
setCurrentIndex( QModelIndex() );

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;