1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

Export XSPF to file instead of clipboard

This commit is contained in:
Leo Franchi
2011-05-22 19:27:47 -04:00
parent f9442372d9
commit 8dc7bca9dd
3 changed files with 18 additions and 5 deletions

View File

@@ -127,17 +127,27 @@ GlobalActionManager::copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& p
}
void
GlobalActionManager::copyPlaylistToClipboard( const Tomahawk::playlist_ptr& playlist )
GlobalActionManager::savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename )
{
XSPFGenerator* g = new XSPFGenerator( playlist, this );
g->setProperty( "filename", filename );
connect( g, SIGNAL( generated( QByteArray ) ), this, SLOT( xspfCreated( QByteArray ) ) );
}
void
GlobalActionManager::xspfCreated( const QByteArray& xspf )
{
QClipboard* cb = QApplication::clipboard();
cb->setText( xspf );
QString filename = sender()->property( "filename" ).toString();
QFile f( filename );
if( !f.open( QIODevice::WriteOnly ) ) {
qWarning() << "Failed to open file to save XSPF:" << filename;
return;
}
f.write( xspf );
f.close();
sender()->deleteLater();
}

View File

@@ -39,7 +39,7 @@ public:
void copyToClipboard( const Tomahawk::query_ptr& query ) const;
void copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
void copyPlaylistToClipboard( const Tomahawk::playlist_ptr& playlist );
void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename );
public slots:
bool parseTomahawkLink( const QString& link );

View File

@@ -34,6 +34,7 @@
#include <QStyledItemDelegate>
#include <QSize>
#include <globalactionmanager.h>
#include <QFileDialog>
using namespace Tomahawk;
@@ -250,7 +251,9 @@ SourceTreeView::copyPlaylistLink()
{
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
playlist_ptr playlist = item->playlist();
GlobalActionManager::instance()->copyPlaylistToClipboard( playlist );
QString filename = QFileDialog::getSaveFileName( this, tr( "Save XSPF" ), QDir::homePath(), tr( "Playlists (*.xspf)" ) );
GlobalActionManager::instance()->savePlaylistToFile( playlist, filename );
}
}