File indexing completed on 2024-05-05 04:48:36
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef MUSICDNSFINDER_H 0018 #define MUSICDNSFINDER_H 0019 0020 #include "Version.h" 0021 #include "core/meta/forward_declarations.h" 0022 #include "musicbrainz/MusicDNSAudioDecoder.h" 0023 #include "musicbrainz/MusicDNSXmlParser.h" 0024 #include "network/NetworkAccessManagerProxy.h" 0025 0026 #include <QTimer> 0027 #include <ThreadWeaver/Job> 0028 0029 #define AMAROK_MUSICDNS_CLIENT_ID "0c6019606b1d8a54d0985e448f3603ca" 0030 0031 class MusicDNSFinder: public QObject 0032 { 0033 Q_OBJECT 0034 public: 0035 explicit MusicDNSFinder( QObject *parent = nullptr, 0036 const QString &host = "ofa.musicdns.org", 0037 const int port = 80, 0038 const QString &pathPrefix = "/ofa/1", 0039 const QString &clietnId = AMAROK_MUSICDNS_CLIENT_ID, 0040 const QString &clientVersion = AMAROK_VERSION ); 0041 public Q_SLOTS: 0042 void run( const Meta::TrackList &tracks ); 0043 0044 Q_SIGNALS: 0045 void trackFound( const Meta::TrackPtr &track, const QString &puid ); 0046 void progressStep(); 0047 void done(); 0048 0049 private Q_SLOTS: 0050 0051 void sendNewRequest(); 0052 void gotReply( QNetworkReply *reply ); 0053 void replyError( QNetworkReply::NetworkError code ); 0054 0055 void trackDecoded( const Meta::TrackPtr track, const QString fingerprint ); 0056 void decodingDone( ThreadWeaver::JobPointer _decoder ); 0057 0058 void parsingDone( ThreadWeaver::JobPointer _parser ); 0059 0060 private: 0061 QNetworkRequest compileRequest( const QString &fingerprint, const Meta::TrackPtr track ); 0062 void checkDone(); 0063 0064 QString mdns_host; 0065 int mdns_port; 0066 QString mdns_pathPrefix; 0067 QString mdns_clientId; 0068 QString mdns_clientVersion; 0069 0070 QNetworkAccessManager *net; 0071 QList < QPair < Meta::TrackPtr, QNetworkRequest > > m_requests; 0072 QMap < QNetworkReply *, Meta::TrackPtr > m_replyes; 0073 0074 QMap < MusicDNSXmlParser *, Meta::TrackPtr > m_parsers; 0075 0076 bool decodingComplete; 0077 0078 QTimer *_timer; 0079 }; 0080 0081 #endif // MUSICDNSFINDER_H