Skip to content

Commit

Permalink
* DRY PlayableItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed May 21, 2012
1 parent 1b74820 commit e426e26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 105 deletions.
139 changes: 35 additions & 104 deletions src/libtomahawk/playlist/PlayableItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,15 @@ 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 );
}


PlayableItem::PlayableItem( const Tomahawk::album_ptr& album, PlayableItem* parent, int row )
: 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() ) );
}
Expand All @@ -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() ) );
}
Expand All @@ -116,51 +73,15 @@ 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 );
}


PlayableItem::PlayableItem( const Tomahawk::query_ptr& query, PlayableItem* parent, int row )
: 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() ) );
Expand All @@ -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() ) );
Expand All @@ -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()
{
Expand Down
4 changes: 3 additions & 1 deletion src/libtomahawk/playlist/PlayableItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Q_OBJECT
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; }
Expand All @@ -59,7 +60,6 @@ Q_OBJECT

QList<PlayableItem*> children;

int childCount;
QPersistentModelIndex index;
QAbstractItemModel* model;

Expand All @@ -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;
Expand Down

0 comments on commit e426e26

Please sign in to comment.