2011-03-12 22:19:41 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-06 17:51:27 +01:00
|
|
|
#ifndef ACOUSTIDCLIENT_H
|
|
|
|
#define ACOUSTIDCLIENT_H
|
2011-03-12 22:19:41 +01:00
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
#include <QObject>
|
|
|
|
|
2011-03-13 14:17:35 +01:00
|
|
|
class NetworkTimeouts;
|
|
|
|
|
2011-03-12 22:19:41 +01:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
|
2012-01-06 17:51:27 +01:00
|
|
|
class AcoustidClient : public QObject {
|
2011-03-12 22:19:41 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2012-01-06 17:31:29 +01:00
|
|
|
// Gets a MBID from a Chromaprint fingerprint.
|
2011-03-12 23:29:03 +01:00
|
|
|
// A fingerprint identifies one particular encoding of a song and is created
|
2012-01-06 17:31:29 +01:00
|
|
|
// by Fingerprinter. An MBID identifies the actual song and can be passed to
|
2011-03-12 23:29:03 +01:00
|
|
|
// Musicbrainz to get metadata.
|
2012-01-06 17:51:27 +01:00
|
|
|
// You can create one AcoustidClient and make multiple requests using it.
|
2011-03-12 23:29:03 +01:00
|
|
|
// IDs are provided by the caller when a request is started and included in
|
2012-01-06 17:51:27 +01:00
|
|
|
// the Finished signal - they have no meaning to AcoustidClient.
|
2011-03-12 23:29:03 +01:00
|
|
|
|
2011-03-12 22:19:41 +01:00
|
|
|
public:
|
2012-01-06 17:51:27 +01:00
|
|
|
AcoustidClient(QObject* parent = 0);
|
2011-03-12 22:19:41 +01:00
|
|
|
|
2011-03-13 14:17:35 +01:00
|
|
|
// Network requests will be aborted after this interval.
|
|
|
|
void SetTimeout(int msec);
|
|
|
|
|
2011-03-12 23:29:03 +01:00
|
|
|
// Starts a request and returns immediately. Finished() will be emitted
|
|
|
|
// later with the same ID.
|
2011-03-12 22:19:41 +01:00
|
|
|
void Start(int id, const QString& fingerprint, int duration_msec);
|
2011-03-12 23:29:03 +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.
|
2011-03-12 22:19:41 +01:00
|
|
|
void Cancel(int id);
|
2011-03-12 23:29:03 +01:00
|
|
|
|
|
|
|
// Cancels all requests. Finished() will never be emitted for any pending
|
|
|
|
// requests.
|
2011-03-12 22:19:41 +01:00
|
|
|
void CancelAll();
|
|
|
|
|
|
|
|
signals:
|
2012-01-06 17:31:29 +01:00
|
|
|
void Finished(int id, const QString& mbid);
|
2011-03-12 22:19:41 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void RequestFinished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const char* kClientId;
|
|
|
|
static const char* kUrl;
|
2011-03-13 14:17:35 +01:00
|
|
|
static const int kDefaultTimeout;
|
2011-03-12 22:19:41 +01:00
|
|
|
|
|
|
|
QNetworkAccessManager* network_;
|
2011-03-13 14:17:35 +01:00
|
|
|
NetworkTimeouts* timeouts_;
|
2011-03-12 22:19:41 +01:00
|
|
|
QMap<QNetworkReply*, int> requests_;
|
|
|
|
};
|
|
|
|
|
2012-01-06 17:51:27 +01:00
|
|
|
#endif // ACOUSTIDCLIENT_H
|