1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Find playlist/dynplaylist item to activate if opened from non-sidebar. TWK-300. Ugh.

This commit is contained in:
Leo Franchi 2011-08-08 23:23:52 -04:00
parent fc43a6a851
commit 339710c86a
5 changed files with 64 additions and 1 deletions

View File

@ -63,6 +63,7 @@ public:
virtual ~DynamicWidget();
void loadDynamicPlaylist( const dynplaylist_ptr& playlist );
dynplaylist_ptr playlist() { return m_playlist; }
virtual PlaylistInterface* playlistInterface() const;

View File

@ -180,6 +180,20 @@ PlaylistItem::setData( const QVariant& v, bool role )
return false;
}
bool
PlaylistItem::activateCurrent()
{
if( ViewManager::instance()->pageForPlaylist( m_playlist ) == ViewManager::instance()->currentPage() )
{
model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() );
emit selectRequest( this );
return true;
}
return false;
}
DynamicPlaylistItem::DynamicPlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const dynplaylist_ptr& pl, int index )
: PlaylistItem( mdl, parent, pl.staticCast< Playlist >(), index )
@ -312,3 +326,18 @@ DynamicPlaylistItem::icon() const
return QIcon( RESPATH "images/automatic-playlist.png" );
}
}
bool
DynamicPlaylistItem::activateCurrent()
{
if( ViewManager::instance()->pageForDynPlaylist( m_dynplaylist ) == ViewManager::instance()->currentPage() )
{
model()->linkSourceItemToPage( this, ViewManager::instance()->currentPage() );
emit selectRequest( this );
return true;
}
return false;
}

View File

@ -37,6 +37,8 @@ public:
virtual bool setData(const QVariant& v, bool role);
virtual int peerSortValue() const;
virtual bool activateCurrent();
protected:
void setLoaded( bool loaded );
@ -65,6 +67,7 @@ public:
virtual int peerSortValue() const;
virtual QIcon icon() const;
virtual bool activateCurrent();
private slots:
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );

View File

@ -33,6 +33,7 @@
#include "utils/logger.h"
#include "globalactionmanager.h"
#include "items/playlistitems.h"
using namespace Tomahawk;
@ -281,10 +282,38 @@ SourcesModel::viewPageActivated( Tomahawk::ViewPage* page )
}
else
{
m_viewPageDelayedCacheItem = page;
// HACK
// try to find it if it is a playlist. not pretty at all.... but this happens when ViewManager loads a playlist or dynplaylist NOT from the sidebar but from somewhere else
// we don't know which sourcetreeitem is related to it, so we have to find it. we also don't know if this page is a playlist or dynplaylist or not, but we can't check as we can't
// include DynamicWidget.h here (so can't dynamic_cast).
// this could also be fixed by keeping a master list of playlists/sourcetreeitems... but that's even uglier i think. this is only called the first time a certain viewpage is clicked from external
// sources.
if( activatePlaylistPage( page, m_rootItem ) )
m_viewPageDelayedCacheItem = page;
}
}
bool
SourcesModel::activatePlaylistPage( ViewPage* p, SourceTreeItem* i )
{
if( !i )
return false;
qDebug() << "Doing an activation check on:" << p << i;
if( qobject_cast< PlaylistItem* >( i ) &&
qobject_cast< PlaylistItem* >( i )->activateCurrent() )
return true;
bool ret = false;
for( int k = 0; k < i->children().size(); k++ )
{
if( activatePlaylistPage( p, i->children().at( k ) ) )
ret = true;
}
return ret;
}
void
SourcesModel::loadSources()

View File

@ -113,6 +113,7 @@ private slots:
private:
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
int rowForItem( SourceTreeItem* item ) const;
bool activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
SourceTreeItem* m_rootItem;