File indexing completed on 2024-05-12 04:55:36
0001 /** 0002 * \file musicbrainzclient.h 0003 * MusicBrainz client. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 15 Sep 2005 0008 * 0009 * Copyright (C) 2005-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QObject> 0030 #include "servertrackimporter.h" 0031 #include "trackdata.h" 0032 0033 class QByteArray; 0034 class FingerprintCalculator; 0035 0036 /** 0037 * MusicBrainz client. 0038 */ 0039 class MusicBrainzClient : public ServerTrackImporter { 0040 Q_OBJECT 0041 public: 0042 /** 0043 * Constructor. 0044 * 0045 * @param netMgr network access manager 0046 * @param trackDataModel track data to be filled with imported values, 0047 * is passed with filenames set 0048 */ 0049 MusicBrainzClient(QNetworkAccessManager* netMgr, 0050 TrackDataModel* trackDataModel); 0051 0052 /** 0053 * Destructor. 0054 */ 0055 ~MusicBrainzClient() override = default; 0056 0057 /** 0058 * Name of import source. 0059 * @return name. 0060 */ 0061 const char* name() const override; 0062 0063 /** NULL-terminated array of server strings, 0 if not used */ 0064 const char** serverList() const override; 0065 0066 /** default server, 0 to disable */ 0067 const char* defaultServer() const override; 0068 0069 /** anchor to online help, 0 to disable */ 0070 const char* helpAnchor() const override; 0071 0072 /** configuration, 0 if not used */ 0073 ServerImporterConfig* config() const override; 0074 0075 /** 0076 * Set configuration. 0077 * 0078 * @param cfg import server configuration, 0 if not used 0079 */ 0080 void setConfig(const ServerImporterConfig* cfg) override; 0081 0082 /** 0083 * Add the files in the file list. 0084 */ 0085 void start() override; 0086 0087 /** 0088 * Reset the client state. 0089 */ 0090 void stop() override; 0091 0092 private slots: 0093 void receiveBytes(const QByteArray& bytes); 0094 0095 void receiveFingerprint(const QString& fingerprint, int duration, int error); 0096 0097 private: 0098 enum State { 0099 Idle, 0100 CalculatingFingerprint, 0101 GettingIds, 0102 GettingMetadata 0103 }; 0104 0105 bool verifyIdIndex(); 0106 bool verifyTrackIndex(); 0107 void processNextStep(); 0108 void processNextTrack(); 0109 0110 FingerprintCalculator* m_fingerprintCalculator; 0111 State m_state; 0112 QVector<QString> m_filenameOfTrack; 0113 QVector<QStringList> m_idsOfTrack; 0114 int m_currentIndex; 0115 ImportTrackDataVector m_currentTrackData; 0116 QMap<QByteArray, QByteArray> m_headers; 0117 };