mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Encode spaces as + and unify encoding logic in GlobalActionManager
This commit is contained in:
@@ -103,8 +103,7 @@ GlobalActionManager::copyOpenLink( const artist_ptr& artist ) const
|
|||||||
const QUrl link( QString( "%1/artist/%2" ).arg( hostname() ).arg( artist->name() ) );
|
const QUrl link( QString( "%1/artist/%2" ).arg( hostname() ).arg( artist->name() ) );
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QClipboard* cb = QApplication::clipboard();
|
||||||
QByteArray data = link.toEncoded();
|
QByteArray data = percentEncode( link );
|
||||||
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 );
|
cb->setText( data );
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
@@ -114,11 +113,11 @@ GlobalActionManager::copyOpenLink( const artist_ptr& artist ) const
|
|||||||
QUrl
|
QUrl
|
||||||
GlobalActionManager::copyOpenLink( const album_ptr& album ) const
|
GlobalActionManager::copyOpenLink( const album_ptr& album ) const
|
||||||
{
|
{
|
||||||
const QUrl link( QString( "%1/album/%2/%3" ).arg( hostname() ).arg( album->artist().isNull() ? QString() : album->artist()->name() ).arg( album->name()) );
|
const QUrl link = QUrl::fromUserInput( QString( "%1/album/%2/%3" ).arg( hostname() ).arg( album->artist().isNull() ? QString() : album->artist()->name() ).arg( album->name() ) );
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QClipboard* cb = QApplication::clipboard();
|
||||||
QByteArray data = link.toEncoded();
|
QByteArray data = percentEncode( link );
|
||||||
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 );
|
cb->setText( data );
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
@@ -255,8 +254,7 @@ GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
|||||||
}
|
}
|
||||||
|
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QClipboard* cb = QApplication::clipboard();
|
||||||
QByteArray data = link.toEncoded();
|
QByteArray data = percentEncode( link );
|
||||||
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 );
|
cb->setText( data );
|
||||||
|
|
||||||
return link.toString();
|
return link.toString();
|
||||||
@@ -1217,8 +1215,7 @@ GlobalActionManager::shortenLinkRequestFinished()
|
|||||||
{
|
{
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QClipboard* cb = QApplication::clipboard();
|
||||||
|
|
||||||
QByteArray data = error ? longUrl.toEncoded() : shortUrl.toEncoded();
|
QByteArray data = percentEncode( error ? longUrl : shortUrl );
|
||||||
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 );
|
cb->setText( data );
|
||||||
|
|
||||||
m_clipboardLongUrl.clear();
|
m_clipboardLongUrl.clear();
|
||||||
@@ -1250,8 +1247,7 @@ GlobalActionManager::postShortenFinished()
|
|||||||
qDebug() << "GOT POSTED SHORT URL:" << url.toString();
|
qDebug() << "GOT POSTED SHORT URL:" << url.toString();
|
||||||
QClipboard* cb = QApplication::clipboard();
|
QClipboard* cb = QApplication::clipboard();
|
||||||
|
|
||||||
QByteArray data = url.toEncoded();
|
const QByteArray data = percentEncode( url );
|
||||||
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 );
|
cb->setText( data );
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
@@ -1387,5 +1383,18 @@ GlobalActionManager::openRdioLink( const QString& link )
|
|||||||
QString
|
QString
|
||||||
GlobalActionManager::hostname() const
|
GlobalActionManager::hostname() const
|
||||||
{
|
{
|
||||||
return QString( "http://toma.hk" );
|
return QString( "http://stage.toma.hk" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
GlobalActionManager::percentEncode (const QUrl &url ) const
|
||||||
|
{
|
||||||
|
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.
|
||||||
|
data.replace( "%20", "+" );
|
||||||
|
data.replace( "&", "%26" );
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
@@ -131,6 +131,8 @@ private:
|
|||||||
|
|
||||||
QString hostname() const;
|
QString hostname() const;
|
||||||
|
|
||||||
|
inline QByteArray percentEncode( const QUrl& url ) const;
|
||||||
|
|
||||||
Tomahawk::playlist_ptr m_toShow;
|
Tomahawk::playlist_ptr m_toShow;
|
||||||
Tomahawk::query_ptr m_waitingToBookmark;
|
Tomahawk::query_ptr m_waitingToBookmark;
|
||||||
Tomahawk::query_ptr m_waitingToPlay;
|
Tomahawk::query_ptr m_waitingToPlay;
|
||||||
|
Reference in New Issue
Block a user