1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02:00

* DRY PlayableItem.

This commit is contained in:
Christian Muehlhaeuser
2012-05-21 12:42:25 +02:00
parent 1b748201bc
commit e426e26e8d
2 changed files with 38 additions and 105 deletions

View File

@@ -45,16 +45,7 @@ PlayableItem::~PlayableItem()
PlayableItem::PlayableItem( PlayableItem* parent, QAbstractItemModel* model )
{
m_parent = parent;
this->model = model;
childCount = 0;
m_fetchingMore = false;
m_isPlaying = false;
if ( m_parent )
{
m_parent->children.append( this );
}
init( parent );
}
@@ -62,24 +53,7 @@ PlayableItem::PlayableItem( const Tomahawk::album_ptr& album, PlayableItem* pare
: QObject( parent )
, m_album( album )
{
m_parent = parent;
m_fetchingMore = false;
m_isPlaying = false;
if ( parent )
{
if ( row < 0 )
{
parent->children.append( this );
row = parent->children.count() - 1;
}
else
{
parent->children.insert( row, this );
}
this->model = parent->model;
}
init( parent, row );
connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
}
@@ -89,24 +63,7 @@ PlayableItem::PlayableItem( const Tomahawk::artist_ptr& artist, PlayableItem* pa
: QObject( parent )
, m_artist( artist )
{
m_parent = parent;
m_fetchingMore = false;
m_isPlaying = false;
if ( parent )
{
if ( row < 0 )
{
parent->children.append( this );
row = parent->children.count() - 1;
}
else
{
parent->children.insert( row, this );
}
this->model = parent->model;
}
init( parent, row );
connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
}
@@ -116,24 +73,7 @@ PlayableItem::PlayableItem( const Tomahawk::result_ptr& result, PlayableItem* pa
: QObject( parent )
, m_result( result )
{
m_parent = parent;
m_fetchingMore = false;
m_isPlaying = false;
if ( parent )
{
if ( row < 0 )
{
parent->children.append( this );
row = parent->children.count() - 1;
}
else
{
parent->children.insert( row, this );
}
this->model = parent->model;
}
init( parent, row );
}
@@ -141,26 +81,7 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare
: QObject( parent )
, m_query( query )
{
m_parent = parent;
m_fetchingMore = false;
m_isPlaying = false;
if ( parent )
{
if ( row < 0 )
{
parent->children.append( this );
row = parent->children.count() - 1;
}
else
{
parent->children.insert( row, this );
}
this->model = parent->model;
}
onResultsChanged();
init( parent, row );
connect( query.data(), SIGNAL( socialActionsLoaded() ),
SIGNAL( dataChanged() ) );
@@ -183,10 +104,32 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
: QObject( parent )
, m_entry( entry )
{
m_parent = parent;
m_query = entry->query();
init( parent, row );
connect( m_query.data(), SIGNAL( socialActionsLoaded() ),
SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( updated() ),
SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ),
SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ),
SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ),
SLOT( onResultsChanged() ) );
}
void
PlayableItem::init( PlayableItem* parent, int row )
{
m_fetchingMore = false;
m_isPlaying = false;
m_query = entry->query();
m_parent = parent;
if ( parent )
{
@@ -203,22 +146,10 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
this->model = parent->model;
}
if ( !m_query.isNull() )
{
onResultsChanged();
connect( m_query.data(), SIGNAL( socialActionsLoaded() ),
SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( updated() ),
SIGNAL( dataChanged() ) );
connect( m_query.data(), SIGNAL( resultsAdded( QList<Tomahawk::result_ptr> ) ),
SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( resultsRemoved( Tomahawk::result_ptr ) ),
SLOT( onResultsChanged() ) );
connect( m_query.data(), SIGNAL( resultsChanged() ),
SLOT( onResultsChanged() ) );
}
}

View File

@@ -48,6 +48,7 @@ public:
const Tomahawk::result_ptr& result() const;
PlayableItem* parent() const { return m_parent; }
bool isPlaying() const { return m_isPlaying; }
void setIsPlaying( bool b ) { m_isPlaying = b; emit dataChanged(); }
bool fetchingMore() const { return m_fetchingMore; }
@@ -59,7 +60,6 @@ public:
QList<PlayableItem*> children;
int childCount;
QPersistentModelIndex index;
QAbstractItemModel* model;
@@ -70,6 +70,8 @@ private slots:
void onResultsChanged();
private:
void init( PlayableItem* parent, int row = -1 );
Tomahawk::artist_ptr m_artist;
Tomahawk::album_ptr m_album;
Tomahawk::result_ptr m_result;