diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-06-04 09:51:40 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-06-04 09:51:40 +0000 |
| commit | a4da0eb5e46e178d34a848b5fdb76dd8453510cd (patch) | |
| tree | 57edc1f26bfd1f58dcad71933aa5383b08e1d262 /src/plugins/PlaylistFormats/xspf | |
| parent | 5a1055301b485554ade9ce0555105cef4a58f50d (diff) | |
| download | qmmp-a4da0eb5e46e178d34a848b5fdb76dd8453510cd.tar.gz qmmp-a4da0eb5e46e178d34a848b5fdb76dd8453510cd.tar.bz2 qmmp-a4da0eb5e46e178d34a848b5fdb76dd8453510cd.zip | |
moved playlist formats support to plugins
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@397 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/PlaylistFormats/xspf')
| -rw-r--r-- | src/plugins/PlaylistFormats/xspf/CMakeLists.txt | 52 | ||||
| -rw-r--r-- | src/plugins/PlaylistFormats/xspf/xspf.pro | 28 | ||||
| -rw-r--r-- | src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp | 144 | ||||
| -rw-r--r-- | src/plugins/PlaylistFormats/xspf/xspfplaylistformat.h | 47 |
4 files changed, 271 insertions, 0 deletions
diff --git a/src/plugins/PlaylistFormats/xspf/CMakeLists.txt b/src/plugins/PlaylistFormats/xspf/CMakeLists.txt new file mode 100644 index 000000000..077d040bd --- /dev/null +++ b/src/plugins/PlaylistFormats/xspf/CMakeLists.txt @@ -0,0 +1,52 @@ +project(libxspfplaylistformat) + +cmake_minimum_required(VERSION 2.4.0) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +SET(QT_USE_QTXML TRUE) + +INCLUDE(FindQt4) +INCLUDE(${QT_USE_FILE}) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../../../ +) + +# libqmmpui +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmpui) + +SET(libxspfplaylistformat_SRCS + xspfplaylistformat.cpp +) + +SET(libxspfplaylistformat_MOC_HDRS + xspfplaylistformat.h +) + +QT4_ADD_RESOURCES(libxspfplaylistformat_RCC_SRCS ${libxspfplaylistformat_RCCS}) + +QT4_WRAP_CPP(libxspfplaylistformat_MOC_SRCS ${libxspfplaylistformat_MOC_HDRS}) + + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +ADD_LIBRARY(xspfplaylistformat SHARED ${libxspfplaylistformat_SRCS} ${libxspfplaylistformat_MOC_SRCS}) +target_link_libraries(xspfplaylistformat ${QT_LIBRARIES} -lqmmpui) +install(TARGETS xspfplaylistformat DESTINATION ${LIB_DIR}/qmmp/PlaylistFormats) diff --git a/src/plugins/PlaylistFormats/xspf/xspf.pro b/src/plugins/PlaylistFormats/xspf/xspf.pro new file mode 100644 index 000000000..6a2c036a6 --- /dev/null +++ b/src/plugins/PlaylistFormats/xspf/xspf.pro @@ -0,0 +1,28 @@ +include(../../plugins.pri) + +CONFIG += release \ +warn_on \ +plugin \ + lib + +TARGET =$$PLUGINS_PREFIX/PlaylistFormats/xspfplaylistformat +QMAKE_CLEAN =$$PLUGINS_PREFIX/PlaylistFormats/libxsplaylistformat.so + +TEMPLATE = lib +QMAKE_LIBDIR += ../../../../lib + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/PlayListFormats +INSTALLS += target + +INCLUDEPATH += ../../../../src + +LIBS += -lqmmpui + +QT += xml +SOURCES += xspfplaylistformat.cpp + +HEADERS += xspfplaylistformat.h + diff --git a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp new file mode 100644 index 000000000..6e7c9ab5f --- /dev/null +++ b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp @@ -0,0 +1,144 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QDomDocument> +#include <QDomElement> +#include <QFileInfo> +#include <QUrl> +#include <QtPlugin> + +#ifndef QMMP_STR_VERSION +#define QMMP_STR_VERSION "0.2.0" +#endif + +#include "xspfplaylistformat.h" + +// Needs more work - it's better use libSpiff there and put it as plugin. + +QStringList XSPFPlaylistFormat::decode(const QString & contents) +{ + QStringList out; + QDomDocument doc; + QString errorMsg; + int errorCol; + int errorRow; + bool ok = doc.setContent(contents, &errorMsg, &errorRow, &errorCol); + + if (!ok) + qDebug("Parse Error: %s\tRow:%d\tCol%d", + qPrintable(errorMsg), errorRow, errorCol ); + + QDomElement rootElement = doc.firstChildElement("playlist"); + if (rootElement.isNull()) + qWarning("Error parsing XSPF: can't find 'playlist' element"); + + QDomElement tracklistElement = rootElement.firstChildElement("trackList"); + if (tracklistElement.isNull()) + qWarning("Error parsing XSPF: can't find 'trackList' element"); + + QDomElement child = tracklistElement.firstChildElement("track"); + + while (!child.isNull()) + { + QString str = QUrl(child.firstChildElement("location").text()).toString(QUrl::RemoveScheme); + out << str; + child = child.nextSiblingElement(); + } + + return out; +} + +// Needs more work - it's better use libSpiff there and put it as plugin. + +QString XSPFPlaylistFormat::encode(const QList< SongInfo * > & files) +{ + QDomDocument doc; + QDomElement root = doc.createElement("playlist"); + root.setAttribute("version",QString("1")); + root.setAttribute("xmlns",QString("http://xspf.org/ns/0")); + + QDomElement creator = doc.createElement("creator"); + QDomText text = doc.createTextNode("qmmp-" + QString(QMMP_STR_VERSION)); + creator.appendChild(text); + root.appendChild(creator); + + QDomElement tracklist = doc.createElement("trackList"); + + int counter = 1; + foreach(SongInfo* f,files) + { + QDomElement track = doc.createElement("track"); + + QDomElement ch = doc.createElement("location"); + QDomText text = doc.createTextNode(/*QString("file://") + */QFileInfo(f->path()).absoluteFilePath()); + ch.appendChild(text); + track.appendChild(ch); + + ch = doc.createElement("title"); + text = doc.createTextNode(f->title()); + ch.appendChild(text); + track.appendChild(ch); + + ch = doc.createElement("trackNum"); + text = doc.createTextNode(QString::number(counter)); + ch.appendChild(text); + track.appendChild(ch); + + ch = doc.createElement("year"); + text = doc.createTextNode(QString::number(f->year())); + ch.appendChild(text); + track.appendChild(ch); + + tracklist.appendChild(track); + counter ++; + } + + root.appendChild(tracklist); + doc.appendChild( root ); + QString xml_header("<?xml version='1.0' encoding='UTF-8'?>\n"); + return doc.toString().prepend(xml_header); +} + +XSPFPlaylistFormat::XSPFPlaylistFormat() +{ + m_supported_formats << "xspf"; +} + +bool XSPFPlaylistFormat::hasFormat(const QString & f) +{ + foreach(QString s,m_supported_formats) + if (f == s) + return true; + + return false; +} + +QStringList XSPFPlaylistFormat::getExtensions() const +{ + return m_supported_formats; +} + + +QString XSPFPlaylistFormat::name() const +{ + return "XSPFPlaylistFormat"; +} + +Q_EXPORT_PLUGIN(XSPFPlaylistFormat) diff --git a/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.h b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.h new file mode 100644 index 000000000..f8774c868 --- /dev/null +++ b/src/plugins/PlaylistFormats/xspf/xspfplaylistformat.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef XSPFPLAYLISTFORMAT_H +#define XSPFPLAYLISTFORMAT_H + +#include <QObject> +#include <QString> +#include <QStringList> +#include <qmmpui/playlistformat.h> +#include <qmmpui/songinfo.h> + +/*! + * Class for XSPF playlist format parsing + */ +class XSPFPlaylistFormat : public QObject, public PlaylistFormat +{ + Q_OBJECT + Q_INTERFACES(PlaylistFormat) +public: + XSPFPlaylistFormat(); + virtual QStringList getExtensions()const; + virtual bool hasFormat(const QString&); + virtual QStringList decode(const QString& contents); + virtual QString encode(const QList<SongInfo*>& contents); + virtual QString name()const; +protected: + QStringList m_supported_formats; +}; + +#endif |
