File indexing completed on 2024-05-12 16:18:06

0001 /***************************************************************************
0002  *   Copyright (C) 2010 Ralf Engels <ralf-engels@gmx.de>                  *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #include "Playlist.h"
0021 #include "utils.h"
0022 
0023 #include <QDir>
0024 #include <QXmlStreamReader>
0025 #include <QXmlStreamWriter>
0026 
0027 CollectionScanner::Playlist::Playlist( const QString &path )
0028 {
0029     m_path = path;
0030     m_rpath = QDir::current().relativeFilePath( path );
0031 }
0032 
0033 CollectionScanner::Playlist::Playlist( QXmlStreamReader *reader )
0034 {
0035    while (!reader->atEnd()) {
0036         reader->readNext();
0037 
0038         if( reader->isStartElement() )
0039         {
0040             if( reader->name() == QLatin1String("path") )
0041                 m_path = reader->readElementText();
0042             else if( reader->name() == QLatin1String("rpath") )
0043                 m_rpath = reader->readElementText();
0044             else
0045                 reader->readElementText(); // just read over the element
0046         }
0047 
0048         else if( reader->isEndElement() )
0049         {
0050             break;
0051         }
0052     }
0053 }
0054 
0055 QString
0056 CollectionScanner::Playlist::path() const
0057 {
0058     return m_path;
0059 }
0060 
0061 QString
0062 CollectionScanner::Playlist::rpath() const
0063 {
0064     return m_rpath;
0065 }
0066 
0067 void
0068 CollectionScanner::Playlist::toXml( QXmlStreamWriter *writer ) const
0069 {
0070     writer->writeTextElement( QStringLiteral("path"), escapeXml10(m_path) );
0071     writer->writeTextElement( QStringLiteral("rpath"), escapeXml10(m_rpath) );
0072 }