コード例 #1
0
void UrlSearchProvider::SearchAsync(int id, const QString& query) {
  Result result(this);
  result.group_automatically_ = false;
  result.metadata_.set_url(QUrl::fromUserInput(query));
  result.metadata_.set_title(result.metadata_.url().toString());
  result.metadata_.set_filetype(Song::Type_Stream);

  emit ResultsAvailable(id, ResultList() << result);
}
コード例 #2
0
ファイル: searchprovider.cpp プロジェクト: Gu1/Clementine
void BlockingSearchProvider::BlockingSearchFinished() {
  BoundFutureWatcher<ResultList, int>* watcher =
      static_cast<BoundFutureWatcher<ResultList, int>*>(sender());
  watcher->deleteLater();

  const int id = watcher->data();
  emit ResultsAvailable(id, watcher->result());
  emit SearchFinished(id);
}
コード例 #3
0
void SoundCloudSearchProvider::SearchDone(int id, const SongList& songs) {
  // Map back to the original id.
  const PendingState state = pending_searches_.take(id);
  const int global_search_id = state.orig_id_;

  ResultList ret;
  for (const Song& song : songs) {
    Result result(this);
    result.metadata_ = song;

    ret << result;
  }

  emit ResultsAvailable(global_search_id, ret);
  MaybeSearchFinished(global_search_id);
}
コード例 #4
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_);
}
コード例 #5
0
void GlobalSearch::ResultsAvailableSlot(int id,
                                        SearchProvider::ResultList results) {
  if (results.isEmpty()) return;

  // Limit the number of results that are used from each emission.
  // Just a sanity check to stop some providers (Jamendo) returning thousands
  // of results.
  if (results.count() > kMaxResultsPerEmission) {
    SearchProvider::ResultList::iterator begin = results.begin();
    std::advance(begin, kMaxResultsPerEmission);
    results.erase(begin, results.end());
  }

  // Load cached pixmaps into the results
  for (SearchProvider::ResultList::iterator it = results.begin();
       it != results.end(); ++it) {
    it->pixmap_cache_key_ = PixmapCacheKey(*it);
  }

  emit ResultsAvailable(id, results);
}
コード例 #6
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_);
}