1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-05 21:57:41 +02:00

Added support for showing multiple collections in a SourceItem.

This commit is contained in:
Teo Mrnjavac
2013-01-22 16:08:38 +01:00
parent 3500195708
commit 32780f79a0
8 changed files with 90 additions and 19 deletions

View File

@@ -56,6 +56,13 @@ Collection::name() const
} }
QString
Collection::prettyName() const
{
return tr( "Collection" );
}
const const
source_ptr& Collection::source() const source_ptr& Collection::source() const
{ {

View File

@@ -48,6 +48,7 @@ public:
virtual ~Collection(); virtual ~Collection();
virtual QString name() const; virtual QString name() const;
virtual QString prettyName() const;
virtual QString type() const { return QString(); } virtual QString type() const { return QString(); }
virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; }

View File

@@ -210,7 +210,7 @@ Source::setDbFriendlyName( const QString& dbFriendlyName )
void void
Source::addCollection( const collection_ptr& c ) 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 ); m_collections.append( c );
emit collectionAdded( c ); emit collectionAdded( c );
} }
@@ -219,7 +219,7 @@ Source::addCollection( const collection_ptr& c )
void void
Source::removeCollection( const collection_ptr& c ) 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 ); m_collections.removeAll( c );
emit collectionRemoved( c ); emit collectionRemoved( c );
} }

View File

@@ -78,6 +78,7 @@ public:
#endif #endif
collection_ptr dbCollection() const; collection_ptr dbCollection() const;
QList< Tomahawk::collection_ptr > collections() const { return m_collections; }
void addCollection( const Tomahawk::collection_ptr& c ); void addCollection( const Tomahawk::collection_ptr& c );
void removeCollection( const Tomahawk::collection_ptr& c ); void removeCollection( const Tomahawk::collection_ptr& c );
@@ -105,8 +106,8 @@ signals:
void online(); void online();
void offline(); void offline();
void collectionAdded( const collection_ptr& collection ); void collectionAdded( const Tomahawk::collection_ptr& collection );
void collectionRemoved( const collection_ptr& collection ); void collectionRemoved( const Tomahawk::collection_ptr& collection );
void stats( const QVariantMap& ); void stats( const QVariantMap& );

View File

@@ -40,3 +40,10 @@ ScriptCollection::~ScriptCollection()
{ {
} }
QString
ScriptCollection::prettyName() const
{
return QString();
}

View File

@@ -40,6 +40,7 @@ public:
QObject* parent = 0 ); QObject* parent = 0 );
virtual ~ScriptCollection(); virtual ~ScriptCollection();
virtual QString prettyName() const;
virtual QString type() const { return "scriptcollection"; } virtual QString type() const { return "scriptcollection"; }
private: private:

View File

