/* * Strawberry Music Player * Copyright 2018, Jonas Kvinge * * Strawberry is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Strawberry is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Strawberry. If not, see . * */ #ifndef LYRICSFETCHER_H #define LYRICSFETCHER_H #include "config.h" #include #include #include #include #include #include #include #include #include class QTimer; class LyricsProviders; class LyricsFetcherSearch; struct LyricsSearchRequest { explicit LyricsSearchRequest() : id(-1) {} quint64 id; QString artist; QString album; QString title; }; struct LyricsSearchResult { explicit LyricsSearchResult() : score(0.0) {} QString provider; QString artist; QString album; QString title; QString lyrics; float score; }; typedef QList LyricsSearchResults; Q_DECLARE_METATYPE(LyricsSearchResult) Q_DECLARE_METATYPE(QList) class LyricsFetcher : public QObject { Q_OBJECT public: explicit LyricsFetcher(LyricsProviders *lyrics_providers, QObject *parent = nullptr); virtual ~LyricsFetcher() {} quint64 Search(const QString &artist, const QString &album, const QString &title); void Clear(); private: void AddRequest(const LyricsSearchRequest &req); signals: void LyricsFetched(const quint64 request_id, const QString &provider, const QString &lyrics); void SearchFinished(const quint64 request_id, const LyricsSearchResults &results); private slots: void SingleSearchFinished(const quint64 request_id, const LyricsSearchResults &results); void SingleLyricsFetched(const quint64 request_id, const QString &provider, const QString &lyrics); void StartRequests(); private: static const int kMaxConcurrentRequests; LyricsProviders *lyrics_providers_; quint64 next_id_; QQueue queued_requests_; QHash active_requests_; QTimer *request_starter_; }; #endif // LYRICSFETCHER_H