Make drag & drop work for Spotify user playlists.
This commit is contained in:
parent
df6e8037cd
commit
2e2f4e570c
@ -109,7 +109,7 @@ void SpotifyService::LazyPopulate(QStandardItem* item) {
|
|||||||
server_->LoadStarred();
|
server_->LoadStarred();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Type_UserPlaylist:
|
case InternetModel::Type_UserPlaylist:
|
||||||
EnsureServerCreated();
|
EnsureServerCreated();
|
||||||
server_->LoadUserPlaylist(item->data(Role_UserPlaylistIndex).toInt());
|
server_->LoadUserPlaylist(item->data(Role_UserPlaylistIndex).toInt());
|
||||||
break;
|
break;
|
||||||
@ -336,12 +336,16 @@ void SpotifyService::PlaylistsUpdated(const spotify_pb::Playlists& response) {
|
|||||||
const spotify_pb::Playlists::Playlist& msg = response.playlist(i);
|
const spotify_pb::Playlists::Playlist& msg = response.playlist(i);
|
||||||
|
|
||||||
QStandardItem* item = new QStandardItem(QStringFromStdString(msg.name()));
|
QStandardItem* item = new QStandardItem(QStringFromStdString(msg.name()));
|
||||||
item->setData(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(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
|
||||||
|
|
||||||
root_->appendRow(item);
|
root_->appendRow(item);
|
||||||
playlists_ << item;
|
playlists_ << item;
|
||||||
|
|
||||||
|
// Preload the playlist items so that drag & drop works immediately.
|
||||||
|
LazyPopulate(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,6 +396,7 @@ void SpotifyService::UserPlaylistLoaded(const spotify_pb::LoadPlaylistResponse&
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SpotifyService::FillPlaylist(QStandardItem* item, const spotify_pb::LoadPlaylistResponse& response) {
|
void SpotifyService::FillPlaylist(QStandardItem* item, const spotify_pb::LoadPlaylistResponse& response) {
|
||||||
|
qLog(Debug) << "Filling playlist:" << item->text();
|
||||||
if (item->hasChildren())
|
if (item->hasChildren())
|
||||||
item->removeRows(0, item->rowCount());
|
item->removeRows(0, item->rowCount());
|
||||||
|
|
||||||
@ -464,9 +469,8 @@ void SpotifyService::SyncPlaylist() {
|
|||||||
QStandardItem* item = playlist_sync_action_->data().value<QStandardItem*>();
|
QStandardItem* item = playlist_sync_action_->data().value<QStandardItem*>();
|
||||||
Q_ASSERT(item);
|
Q_ASSERT(item);
|
||||||
|
|
||||||
Type type = static_cast<Type>(item->data(InternetModel::Role_Type).toInt());
|
switch (item->data(InternetModel::Role_Type).toInt()) {
|
||||||
switch (type) {
|
case InternetModel::Type_UserPlaylist: {
|
||||||
case Type_UserPlaylist: {
|
|
||||||
int index = item->data(Role_UserPlaylistIndex).toInt();
|
int index = item->data(Role_UserPlaylistIndex).toInt();
|
||||||
server_->SyncUserPlaylist(index);
|
server_->SyncUserPlaylist(index);
|
||||||
playlist_sync_ids_[index] =
|
playlist_sync_ids_[index] =
|
||||||
@ -550,10 +554,10 @@ void SpotifyService::ShowContextMenu(const QModelIndex& index, const QPoint& glo
|
|||||||
EnsureMenuCreated();
|
EnsureMenuCreated();
|
||||||
QStandardItem* item = model()->itemFromIndex(index);
|
QStandardItem* item = model()->itemFromIndex(index);
|
||||||
if (item) {
|
if (item) {
|
||||||
Type type = static_cast<Type>(item->data(InternetModel::Role_Type).toInt());
|
int type = item->data(InternetModel::Role_Type).toInt();
|
||||||
if (type == Type_InboxPlaylist ||
|
if (type == Type_InboxPlaylist ||
|
||||||
type == Type_StarredPlaylist ||
|
type == Type_StarredPlaylist ||
|
||||||
type == Type_UserPlaylist) {
|
type == InternetModel::Type_UserPlaylist) {
|
||||||
playlist_sync_action_->setData(qVariantFromValue(item));
|
playlist_sync_action_->setData(qVariantFromValue(item));
|
||||||
playlist_context_menu_->popup(global_pos);
|
playlist_context_menu_->popup(global_pos);
|
||||||
return;
|
return;
|
||||||
|
@ -26,7 +26,6 @@ public:
|
|||||||
Type_SearchResults = InternetModel::TypeCount,
|
Type_SearchResults = InternetModel::TypeCount,
|
||||||
Type_StarredPlaylist,
|
Type_StarredPlaylist,
|
||||||
Type_InboxPlaylist,
|
Type_InboxPlaylist,
|
||||||
Type_UserPlaylist,
|
|
||||||
Type_Track,
|
Type_Track,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user