QString GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist ) { QUrl link( QString( "%1/%2/create/" ).arg( hostname() ).arg( playlist->mode() == OnDemand ? "station" : "autoplaylist" ) ); if ( playlist->generator()->type() != "echonest" ) { tLog() << "Only echonest generators are supported"; return QString(); } link.addEncodedQueryItem( "type", "echonest" ); link.addQueryItem( "title", playlist->title() ); QList< dyncontrol_ptr > controls = playlist->generator()->controls(); foreach ( const dyncontrol_ptr& c, controls ) { if ( c->selectedType() == "Artist" ) { if ( c->match().toInt() == Echonest::DynamicPlaylist::ArtistType ) link.addQueryItem( "artist_limitto", c->input() ); else link.addQueryItem( "artist", c->input() ); } else if ( c->selectedType() == "Artist Description" ) { link.addQueryItem( "description", c->input() ); } else { QString name = c->selectedType().toLower().replace( " ", "_" ); Echonest::DynamicPlaylist::PlaylistParam p = static_cast< Echonest::DynamicPlaylist::PlaylistParam >( c->match().toInt() ); // if it is a max, set that too if ( p == Echonest::DynamicPlaylist::MaxTempo || p == Echonest::DynamicPlaylist::MaxDuration || p == Echonest::DynamicPlaylist::MaxLoudness || p == Echonest::DynamicPlaylist::MaxDanceability || p == Echonest::DynamicPlaylist::MaxEnergy || p == Echonest::DynamicPlaylist::ArtistMaxFamiliarity || p == Echonest::DynamicPlaylist::ArtistMaxHotttnesss || p == Echonest::DynamicPlaylist::SongMaxHotttnesss || p == Echonest::DynamicPlaylist::ArtistMaxLatitude || p == Echonest::DynamicPlaylist::ArtistMaxLongitude ) name += "_max"; link.addQueryItem( name, c->input() ); } } QClipboard* cb = QApplication::clipboard(); QByteArray data = link.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 ); return link.toString(); }
QString GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist ) { QUrl link( QString( "%1/%2/create/" ).arg( hostname() ).arg( playlist->mode() == OnDemand ? "station" : "autoplaylist" ) ); if ( playlist->generator()->type() != "echonest" ) { tLog() << "Only echonest generators are supported"; return QString(); } TomahawkUtils::urlAddQueryItem( link, "type", "echonest" ); TomahawkUtils::urlAddQueryItem( link, "title", playlist->title() ); QList< dyncontrol_ptr > controls = playlist->generator()->controls(); foreach ( const dyncontrol_ptr& c, controls ) { if ( c->selectedType() == "Artist" ) { if ( c->match().toInt() == Echonest::DynamicPlaylist::ArtistType ) TomahawkUtils::urlAddQueryItem( link, "artist_limitto", c->input() ); else TomahawkUtils::urlAddQueryItem( link, "artist", c->input() ); } else if ( c->selectedType() == "Artist Description" ) { TomahawkUtils::urlAddQueryItem( link, "description", c->input() ); } else { QString name = c->selectedType().toLower().replace( " ", "_" ); Echonest::DynamicPlaylist::PlaylistParam p = static_cast< Echonest::DynamicPlaylist::PlaylistParam >( c->match().toInt() ); // if it is a max, set that too if ( p == Echonest::DynamicPlaylist::MaxTempo || p == Echonest::DynamicPlaylist::MaxDuration || p == Echonest::DynamicPlaylist::MaxLoudness || p == Echonest::DynamicPlaylist::MaxDanceability || p == Echonest::DynamicPlaylist::MaxEnergy || p == Echonest::DynamicPlaylist::ArtistMaxFamiliarity || p == Echonest::DynamicPlaylist::ArtistMaxHotttnesss || p == Echonest::DynamicPlaylist::SongMaxHotttnesss || p == Echonest::DynamicPlaylist::ArtistMaxLatitude || p == Echonest::DynamicPlaylist::ArtistMaxLongitude ) name += "_max"; TomahawkUtils::urlAddQueryItem( link, name, c->input() ); } } QClipboard* cb = QApplication::clipboard(); QByteArray data = percentEncode( link ); cb->setText( data ); return link.toString(); }