1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 23:26:40 +02:00

Add a new source item for temporary pages.

This fixes TWK-182. Also, ensure that what is selected on the left is always
in sync with what is on the right. In addition, expand the parent nodes when selecting
an item automatically in the tree.
This commit is contained in:
Leo Franchi
2011-05-29 16:56:25 -04:00
parent f2952f783e
commit 07cb94b1bc
17 changed files with 125 additions and 27 deletions

View File

@@ -64,7 +64,10 @@ DynamicModel::loadPlaylist( const Tomahawk::dynplaylist_ptr& playlist, bool load
QString
DynamicModel::description() const
{
if( !m_playlist.isNull() && !m_playlist->generator().isNull() )
return m_playlist->generator()->sentenceSummary();
else
return QString();
}

View File

@@ -34,6 +34,7 @@ using namespace Tomahawk;
PlaylistModel::PlaylistModel( QObject* parent )
: TrackModel( parent )
, m_waitForUpdate( false )
, m_isTemporary( false )
{
qDebug() << Q_FUNC_INFO;
@@ -91,6 +92,7 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn
setTitle( playlist->title() );
setDescription( tr( "A playlist by %1" ).arg( playlist->author()->isLocal() ? tr( "you" ) : playlist->author()->friendlyName() ) );
m_isTemporary = false;
if ( !loadEntries )
return;
@@ -192,6 +194,12 @@ PlaylistModel::append( const Tomahawk::album_ptr& album )
connect( album.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
if( rowCount( QModelIndex() ) == 0 ) {
setTitle( album->name() );
setDescription( tr( "All tracks by %1 on album %2" ).arg( album->artist()->name() ).arg( album->name() ) );
m_isTemporary = true;
}
onTracksAdded( album->tracks() );
}
@@ -205,6 +213,12 @@ PlaylistModel::append( const Tomahawk::artist_ptr& artist )
connect( artist.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
if( rowCount( QModelIndex() ) == 0 ) {
setTitle( artist->name() );
setDescription( tr( "All tracks by %1" ).arg( artist->name() ) );
m_isTemporary = true;
}
onTracksAdded( artist->tracks() );
}
@@ -494,3 +508,9 @@ PlaylistModel::removeIndex( const QModelIndex& index, bool moreToCome )
onPlaylistChanged();
}
}
bool
PlaylistModel::isTemporary() const
{
return m_isTemporary;
}

View File

@@ -67,6 +67,7 @@ public:
void remove( unsigned int row, bool moreToCome = false );
virtual void removeIndex( const QModelIndex& index, bool moreToCome = false );
bool isTemporary() const;
signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled );
@@ -90,7 +91,7 @@ private:
QList<Tomahawk::plentry_ptr> playlistEntries() const;
Tomahawk::playlist_ptr m_playlist;
bool m_waitForUpdate;
bool m_waitForUpdate, m_isTemporary;
QList< Tomahawk::Query* > m_waitingForResolved;
};

View File

@@ -71,8 +71,12 @@ PlaylistView::setPlaylistModel( PlaylistModel* model )
if ( !m_model->playlist().isNull() )
setGuid( QString( "playlistview/%1" ).arg( m_model->playlist()->guid() ) );
else
{
setGuid( "playlistview" );
m_model->title();
m_model->description();
}
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
connect( m_model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
connect( m_model, SIGNAL( playlistChanged() ), SLOT( onChanged() ) );
@@ -191,3 +195,13 @@ PlaylistView::onChanged()
ViewManager::instance()->currentPage() == this )
emit nameChanged( m_model->playlist()->title() );
}
bool
PlaylistView::isTemporaryPage() const
{
if ( m_model ) {
return m_model->isTemporary();
} else {
return false;
}
}

View File

