From 13a3178f709b6bf742d58cd870ef3e70f05f15a4 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 16 Jun 2014 14:48:44 +0200 Subject: [PATCH] * Added SourceTreeView::renamePlaylist( playlist_ptr ). --- src/tomahawk/sourcetree/SourceTreeView.cpp | 51 +++++++++++++++++----- src/tomahawk/sourcetree/SourceTreeView.h | 1 + 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/tomahawk/sourcetree/SourceTreeView.cpp b/src/tomahawk/sourcetree/SourceTreeView.cpp index 28f136fb2..f0ec96d6a 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.cpp +++ b/src/tomahawk/sourcetree/SourceTreeView.cpp @@ -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 ); diff --git a/src/tomahawk/sourcetree/SourceTreeView.h b/src/tomahawk/sourcetree/SourceTreeView.h index d08454f8d..882a80df2 100644 --- a/src/tomahawk/sourcetree/SourceTreeView.h +++ b/src/tomahawk/sourcetree/SourceTreeView.h @@ -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 );