mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 03:10:12 +02:00
Copy XSPF to clipboard for normal playlists. TODO: Upload to a server and provide a link
This commit is contained in:
@@ -158,6 +158,7 @@ set( libSources
|
|||||||
utils/widgetdragfilter.cpp
|
utils/widgetdragfilter.cpp
|
||||||
utils/animatedsplitter.cpp
|
utils/animatedsplitter.cpp
|
||||||
utils/xspfloader.cpp
|
utils/xspfloader.cpp
|
||||||
|
utils/xspfgenerator.cpp
|
||||||
|
|
||||||
widgets/newplaylistwidget.cpp
|
widgets/newplaylistwidget.cpp
|
||||||
widgets/welcomewidget.cpp
|
widgets/welcomewidget.cpp
|
||||||
@@ -320,6 +321,7 @@ set( libHeaders
|
|||||||
utils/widgetdragfilter.h
|
utils/widgetdragfilter.h
|
||||||
utils/animatedsplitter.h
|
utils/animatedsplitter.h
|
||||||
utils/xspfloader.h
|
utils/xspfloader.h
|
||||||
|
utils/xspfgenerator.h
|
||||||
|
|
||||||
widgets/newplaylistwidget.h
|
widgets/newplaylistwidget.h
|
||||||
widgets/welcomewidget.h
|
widgets/welcomewidget.h
|
||||||
|
@@ -34,6 +34,7 @@
|
|||||||
#include <Playlist.h>
|
#include <Playlist.h>
|
||||||
#include <qclipboard.h>
|
#include <qclipboard.h>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
#include "utils/xspfgenerator.h"
|
||||||
|
|
||||||
GlobalActionManager* GlobalActionManager::s_instance = 0;
|
GlobalActionManager* GlobalActionManager::s_instance = 0;
|
||||||
|
|
||||||
@@ -125,6 +126,22 @@ GlobalActionManager::copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& p
|
|||||||
cb->setText( link.toEncoded() );
|
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
|
void
|
||||||
GlobalActionManager::copyToClipboard( const Tomahawk::query_ptr& query ) const
|
GlobalActionManager::copyToClipboard( const Tomahawk::query_ptr& query ) const
|
||||||
|
@@ -39,6 +39,7 @@ public:
|
|||||||
|
|
||||||
void copyToClipboard( const Tomahawk::query_ptr& query ) const;
|
void copyToClipboard( const Tomahawk::query_ptr& query ) const;
|
||||||
void copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
|
void copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
|
||||||
|
void copyPlaylistToClipboard( const Tomahawk::playlist_ptr& playlist );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool parseTomahawkLink( const QString& link );
|
bool parseTomahawkLink( const QString& link );
|
||||||
@@ -48,6 +49,8 @@ private slots:
|
|||||||
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
||||||
void showPlaylist();
|
void showPlaylist();
|
||||||
|
|
||||||
|
void xspfCreated( const QByteArray& xspf );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GlobalActionManager( QObject* parent = 0 );
|
explicit GlobalActionManager( QObject* parent = 0 );
|
||||||
void doBookmark( const Tomahawk::playlist_ptr& pl, const Tomahawk::query_ptr& q );
|
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 );
|
DynamicPlaylistItem* item = itemFromIndex< DynamicPlaylistItem >( m_contextMenuIndex );
|
||||||
dynplaylist_ptr playlist = item->dynPlaylist();
|
dynplaylist_ptr playlist = item->dynPlaylist();
|
||||||
GlobalActionManager::instance()->copyPlaylistToClipboard( playlist );
|
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
Submodule thirdparty/jreen updated: a231a2b386...8f995f2466
Reference in New Issue
Block a user