1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 22:26:32 +02:00

POST and jspf handling

This commit is contained in:
Leo Franchi
2012-04-22 04:15:17 -04:00
parent a48fff23c2
commit 24ec94ed96
3 changed files with 35 additions and 21 deletions

View File

@@ -148,32 +148,35 @@ void
GlobalActionManager::getShortLink( const playlist_ptr& pl ) GlobalActionManager::getShortLink( const playlist_ptr& pl )
{ {
QVariantMap m; QVariantMap m;
m[ "title" ] = playlist->title(); m[ "title" ] = pl->title();
m[ "creator" ] = pl->author().isNull() ? "" : pl->author()->friendlyName();
QVariantList tracks; QVariantList tracks;
foreach( const plentry_ptr& pl, playlist->entries() ) foreach( const plentry_ptr& pl, pl->entries() )
{ {
if ( pl->query().isNull() ) if ( pl->query().isNull() )
continue; continue;
QVariantMap track; QVariantMap track;
track[ "title" ] = pl->query()->track(); track[ "title" ] = pl->query()->track();
track[ "artist" ] = pl->query()->artist(); track[ "creator" ] = pl->query()->artist();
track[ "album" ] = pl->query()->album(); track[ "album" ] = pl->query()->album();
tracks << track; tracks << track;
} }
m[ "tracks" ] = tracks; m[ "track" ] = tracks;
QJson::Parser p; QVariantMap jspf;
QByteArray msg = p.parse( m ); jspf["playlist"] = m;
QJson::Serializer s;
QByteArray msg = s.serialize( jspf );
qDebug() << "POSTING DATA:" << msg; qDebug() << "POSTING DATA:" << msg;
const QUrl url( QString( "%1/playlist").arg( hostname() ) ); const QUrl url( QString( "%1/playlist/").arg( hostname() ) );
QNetworkRequest req( url ); QNetworkRequest req( url );
req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) ); req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
QNetworkReply *reply = TomahawkUtils::nam()->get( request ); QNetworkReply *reply = TomahawkUtils::nam()->post( req, msg );
if ( callbackObj.isValid() )
reply->setProperty( "callbackobj", callbackObj );
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) ); connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) ); connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
} }
@@ -375,18 +378,29 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
if ( parts[ 0 ] == "import" ) if ( parts[ 0 ] == "import" )
{ {
if ( !url.hasQueryItem( "xspf" ) ) if ( !url.hasQueryItem( "xspf" ) && !url.hasQueryItem( "jspf") )
{ {
tDebug() << "No xspf to load..."; tDebug() << "No xspf or jspf to load...";
return false; return false;
} }
QUrl xspf = QUrl::fromUserInput( url.queryItemValue( "xspf" ) ); if ( url.hasQueryItem( "xspf") )
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString(); {
XSPFLoader* l= new XSPFLoader( true, this ); QUrl xspf = QUrl::fromUserInput( url.queryItemValue( "xspf" ) );
l->setOverrideTitle( title ); QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
l->load( xspf ); XSPFLoader* l= new XSPFLoader( true, this );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) ); l->setOverrideTitle( title );
l->load( xspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
}
else if ( url.hasQueryItem( "jspf" ) )
{
QUrl jspf = QUrl::fromUserInput( url.queryItemValue( "jspf" ) );
QString title = url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString();
JSPFLoader* l= new JSPFLoader( true, this );
l->setOverrideTitle( title );
l->load( jspf );
connect( l, SIGNAL( ok( Tomahawk::playlist_ptr ) ), this, SLOT( playlistCreatedToShow( Tomahawk::playlist_ptr) ) );
}
} }
else if ( parts [ 0 ] == "new" ) else if ( parts [ 0 ] == "new" )
{ {

View File

@@ -57,7 +57,7 @@ public:
public slots: public slots:
void shortenLink( const QUrl& url, const QVariant &callbackObj = QVariant() ); void shortenLink( const QUrl& url, const QVariant &callbackObj = QVariant() );
void getShortLink( const playlist_ptr& playlist ); void getShortLink( const Tomahawk::playlist_ptr& playlist );
bool parseTomahawkLink( const QString& link ); bool parseTomahawkLink( const QString& link );
void waitingForResolved( bool ); void waitingForResolved( bool );

View File

@@ -361,7 +361,7 @@ SourceTreeView::copyPlaylistLink()
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex ); PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
playlist_ptr playlist = item->playlist(); playlist_ptr playlist = item->playlist();
GlobalActionManager::instance()->getShortLink( playlist ); // GlobalActionManager::instance()->getShortLink( playlist );
// QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title(); // QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title();
// QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ), // QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ),