mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 01:09:42 +01:00
Add proper playlist POSTing
This commit is contained in:
parent
24ec94ed96
commit
7fc03770d0
@ -172,12 +172,21 @@ GlobalActionManager::getShortLink( const playlist_ptr& pl )
|
||||
QByteArray msg = s.serialize( jspf );
|
||||
qDebug() << "POSTING DATA:" << msg;
|
||||
|
||||
const QByteArray boundary = "----------------------------2434992cccab";
|
||||
QByteArray data(QByteArray("--" + boundary + "\r\n"));
|
||||
data += "Content-Disposition: form-data; name=\"data\"; filename=\"playlist.jspf\"\r\n";
|
||||
data += "Content-Type: application/octet-stream\r\n\r\n";
|
||||
data += msg;
|
||||
data += "\r\n\r\n";
|
||||
data += "--" + boundary + "--\r\n\r\n";
|
||||
|
||||
const QUrl url( QString( "%1/playlist/").arg( hostname() ) );
|
||||
QNetworkRequest req( url );
|
||||
req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String( "application/x-www-form-urlencoded" ) );
|
||||
QNetworkReply *reply = TomahawkUtils::nam()->post( req, msg );
|
||||
qDebug() << "POSTING TO:" << url.toString();
|
||||
req.setHeader( QNetworkRequest::ContentTypeHeader, QString( "multipart/form-data; boundary=%1" ).arg( QString::fromLatin1( boundary ) ) );
|
||||
QNetworkReply *reply = TomahawkUtils::nam()->post( req, data );
|
||||
|
||||
connect( reply, SIGNAL( finished() ), SLOT( shortenLinkRequestFinished() ) );
|
||||
connect( reply, SIGNAL( finished() ), SLOT( postShortenFinished() ) );
|
||||
connect( reply, SIGNAL( error( QNetworkReply::NetworkError ) ), SLOT( shortenLinkRequestError( QNetworkReply::NetworkError ) ) );
|
||||
}
|
||||
|
||||
@ -1102,6 +1111,25 @@ GlobalActionManager::shortenLinkRequestFinished()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlobalActionManager::postShortenFinished()
|
||||
{
|
||||
QNetworkReply* reply = qobject_cast<QNetworkReply*>( sender() );
|
||||
Q_ASSERT( reply );
|
||||
const QByteArray raw = reply->readAll();
|
||||
qDebug() << "GOT REPLYL" << raw;
|
||||
|
||||
const QUrl url = QUrl::fromUserInput( raw );
|
||||
qDebug() << "GOT POSTED SHORT URL:" << url.toString();
|
||||
QClipboard* cb = QApplication::clipboard();
|
||||
|
||||
QByteArray data = url.toEncoded();
|
||||
data.replace( "'", "%27" ); // QUrl doesn't encode ', which it doesn't have to. Some apps don't like ' though, and want %27. Both are valid.
|
||||
cb->setText( data );
|
||||
|
||||
reply->deleteLater();
|
||||
}
|
||||
|
||||
void
|
||||
GlobalActionManager::shortenLinkRequestError( QNetworkReply::NetworkError error )
|
||||
{
|
||||
|
@ -72,6 +72,7 @@ signals:
|
||||
|
||||
private slots:
|
||||
void shortenLinkRequestFinished();
|
||||
void postShortenFinished();
|
||||
void shortenLinkRequestError( QNetworkReply::NetworkError );
|
||||
|
||||
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
||||
|
@ -361,7 +361,7 @@ SourceTreeView::copyPlaylistLink()
|
||||
PlaylistItem* item = itemFromIndex< PlaylistItem >( m_contextMenuIndex );
|
||||
playlist_ptr playlist = item->playlist();
|
||||
|
||||
// GlobalActionManager::instance()->getShortLink( playlist );
|
||||
GlobalActionManager::instance()->getShortLink( playlist );
|
||||
|
||||
// QString suggestedFilename = TomahawkSettings::instance()->playlistDefaultPath() + "/" + playlist->title();
|
||||
// QString filename = QFileDialog::getSaveFileName( TomahawkUtils::tomahawkWindow(), tr( "Save XSPF" ),
|
||||
|
Loading…
x
Reference in New Issue
Block a user