@@ -52,7 +52,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
, m_latchedOn( false ) , m_latchedOn( false )
, m_sourceInfoItem( 0 ) , m_sourceInfoItem( 0 )
, m_coolPlaylistsItem( 0 ) , m_coolPlaylistsItem( 0 )
, m_collectionPage( 0 )
, m_sourceInfoPage( 0 ) , m_sourceInfoPage( 0 )
, m_coolPlaylistsPage( 0 ) , m_coolPlaylistsPage( 0 )
, m_latestAdditionsPage( 0 ) , m_latestAdditionsPage( 0 )
@@ -64,9 +63,15 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
return; return;
} }
m_collectionItem = new GenericPageItem( model(), this, tr( "Collection" ), ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon connect( source.data(), SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ),
boost::bind( &SourceItem::collectionClicked, this ), SLOT( onCollectionAdded( Tomahawk::collection_ptr ) ) );
boost::bind( &SourceItem::getCollectionPage, this ) ); 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" ), /* m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon( RESPATH "images/new-additions.png" ),
boost::bind( &SourceItem::sourceInfoClicked, this ), boost::bind( &SourceItem::sourceInfoClicked, this ),
@@ -82,7 +87,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw
new LovedTracksItem( model(), this ); new LovedTracksItem( model(), this );
m_collectionItem->setSortValue( -350 );
// m_sourceInfoItem->setSortValue( -300 ); // m_sourceInfoItem->setSortValue( -300 );
m_latestAdditionsItem->setSortValue( -250 ); m_latestAdditionsItem->setSortValue( -250 );
m_recentPlaysItem->setSortValue( -200 ); 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( stateChanged() ), SIGNAL( updated() ) );
connect( source.data(), SIGNAL( offline() ), SIGNAL( updated() ) ); connect( source.data(), SIGNAL( offline() ), SIGNAL( updated() ) );
connect( source.data(), SIGNAL( online() ), 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( 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 ) ) ); 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 void
SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists ) 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 > template< typename T >
void void
SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p ) SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
@@ -498,20 +546,20 @@ SourceItem::getSourceInfoPage() const
ViewPage* ViewPage*
SourceItem::collectionClicked() SourceItem::collectionClicked( const Tomahawk::collection_ptr& collection )
{ {
if ( m_source.isNull() ) if ( m_source.isNull() )
return 0; return 0;
m_collectionPage = ViewManager::instance()->show( m_source->dbCollection() ); m_collectionPages[ collection ] = ViewManager::instance()->show( collection );
return m_collectionPage; return m_collectionPages[ collection ];
} }
ViewPage* ViewPage*
SourceItem::getCollectionPage() const SourceItem::getCollectionPage( const Tomahawk::collection_ptr& collection ) const
{ {
return m_collectionPage;; return m_collectionPages[ collection ];
} }

View File

@@ -1,6 +1,7 @@
/* /*
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.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 * 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 * 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 latchedOff( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& );
void latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode ); 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(); void requestExpanding();
Tomahawk::ViewPage* sourceInfoClicked(); Tomahawk::ViewPage* sourceInfoClicked();
Tomahawk::ViewPage* getSourceInfoPage() const; Tomahawk::ViewPage* getSourceInfoPage() const;
Tomahawk::ViewPage* collectionClicked(); Tomahawk::ViewPage* collectionClicked( const Tomahawk::collection_ptr& collection );
Tomahawk::ViewPage* getCollectionPage() const; Tomahawk::ViewPage* getCollectionPage( const Tomahawk::collection_ptr& collection ) const;
Tomahawk::ViewPage* coolPlaylistsClicked(); Tomahawk::ViewPage* coolPlaylistsClicked();
Tomahawk::ViewPage* getCoolPlaylistsPage() const; Tomahawk::ViewPage* getCoolPlaylistsPage() const;
@@ -90,6 +94,7 @@ private:
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists ); void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
template< typename T > template< typename T >
void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists ); void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists );
void performAddCollectionItem( const Tomahawk::collection_ptr& collection );
Tomahawk::source_ptr m_source; Tomahawk::source_ptr m_source;
CategoryItem* m_playlists; CategoryItem* m_playlists;
@@ -98,13 +103,14 @@ private:
bool m_latchedOn; bool m_latchedOn;
Tomahawk::source_ptr m_latchedOnTo; 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_sourceInfoItem;
GenericPageItem* m_coolPlaylistsItem; GenericPageItem* m_coolPlaylistsItem;
GenericPageItem* m_latestAdditionsItem; GenericPageItem* m_latestAdditionsItem;
GenericPageItem* m_recentPlaysItem; GenericPageItem* m_recentPlaysItem;
Tomahawk::ViewPage* m_collectionPage;
Tomahawk::ViewPage* m_sourceInfoPage; Tomahawk::ViewPage* m_sourceInfoPage;
Tomahawk::ViewPage* m_coolPlaylistsPage; Tomahawk::ViewPage* m_coolPlaylistsPage;
Tomahawk::ViewPage* m_latestAdditionsPage; Tomahawk::ViewPage* m_latestAdditionsPage;