void SpotifyService::SearchResults( const pb::spotify::SearchResponse& response) { if (QStringFromStdString(response.request().query()) != pending_search_) { qLog(Debug) << "Old search result for" << QStringFromStdString(response.request().query()) << "expecting" << pending_search_; return; } pending_search_.clear(); SongList songs; for (int i = 0; i < response.result_size(); ++i) { Song song; SongFromProtobuf(response.result(i), &song); songs << song; } qLog(Debug) << "Got" << songs.count() << "results"; ClearSearchResults(); // Fill results list for (const Song& song : songs) { QStandardItem* child = CreateSongItem(song); search_->appendRow(child); } const QString did_you_mean_suggestion = QStringFromStdString(response.did_you_mean()); qLog(Debug) << "Did you mean suggestion: " << did_you_mean_suggestion; if (!did_you_mean_suggestion.isEmpty()) { search_box_->did_you_mean()->Show(did_you_mean_suggestion); } else { // In case something else was previously displayed search_box_->did_you_mean()->hide(); } QModelIndex index = model()->merged_model()->mapFromSource(search_->index()); ScrollToIndex(index); }
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_); }
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_); }