mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Find playlist/dynplaylist item to activate if opened from non-sidebar. TWK-300. Ugh.
This commit is contained in:
@@ -63,6 +63,7 @@ public:
|
|||||||
virtual ~DynamicWidget();
|
virtual ~DynamicWidget();
|
||||||
|
|
||||||
void loadDynamicPlaylist( const dynplaylist_ptr& playlist );
|
void loadDynamicPlaylist( const dynplaylist_ptr& playlist );
|
||||||
|
dynplaylist_ptr playlist() { return m_playlist; }
|
||||||
|
|
||||||
virtual PlaylistInterface* playlistInterface() const;
|
virtual PlaylistInterface* playlistInterface() const;
|
||||||
|
|
||||||
|
@@ -180,6 +180,20 @@ PlaylistItem::setData( const QVariant& v, bool role )
|
|||||||
return false;
|
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 )
|
DynamicPlaylistItem::DynamicPlaylistItem( SourcesModel* mdl, SourceTreeItem* parent, const dynplaylist_ptr& pl, int index )
|
||||||
: PlaylistItem( mdl, parent, pl.staticCast< Playlist >(), index )
|
: PlaylistItem( mdl, parent, pl.staticCast< Playlist >(), index )
|
||||||
@@ -312,3 +326,18 @@ DynamicPlaylistItem::icon() const
|
|||||||
return QIcon( RESPATH "images/automatic-playlist.png" );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -37,6 +37,8 @@ public:
|
|||||||
virtual bool setData(const QVariant& v, bool role);
|
virtual bool setData(const QVariant& v, bool role);
|
||||||
virtual int peerSortValue() const;
|
virtual int peerSortValue() const;
|
||||||
|
|
||||||
|
virtual bool activateCurrent();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setLoaded( bool loaded );
|
void setLoaded( bool loaded );
|
||||||
|
|
||||||
@@ -65,6 +67,7 @@ public:
|
|||||||
virtual int peerSortValue() const;
|
virtual int peerSortValue() const;
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
|
|
||||||
|
virtual bool activateCurrent();
|
||||||
private slots:
|
private slots:
|
||||||
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
void onDynamicPlaylistLoaded( Tomahawk::DynamicPlaylistRevision revision );
|
||||||
|
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "globalactionmanager.h"
|
#include "globalactionmanager.h"
|
||||||
|
#include "items/playlistitems.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -281,10 +282,38 @@ SourcesModel::viewPageActivated( Tomahawk::ViewPage* page )
|
|||||||
}
|
}
|
||||||
else
|
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
|
void
|
||||||
SourcesModel::loadSources()
|
SourcesModel::loadSources()
|
||||||
|
@@ -113,6 +113,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
|
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
|
||||||
int rowForItem( SourceTreeItem* item ) const;
|
int rowForItem( SourceTreeItem* item ) const;
|
||||||
|
bool activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
|
||||||
|
|
||||||
SourceTreeItem* m_rootItem;
|
SourceTreeItem* m_rootItem;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user