1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-18 23:09:42 +01:00

* Added SourceTreeView::renamePlaylist( playlist_ptr ).

This commit is contained in:
Christian Muehlhaeuser 2014-06-16 14:48:44 +02:00
parent de77bdb1a6
commit 13a3178f70
2 changed files with 41 additions and 11 deletions

View File

@ -185,7 +185,6 @@ SourceTreeView::setupMenus()
QAction* latchOnAction = ActionCollection::instance()->getAction( "latchOn" );
m_latchMenu.addAction( latchOnAction );
m_privacyMenu.addAction( ActionCollection::instance()->getAction( "togglePrivacy" ) );
if ( type == SourcesModel::Collection )
@ -253,7 +252,7 @@ SourceTreeView::setupMenus()
// Handle any custom actions registered for playlists
if ( type == SourcesModel::StaticPlaylist && !readonly &&
!ActionCollection::instance()->getAction( ActionCollection::LocalPlaylists ).isEmpty() )
!ActionCollection::instance()->getAction( ActionCollection::LocalPlaylists ).isEmpty() )
{
m_playlistMenu.addSeparator();
@ -449,7 +448,6 @@ SourceTreeView::onDeletePlaylistResult( bool result )
const QMap< int, bool > questionResults = m_popupDialog.data()->questionResults();
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( idx, SourcesModel::SourceTreeItemTypeRole ).toInt();
if ( type == SourcesModel::StaticPlaylist )
{
PlaylistItem* item = itemFromIndex< PlaylistItem >( idx );
@ -595,7 +593,6 @@ void
SourceTreeView::latchOff()
{
disconnect( this, SLOT( latchOff() ) );
qDebug() << Q_FUNC_INFO;
if ( !m_contextMenuIndex.isValid() )
return;
@ -630,9 +627,8 @@ SourceTreeView::latchOff( const Tomahawk::source_ptr& source )
void
SourceTreeView::latchModeToggled( bool checked )
{
tDebug() << Q_FUNC_INFO << checked;
disconnect( this, SLOT( latchOff() ) );
qDebug() << Q_FUNC_INFO;
if ( !m_contextMenuIndex.isValid() )
return;
@ -646,6 +642,42 @@ SourceTreeView::latchModeToggled( bool checked )
}
void
SourceTreeView::renamePlaylist( const Tomahawk::playlist_ptr& playlist )
{
//FIXME: this is unbelievably ugly
QModelIndex editIndex;
for ( int i = 0; i < model()->rowCount(); i++ )
{
const QModelIndex topIdx = model()->index( i, 0, QModelIndex() );
for ( int j = 0; j < model()->rowCount( topIdx ); j++ )
{
const QModelIndex colIdx = model()->index( j, 0, QModelIndex( topIdx ) );
for ( int x = 0; x < model()->rowCount( colIdx ); x++ )
{
const QModelIndex grpIdx = model()->index( x, 0, QModelIndex( colIdx ) );
for ( int y = 0; y < model()->rowCount( grpIdx ); y++ )
{
const QModelIndex plIdx = model()->index( y, 0, QModelIndex( grpIdx ) );
SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( plIdx, SourcesModel::SourceTreeItemTypeRole ).toInt();
if ( type == SourcesModel::StaticPlaylist )
{
const PlaylistItem* item = itemFromIndex< PlaylistItem >( plIdx );
if ( item->playlist() == playlist )
{
editIndex = plIdx;
}
}
}
}
}
}
if ( editIndex.isValid() )
edit( editIndex );
}
void
SourceTreeView::renamePlaylist()
{
@ -659,8 +691,6 @@ SourceTreeView::renamePlaylist()
void
SourceTreeView::onCustomContextMenu( const QPoint& pos )
{
qDebug() << Q_FUNC_INFO;
QModelIndex idx = m_contextMenuIndex = indexAt( pos );
if ( !idx.isValid() )
return;
@ -700,7 +730,7 @@ SourceTreeView::onCustomContextMenu( const QPoint& pos )
void
SourceTreeView::dragEnterEvent( QDragEnterEvent* event )
{
qDebug() << Q_FUNC_INFO;
tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
QTreeView::dragEnterEvent( event );
if ( DropJob::acceptsMimeData( event->mimeData(), DropJob::Track | DropJob::Artist | DropJob::Album | DropJob::Playlist, DropJob::Create ) )
@ -820,13 +850,12 @@ SourceTreeView::dropEvent( QDropEvent* event )
Q_ASSERT( item );
item->setDropType( m_delegate->hoveredDropType() );
qDebug() << Q_FUNC_INFO << "dropType is " << m_delegate->hoveredDropType();
tDebug() << Q_FUNC_INFO << "dropType is" << m_delegate->hoveredDropType();
}
// if it's a playlist drop, accept it anywhere in the sourcetree by manually parsing it.
if ( DropJob::isDropType( DropJob::Playlist, event->mimeData() ) )
{
qDebug() << Q_FUNC_INFO << "Current Event";
DropJob* dropThis = new DropJob;
dropThis->setDropTypes( DropJob::Playlist );
dropThis->setDropAction( DropJob::Create );

View File

@ -49,6 +49,7 @@ public:
public slots:
void showOfflineSources( bool offlineSourcesShown );
void renamePlaylist( const Tomahawk::playlist_ptr& playlist );
void renamePlaylist();
void update( const QModelIndex &index );