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 #define DEBUG_PREFIX "MusicDNSXmlParser" 0018 0019 #include "MusicDNSXmlParser.h" 0020 0021 #include "core/support/Debug.h" 0022 0023 MusicDNSXmlParser::MusicDNSXmlParser( QString &doc ) 0024 : QObject() 0025 , ThreadWeaver::Job() 0026 , m_doc( "musicdns" ) 0027 { 0028 m_doc.setContent( doc ); 0029 } 0030 0031 void 0032 MusicDNSXmlParser::run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) 0033 { 0034 Q_UNUSED(self); 0035 Q_UNUSED(thread); 0036 DEBUG_BLOCK 0037 QDomElement docElem = m_doc.documentElement(); 0038 parseElement( docElem ); 0039 } 0040 0041 void 0042 MusicDNSXmlParser::defaultBegin(const ThreadWeaver::JobPointer& self, ThreadWeaver::Thread *thread) 0043 { 0044 Q_EMIT started(self); 0045 ThreadWeaver::Job::defaultBegin(self, thread); 0046 } 0047 0048 void 0049 MusicDNSXmlParser::defaultEnd(const ThreadWeaver::JobPointer& self, ThreadWeaver::Thread *thread) 0050 { 0051 ThreadWeaver::Job::defaultEnd(self, thread); 0052 if (!self->success()) { 0053 Q_EMIT failed(self); 0054 } 0055 Q_EMIT done(self); 0056 } 0057 0058 QStringList 0059 MusicDNSXmlParser::puid() 0060 { 0061 return ( m_puid.isEmpty() )?m_puid << "00000000-0000-0000-0000-000000000000":m_puid; 0062 } 0063 0064 void 0065 MusicDNSXmlParser::parseElement( const QDomElement &e ) 0066 { 0067 QString elementName = e.tagName(); 0068 if( elementName == "track" ) 0069 parseTrack( e ); 0070 else 0071 parseChildren( e ); 0072 } 0073 0074 void 0075 MusicDNSXmlParser::parseChildren( const QDomElement &e ) 0076 { 0077 QDomNode child = e.firstChild(); 0078 while( !child.isNull() ) 0079 { 0080 if( child.isElement() ) 0081 parseElement( child.toElement() ); 0082 child = child.nextSibling(); 0083 } 0084 } 0085 0086 void 0087 MusicDNSXmlParser::parseTrack( const QDomElement &e ) 0088 { 0089 QDomNode dNode = e.firstChild(); 0090 QDomElement dElement; 0091 0092 while( !dNode.isNull() ) 0093 { 0094 if( dNode.isElement() ) 0095 { 0096 dElement = dNode.toElement(); 0097 0098 if( dElement.tagName() == "puid-list" ) 0099 parsePUIDList( dElement ); 0100 } 0101 dNode = dNode.nextSibling(); 0102 } 0103 } 0104 0105 void 0106 MusicDNSXmlParser::parsePUIDList( const QDomElement &e ) 0107 { 0108 QDomNode dNode = e.firstChild(); 0109 QDomElement dElement; 0110 0111 while( !dNode.isNull() ) 0112 { 0113 if( dNode.isElement() ) 0114 { 0115 dElement = dNode.toElement(); 0116 0117 if( dElement.tagName() == "puid" ) 0118 parsePUID( dElement ); 0119 } 0120 dNode = dNode.nextSibling(); 0121 } 0122 } 0123 0124 void 0125 MusicDNSXmlParser::parsePUID( const QDomElement &e ) 0126 { 0127 if( e.hasAttribute( "id" ) ) 0128 { 0129 QString id = e.attribute( "id" ); 0130 if( id.isEmpty() ) 0131 return; 0132 m_puid << id; 0133 } 0134 }