예제 #1
0
void SpotifySearchProvider::SearchFinishedSlot(const pb::spotify::SearchResponse& response) {
  QString query_string = QString::fromUtf8(response.request().query().c_str());
  QMap<QString, PendingState>::iterator it = queries_.find(query_string);
  if (it == queries_.end())
    return;

  PendingState state = it.value();
  queries_.erase(it);

  ResultList ret;
  for (int i=0; i < response.result_size() ; ++i) {
    const pb::spotify::Track& track = response.result(i);

    Result result(this);
    result.type_ = globalsearch::Type_Track;
    SpotifyService::SongFromProtobuf(track, &result.metadata_);
    result.match_quality_ = MatchQuality(state.tokens_, result.metadata_.title());

    ret << result;
  }

  for (int i=0 ; i<response.album_size() ; ++i) {
    const pb::spotify::Album& album = response.album(i);

    Result result(this);
    result.type_ = globalsearch::Type_Album;
    SpotifyService::SongFromProtobuf(album.metadata(), &result.metadata_);
    result.match_quality_ =
        qMin(MatchQuality(state.tokens_, result.metadata_.album()),
             MatchQuality(state.tokens_, result.metadata_.artist()));
    result.album_size_ = album.metadata().track();

    for (int j=0; j < album.track_size() ; ++j) {
      Song track_song;
      SpotifyService::SongFromProtobuf(album.track(j), &track_song);
      result.album_songs_ << track_song;
    }

    ret << result;
  }

  emit ResultsAvailable(state.orig_id_, ret);
  emit SearchFinished(state.orig_id_);
}
예제 #2
0
void SpotifySearchProvider::SearchFinishedSlot(const pb::spotify::SearchResponse& response) {
  QString query_string = QString::fromUtf8(response.request().query().c_str());
  QMap<QString, PendingState>::iterator it = queries_.find(query_string);
  if (it == queries_.end())
    return;

  PendingState state = it.value();
  queries_.erase(it);

  ResultList ret;
  for (int i=0; i < response.result_size() ; ++i) {
    const pb::spotify::Track& track = response.result(i);

    Result result(this);
    SpotifyService::SongFromProtobuf(track, &result.metadata_);

    ret << result;
  }

  for (int i=0 ; i<response.album_size() ; ++i) {
    const pb::spotify::Album& album = response.album(i);

    for (int j=0; j < album.track_size() ; ++j) {
      Result result(this);
      SpotifyService::SongFromProtobuf(album.track(j), &result.metadata_);

      // Just use the album index as an id.
      result.metadata_.set_album_id(i);

      ret << result;
    }
  }

  emit ResultsAvailable(state.orig_id_, ret);
  emit SearchFinished(state.orig_id_);
}