Add ability to get a link to share Spotify songs
This commit is contained in:
parent
2d90789cbd
commit
cbddecb6c8
|
@ -22,7 +22,12 @@
|
|||
|
||||
#include "internet/core/internetservice.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QStandardItem>
|
||||
|
||||
#include "internet/core/internetmodel.h"
|
||||
|
@ -42,6 +47,22 @@ InternetService::InternetService(const QString& name, Application* app,
|
|||
open_in_new_playlist_(nullptr),
|
||||
separator_(nullptr) {}
|
||||
|
||||
void InternetService::ShowUrlBox(const QString& title, const QString& url) {
|
||||
QMessageBox url_box;
|
||||
url_box.setWindowTitle(title);
|
||||
url_box.setWindowIcon(QIcon(":/icon.png"));
|
||||
url_box.setText(url);
|
||||
url_box.setStandardButtons(QMessageBox::Ok);
|
||||
QPushButton* copy_to_clipboard_button =
|
||||
url_box.addButton(tr("Copy to clipboard"), QMessageBox::ActionRole);
|
||||
|
||||
url_box.exec();
|
||||
|
||||
if (url_box.clickedButton() == copy_to_clipboard_button) {
|
||||
QApplication::clipboard()->setText(url);
|
||||
}
|
||||
}
|
||||
|
||||
QList<QAction*> InternetService::GetPlaylistActions() {
|
||||
if (!separator_) {
|
||||
separator_ = new QAction(this);
|
||||
|
|
|
@ -48,6 +48,10 @@ class InternetService : public QObject {
|
|||
QObject* parent = nullptr);
|
||||
virtual ~InternetService() {}
|
||||
|
||||
// Convenient method that shows URL in a QMessageBox. Used by several Internet
|
||||
// services
|
||||
static void ShowUrlBox(const QString& title, const QString& url);
|
||||
|
||||
QString name() const { return name_; }
|
||||
InternetModel* model() const { return model_; }
|
||||
|
||||
|
|
|
@ -1205,22 +1205,6 @@ void GroovesharkService::PlaylistUrlToShareReceived(QNetworkReply* reply) {
|
|||
ShowUrlBox(tr("Grooveshark playlist's URL"), url);
|
||||
}
|
||||
|
||||
void GroovesharkService::ShowUrlBox(const QString& title, const QString& url) {
|
||||
QMessageBox url_box;
|
||||
url_box.setWindowTitle(title);
|
||||
url_box.setWindowIcon(QIcon(":/icon.png"));
|
||||
url_box.setText(url);
|
||||
url_box.setStandardButtons(QMessageBox::Ok);
|
||||
QPushButton* copy_to_clipboard_button =
|
||||
url_box.addButton(tr("Copy to clipboard"), QMessageBox::ActionRole);
|
||||
|
||||
url_box.exec();
|
||||
|
||||
if (url_box.clickedButton() == copy_to_clipboard_button) {
|
||||
QApplication::clipboard()->setText(url);
|
||||
}
|
||||
}
|
||||
|
||||
void GroovesharkService::AddCurrentSongToPlaylist(QAction* action) {
|
||||
int playlist_id = action->data().toInt();
|
||||
if (!playlists_.contains(playlist_id)) {
|
||||
|
|
|
@ -231,7 +231,6 @@ class GroovesharkService : public InternetService {
|
|||
// Convenient function which block until 'reply' replies, or timeout after 10
|
||||
// seconds. Returns false if reply has timeouted
|
||||
bool WaitForReply(QNetworkReply* reply);
|
||||
void ShowUrlBox(const QString& title, const QString& url);
|
||||
// Convenient function for extracting result from reply
|
||||
QVariantMap ExtractResult(QNetworkReply* reply);
|
||||
// Convenient function for extracting songs from grooveshark result. result
|
||||
|
|
|
@ -604,6 +604,11 @@ QList<QAction*> SpotifyService::playlistitem_actions(const Song& song) {
|
|||
add_to_playlists->setMenu(playlists_menu);
|
||||
playlistitem_actions_.append(add_to_playlists);
|
||||
|
||||
QAction* share_song =
|
||||
new QAction(tr("Get a URL to share this Spotify song"), this);
|
||||
connect(share_song, SIGNAL(triggered()), SLOT(GetCurrentSongUrlToShare()));
|
||||
playlistitem_actions_.append(share_song);
|
||||
|
||||
// Keep in mind the current song URL
|
||||
current_song_url_ = song.url();
|
||||
|
||||
|
@ -638,6 +643,8 @@ void SpotifyService::EnsureMenuCreated() {
|
|||
remove_from_playlist_ = song_context_menu_->addAction(
|
||||
IconLoader::Load("list-remove"), tr("Remove from playlist"), this,
|
||||
SLOT(RemoveCurrentFromPlaylist()));
|
||||
song_context_menu_->addAction(tr("Get a URL to share this Spotify song"),
|
||||
this, SLOT(GetCurrentSongUrlToShare()));
|
||||
|
||||
song_context_menu_->addAction(GetNewShowConfigAction());
|
||||
}
|
||||
|
@ -765,6 +772,7 @@ void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
|
|||
playlist_context_menu_->popup(global_pos);
|
||||
return;
|
||||
} else if (type == InternetModel::Type_Track) {
|
||||
current_song_url_ = item->data(InternetModel::Role_Url).toUrl();
|
||||
// Is this track contained in a playlist we can modify?
|
||||
bool is_playlist_modifiable =
|
||||
item->parent() &&
|
||||
|
@ -779,6 +787,14 @@ void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
|
|||
context_menu_->popup(global_pos);
|
||||
}
|
||||
|
||||
void SpotifyService::GetCurrentSongUrlToShare() const {
|
||||
QString url = current_song_url_.toEncoded();
|
||||
// URLs we use can be opened with Spotify application, but I believe it's
|
||||
// better to give website links instead.
|
||||
url.replace("spotify:track:", "https://play.spotify.com/track/");
|
||||
InternetService::ShowUrlBox(tr("Spotify song's URL"), url);
|
||||
}
|
||||
|
||||
void SpotifyService::ItemDoubleClicked(QStandardItem* item) {}
|
||||
|
||||
void SpotifyService::DropMimeData(const QMimeData* data,
|
||||
|
|
|
@ -139,6 +139,7 @@ class SpotifyService : public InternetService {
|
|||
void SearchResults(const pb::spotify::SearchResponse& response);
|
||||
void SyncPlaylistProgress(const pb::spotify::SyncPlaylistProgress& progress);
|
||||
void ToplistLoaded(const pb::spotify::BrowseToplistResponse& response);
|
||||
void GetCurrentSongUrlToShare() const;
|
||||
|
||||
void DoSearch();
|
||||
|
||||
|
|
Loading…
Reference in New Issue