Add a new PlayBehaviour (MultiplesItems) for loading playlits' songs by drag'n'drop for Internet services.

Use it for Spotify and Grooveshark.
This commit is contained in:
Arnaud Bienner 2012-07-29 01:35:05 +02:00
parent 20031870df
commit b08172138a
4 changed files with 22 additions and 10 deletions

View File

@ -580,7 +580,7 @@ void GroovesharkService::EnsureItemsCreated() {
tr("Search results"));
search_->setToolTip(tr("Start typing something on the search box above to "
"fill this search results list"));
search_->setData(InternetModel::PlayBehaviour_DoubleClickAction,
search_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
root_->appendRow(search_);
@ -591,14 +591,14 @@ void GroovesharkService::EnsureItemsCreated() {
popular_month_ = new QStandardItem(QIcon(":/star-on.png"), tr("Popular songs of the Month"));
popular_month_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
popular_month_->setData(true, InternetModel::Role_CanLazyLoad);
popular_month_->setData(InternetModel::PlayBehaviour_SingleItem,
popular_month_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
popular->appendRow(popular_month_);
popular_today_ = new QStandardItem(QIcon(":/star-on.png"), tr("Popular songs today"));
popular_today_->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
popular_today_->setData(true, InternetModel::Role_CanLazyLoad);
popular_today_->setData(InternetModel::PlayBehaviour_SingleItem,
popular_today_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
popular->appendRow(popular_today_);
@ -621,7 +621,7 @@ void GroovesharkService::EnsureItemsCreated() {
library_->setData(UserLibrary, Role_PlaylistType);
library_->setData(true, InternetModel::Role_CanLazyLoad);
library_->setData(true, InternetModel::Role_CanBeModified);
library_->setData(InternetModel::PlayBehaviour_SingleItem,
library_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
root_->appendRow(library_);
@ -630,7 +630,7 @@ void GroovesharkService::EnsureItemsCreated() {
favorites_->setData(UserFavorites, Role_PlaylistType);
favorites_->setData(true, InternetModel::Role_CanLazyLoad);
favorites_->setData(true, InternetModel::Role_CanBeModified);
favorites_->setData(InternetModel::PlayBehaviour_SingleItem,
favorites_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
root_->appendRow(favorites_);
@ -664,7 +664,7 @@ QStandardItem* GroovesharkService::CreatePlaylistItem(const QString& playlist_na
item->setData(UserPlaylist, Role_PlaylistType);
item->setData(true, InternetModel::Role_CanLazyLoad);
item->setData(true, InternetModel::Role_CanBeModified);
item->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
item->setData(InternetModel::PlayBehaviour_MultipleItems, InternetModel::Role_PlayBehaviour);
item->setData(playlist_id, Role_UserPlaylistId);
return item;
}

View File

@ -181,7 +181,8 @@ bool InternetModel::IsPlayable(const QModelIndex& index) const {
return false;
PlayBehaviour pb = PlayBehaviour(behaviour.toInt());
return (pb == PlayBehaviour_SingleItem || PlayBehaviour_UseSongLoader);
return (pb == PlayBehaviour_MultipleItems || pb == PlayBehaviour_SingleItem ||
pb == PlayBehaviour_UseSongLoader);
}
QStringList InternetModel::mimeTypes() const {
@ -218,7 +219,7 @@ QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
continue;
last_valid_index = index;
if (index.data(Role_Type).toInt() == Type_UserPlaylist) {
if (index.data(Role_PlayBehaviour).toInt() == PlayBehaviour_MultipleItems) {
// Get children
int row = 0;
int column = 0;

View File

@ -107,6 +107,11 @@ public:
// the user starts playing.
PlayBehaviour_SingleItem,
// This item's children have PlayBehaviour_SingleItem set.
// This is used when dragging a playlist item for instance, to have all the
// playlit's items info loaded in the mime data.
PlayBehaviour_MultipleItems,
// This item might not represent a song - the service's ItemDoubleClicked()
// slot will get called instead to do some custom action.
PlayBehaviour_DoubleClickAction,

View File

@ -344,20 +344,26 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
search_->setToolTip(tr("Start typing something on the search box above to "
"fill this search results list"));
search_->setData(Type_SearchResults, InternetModel::Role_Type);
search_->setData(InternetModel::PlayBehaviour_DoubleClickAction,
search_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
starred_ = new QStandardItem(QIcon(":/star-on.png"), tr("Starred"));
starred_->setData(Type_StarredPlaylist, InternetModel::Role_Type);
starred_->setData(true, InternetModel::Role_CanLazyLoad);
starred_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
inbox_ = new QStandardItem(IconLoader::Load("mail-message"), tr("Inbox"));
inbox_->setData(Type_InboxPlaylist, InternetModel::Role_Type);
inbox_->setData(true, InternetModel::Role_CanLazyLoad);
inbox_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
toplist_ = new QStandardItem(QIcon(), tr("Top tracks"));
toplist_->setData(Type_Toplist, InternetModel::Role_Type);
toplist_->setData(true, InternetModel::Role_CanLazyLoad);
toplist_->setData(InternetModel::PlayBehaviour_MultipleItems,
InternetModel::Role_PlayBehaviour);
root_->appendRow(search_);
root_->appendRow(toplist_);
@ -384,7 +390,7 @@ void SpotifyService::PlaylistsUpdated(const pb::spotify::Playlists& response) {
item->setData(InternetModel::Type_UserPlaylist, InternetModel::Role_Type);
item->setData(true, InternetModel::Role_CanLazyLoad);
item->setData(msg.index(), Role_UserPlaylistIndex);
item->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
item->setData(InternetModel::PlayBehaviour_MultipleItems, InternetModel::Role_PlayBehaviour);
root_->appendRow(item);
playlists_ << item;