mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 16:29:43 +01:00
* DRY PlayableItem.
This commit is contained in:
parent
1b748201bc
commit
e426e26e8d
@ -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,27 +104,8 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
|
||||
: QObject( parent )
|
||||
, m_entry( entry )
|
||||
{
|
||||
m_parent = parent;
|
||||
m_fetchingMore = false;
|
||||
m_isPlaying = false;
|
||||
m_query = entry->query();
|
||||
|
||||
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( m_query.data(), SIGNAL( socialActionsLoaded() ),
|
||||
SIGNAL( dataChanged() ) );
|
||||
@ -222,6 +124,35 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableItem::init( PlayableItem* parent, int row )
|
||||
{
|
||||
m_fetchingMore = false;
|
||||
m_isPlaying = false;
|
||||
m_parent = parent;
|
||||
|
||||
if ( parent )
|
||||
{
|
||||
if ( row < 0 )
|
||||
{
|
||||
parent->children.append( this );
|
||||
row = parent->children.count() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
parent->children.insert( row, this );
|
||||
}
|
||||
|
||||
this->model = parent->model;
|
||||
}
|
||||
|
||||
if ( !m_query.isNull() )
|
||||
{
|
||||
onResultsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlayableItem::onResultsChanged()
|
||||
{
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user