Make Grooveshark playlists drag'n'drop possible

This commit is contained in:
Arnaud Bienner 2011-10-14 00:10:18 +02:00
parent b3b890b9cf
commit 03e30d19c4
2 changed files with 20 additions and 4 deletions

View File

@ -402,6 +402,7 @@ void GroovesharkService::ResetSessionId() {
void GroovesharkService::ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {
EnsureMenuCreated();
context_menu_->popup(global_pos);
context_item_ = index;
}
QModelIndex GroovesharkService::GetCurrentIndex() {
@ -423,8 +424,7 @@ void GroovesharkService::EnsureMenuCreated() {
}
void GroovesharkService::EnsureItemsCreated() {
if (!session_id_.isEmpty() /* only if user is authenticated */ &&
!search_) {
if (IsLoggedIn() && !search_) {
search_ = new QStandardItem(IconLoader::Load("edit-find"),
tr("Search Grooveshark (opens a new tab)"));
search_->setData(Type_SearchResults, InternetModel::Role_Type);
@ -490,6 +490,7 @@ void GroovesharkService::PlaylistSongsRetrieved() {
QStandardItem* item = new QStandardItem(playlist_info.name_);
item->setData(Type_UserPlaylist, InternetModel::Role_Type);
item->setData(true, InternetModel::Role_CanLazyLoad);
item->setData(InternetModel::PlayBehaviour_SingleItem, InternetModel::Role_PlayBehaviour);
QVariantMap result = ExtractResult(reply);
SongList songs = ExtractSongs(result);

View File

@ -199,6 +199,7 @@ QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
}
QList<QUrl> urls;
QModelIndexList new_indexes;
QModelIndex last_valid_index;
foreach (const QModelIndex& index, indexes) {
@ -206,7 +207,21 @@ QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
continue;
last_valid_index = index;
urls << index.data(Role_Url).toUrl();
QUrl url = index.data(Role_Url).toUrl();
if (url.isEmpty()) {
// If this particular item has nothing, check if its children have something
int row = 0;
int column = 0;
QModelIndex child = index.child(row, column);
while (child.isValid()) {
new_indexes << child;
urls << child.data(Role_Url).toUrl();
child = index.child(++row, column);
}
} else {
new_indexes = indexes;
urls << url;
}
}
if (urls.isEmpty())
@ -214,7 +229,7 @@ QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
InternetMimeData* data = new InternetMimeData(this);
data->setUrls(urls);
data->indexes = indexes;
data->indexes = new_indexes;
data->name_for_new_playlist_ = InternetModel::ServiceForIndex(last_valid_index)->name();
return data;