mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 15:16:34 +02:00
Export XSPF to file instead of clipboard
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
@@ -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 );
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user