1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-21 05:11:44 +02:00

Implement track count for ScriptCollections.

This commit is contained in:
Teo Mrnjavac
2013-02-25 22:28:46 +01:00
parent d046077656
commit 232c66736a
8 changed files with 72 additions and 12 deletions

View File

@@ -108,6 +108,13 @@ source_ptr& Collection::source() const
}
int
Collection::trackCount() const
{
return -1;
}
void
Collection::addPlaylist( const Tomahawk::playlist_ptr& p )
{

View File

@@ -98,6 +98,8 @@ public:
const source_ptr& source() const;
unsigned int lastmodified() const { return m_lastmodified; }
virtual int trackCount() const;
signals:
void tracksAdded( const QList<unsigned int>& fileids );
void tracksRemoved( const QList<unsigned int>& fileids );

View File

@@ -177,6 +177,13 @@ DatabaseCollection::requestTracks( const Tomahawk::album_ptr& album )
}
int
DatabaseCollection::trackCount() const
{
return source()->trackCount();
}
void
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
{

View File

@@ -54,6 +54,8 @@ public:
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
virtual int trackCount() const;
public slots:
virtual void addTracks( const QList<QVariant>& newitems );
virtual void removeTracks( const QDir& dir );

View File

@@ -914,6 +914,15 @@ QtScriptResolver::loadCollections()
// at this point we assume that all the tracks browsable through a resolver belong to the local source
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this );
sc->setDescription( desc );
if ( collectionInfo.contains( "trackcount" ) ) //a resolver might not expose this
{
bool ok = false;
int trackCount = collectionInfo.value( "trackcount" ).toInt( &ok );
if ( ok )
sc->setTrackCount( trackCount );
}
Tomahawk::collection_ptr collection( sc );
m_collections.insert( collection->name(), collection );

View File

@@ -37,6 +37,7 @@ ScriptCollection::ScriptCollection( const source_ptr& source,
ExternalResolver* resolver,
QObject* parent )
: Collection( source, QString( "scriptcollection:" + resolver->name() + ":" + uuid() ), parent )
, m_trackCount( -1 ) //null value
{
Q_ASSERT( resolver != 0 );
qDebug() << Q_FUNC_INFO << resolver->name() << name();
@@ -155,3 +156,17 @@ ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
return cmd;
}
void
ScriptCollection::setTrackCount( int count )
{
m_trackCount = count;
}
int
ScriptCollection::trackCount() const
{
return m_trackCount;
}

View File

@@ -57,9 +57,13 @@ public:
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
virtual void setTrackCount( int count );
virtual int trackCount() const;
private:
ExternalResolver* m_resolver;
QString m_description;
int m_trackCount;
};
} //ns

View File

@@ -204,6 +204,12 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
if ( !scItem->collection().isNull() )
{
int trackCount = scItem->collection()->trackCount();
if ( trackCount >= 0 )
{
tracks = QString::number( trackCount );
figWidth = QFontMetrics( figFont ).width( tracks );
}
name = scItem->collection()->itemName();
}
@@ -311,6 +317,7 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
painter->setPen( descColor );
painter->drawText( textRect, text, to );
bool shouldPaintTrackCount = false;
if ( type == SourcesModel::Collection )
{
SourceItem* colItem = qobject_cast< SourceItem* >( item );
@@ -321,23 +328,30 @@ SourceDelegate::paintCollection( QPainter* painter, const QStyleOptionViewItem&
m_trackRects[ index ] = textRect.adjusted( 0, 0, -textRect.width() + painter->fontMetrics().width( text ), 0 );
else
m_trackRects.remove( index );
if ( status && !tracks.isEmpty() )
shouldPaintTrackCount = true;
}
else if ( type == SourcesModel::ScriptCollection )
{
if ( !tracks.isEmpty() )
shouldPaintTrackCount = true;
}
if ( status )
{
painter->setRenderHint( QPainter::Antialiasing );
if ( shouldPaintTrackCount )
{
painter->setRenderHint( QPainter::Antialiasing );
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 13, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
int hd = ( option.rect.height() - figRect.height() ) / 2;
figRect.adjust( 0, hd, 0, hd );
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 13, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
int hd = ( option.rect.height() - figRect.height() ) / 2;
figRect.adjust( 0, hd, 0, hd );
painter->setFont( figFont );
painter->setFont( figFont );
QColor figColor( 167, 183, 211 );
painter->setPen( figColor );
painter->setBrush( figColor );
QColor figColor( 167, 183, 211 );
painter->setPen( figColor );
painter->setBrush( figColor );
TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, figRect );
}
TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, figRect );
}
painter->restore();