diff --git a/src/sourcetree/SourceTreeView.cpp b/src/sourcetree/SourceTreeView.cpp index 6316407e3..b56185cc1 100644 --- a/src/sourcetree/SourceTreeView.cpp +++ b/src/sourcetree/SourceTreeView.cpp @@ -190,6 +190,13 @@ SourceTreeView::setupMenus() m_playlistMenu.addSeparator(); QAction *copyPlaylistAction = m_playlistMenu.addAction( tr( "&Copy Link" ) ); + + if ( type == SourcesModel::StaticPlaylist ) + { + QAction* exportPlaylist = m_playlistMenu.addAction( tr( "&Export Playlist") ); + connect( exportPlaylist, SIGNAL( triggered() ), this, SLOT( exportPlaylist() ) ); + } + QAction *deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete %1" ).arg( SourcesModel::rowTypeToString( type ) ) ); QString addToText; @@ -227,9 +234,6 @@ SourceTreeView::setupMenus() } } - if ( type == SourcesModel::StaticPlaylist ) - copyPlaylistAction->setText( tr( "&Copy Playlist Link" ) ); - connect( loadPlaylistAction, SIGNAL( triggered() ), SLOT( loadPlaylist() ) ); connect( renamePlaylistAction, SIGNAL( triggered() ), SLOT( renamePlaylist() ) ); connect( deletePlaylistAction, SIGNAL( triggered() ), SLOT( deletePlaylist() ) ); @@ -398,23 +402,37 @@ SourceTreeView::copyPlaylistLink() } else if ( type == SourcesModel::StaticPlaylist ) { - // Disable toma.hk playlist mode until ready - PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); - playlist_ptr playlist = item->playlist(); - GlobalActionManager::instance()->getShortLink( playlist ); -/* - PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); - playlist_ptr playlist = item->playlist(); + const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); + const playlist_ptr playlist = item->playlist(); - QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title(); - QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ), - suggestedFilename, tr( "Playlists (*.xspf)" ) ); - if ( !filename.isEmpty() ) - { - QFileInfo playlistAbsoluteFilePath = filename; - TomahawkSettings::instance()->setPlaylistDefaultPath( playlistAbsoluteFilePath.absolutePath() ); - GlobalActionManager::instance()->savePlaylistToFile( playlist, filename ); - } */ + GlobalActionManager::instance()->getShortLink( playlist ); + } +} + + +void +SourceTreeView::exportPlaylist() +{ + const QModelIndex idx = m_contextMenuIndex; + if ( !idx.isValid() ) + return; + + const SourcesModel::RowType type = ( SourcesModel::RowType )model()->data( m_contextMenuIndex, SourcesModel::SourceTreeItemTypeRole ).toInt(); + Q_ASSERT( type == SourcesModel::StaticPlaylist ); + if ( type != SourcesModel::StaticPlaylist ) + return; + + const PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); + const playlist_ptr playlist = item->playlist(); + + const QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title(); + const QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ), + suggestedFilename, tr( "Playlists (*.xspf)" ) ); + if ( !filename.isEmpty() ) + { + const QFileInfo playlistAbsoluteFilePath( filename ); + TomahawkSettings::instance()->setPlaylistDefaultPath( playlistAbsoluteFilePath.absolutePath() ); + GlobalActionManager::instance()->savePlaylistToFile( playlist, filename ); } } diff --git a/src/sourcetree/SourceTreeView.h b/src/sourcetree/SourceTreeView.h index 388649d3c..775ecb62b 100644 --- a/src/sourcetree/SourceTreeView.h +++ b/src/sourcetree/SourceTreeView.h @@ -72,6 +72,7 @@ private slots: void loadPlaylist(); void deletePlaylist( const QModelIndex& = QModelIndex() ); void copyPlaylistLink(); + void exportPlaylist(); void addToLocal(); void latchOnOrCatchUp();