File indexing completed on 2024-05-05 04:48:35

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com>                                 *
0003  * Copyright (c) 2013 Alberto Villa <avilla@FreeBSD.org>                                *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef MUSICBRAINZXMLPARSER_H
0019 #define MUSICBRAINZXMLPARSER_H
0020 
0021 #include <ThreadWeaver/Job>
0022 
0023 #include <QDomDocument>
0024 #include <QStringList>
0025 #include <QVariantMap>
0026 
0027 class MusicBrainzXmlParser : public QObject, public ThreadWeaver::Job
0028 {
0029     Q_OBJECT
0030 
0031     public:
0032         enum {
0033             TrackList,
0034             ReleaseGroup
0035         };
0036 
0037         explicit MusicBrainzXmlParser( const QString &doc );
0038 
0039         void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override;
0040 
0041         int type();
0042 
0043         QMap<QString, QVariantMap> tracks;
0044         QMap<QString, QString> artists;
0045         QMap<QString, QVariantMap> releases;
0046         QMap<QString, QVariantMap> releaseGroups;
0047 
0048     Q_SIGNALS:
0049         /** This signal is emitted when this job is being processed by a thread. */
0050         void started(ThreadWeaver::JobPointer);
0051         /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */
0052         void done(ThreadWeaver::JobPointer);
0053         /** This job has failed.
0054          * This signal is emitted when success() returns false after the job is executed. */
0055         void failed(ThreadWeaver::JobPointer);
0056 
0057     private:
0058         void parseElement( const QDomElement &e );
0059         void parseChildren( const QDomElement &e );
0060 
0061         QStringList parseRecordingList( const QDomElement &e );
0062         QString parseRecording( const QDomElement &e );
0063 
0064         QStringList parseReleaseList( const QDomElement &e );
0065         QString parseRelease( const QDomElement &e );
0066 
0067         QVariantMap parseMediumList( const QDomElement &e );
0068         QVariantMap parseMedium( const QDomElement &e );
0069         QVariantMap parseTrackList( const QDomElement &e );
0070         QVariantMap parseTrack( const QDomElement &e );
0071 
0072         QString parseReleaseGroup( const QDomElement &e );
0073 
0074         QStringList parseArtist( const QDomElement &e );
0075 
0076         QDomDocument m_doc;
0077 
0078         int m_type;
0079 
0080         QVariantMap m_currentTrackInfo;
0081 
0082     protected:
0083         void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0084         void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override;
0085 
0086 };
0087 
0088 #endif // MUSICBRAINZXMLPARSER_H