@@ -52,6 +52,7 @@ public:
virtual QPixmap pixmap() const { return QPixmap( RESPATH "images/playlist-icon.png" ); }
virtual bool jumpToCurrentTrack();
virtual bool isTemporaryPage() const;
signals:
void nameChanged( const QString& title );
@@ -75,6 +76,8 @@ private:
PlaylistModel* m_model;
QMenu m_itemMenu;
QString m_customTitle;
QString m_customDescripton;
QAction* m_playItemAction;
QAction* m_addItemsToQueueAction;

View File

@@ -599,24 +599,12 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
setHistoryPosition( m_pageHistory.count() - 1 );
}
if ( !playlistForInterface( currentPlaylistInterface() ).isNull() )
emit playlistActivated( playlistForInterface( currentPlaylistInterface() ) );
else if ( dynamicPlaylistForInterface( currentPlaylistInterface() ) )
emit dynamicPlaylistActivated( dynamicPlaylistForInterface( currentPlaylistInterface() ) );
else if ( collectionForInterface( currentPlaylistInterface() ) )
emit collectionActivated( collectionForInterface( currentPlaylistInterface() ) );
else if ( isSuperCollectionVisible() )
emit superCollectionActivated();
else if( isNewPlaylistPageVisible() )
emit newPlaylistActivated();
/* TODO refactor. now we have rows in the sourcetreeview that are connected to pages, e.g. Stations, Recently Updated, etc
else if ( !currentPlaylistInterface() )
emit tempPageActivated();*/
qDebug() << "View page shown:" << page->title();
emit viewPageActivated( page );
if( page->isTemporaryPage() )
emit tempPageActivated( page );
if ( !AudioEngine::instance()->playlist() )
AudioEngine::instance()->setPlaylist( currentPlaylistInterface() );

View File

@@ -111,13 +111,7 @@ signals:
void historyBackAvailable( bool avail );
void historyForwardAvailable( bool avail );
void tempPageActivated();
void superCollectionActivated();
void collectionActivated( const Tomahawk::collection_ptr& collection );
void playlistActivated( const Tomahawk::playlist_ptr& playlist );
void dynamicPlaylistActivated( const Tomahawk::dynplaylist_ptr& playlist );
void newPlaylistActivated();
void tempPageActivated( Tomahawk::ViewPage* );
void viewPageActivated( Tomahawk::ViewPage* );
public slots:

View File

