예제 #1
0
QMimeData* LibraryModel::mimeData(const QModelIndexList& indexes) const {
  if (indexes.isEmpty()) return nullptr;

  // Special case: a smart playlist was dragged
  if (IndexToItem(indexes.first())->type == LibraryItem::Type_SmartPlaylist) {
    GeneratorPtr generator = CreateGenerator(indexes.first());
    if (!generator) return nullptr;

    GeneratorMimeData* data = new GeneratorMimeData(generator);
    data->setData(kSmartPlaylistsMimeType, QByteArray());
    data->name_for_new_playlist_ = this->data(indexes.first()).toString();
    return data;
  }

  SongMimeData* data = new SongMimeData;
  QList<QUrl> urls;
  QSet<int> song_ids;

  data->backend = backend_;

  for (const QModelIndex& index : indexes) {
    GetChildSongs(IndexToItem(index), &urls, &data->songs, &song_ids);
  }

  data->setUrls(urls);
  data->name_for_new_playlist_ =
      PlaylistManager::GetNameForNewPlaylist(data->songs);

  return data;
}
예제 #2
0
QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
  // Special case for when the user double clicked on a special item.
  if (indexes.count() == 1 &&
      indexes[0].data(Role_PlayBehaviour).toInt() ==
          PlayBehaviour_DoubleClickAction) {
    InternetModel::ServiceForIndex(indexes[0])
        ->ItemDoubleClicked(itemFromIndex(indexes[0]));
    return nullptr;
  }

  if (indexes.count() == 1 &&
      indexes[0].data(Role_Type).toInt() == Type_SmartPlaylist) {
    GeneratorPtr generator = InternetModel::ServiceForIndex(indexes[0])
                                 ->CreateGenerator(itemFromIndex(indexes[0]));
    if (!generator) return nullptr;
    GeneratorMimeData* data = new GeneratorMimeData(generator);
    data->setData(LibraryModel::kSmartPlaylistsMimeType, QByteArray());
    data->name_for_new_playlist_ = this->data(indexes.first()).toString();
    return data;
  }

  QList<QUrl> urls;
  QModelIndexList new_indexes;

  QModelIndex last_valid_index;
  for (const QModelIndex& index : indexes) {
    if (!IsPlayable(index)) continue;

    last_valid_index = index;
    if (index.data(Role_PlayBehaviour).toInt() == PlayBehaviour_MultipleItems) {
      // Get children
      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 << index.data(Role_Url).toUrl();
    }
  }

  if (urls.isEmpty()) return nullptr;

  InternetMimeData* data = new InternetMimeData(this);
  data->setUrls(urls);
  data->indexes = new_indexes;
  data->name_for_new_playlist_ =
      InternetModel::ServiceForIndex(last_valid_index)->name();

  return data;
}
예제 #3
0
QMimeData* InternetModel::mimeData(const QModelIndexList& indexes) const {
  // Special case for when the user double clicked on a special item.
  if (indexes.count() == 1 &&
      indexes[0].data(Role_PlayBehaviour).toInt() ==
          PlayBehaviour_DoubleClickAction) {
    InternetModel::ServiceForIndex(indexes[0])->ItemDoubleClicked(itemFromIndex(indexes[0]));
    return NULL;
  }

  if (indexes.count() == 1 &&
      indexes[0].data(Role_Type).toInt() == Type_SmartPlaylist) {
    GeneratorPtr generator =
        InternetModel::ServiceForIndex(indexes[0])->CreateGenerator(itemFromIndex(indexes[0]));
    if (!generator)
      return NULL;
    GeneratorMimeData* data = new GeneratorMimeData(generator);
    data->setData(LibraryModel::kSmartPlaylistsMimeType, QByteArray());
    data->name_for_new_playlist_ = this->data(indexes.first()).toString();
    return data;
  }

  QList<QUrl> urls;
  QModelIndexList new_indexes;

  QModelIndex last_valid_index;
  foreach (const QModelIndex& index, indexes) {
    if (!IsPlayable(index))
      continue;

    last_valid_index = index;
    if (index.data(Role_Type).toInt() == Type_UserPlaylist) {
      // Get children
      int row = 0;
      int column = 0;
      QModelIndex child = index.child(row, column);
      while (child.isValid()) {
        // If the playlist contains another playlist, expand it
        if (child.data(Role_Type).toInt() == Type_UserPlaylist) {
          // "List" of indexes to recurse on
          QModelIndexList templist;
          templist.append(child);
          // We know this is going to be an InternetMimeData because we're calling
          // ourselves with something that we always return InternetMimeData for!
          InternetMimeData* recurse = qobject_cast<InternetMimeData*>(mimeData(templist));
          // Add children if there were any
          if (recurse) {
            new_indexes.append(recurse->indexes);
            urls.append(recurse->urls());
            delete recurse;
          }
        } else {
          new_indexes << child;
          urls << child.data(Role_Url).toUrl();
        }
        child = index.child(++row, column);
      }
    } else {
      new_indexes = indexes;
      urls << index.data(Role_Url).toUrl();
    }
  }

  if (urls.isEmpty())
    return NULL;

  InternetMimeData* data = new InternetMimeData(this);
  data->setUrls(urls);
  data->indexes = new_indexes;
  data->name_for_new_playlist_ = InternetModel::ServiceForIndex(last_valid_index)->name();

  return data;
}