2010-10-02 18:23:33 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-02 18:23:33 +02:00
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
#ifndef SONGINFOFETCHER_H
|
|
|
|
#define SONGINFOFETCHER_H
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-10-09 15:34:28 +02:00
|
|
|
#include <QMap>
|
2010-10-02 18:23:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
|
2010-10-09 14:39:49 +02:00
|
|
|
#include "collapsibleinfopane.h"
|
2010-10-10 18:09:20 +02:00
|
|
|
#include "core/song.h"
|
2010-10-09 14:39:49 +02:00
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
class SongInfoProvider;
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
class SongInfoFetcher : public QObject {
|
2010-10-02 18:23:33 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
SongInfoFetcher(QObject* parent = nullptr);
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-10-09 15:34:28 +02:00
|
|
|
struct Result {
|
|
|
|
QList<QUrl> images_;
|
|
|
|
QList<CollapsibleInfoPane::Data> info_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
static const int kDefaultTimeoutDuration = 25000; // msec
|
2010-12-19 14:58:53 +01:00
|
|
|
|
2010-10-10 18:09:20 +02:00
|
|
|
void AddProvider(SongInfoProvider* provider);
|
|
|
|
int FetchInfo(const Song& metadata);
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-10-10 18:46:35 +02:00
|
|
|
QList<SongInfoProvider*> providers() const { return providers_; }
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2014-02-07 16:34:20 +01:00
|
|
|
void InfoResultReady(int id, const CollapsibleInfoPane::Data& data);
|
2010-10-10 18:09:20 +02:00
|
|
|
void ResultReady(int id, const SongInfoFetcher::Result& result);
|
2010-10-09 15:34:28 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2010-10-02 18:23:33 +02:00
|
|
|
void ImageReady(int id, const QUrl& url);
|
2010-10-09 15:34:28 +02:00
|
|
|
void InfoReady(int id, const CollapsibleInfoPane::Data& data);
|
|
|
|
void ProviderFinished(int id);
|
2010-12-19 14:58:53 +01:00
|
|
|
void Timeout(int id);
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2010-10-10 18:09:20 +02:00
|
|
|
QList<SongInfoProvider*> providers_;
|
2010-10-02 18:23:33 +02:00
|
|
|
|
2010-10-09 15:34:28 +02:00
|
|
|
QMap<int, Result> results_;
|
2020-09-18 16:15:19 +02:00
|
|
|
QMap<int, QList<SongInfoProvider*>> waiting_for_;
|
2010-12-19 14:58:53 +01:00
|
|
|
QMap<int, QTimer*> timeout_timers_;
|
|
|
|
|
|
|
|
int timeout_duration_;
|
2010-10-09 15:34:28 +02:00
|
|
|
|
2010-10-02 18:23:33 +02:00
|
|
|
int next_id_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // SONGINFOFETCHER_H
|