strawberry-audio-player-win.../src/musicbrainz/acoustidclient.h

76 lines
2.6 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
2018-02-27 18:06:05 +01:00
*
* 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 <http://www.gnu.org/licenses/>.
2018-08-09 18:39:44 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef ACOUSTIDCLIENT_H
#define ACOUSTIDCLIENT_H
#include "config.h"
#include <QObject>
#include <QMap>
#include <QString>
#include <QStringList>
2018-02-27 18:06:05 +01:00
#include "core/shared_ptr.h"
2020-02-09 02:29:35 +01:00
class QNetworkReply;
2020-12-09 18:39:37 +01:00
class NetworkAccessManager;
2018-02-27 18:06:05 +01:00
class NetworkTimeouts;
class AcoustidClient : public QObject {
Q_OBJECT
// Gets a MBID from a Chromaprint fingerprint.
2018-10-02 00:46:54 +02:00
// A fingerprint identifies one particular encoding of a song and is created by Fingerprinter.
// An MBID identifies the actual song and can be passed to Musicbrainz to get metadata.
2018-02-27 18:06:05 +01:00
// You can create one AcoustidClient and make multiple requests using it.
// IDs are provided by the caller when a request is started and included in the Finished signal - they have no meaning to AcoustidClient.
2018-02-27 18:06:05 +01:00
public:
explicit AcoustidClient(SharedPtr<NetworkAccessManager> network, QObject *parent = nullptr);
2020-06-15 21:55:05 +02:00
~AcoustidClient() override;
2018-02-27 18:06:05 +01:00
// Network requests will be aborted after this interval.
void SetTimeout(const int msec);
2018-02-27 18:06:05 +01:00
// Starts a request and returns immediately. Finished() will be emitted later with the same ID.
void Start(const int id, const QString &fingerprint, int duration_msec);
2018-02-27 18:06:05 +01:00
// Cancels the request with the given ID. Finished() will never be emitted for that ID. Does nothing if there is no request with the given ID.
void Cancel(const int id);
2018-02-27 18:06:05 +01:00
// Cancels all requests. Finished() will never be emitted for any pending requests.
2018-02-27 18:06:05 +01:00
void CancelAll();
signals:
void Finished(const int id, const QStringList &mbid_list, const QString &error = QString());
2018-02-27 18:06:05 +01:00
private slots:
void RequestFinished(QNetworkReply *reply, const int id);
2018-02-27 18:06:05 +01:00
private:
SharedPtr<NetworkAccessManager> network_;
2018-02-27 18:06:05 +01:00
NetworkTimeouts *timeouts_;
QMap<int, QNetworkReply*> requests_;
};
#endif // ACOUSTIDCLIENT_H