mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 12:02:48 +01:00
Add Spotify tracks to Spotify playlists by drag and drop
This commit is contained in:
parent
f7924905d2
commit
f34f868c0f
@ -300,7 +300,8 @@ bool InternetModel::dropMimeData(const QMimeData* data, Qt::DropAction action,
|
|||||||
if (action == Qt::IgnoreAction) {
|
if (action == Qt::IgnoreAction) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (parent.data(Role_CanBeModified).toBool()) {
|
if (parent.data(Role_CanBeModified).toBool() ||
|
||||||
|
parent.parent().data(Role_CanBeModified).toBool()) {
|
||||||
InternetModel::ServiceForIndex(parent)->DropMimeData(data, parent);
|
InternetModel::ServiceForIndex(parent)->DropMimeData(data, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
|
|||||||
item->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
|
item->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
|
||||||
item->setData(true, InternetModel::Role_CanLazyLoad);
|
item->setData(true, InternetModel::Role_CanLazyLoad);
|
||||||
item->setData(msg.index(), Role_UserPlaylistIndex);
|
item->setData(msg.index(), Role_UserPlaylistIndex);
|
||||||
item->setData(msg.is_mine(), Role_UserPlaylistIsMine);
|
item->setData(msg.is_mine(), InternetModel::Role_CanBeModified);
|
||||||
item->setData(InternetModel::PlayBehaviour_MultipleItems,
|
item->setData(InternetModel::PlayBehaviour_MultipleItems,
|
||||||
InternetModel::Role_PlayBehaviour);
|
InternetModel::Role_PlayBehaviour);
|
||||||
|
|
||||||
@ -568,7 +568,7 @@ QList<QAction*> SpotifyService::playlistitem_actions(const Song& song) {
|
|||||||
tr("Add to Spotify playlists"), this);
|
tr("Add to Spotify playlists"), this);
|
||||||
QMenu* playlists_menu = new QMenu();
|
QMenu* playlists_menu = new QMenu();
|
||||||
for (const QStandardItem* playlist_item : playlists_) {
|
for (const QStandardItem* playlist_item : playlists_) {
|
||||||
if (!playlist_item->data(Role_UserPlaylistIsMine).toBool()) {
|
if (!playlist_item->data(InternetModel::Role_CanBeModified).toBool()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QAction* add_to_playlist = new QAction(playlist_item->text(), this);
|
QAction* add_to_playlist = new QAction(playlist_item->text(), this);
|
||||||
@ -744,7 +744,7 @@ void SpotifyService::ShowContextMenu(const QPoint& global_pos) {
|
|||||||
// Is this track contained in a playlist we can modify?
|
// Is this track contained in a playlist we can modify?
|
||||||
bool is_playlist_modifiable =
|
bool is_playlist_modifiable =
|
||||||
item->parent() &&
|
item->parent() &&
|
||||||
item->parent()->data(Role_UserPlaylistIsMine).toBool();
|
item->parent()->data(InternetModel::Role_CanBeModified).toBool();
|
||||||
remove_from_playlist_->setVisible(is_playlist_modifiable);
|
remove_from_playlist_->setVisible(is_playlist_modifiable);
|
||||||
|
|
||||||
song_context_menu_->popup(global_pos);
|
song_context_menu_->popup(global_pos);
|
||||||
@ -759,7 +759,15 @@ void SpotifyService::ItemDoubleClicked(QStandardItem* item) {}
|
|||||||
|
|
||||||
void SpotifyService::DropMimeData(const QMimeData* data,
|
void SpotifyService::DropMimeData(const QMimeData* data,
|
||||||
const QModelIndex& index) {
|
const QModelIndex& index) {
|
||||||
qLog(Debug) << Q_FUNC_INFO << data->urls();
|
QVariant q_playlist_index = index.data(Role_UserPlaylistIndex);
|
||||||
|
if (!q_playlist_index.isValid()) {
|
||||||
|
// In case song was dropped on a playlist item, not on the playlist title/root element
|
||||||
|
q_playlist_index = index.parent().data(Role_UserPlaylistIndex);
|
||||||
|
}
|
||||||
|
if (!q_playlist_index.isValid())
|
||||||
|
return;
|
||||||
|
|
||||||
|
AddSongsToPlaylist(q_playlist_index.toInt(), data->urls());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpotifyService::LoadImage(const QString& id) {
|
void SpotifyService::LoadImage(const QString& id) {
|
||||||
|
@ -28,11 +28,7 @@ class SpotifyService : public InternetService {
|
|||||||
Type_Toplist,
|
Type_Toplist,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Role {
|
enum Role { Role_UserPlaylistIndex = InternetModel::RoleCount, };
|
||||||
Role_UserPlaylistIndex = InternetModel::RoleCount,
|
|
||||||
Role_UserPlaylistIsMine, // Is this playlist owned by the user currently
|
|
||||||
// logged-in?
|
|
||||||
};
|
|
||||||
|
|
||||||
// Values are persisted - don't change.
|
// Values are persisted - don't change.
|
||||||
enum LoginState {
|
enum LoginState {
|
||||||
@ -57,8 +53,8 @@ class SpotifyService : public InternetService {
|
|||||||
void ItemDoubleClicked(QStandardItem* item) override;
|
void ItemDoubleClicked(QStandardItem* item) override;
|
||||||
void DropMimeData(const QMimeData* data, const QModelIndex& index) override;
|
void DropMimeData(const QMimeData* data, const QModelIndex& index) override;
|
||||||
QList<QAction*> playlistitem_actions(const Song& song) override;
|
QList<QAction*> playlistitem_actions(const Song& song) override;
|
||||||
PlaylistItem::Options playlistitem_options() const;
|
PlaylistItem::Options playlistitem_options() const override;
|
||||||
QWidget* HeaderWidget() const;
|
QWidget* HeaderWidget() const override;
|
||||||
|
|
||||||
void Logout();
|
void Logout();
|
||||||
void Login(const QString& username, const QString& password);
|
void Login(const QString& username, const QString& password);
|
||||||
|
Loading…
Reference in New Issue
Block a user