1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Limit to 5 temp pages at once

This commit is contained in:
Leo Franchi 2011-10-21 14:27:06 -04:00
parent 0a686337f8
commit 8bbe15edee
4 changed files with 35 additions and 3 deletions

View File

@ -409,7 +409,8 @@ CollectionItem::requestExpanding()
void
CollectionItem::tempPageActivated( Tomahawk::ViewPage* v )
{
int idx = children().count();
const int idx = children().count();
const int latest = children().last()->IDValue();
foreach ( TemporaryPageItem* page, m_tempItems )
{
@ -420,13 +421,28 @@ CollectionItem::tempPageActivated( Tomahawk::ViewPage* v )
}
}
// Only keep 5 temporary pages at once
while ( m_tempItems.size() > 5 )
{
TemporaryPageItem* item = m_tempItems.takeFirst();
QTimer::singleShot( 0, item, SLOT( removeFromList() ) );
}
emit beginRowsAdded( idx, idx );
TemporaryPageItem* tempPage = new TemporaryPageItem( model(), this, v, idx );
TemporaryPageItem* tempPage = new TemporaryPageItem( model(), this, v, latest + 1 );
connect( tempPage, SIGNAL( removed() ), this, SLOT( temporaryPageDestroyed() ) );
m_tempItems << tempPage;
endRowsAdded();
emit selectRequest( tempPage );
}
void
CollectionItem::temporaryPageDestroyed()
{
TemporaryPageItem* tempPage = qobject_cast< TemporaryPageItem* >( sender() );
Q_ASSERT( tempPage );
m_tempItems.removeAll( tempPage );
}
ViewPage*
CollectionItem::sourceInfoClicked()

View File

@ -65,6 +65,7 @@ private slots:
void requestExpanding();
void tempPageActivated( Tomahawk::ViewPage* );
void temporaryPageDestroyed();
Tomahawk::ViewPage* sourceInfoClicked();
Tomahawk::ViewPage* getSourceInfoPage() const;

View File

@ -55,6 +55,13 @@ TemporaryPageItem::peerSortValue() const
return m_sortValue;
}
int
TemporaryPageItem::IDValue() const
{
return m_sortValue;
}
void
TemporaryPageItem::removeFromList()
{
@ -67,5 +74,7 @@ TemporaryPageItem::removeFromList()
parent()->removeChild( this );
parent()->endRowsRemoved();
emit removed();
deleteLater();
}

View File

@ -33,11 +33,17 @@ public:
virtual QIcon icon() const;
virtual int peerSortValue() const;
virtual int IDValue() const;
void removeFromList();
Tomahawk::ViewPage* page() const { return m_page; }
virtual bool isBeingPlayed() const { return m_page->isBeingPlayed(); }
public slots:
void removeFromList();
signals:
bool removed();
private:
Tomahawk::ViewPage* m_page;
QIcon m_icon;