Add ability to get a link to share Spotify playlists
This commit is contained in:
parent
cbddecb6c8
commit
7278e7c4d0
|
@ -458,6 +458,12 @@ void SpotifyClient::SendPlaylistList() {
|
|||
msg->set_download_progress(0);
|
||||
}
|
||||
msg->set_nb_tracks(sp_playlist_num_tracks(playlist));
|
||||
// URI - Blugh
|
||||
char uri[256];
|
||||
sp_link* link = sp_link_create_from_playlist(playlist);
|
||||
sp_link_as_string(link, uri, arraysize(uri));
|
||||
sp_link_release(link);
|
||||
msg->set_uri(uri);
|
||||
}
|
||||
|
||||
SendMessage(message);
|
||||
|
|
|
@ -50,8 +50,9 @@ message Playlists {
|
|||
required bool is_mine = 4;
|
||||
required string owner= 5;
|
||||
required bool is_offline = 6;
|
||||
required string uri = 7;
|
||||
// Offline sync progress between 0-100.
|
||||
optional int32 download_progress = 7;
|
||||
optional int32 download_progress = 8;
|
||||
}
|
||||
|
||||
repeated Playlist playlist = 1;
|
||||
|
|
|
@ -80,6 +80,7 @@ SpotifyService::SpotifyService(Application* app, InternetModel* parent)
|
|||
playlist_context_menu_(nullptr),
|
||||
song_context_menu_(nullptr),
|
||||
playlist_sync_action_(nullptr),
|
||||
get_url_to_share_playlist_(nullptr),
|
||||
remove_from_playlist_(nullptr),
|
||||
search_box_(new SearchBoxWidget(this)),
|
||||
search_delay_(new QTimer(this)),
|
||||
|
@ -454,6 +455,7 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
|
|||
item->setData(msg.is_mine(), InternetModel::Role_CanBeModified);
|
||||
item->setData(InternetModel::PlayBehaviour_MultipleItems,
|
||||
InternetModel::Role_PlayBehaviour);
|
||||
item->setData(QUrl(QStringFromStdString(msg.uri())), InternetModel::Role_Url);
|
||||
|
||||
root_->appendRow(item);
|
||||
playlists_ << item;
|
||||
|
@ -636,6 +638,9 @@ void SpotifyService::EnsureMenuCreated() {
|
|||
playlist_sync_action_ = playlist_context_menu_->addAction(
|
||||
IconLoader::Load("view-refresh"), tr("Make playlist available offline"),
|
||||
this, SLOT(SyncPlaylist()));
|
||||
get_url_to_share_playlist_ =
|
||||
playlist_context_menu_->addAction(tr("Get a URL to share this playlist"),
|
||||
this, SLOT(GetCurrentPlaylistUrlToShare()));
|
||||
playlist_context_menu_->addSeparator();
|
||||
playlist_context_menu_->addAction(GetNewShowConfigAction());
|
||||
|
||||
|
@ -770,6 +775,8 @@ void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
|
|||
type == InternetModel::Type_UserPlaylist) {
|
||||
playlist_sync_action_->setData(qVariantFromValue(item));
|
||||
playlist_context_menu_->popup(global_pos);
|
||||
current_playlist_url_ = item->data(InternetModel::Role_Url).toUrl();
|
||||
get_url_to_share_playlist_->setVisible(type == InternetModel::Type_UserPlaylist);
|
||||
return;
|
||||
} else if (type == InternetModel::Type_Track) {
|
||||
current_song_url_ = item->data(InternetModel::Role_Url).toUrl();
|
||||
|
@ -795,6 +802,15 @@ void SpotifyService::GetCurrentSongUrlToShare() const {
|
|||
InternetService::ShowUrlBox(tr("Spotify song's URL"), url);
|
||||
}
|
||||
|
||||
void SpotifyService::GetCurrentPlaylistUrlToShare() const {
|
||||
QString url = current_playlist_url_.toEncoded();
|
||||
// URLs we use can be opened with Spotify application, but I believe it's
|
||||
// better to give website links instead.
|
||||
url.replace(QRegExp("spotify:user:([^:]*):playlist:([^:]*)"),
|
||||
"https://play.spotify.com/user/\\1/playlist/\\2");
|
||||
InternetService::ShowUrlBox(tr("Spotify playlist's URL"), url);
|
||||
}
|
||||
|
||||
void SpotifyService::ItemDoubleClicked(QStandardItem* item) {}
|
||||
|
||||
void SpotifyService::DropMimeData(const QMimeData* data,
|
||||
|
|
|
@ -140,6 +140,7 @@ class SpotifyService : public InternetService {
|
|||
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
||||
void ToplistLoaded(const pb::spotify::BrowseToplistResponse& response);
|
||||
void GetCurrentSongUrlToShare() const;
|
||||
void GetCurrentPlaylistUrlToShare() const;
|
||||
|
||||
void DoSearch();
|
||||
|
||||
|
@ -168,9 +169,11 @@ class SpotifyService : public InternetService {
|
|||
QMenu* playlist_context_menu_;
|
||||
QMenu* song_context_menu_;
|
||||
QAction* playlist_sync_action_;
|
||||
QAction* get_url_to_share_playlist_;
|
||||
QList<QAction*> playlistitem_actions_;
|
||||
QAction* remove_from_playlist_;
|
||||
QUrl current_song_url_;
|
||||
QUrl current_playlist_url_;
|
||||
|
||||
SearchBoxWidget* search_box_;
|
||||
|
||||
|
|
Loading…
Reference in New Issue