mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Added support for showing multiple collections in a SourceItem.
This commit is contained in:
parent
3500195708
commit
32780f79a0
@ -56,6 +56,13 @@ Collection::name() const
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
Collection::prettyName() const
|
||||
{
|
||||
return tr( "Collection" );
|
||||
}
|
||||
|
||||
|
||||
const
|
||||
source_ptr& Collection::source() const
|
||||
{
|
||||
|
@ -48,6 +48,7 @@ public:
|
||||
virtual ~Collection();
|
||||
|
||||
virtual QString name() const;
|
||||
virtual QString prettyName() const;
|
||||
virtual QString type() const { return QString(); }
|
||||
|
||||
virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; }
|
||||
|
@ -210,7 +210,7 @@ Source::setDbFriendlyName( const QString& dbFriendlyName )
|
||||
void
|
||||
Source::addCollection( const collection_ptr& c )
|
||||
{
|
||||
Q_ASSERT( m_collections.length() == 0 ); // only 1 source supported atm
|
||||
//Q_ASSERT( m_collections.length() == 0 ); // only 1 source supported atm
|
||||
m_collections.append( c );
|
||||
emit collectionAdded( c );
|
||||
}
|
||||
@ -219,7 +219,7 @@ Source::addCollection( const collection_ptr& c )
|
||||
void
|
||||
Source::removeCollection( const collection_ptr& c )
|
||||
{
|
||||
Q_ASSERT( m_collections.length() == 1 && m_collections.first() == c ); // only 1 source supported atm
|
||||
//Q_ASSERT( m_collections.length() == 1 && m_collections.first() == c ); // only 1 source supported atm
|
||||
m_collections.removeAll( c );
|
||||
emit collectionRemoved( c );
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ public:
|
||||
#endif
|
||||
|
||||
collection_ptr dbCollection() const;
|
||||
QList< Tomahawk::collection_ptr > collections() const { return m_collections; }
|
||||
void addCollection( const Tomahawk::collection_ptr& c );
|
||||
void removeCollection( const Tomahawk::collection_ptr& c );
|
||||
|
||||
@ -105,8 +106,8 @@ signals:
|
||||
void online();
|
||||
void offline();
|
||||
|
||||
void collectionAdded( const collection_ptr& collection );
|
||||
void collectionRemoved( const collection_ptr& collection );
|
||||
void collectionAdded( const Tomahawk::collection_ptr& collection );
|
||||
void collectionRemoved( const Tomahawk::collection_ptr& collection );
|
||||
|
||||
void stats( const QVariantMap& );
|
||||
|
||||
|
@ -40,3 +40,10 @@ ScriptCollection::~ScriptCollection()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
ScriptCollection::prettyName() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public:
|
||||
QObject* parent = 0 );
|
||||
virtual ~ScriptCollection();
|
||||
|
||||
virtual QString prettyName() const;
|
||||
virtual QString type() const { return "scriptcollection"; }
|
||||
|
||||
private:
|
||||
|
@ -52,7 +52,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
|
||||
, m_latchedOn( false )
|
||||
, m_sourceInfoItem( 0 )
|
||||
, m_coolPlaylistsItem( 0 )
|
||||
, m_collectionPage( 0 )
|
||||
, m_sourceInfoPage( 0 )
|
||||
, m_coolPlaylistsPage( 0 )
|
||||
, m_latestAdditionsPage( 0 )
|
||||
@ -64,9 +63,15 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
|
||||
return;
|
||||
}
|
||||
|
||||
m_collectionItem = new GenericPageItem( model(), this, tr( "Collection" ), ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon
|
||||
boost::bind( &SourceItem::collectionClicked, this ),
|
||||
boost::bind( &SourceItem::getCollectionPage, this ) );
|
||||
connect( source.data(), SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ),
|
||||
SLOT( onCollectionAdded( Tomahawk::collection_ptr ) ) );
|
||||
connect( source.data(), SIGNAL( collectionRemoved( Tomahawk::collection_ptr ) ),
|
||||
SLOT( onCollectionRemoved( Tomahawk::collection_ptr ) ) );
|
||||
|
||||
foreach ( const Tomahawk::collection_ptr& collection, source->collections() )
|
||||
{
|
||||
performAddCollectionItem( collection );
|
||||
}
|
||||
|
||||
/* m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon( RESPATH "images/new-additions.png" ),
|
||||
boost::bind( &SourceItem::sourceInfoClicked, this ),
|
||||
@ -82,7 +87,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
|
||||
|
||||
new LovedTracksItem( model(), this );
|
||||
|
||||
m_collectionItem->setSortValue( -350 );
|
||||
// m_sourceInfoItem->setSortValue( -300 );
|
||||
m_latestAdditionsItem->setSortValue( -250 );
|
||||
m_recentPlaysItem->setSortValue( -200 );
|
||||
@ -114,6 +118,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
|
||||
connect( source.data(), SIGNAL( stateChanged() ), SIGNAL( updated() ) );
|
||||
connect( source.data(), SIGNAL( offline() ), SIGNAL( updated() ) );
|
||||
connect( source.data(), SIGNAL( online() ), SIGNAL( updated() ) );
|
||||
|
||||
connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );
|
||||
connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) );
|
||||
|
||||
@ -294,6 +299,30 @@ SourceItem::latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SourceItem::onCollectionAdded( const collection_ptr& collection )
|
||||
{
|
||||
if ( m_collectionItems.contains( collection ) )
|
||||
return;
|
||||
|
||||
beginRowsAdded( model()->rowCount( model()->indexFromItem( this ) ),
|
||||
model()->rowCount( model()->indexFromItem( this ) ) );
|
||||
performAddCollectionItem( collection );
|
||||
endRowsAdded();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SourceItem::onCollectionRemoved( const collection_ptr& collection )
|
||||
{
|
||||
delete m_collectionPages.value( collection, 0 );
|
||||
m_collectionPages.remove( collection );
|
||||
|
||||
m_collectionItems.value( collection )->deleteLater();
|
||||
m_collectionItems.remove( collection );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists )
|
||||
{
|
||||
@ -332,6 +361,25 @@ SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplay
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SourceItem::performAddCollectionItem( const collection_ptr& collection )
|
||||
{
|
||||
GenericPageItem* item = new GenericPageItem( model(),
|
||||
this,
|
||||
collection->prettyName(),
|
||||
ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon
|
||||
boost::bind( &SourceItem::collectionClicked, this, collection ),
|
||||
boost::bind( &SourceItem::getCollectionPage, this, collection ) );
|
||||
|
||||
if ( collection->type() == "databasecollection" )
|
||||
item->setSortValue( -350 );
|
||||
else
|
||||
item->setSortValue( -340 );
|
||||
|
||||
m_collectionItems.insert( collection, item );
|
||||
}
|
||||
|
||||
|
||||
template< typename T >
|
||||
void
|
||||
SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
|
||||
@ -498,20 +546,20 @@ SourceItem::getSourceInfoPage() const
|
||||
|
||||
|
||||
ViewPage*
|
||||
SourceItem::collectionClicked()
|
||||
SourceItem::collectionClicked( const Tomahawk::collection_ptr& collection )
|
||||
{
|
||||
if ( m_source.isNull() )
|
||||
return 0;
|
||||
|
||||
m_collectionPage = ViewManager::instance()->show( m_source->dbCollection() );
|
||||
return m_collectionPage;
|
||||
m_collectionPages[ collection ] = ViewManager::instance()->show( collection );
|
||||
return m_collectionPages[ collection ];
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
SourceItem::getCollectionPage() const
|
||||
{
|
||||
return m_collectionPage;;
|
||||
SourceItem::getCollectionPage( const Tomahawk::collection_ptr& collection ) const
|
||||
{
|
||||
return m_collectionPages[ collection ];
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -69,13 +70,16 @@ private slots:
|
||||
void latchedOff( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& );
|
||||
void latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode );
|
||||
|
||||
void onCollectionAdded( const Tomahawk::collection_ptr& ); //never call from ctor because of begin/endRowsAdded!
|
||||
void onCollectionRemoved( const Tomahawk::collection_ptr& );
|
||||
|
||||
void requestExpanding();
|
||||
|
||||
Tomahawk::ViewPage* sourceInfoClicked();
|
||||
Tomahawk::ViewPage* getSourceInfoPage() const;
|
||||
|
||||
Tomahawk::ViewPage* collectionClicked();
|
||||
Tomahawk::ViewPage* getCollectionPage() const;
|
||||
Tomahawk::ViewPage* collectionClicked( const Tomahawk::collection_ptr& collection );
|
||||
Tomahawk::ViewPage* getCollectionPage( const Tomahawk::collection_ptr& collection ) const;
|
||||
|
||||
Tomahawk::ViewPage* coolPlaylistsClicked();
|
||||
Tomahawk::ViewPage* getCoolPlaylistsPage() const;
|
||||
@ -90,6 +94,7 @@ private:
|
||||
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
|
||||
template< typename T >
|
||||
void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists );
|
||||
void performAddCollectionItem( const Tomahawk::collection_ptr& collection );
|
||||
|
||||
Tomahawk::source_ptr m_source;
|
||||
CategoryItem* m_playlists;
|
||||
@ -98,13 +103,14 @@ private:
|
||||
bool m_latchedOn;
|
||||
Tomahawk::source_ptr m_latchedOnTo;
|
||||
|
||||
GenericPageItem* m_collectionItem;
|
||||
QMap< Tomahawk::collection_ptr, GenericPageItem* > m_collectionItems;
|
||||
QMap< Tomahawk::collection_ptr, Tomahawk::ViewPage* > m_collectionPages;
|
||||
|
||||
GenericPageItem* m_sourceInfoItem;
|
||||
GenericPageItem* m_coolPlaylistsItem;
|
||||
GenericPageItem* m_latestAdditionsItem;
|
||||
GenericPageItem* m_recentPlaysItem;
|
||||
|
||||
Tomahawk::ViewPage* m_collectionPage;
|
||||
Tomahawk::ViewPage* m_sourceInfoPage;
|
||||
Tomahawk::ViewPage* m_coolPlaylistsPage;
|
||||
Tomahawk::ViewPage* m_latestAdditionsPage;
|
||||
|
Loading…
x
Reference in New Issue
Block a user