@@ -51,7 +51,10 @@ public:
virtual bool jumpToCurrentTrack() = 0;
virtual bool isTemporaryPage() const { return false; }
/** subclasses implementing ViewPage can emit the following signals:
* nameChanged( const QString& )
* descriptionChanged( const QString& )
* destroyed( QWidget* widget );
*

View File

@@ -21,6 +21,7 @@
#include "playlistitems.h"
#include "viewmanager.h"
#include "playlist.h"
#include "genericpageitems.h"
/// CollectionItem
@@ -31,8 +32,12 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
, m_source( source )
, m_playlists( 0 )
, m_stations( 0 )
, m_tempItem( 0 )
, m_curTempPage( 0 )
{
if( m_source.isNull() ) { // super collection
connect( ViewManager::instance(), SIGNAL( tempPageActivated( Tomahawk::ViewPage*) ), this, SLOT( tempPageActivated( Tomahawk::ViewPage* ) ) );
return;
}
// create category items if there are playlists to show, or stations to show
@@ -264,3 +269,40 @@ CollectionItem::onStationsDeleted( const QList< dynplaylist_ptr >& stations )
{
playlistsDeletedInternal( m_stations, stations );
}
void
CollectionItem::tempPageActivated( Tomahawk::ViewPage* v )
{
QString name = v->title();
m_curTempPage = v;
if( !m_tempItem ) {
emit beginRowsAdded( children().count(), children().count() );
m_tempItem = new GenericPageItem( model(), this, name, QIcon( RESPATH "images/playlist-icon.png" ),
boost::bind( &CollectionItem::tempItemClicked, this ),
boost::bind( &CollectionItem::getTempPage, this )
);
emit endRowsAdded();
} else {
m_tempItem->setText( name );
}
model()->linkSourceItemToPage( m_tempItem, v );
emit selectRequest( m_tempItem );
}
ViewPage*
CollectionItem::tempItemClicked()
{
if( m_curTempPage ) {
// show the last temporary page the user displayed
return ViewManager::instance()->show( m_curTempPage );
}
return 0;
}
ViewPage*
CollectionItem::getTempPage() const
{
return m_curTempPage;
}

View File

@@ -19,7 +19,11 @@
#include "sourcetreeitem.h"
class GenericPageItem;
class CategoryItem;
namespace Tomahawk {
class ViewPage;
}
class CollectionItem : public SourceTreeItem
{
@@ -38,6 +42,7 @@ public:
CategoryItem* playlistsCategory() const { return m_playlists; }
void setStationsCategory( CategoryItem* item ) { m_stations = item; }
void setPlaylistsCategory( CategoryItem* item ) { m_playlists = item; }
private slots:
void onPlaylistsAdded( const QList<Tomahawk::playlist_ptr>& playlists );
void onPlaylistsDeleted( const QList<Tomahawk::playlist_ptr>& playlists );
@@ -46,6 +51,10 @@ private slots:
void onStationsAdded( const QList<Tomahawk::dynplaylist_ptr>& stations );
void onStationsDeleted( const QList<Tomahawk::dynplaylist_ptr>& stations );
void tempPageActivated( Tomahawk::ViewPage* );
Tomahawk::ViewPage* tempItemClicked();
Tomahawk::ViewPage* getTempPage() const;
private:
void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists );
template< typename T >
@@ -54,6 +63,9 @@ private:
Tomahawk::source_ptr m_source;
CategoryItem* m_playlists;
CategoryItem* m_stations;
GenericPageItem* m_tempItem;
Tomahawk::ViewPage* m_curTempPage;
};

View File

@@ -63,3 +63,10 @@ GenericPageItem::willAcceptDrag(const QMimeData* data) const
{
return false;
}
void
GenericPageItem::setText( const QString &text )
{
m_text = text;
emit updated();
}

View File

@@ -36,6 +36,7 @@ public:
virtual bool willAcceptDrag( const QMimeData* data ) const;
virtual QIcon icon() const;
void setText( const QString& text );
signals:
void activated();

View File

@@ -30,7 +30,7 @@ SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, Sou
connect( this, SIGNAL( childRowsAdded() ), m_model, SLOT( onItemRowsAddedDone() ) );
connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) );
connect( this, SIGNAL( updated() ), m_model, SLOT( itemUpdated() ) );
connect( this, SIGNAL( selectRequest( SourceTreeItem* ) ), m_model, SLOT( itemSelectRequest( SourceTreeItem* ) ) );
if( !m_parent )
return;

View File

@@ -62,6 +62,7 @@ public:
signals:
void updated();
void selectRequest( SourceTreeItem* );
void beginChildRowsAdded( int fromRow, int toRow );
void childRowsAdded();

View File

@@ -448,3 +448,9 @@ SourcesModel::rowForItem( SourceTreeItem* item ) const
{
return item->parent()->children().indexOf( item );
}
void
SourcesModel::itemSelectRequest( SourceTreeItem* item )
{
emit selectRequest( indexFromItem( item ) );
}

View File

@@ -101,6 +101,7 @@ public slots:
void viewPageActivated( Tomahawk::ViewPage* );
void itemSelectRequest( SourceTreeItem* item );
signals:
void selectRequest( const QModelIndex& idx );

View File

@@ -199,8 +199,10 @@ void
SourceTreeView::selectRequest( const QModelIndex& idx )
{
if ( !selectionModel()->selectedIndexes().contains( idx ) )
{
scrollTo( idx, QTreeView::EnsureVisible );
selectionModel()->select( idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current );
}
}