mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-21 00:12:06 +02:00
Copy XSPF to clipboard for normal playlists. TODO: Upload to a server and provide a link
This commit is contained in:
parent
d1ee642c12
commit
5bf79e1686
@ -158,6 +158,7 @@ set( libSources
|
||||
utils/widgetdragfilter.cpp
|
||||
utils/animatedsplitter.cpp
|
||||
utils/xspfloader.cpp
|
||||
utils/xspfgenerator.cpp
|
||||
|
||||
widgets/newplaylistwidget.cpp
|
||||
widgets/welcomewidget.cpp
|
||||
@ -320,6 +321,7 @@ set( libHeaders
|
||||
utils/widgetdragfilter.h
|
||||
utils/animatedsplitter.h
|
||||
utils/xspfloader.h
|
||||
utils/xspfgenerator.h
|
||||
|
||||
widgets/newplaylistwidget.h
|
||||
widgets/welcomewidget.h
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <Playlist.h>
|
||||
#include <qclipboard.h>
|
||||
#include <qapplication.h>
|
||||
#include "utils/xspfgenerator.h"
|
||||
|
||||
GlobalActionManager* GlobalActionManager::s_instance = 0;
|
||||
|
||||
@ -125,6 +126,22 @@ GlobalActionManager::copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& p
|
||||
cb->setText( link.toEncoded() );
|
||||
}
|
||||
|
||||
void
|
||||
GlobalActionManager::copyPlaylistToClipboard( const Tomahawk::playlist_ptr& playlist )
|
||||
{
|
||||
XSPFGenerator* g = new XSPFGenerator( playlist, this );
|
||||
connect( g, SIGNAL( generated( QByteArray ) ), this, SLOT( xspfCreated( QByteArray ) ) );
|
||||
}
|
||||
|
||||
void
|
||||
GlobalActionManager::xspfCreated( const QByteArray& xspf )
|
||||
{
|
||||
QClipboard* cb = QApplication::clipboard();
|
||||
cb->setText( xspf );
|
||||
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlobalActionManager::copyToClipboard( const Tomahawk::query_ptr& query ) const
|
||||
|
@ -39,6 +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 );
|
||||
|
||||
public slots:
|
||||
bool parseTomahawkLink( const QString& link );
|
||||
@ -48,6 +49,8 @@ private slots:
|
||||
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
||||
void showPlaylist();
|
||||
|
||||
void xspfCreated( const QByteArray& xspf );
|
||||
|
||||
private:
|
||||
explicit GlobalActionManager( QObject* parent = 0 );
|
||||
void doBookmark( const Tomahawk::playlist_ptr& pl, const Tomahawk::query_ptr& q );
|
||||
|
71
src/libtomahawk/utils/xspfgenerator.cpp
Normal file
71
src/libtomahawk/utils/xspfgenerator.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (C) 2011 Leo Franchi <lfranchi@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "xspfgenerator.h"
|
||||
#include <QXmlStreamWriter>
|
||||
#include <playlist.h>
|
||||
#include <QDateTime>
|
||||
#include <QTimer>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
XSPFGenerator::XSPFGenerator( const playlist_ptr& pl, QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_playlist( pl )
|
||||
{
|
||||
QTimer::singleShot( 0, this, SLOT( generate() ) );
|
||||
}
|
||||
|
||||
XSPFGenerator::~XSPFGenerator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XSPFGenerator::generate()
|
||||
{
|
||||
Q_ASSERT( !m_playlist.isNull() );
|
||||
|
||||
QByteArray xspf;
|
||||
QXmlStreamWriter w( &xspf );
|
||||
w.setAutoFormatting( true );
|
||||
w.writeStartDocument();
|
||||
|
||||
w.writeStartElement( "playlist" );
|
||||
w.writeAttribute( "version", "1" );
|
||||
w.writeAttribute( "xmlns", "http://xspf.org/ns/0/" );
|
||||
|
||||
w.writeTextElement( "title", m_playlist->title() );
|
||||
w.writeTextElement( "creator", m_playlist->creator() );
|
||||
w.writeTextElement( "date", QDateTime::fromTime_t( m_playlist->createdOn() ).toString( Qt::ISODate ) );
|
||||
|
||||
w.writeStartElement( "trackList" );
|
||||
foreach ( const plentry_ptr& q, m_playlist->entries() )
|
||||
{
|
||||
w.writeStartElement( "track" );
|
||||
w.writeTextElement( "title", q->query()->track() );
|
||||
w.writeTextElement( "creator", q->query()->artist() );
|
||||
w.writeTextElement( "album", q->query()->album() );
|
||||
w.writeEndElement();
|
||||
}
|
||||
w.writeEndDocument(); // will close all open elements
|
||||
|
||||
emit generated( xspf );
|
||||
}
|
45
src/libtomahawk/utils/xspfgenerator.h
Normal file
45
src/libtomahawk/utils/xspfgenerator.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (C) 2011 Leo Franchi <lfranchi@kde.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XSPFGENERATOR_H
|
||||
#define XSPFGENERATOR_H
|
||||
|
||||
#include "typedefs.h"
|
||||
|
||||
#include <QtCore/qobject.h>
|
||||
|
||||
|
||||
class XSPFGenerator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit XSPFGenerator( const Tomahawk::playlist_ptr& pl, QObject* parent = 0 );
|
||||
virtual ~XSPFGenerator();
|
||||
|
||||
signals:
|
||||
void generated( const QByteArray& xspf );
|
||||
|
||||
private slots:
|
||||
void generate();
|
||||
|
||||
private:
|
||||
Tomahawk::playlist_ptr m_playlist;
|
||||
};
|
||||
|
||||
#endif // XSPFGENERATOR_H
|
@ -246,6 +246,11 @@ SourceTreeView::copyPlaylistLink()
|
||||
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||
GlobalActionManager::instance()->copyPlaylistToClipboard( playlist );
|
||||
} else if ( type == SourcesModel::StaticPlaylist )
|
||||
{
|
||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
|
||||
playlist_ptr playlist = item->playlist();
|
||||
GlobalActionManager::instance()->copyPlaylistToClipboard( playlist );
|
||||
}
|
||||
}
|
||||
|
||||
|
2
thirdparty/jreen
vendored
2
thirdparty/jreen
vendored
@ -1 +1 @@
|
||||
Subproject commit a231a2b3868baf32312d65cb7e371828212d7745
|
||||
Subproject commit 8f995f246637f533feb7124744e113034a32b505
|
Loading…
x
Reference in New Issue
Block a user