mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 21:27:58 +02:00
* DRY PlayableItem.
This commit is contained in:
@@ -45,16 +45,7 @@ PlayableItem::~PlayableItem()
|
|||||||
|
|
||||||
PlayableItem::PlayableItem( PlayableItem* parent, QAbstractItemModel* model )
|
PlayableItem::PlayableItem( PlayableItem* parent, QAbstractItemModel* model )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
init( parent );
|
||||||
this->model = model;
|
|
||||||
childCount = 0;
|
|
||||||
m_fetchingMore = false;
|
|
||||||
m_isPlaying = false;
|
|
||||||
|
|
||||||
if ( m_parent )
|
|
||||||
{
|
|
||||||
m_parent->children.append( this );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,24 +53,7 @@ PlayableItem::PlayableItem( const Tomahawk::album_ptr& album, PlayableItem* pare
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_album( album )
|
, m_album( album )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
init( parent, row );
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
connect( album.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
||||||
}
|
}
|
||||||
@@ -89,24 +63,7 @@ PlayableItem::PlayableItem( const Tomahawk::artist_ptr& artist, PlayableItem* pa
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_artist( artist )
|
, m_artist( artist )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
init( parent, row );
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
connect( artist.data(), SIGNAL( updated() ), SIGNAL( dataChanged() ) );
|
||||||
}
|
}
|
||||||
@@ -116,24 +73,7 @@ PlayableItem::PlayableItem( const Tomahawk::result_ptr& result, PlayableItem* pa
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_result( result )
|
, m_result( result )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
init( parent, row );
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,26 +81,7 @@ PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* pare
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_query( query )
|
, m_query( query )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
init( parent, row );
|
||||||
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();
|
|
||||||
|
|
||||||
connect( query.data(), SIGNAL( socialActionsLoaded() ),
|
connect( query.data(), SIGNAL( socialActionsLoaded() ),
|
||||||
SIGNAL( dataChanged() ) );
|
SIGNAL( dataChanged() ) );
|
||||||
@@ -183,27 +104,8 @@ PlayableItem::PlayableItem( const Tomahawk::plentry_ptr& entry, PlayableItem* pa
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
, m_entry( entry )
|
, m_entry( entry )
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
|
||||||
m_fetchingMore = false;
|
|
||||||
m_isPlaying = false;
|
|
||||||
m_query = entry->query();
|
m_query = entry->query();
|
||||||
|
init( parent, row );
|
||||||
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();
|
|
||||||
|
|
||||||
connect( m_query.data(), SIGNAL( socialActionsLoaded() ),
|
connect( m_query.data(), SIGNAL( socialActionsLoaded() ),
|
||||||
SIGNAL( dataChanged() ) );
|
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
|
void
|
||||||
PlayableItem::onResultsChanged()
|
PlayableItem::onResultsChanged()
|
||||||
{
|
{
|
||||||
|
@@ -48,6 +48,7 @@ public:
|
|||||||
const Tomahawk::result_ptr& result() const;
|
const Tomahawk::result_ptr& result() const;
|
||||||
|
|
||||||
PlayableItem* parent() const { return m_parent; }
|
PlayableItem* parent() const { return m_parent; }
|
||||||
|
|
||||||
bool isPlaying() const { return m_isPlaying; }
|
bool isPlaying() const { return m_isPlaying; }
|
||||||
void setIsPlaying( bool b ) { m_isPlaying = b; emit dataChanged(); }
|
void setIsPlaying( bool b ) { m_isPlaying = b; emit dataChanged(); }
|
||||||
bool fetchingMore() const { return m_fetchingMore; }
|
bool fetchingMore() const { return m_fetchingMore; }
|
||||||
@@ -59,7 +60,6 @@ public:
|
|||||||
|
|
||||||
QList<PlayableItem*> children;
|
QList<PlayableItem*> children;
|
||||||
|
|
||||||
int childCount;
|
|
||||||
QPersistentModelIndex index;
|
QPersistentModelIndex index;
|
||||||
QAbstractItemModel* model;
|
QAbstractItemModel* model;
|
||||||
|
|
||||||
@@ -70,6 +70,8 @@ private slots:
|
|||||||
void onResultsChanged();
|
void onResultsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init( PlayableItem* parent, int row = -1 );
|
||||||
|
|
||||||
Tomahawk::artist_ptr m_artist;
|
Tomahawk::artist_ptr m_artist;
|
||||||
Tomahawk::album_ptr m_album;
|
Tomahawk::album_ptr m_album;
|
||||||
Tomahawk::result_ptr m_result;
|
Tomahawk::result_ptr m_result;
|
||||||
|
Reference in New Issue
Block a user