aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/plugins/CMakeLists.txt1
-rw-r--r--src/plugins/PlaylistFormats/CMakeLists.txt3
-rw-r--r--src/plugins/PlaylistFormats/PlaylistFormats.pro6
-rw-r--r--src/plugins/PlaylistFormats/m3u/CMakeLists.txt48
-rw-r--r--src/plugins/PlaylistFormats/m3u/m3u.pro27
-rw-r--r--src/plugins/PlaylistFormats/m3u/m3uplaylistformat.cpp89
-rw-r--r--src/plugins/PlaylistFormats/m3u/m3uplaylistformat.h47
-rw-r--r--src/plugins/PlaylistFormats/pls/CMakeLists.txt48
-rw-r--r--src/plugins/PlaylistFormats/pls/pls.pro27
-rw-r--r--src/plugins/PlaylistFormats/pls/plsplaylistformat.cpp103
-rw-r--r--src/plugins/PlaylistFormats/pls/plsplaylistformat.h47
-rw-r--r--src/plugins/PlaylistFormats/xspf/CMakeLists.txt52
-rw-r--r--src/plugins/PlaylistFormats/xspf/xspf.pro28
-rw-r--r--src/plugins/PlaylistFormats/xspf/xspfplaylistformat.cpp144
-rw-r--r--src/plugins/PlaylistFormats/xspf/xspfplaylistformat.h47
-rw-r--r--src/plugins/plugins.pro3
-rw-r--r--src/qmmpui/CMakeLists.txt3
-rw-r--r--src/qmmpui/playlistformat.h67
-rw-r--r--src/qmmpui/playlistparser.cpp101
-rw-r--r--src/qmmpui/playlistparser.h53
-rw-r--r--src/qmmpui/qmmpui.pro25
-rw-r--r--src/ui/CMakeLists.txt3
-rw-r--r--src/ui/addurldialog.cpp32
-rw-r--r--src/ui/mainwindow.cpp8
-rw-r--r--src/ui/playlistformat.cpp292
-rw-r--r--src/ui/playlistformat.h116
-rw-r--r--src/ui/playlistmodel.cpp104
-rw-r--r--src/ui/playlistmodel.h25
-rw-r--r--src/ui/ui.pro4
29 files changed, 1008 insertions, 545 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 9ab96dd16..cd8782700 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -3,3 +3,4 @@ add_subdirectory(Output)
add_subdirectory(Visual)
add_subdirectory(Effect)
add_subdirectory(General)
+add_subdirectory(PlaylistFormats)
diff --git a/src/plugins/PlaylistFormats/CMakeLists.txt b/src/plugins/PlaylistFormats/CMakeLists.txt
new file mode 100644
index 000000000..5fd89ff62
--- /dev/null
+++ b/src/plugins/PlaylistFormats/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_subdirectory(m3u)
+add_subdirectory(pls)
+add_subdirectory(xspf)
diff --git a/src/plugins/PlaylistFormats/PlaylistFormats.pro b/src/plugins/PlaylistFormats/PlaylistFormats.pro
new file mode 100644
index 000000000..f214cffff
--- /dev/null
+++ b/src/plugins/PlaylistFormats/PlaylistFormats.pro
@@ -0,0 +1,6 @@
+TEMPLATE = subdirs
+
+SUBDIRS += m3u pls xspf
+
+
+
diff --git a/src/plugins/PlaylistFormats/m3u/CMakeLists.txt b/src/plugins/PlaylistFormats/m3u/CMakeLists.txt
new file mode 100644
index 000000000..dc75d1140
--- /dev/null
+++ b/src/plugins/PlaylistFormats/m3u/CMakeLists.txt
@@ -0,0 +1,48 @@
+project(libm3uplaylistformat)
+
+cmake_minimum_required(VERSION 2.4.0)
+
+if(COMMAND cmake_policy)
+cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+
+# 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(libm3uplaylistformat_SRCS
+ m3uplaylistformat.cpp
+)
+
+SET(libm3uplaylistformat_MOC_HDRS
+ m3uplaylistformat.h
+)
+
+QT4_ADD_RESOURCES(libm3uplaylistformat_RCC_SRCS ${libm3uplaylistformat_RCCS})
+
+QT4_WRAP_CPP(libm3uplaylistformat_MOC_SRCS ${libm3uplaylistformat_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(m3uplaylistformat SHARED ${libm3uplaylistformat_SRCS} ${libm3uplaylistformat_MOC_SRCS})
+target_link_libraries(m3uplaylistformat ${QT_LIBRARIES} -lqmmpui)
+install(TARGETS m3uplaylistformat DESTINATION ${LIB_DIR}/qmmp/PlaylistFormats)
diff --git a/src/plugins/PlaylistFormats/m3u/m3u.pro b/src/plugins/PlaylistFormats/m3u/m3u.pro
new file mode 100644
index 000000000..d4b7c1a9f
--- /dev/null
+++ b/src/plugins/PlaylistFormats/m3u/m3u.pro
@@ -0,0 +1,27 @@
+include(../../plugins.pri)
+
+CONFIG += release \
+warn_on \
+plugin \
+ lib
+
+TARGET =$$PLUGINS_PREFIX/PlaylistFormats/m3uplaylistformat
+QMAKE_CLEAN =$$PLUGINS_PREFIX/General/libm3uplaylistformat.so
+
+TEMPLATE = lib
+QMAKE_LIBDIR += ../../../../lib
+
+isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+}
+target.path = $$LIB_DIR/qmmp/PlaulistFormats
+INSTALLS += target
+
+INCLUDEPATH += ../../../../src
+
+LIBS += -lqmmpui
+
+HEADERS += m3uplaylistformat.h
+
+SOURCES += m3uplaylistformat.cpp
+
diff --git a/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.cpp b/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.cpp
new file mode 100644
index 000000000..583962025
--- /dev/null
+++ b/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.cpp
@@ -0,0 +1,89 @@
+/***************************************************************************
+ * 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 <QFileInfo>
+#include <QtPlugin>
+
+#include "m3uplaylistformat.h"
+
+bool M3UPlaylistFormat::hasFormat(const QString & f)
+{
+ foreach(QString s,m_supported_formats)
+ if (f == s)
+ return true;
+
+ return false;
+}
+
+QStringList M3UPlaylistFormat::getExtensions() const
+{
+ return m_supported_formats;
+}
+
+M3UPlaylistFormat::M3UPlaylistFormat()
+{
+ m_supported_formats << "m3u";
+}
+
+QStringList M3UPlaylistFormat::decode(const QString & contents)
+{
+ QStringList out;
+ QStringList splitted = contents.split("\n");
+ if (!splitted.isEmpty())
+ {
+ foreach(QString str, splitted)
+ {
+ str = str.trimmed ();
+ if (str.startsWith("#EXTM3U") || str.startsWith("#EXTINF:") || str.isEmpty())
+ ;//TODO: Let's skip it for now...
+ else if (str.startsWith("http://"))
+ out << str;
+ else if (QFileInfo(str).exists())
+ out << QFileInfo(str).absoluteFilePath();
+ else
+ qWarning("File %s does not exist", qPrintable(str));
+ }
+ return out;
+ }
+ else
+ qWarning("Error parsing M3U format");
+
+ return QStringList();
+}
+
+QString M3UPlaylistFormat::encode(const QList< SongInfo * > & contents)
+{
+ QStringList out;
+ out << QString("#EXTM3U");
+ foreach(SongInfo* f,contents)
+ {
+ QString info = "#EXTINF:" + QString::number(f->length()) + "," + f->title();
+ out.append(info);
+ out.append(f->path());
+ }
+ return out.join("\n");
+}
+
+QString M3UPlaylistFormat::name() const
+{
+ return "M3UPlaylistFormat";
+}
+
+Q_EXPORT_PLUGIN(M3UPlaylistFormat)
diff --git a/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.h b/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.h
new file mode 100644
index 000000000..2280e4498
--- /dev/null
+++ b/src/plugins/PlaylistFormats/m3u/m3uplaylistformat.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 M3UPLAYLISTFORMAT_H
+#define M3UPLAYLISTFORMAT_H
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+#include <qmmpui/playlistformat.h>
+#include <qmmpui/songinfo.h>
+
+/*!
+ * Class for M3U playlist format parsing
+ */
+class M3UPlaylistFormat : public QObject, public PlaylistFormat
+{
+ Q_OBJECT
+ Q_INTERFACES(PlaylistFormat)
+public:
+ M3UPlaylistFormat();
+ 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
diff --git a/src/plugins/PlaylistFormats/pls/CMakeLists.txt b/src/plugins/PlaylistFormats/pls/CMakeLists.txt
new file mode 100644
index 000000000..6105837f9
--- /dev/null
+++ b/src/plugins/PlaylistFormats/pls/CMakeLists.txt
@@ -0,0 +1,48 @@
+project(libplsplaylistformat)
+
+cmake_minimum_required(VERSION 2.4.0)
+
+if(COMMAND cmake_policy)
+cmake_policy(SET CMP0003 NEW)
+endif(COMMAND cmake_policy)
+
+
+# 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(libplsplaylistformat_SRCS
+ plsplaylistformat.cpp
+)
+
+SET(libplsplaylistformat_MOC_HDRS
+ plsplaylistformat.h
+)
+
+QT4_ADD_RESOURCES(libplsplaylistformat_RCC_SRCS ${libplsplaylistformat_RCCS})
+
+QT4_WRAP_CPP(libplsplaylistformat_MOC_SRCS ${libplsplaylistformat_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(plsplaylistformat SHARED ${libplsplaylistformat_SRCS} ${libplsplaylistformat_MOC_SRCS})
+target_link_libraries(plsplaylistformat ${QT_LIBRARIES} -lqmmpui)
+install(TARGETS plsplaylistformat DESTINATION ${LIB_DIR}/qmmp/PlaylistFormats)
diff --git a/src/plugins/PlaylistFormats/pls/pls.pro b/src/plugins/PlaylistFormats/pls/pls.pro
new file mode 100644
index 000000000..812f9c9d1
--- /dev/null
+++ b/src/plugins/PlaylistFormats/pls/pls.pro
@@ -0,0 +1,27 @@
+include(../../plugins.pri)
+
+CONFIG += release \
+warn_on \
+plugin \
+ lib
+
+TARGET =$$PLUGINS_PREFIX/PlaylistFormats/plsplaylistformat
+QMAKE_CLEAN =$$PLUGINS_PREFIX/PlaylistFormats/plsplaylistformat.so
+
+TEMPLATE = lib
+QMAKE_LIBDIR += ../../../../lib
+
+isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+}
+target.path = $$LIB_DIR/qmmp/PlaylistFormats
+INSTALLS += target
+
+INCLUDEPATH += ../../../../src
+
+LIBS += -lqmmpui
+
+SOURCES += plsplaylistformat.cpp
+
+HEADERS += plsplaylistformat.h
+
diff --git a/src/plugins/PlaylistFormats/pls/plsplaylistformat.cpp b/src/plugins/PlaylistFormats/pls/plsplaylistformat.cpp
new file mode 100644
index 000000000..086cd6e9d
--- /dev/null
+++ b/src/plugins/PlaylistFormats/pls/plsplaylistformat.cpp
@@ -0,0 +1,103 @@
+/***************************************************************************
+ * 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 <QFileInfo>
+#include <QtPlugin>
+
+#include "plsplaylistformat.h"
+
+bool PLSPlaylistFormat::hasFormat(const QString & f)
+{
+ foreach(QString s,m_supported_formats)
+ if (f == s)
+ return true;
+
+ return false;
+}
+
+QStringList PLSPlaylistFormat::getExtensions() const
+{
+ return m_supported_formats;
+}
+
+PLSPlaylistFormat::PLSPlaylistFormat()
+{
+ m_supported_formats << "pls";
+}
+
+QString PLSPlaylistFormat::name() const
+{
+ return "PLSPlaylistFormat";
+}
+
+
+QStringList PLSPlaylistFormat::decode(const QString & contents)
+{
+ QStringList out;
+ QStringList splitted = contents.split("\n");
+ if (!splitted.isEmpty())
+ {
+ if (splitted.takeAt(0).toLower().contains("[playlist]"))
+ {
+ foreach(QString str, splitted)
+ {
+ if (str.startsWith("File"))
+ {
+ QString unverified = str.remove(0,str.indexOf(QChar('=')) + 1);
+ unverified = unverified.trimmed();
+ if (unverified.startsWith("http://"))
+ {
+ out << unverified;
+ }
+ else if (QFileInfo(unverified).exists())
+ out << QFileInfo(unverified).absoluteFilePath();
+ else
+ qWarning("File %s does not exist", qPrintable(unverified));
+ }
+ }
+ return out;
+ }
+ }
+ else
+ qWarning("Error parsing PLS format");
+
+ return QStringList();
+}
+
+QString PLSPlaylistFormat::encode(const QList<SongInfo *> & contents)
+{
+ QStringList out;
+ out << QString("[playlist]");
+ int counter = 1;
+ foreach(SongInfo* f,contents)
+ {
+ QString begin = "File" + QString::number(counter) + "=";
+ out.append(begin + f->path());
+ begin = "Title" + QString::number(counter) + "=";
+ out.append(begin + f->title());
+ begin = "Length" + QString::number(counter) + "=";
+ out.append(begin + QString::number(f->length()));
+ counter ++;
+ }
+ out << "NumberOfEntries=" + QString::number(contents.count());
+ return out.join("\n");
+}
+
+Q_EXPORT_PLUGIN(PLSPlaylistFormat)
diff --git a/src/plugins/PlaylistFormats/pls/plsplaylistformat.h b/src/plugins/PlaylistFormats/pls/plsplaylistformat.h
new file mode 100644
index 000000000..9ab7e2bff
--- /dev/null
+++ b/src/plugins/PlaylistFormats/pls/plsplaylistformat.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 PLSPLAYLISTFORMAT_H
+#define PLSPLAYLISTFORMAT_H
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+#include <qmmpui/playlistformat.h>
+#include <qmmpui/songinfo.h>
+
+/*!
+ * Class for PLS playlist format parsing
+ */
+class PLSPlaylistFormat : public QObject, public PlaylistFormat
+{
+ Q_OBJECT
+ Q_INTERFACES(PlaylistFormat)
+public:
+ PLSPlaylistFormat();
+ 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
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
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro
index 9be0dd332..ef6fc9e12 100644
--- a/src/plugins/plugins.pro
+++ b/src/plugins/plugins.pro
@@ -3,5 +3,6 @@ SUBDIRS += Input \
Output \
Visual \
Effect \
- General
+ General \
+ PlaylistFormats
TEMPLATE = subdirs
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt
index 496ab8739..b9cc441a6 100644
--- a/src/qmmpui/CMakeLists.txt
+++ b/src/qmmpui/CMakeLists.txt
@@ -27,6 +27,7 @@ SET(libqmmpui_SRCS
generalhandler.cpp
songinfo.cpp
control.cpp
+ playlistparser.cpp
)
SET(libqmmpui_MOC_HDRS
@@ -35,6 +36,8 @@ SET(libqmmpui_MOC_HDRS
generalhandler.h
songinfo.h
control.h
+ playlistparser.h
+ playlistformat.h
)
QT4_WRAP_CPP(libqmmpui_MOC_SRCS ${libqmmpui_MOC_HDRS})
diff --git a/src/qmmpui/playlistformat.h b/src/qmmpui/playlistformat.h
new file mode 100644
index 000000000..0a5bfdbcc
--- /dev/null
+++ b/src/qmmpui/playlistformat.h
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (C) 2006-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 _PALYLISTFORMAT_H
+#define _PALYLISTFORMAT_H
+#include <QStringList>
+
+
+class SongInfo;
+/*!
+ * Abstract interface for playlist formats.
+ *
+ * @author Vladimir Kuznetsov <vovanec@gmail.com>
+ */
+class PlaylistFormat
+{
+public:
+ virtual ~PlaylistFormat()
+ {
+ ;
+ }
+ /*!
+ * Takes raw contents of playlist file, should return string list of
+ * ready file pathes to fill the playlist.
+ */
+ virtual QStringList decode(const QString& contents) = 0;
+
+ /*!
+ * Takes the list of SongInfo objects, should return string of
+ * encoded playlist file
+ */
+ virtual QString encode(const QList<SongInfo*>& contents) = 0;
+
+ /*!
+ * Returns list of file extensions that current format supports
+ */
+ virtual QStringList getExtensions()const = 0;
+
+ /*!
+ * Verifies is the \b ext file extension supported by current playlist format.
+ */
+ virtual bool hasFormat(const QString& ext) = 0;
+
+ /// Unique name of playlist format.
+ virtual QString name()const = 0;
+};
+
+Q_DECLARE_INTERFACE(PlaylistFormat,"PlaylistFormatInterface/1.0");
+
+#endif
diff --git a/src/qmmpui/playlistparser.cpp b/src/qmmpui/playlistparser.cpp
new file mode 100644
index 000000000..45f14595d
--- /dev/null
+++ b/src/qmmpui/playlistparser.cpp
@@ -0,0 +1,101 @@
+/***************************************************************************
+ * 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 <QtGui>
+#include <QObject>
+#include <QList>
+#include <QApplication>
+
+#include "playlistformat.h"
+#include "songinfo.h"
+#include "playlistparser.h"
+
+PlaylistParser *PlaylistParser::m_instance = 0;
+
+PlaylistParser::PlaylistParser(QObject *parent) : QObject (parent)
+{
+ m_instance = this;
+}
+
+PlaylistParser::~PlaylistParser()
+{}
+
+QStringList PlaylistParser::getExtensions()
+{
+ loadExternalPlaylistFormats();
+ QStringList extensions;
+ foreach(PlaylistFormat *format, m_formats)
+ extensions << format->getExtensions();
+ return extensions;
+}
+
+bool PlaylistParser::supports(const QString &filePath)
+{
+ return findByPath(filePath) != 0;
+}
+
+QList<PlaylistFormat*> PlaylistParser::formats()
+{
+ loadExternalPlaylistFormats();
+ return m_formats;
+}
+
+PlaylistFormat *PlaylistParser::findByPath(const QString &filePath)
+{
+ loadExternalPlaylistFormats();
+ foreach(PlaylistFormat* format, m_formats)
+ {
+ if (format->hasFormat(QFileInfo(filePath).suffix().toLower()))
+ return format;
+ }
+ return 0;
+}
+
+PlaylistParser* PlaylistParser::instance()
+{
+ if(!m_instance)
+ qFatal("PlaylistParser: object is not created");
+ return m_instance;
+}
+
+void PlaylistParser::loadExternalPlaylistFormats()
+{
+ if (!m_formats.isEmpty())
+ return;
+ QDir pluginsDir (qApp->applicationDirPath());
+ pluginsDir.cdUp();
+ pluginsDir.cd("./"LIB_DIR"/qmmp/PlaylistFormats");
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files))
+ {
+ QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
+ QObject *plugin = loader.instance();
+ if (loader.isLoaded())
+ qDebug("PlaylistParser: plugin loaded - %s", qPrintable(fileName));
+ else
+ qWarning("PlaylistParser: %s", qPrintable(loader.errorString ()));
+
+ PlaylistFormat *fmt = 0;
+ if (plugin)
+ fmt = qobject_cast<PlaylistFormat *>(plugin);
+
+ if (fmt)
+ m_formats << fmt;
+ }
+}
diff --git a/src/qmmpui/playlistparser.h b/src/qmmpui/playlistparser.h
new file mode 100644
index 000000000..b2c5585ee
--- /dev/null
+++ b/src/qmmpui/playlistparser.h
@@ -0,0 +1,53 @@
+/***************************************************************************
+ * 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 PLAYLISTPARSER_H
+#define PLAYLISTPARSER_H
+
+#include <QObject>
+
+
+class SongInfo;
+class PlaylistFormat;
+
+/**
+ @author Ilya Kotov <forkotov02@hotmail.ru>
+*/
+class PlaylistParser : public QObject
+{
+Q_OBJECT
+public:
+ PlaylistParser(QObject *parent);
+
+ ~PlaylistParser();
+
+ QStringList getExtensions();
+ bool supports(const QString &filePath);
+ QList<PlaylistFormat*> formats();
+ static PlaylistParser* instance();
+ PlaylistFormat *findByPath(const QString &filePath);
+
+private:
+ void loadExternalPlaylistFormats();
+ QList<PlaylistFormat*> m_formats;
+ static PlaylistParser* m_instance;
+
+};
+
+#endif
diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro
index 8ed295534..2d09e43ae 100644
--- a/src/qmmpui/qmmpui.pro
+++ b/src/qmmpui/qmmpui.pro
@@ -7,19 +7,18 @@ qt \
thread
TEMPLATE = lib
-VERSION = $$QMMP_VERSION
-unix:isEmpty(LIB_DIR){
- LIB_DIR = /lib
-}
+unix : isEmpty(LIB_DIR){
+ LIB_DIR = /lib
+ }
-unix:DEFINES += LIB_DIR=\\\"$$LIB_DIR\\\"
+unix : DEFINES += LIB_DIR=\\\"$$LIB_DIR\\\"
DEFINES += QMMP_VERSION=$$QMMP_VERSION
-contains(CONFIG, SVN_VERSION) {
-DEFINES += QMMP_STR_VERSION=\\\"$$QMMP_VERSION-svn\\\"
-} else {
-DEFINES += QMMP_STR_VERSION=\\\"$$QMMP_VERSION\\\"
+contains(CONFIG, SVN_VERSION){
+ DEFINES += QMMP_STR_VERSION=\\\"$$QMMP_VERSION-svn\\\"
+}else {
+ DEFINES += QMMP_STR_VERSION=\\\"$$QMMP_VERSION\\\"
}
target.path = $$LIB_DIR
@@ -28,11 +27,15 @@ HEADERS += general.h \
generalfactory.h \
generalhandler.h \
songinfo.h \
- control.h
+ control.h \
+ playlistformat.h \
+ playlistparser.h
SOURCES += general.cpp \
generalhandler.cpp \
songinfo.cpp \
- control.cpp
+ control.cpp \
+ playlistparser.cpp
DESTDIR = .
+
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index e7047a5a0..e03881bd9 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -7,7 +7,6 @@ if(COMMAND cmake_policy)
cmake_policy(SET CMP0005 OLD)
endif(COMMAND cmake_policy)
-SET(QT_USE_QTXML TRUE)
SET(QT_USE_QTNETWORK TRUE)
INCLUDE(UsePkgConfig)
@@ -64,7 +63,6 @@ SET(ui_SRCS
pixmapwidget.cpp
playlistcontrol.cpp
playlist.cpp
- playlistformat.cpp
playlistmodel.cpp
playlistslider.cpp
playlisttitlebar.cpp
@@ -118,7 +116,6 @@ SET(ui_MOC_HDRS
number.h
pixmapwidget.h
playlistcontrol.h
- playlistformat.h
playlist.h
playlistmodel.h
playlistslider.h
diff --git a/src/ui/addurldialog.cpp b/src/ui/addurldialog.cpp
index fd460ba01..3ace76065 100644
--- a/src/ui/addurldialog.cpp
+++ b/src/ui/addurldialog.cpp
@@ -24,7 +24,8 @@
#include <QUrl>
#include <QMessageBox>
#include "addurldialog.h"
-#include "playlistformat.h"
+#include <qmmpui/playlistparser.h>
+#include <qmmpui/playlistformat.h>
#include "playlistmodel.h"
#define HISTORY_SIZE 10
@@ -74,18 +75,15 @@ void AddUrlDialog::accept( )
s.prepend("http://");
m_history.removeAll(s);
m_history.prepend(s);
- //TODO this code should be removed
- foreach(PlaylistFormat* prs, m_model->registeredPlaylistFormats())
+ PlaylistFormat* prs = PlaylistParser::instance()->findByPath(s);
+ if (prs)
{
- if (prs->hasFormat(QFileInfo(s).suffix().toLower()))
- {
- //download playlist;
- QUrl url(s);
- m_http->setHost(url.host(), url.port(80));
- m_http->get(url.path()); //TODO proxy support
- addButton->setEnabled(FALSE);
- return;
- }
+ //download playlist;
+ QUrl url(s);
+ m_http->setHost(url.host(), url.port(80));
+ m_http->get(url.path()); //TODO proxy support
+ addButton->setEnabled(FALSE);
+ return;
}
m_model->addFile(s);
}
@@ -104,13 +102,11 @@ void AddUrlDialog::processResponse(int, bool error)
void AddUrlDialog::readResponse(const QHttpResponseHeader&)
{
QString s = urlComboBox->currentText();
- foreach(PlaylistFormat* prs, m_model->registeredPlaylistFormats())
+ PlaylistFormat* prs = PlaylistParser::instance()->findByPath(s);
+ if (prs)
{
- if (prs->hasFormat(QFileInfo(s).suffix().toLower()))
- {
- m_model->addFiles(prs->decode(m_http->readAll()));
- break;
- }
+ m_model->addFiles(prs->decode(m_http->readAll()));
+ return;
}
QDialog::accept();
}
diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp
index ff77f6b38..1f18ac97f 100644
--- a/src/ui/mainwindow.cpp
+++ b/src/ui/mainwindow.cpp
@@ -28,6 +28,8 @@
#include <qmmp/soundcore.h>
#include <qmmpui/generalhandler.h>
#include <qmmpui/general.h>
+#include <qmmpui/playlistparser.h>
+#include <qmmpui/playlistformat.h>
#include "textscroller.h"
#include "mainwindow.h"
@@ -39,7 +41,6 @@
#include "dock.h"
#include "eqwidget.h"
#include "mainvisual.h"
-#include "playlistformat.h"
#include "jumptotrackdialog.h"
#include "aboutdialog.h"
#include "addurldialog.h"
@@ -76,6 +77,7 @@ MainWindow::MainWindow(const QStringList& args,CommandLineOptionManager* option_
m_playlistName = tr("Default");
+ new PlaylistParser(this);
m_playlist = new PlayList(this);
connect (m_playlist,SIGNAL(next()),SLOT(next()));
@@ -692,7 +694,7 @@ void MainWindow::newPlaylist()
void MainWindow::loadPlaylist()
{
QStringList l;
- QList<PlaylistFormat*> p_list = m_playListModel->registeredPlaylistFormats();
+ QList<PlaylistFormat*> p_list = PlaylistParser::instance()->formats();
if (!p_list.isEmpty())
{
foreach(PlaylistFormat* fmt,p_list)
@@ -734,7 +736,7 @@ void MainWindow::loadPlaylist()
void MainWindow::savePlaylist()
{
QStringList l;
- QList<PlaylistFormat*> p_list = m_playListModel->registeredPlaylistFormats();
+ QList<PlaylistFormat*> p_list = PlaylistParser::instance()->formats();
if (!p_list.isEmpty())
{
foreach(PlaylistFormat* fmt,p_list)
diff --git a/src/ui/playlistformat.cpp b/src/ui/playlistformat.cpp
deleted file mode 100644
index 0486d7f78..000000000
--- a/src/ui/playlistformat.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/***************************************************************************
-* Copyright (C) 2006-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 <QFileInfo>
-
-#ifndef XSPF_PLUGIN
-#include <QDomDocument>
-#include <QDomElement>
-#include <QUrl>
-#include "version.h"
-#endif
-
-#include "playlistformat.h"
-
-#include "playlistitem.h"
-
-bool PLSPlaylistFormat::hasFormat(const QString & f)
-{
- foreach(QString s,m_supported_formats)
- if (f == s)
- return true;
-
- return false;
-}
-
-QStringList PLSPlaylistFormat::getExtensions() const
-{
- return m_supported_formats;
-}
-
-PLSPlaylistFormat::PLSPlaylistFormat()
-{
- m_supported_formats << "pls";
-}
-
-QString PLSPlaylistFormat::name() const
-{
- return "PLSPlaylistFormat";
-}
-
-
-QStringList PLSPlaylistFormat::decode(const QString & contents)
-{
- QStringList out;
- QStringList splitted = contents.split("\n");
- if (!splitted.isEmpty())
- {
- if (splitted.takeAt(0).toLower().contains("[playlist]"))
- {
- foreach(QString str, splitted)
- {
- if (str.startsWith("File"))
- {
- QString unverified = str.remove(0,str.indexOf(QChar('=')) + 1);
- unverified = unverified.trimmed();
- if (unverified.startsWith("http://"))
- {
- out << unverified;
- }
- else if (QFileInfo(unverified).exists())
- out << QFileInfo(unverified).absoluteFilePath();
- else
- qWarning("File %s does not exist", qPrintable(unverified));
- }
- }
- return out;
- }
- }
- else
- qWarning("Error parsing PLS format");
-
- return QStringList();
-}
-
-QString PLSPlaylistFormat::encode(const QList< PlayListItem * > & contents)
-{
- QStringList out;
- out << QString("[playlist]");
- int counter = 1;
- foreach(PlayListItem* f,contents)
- {
- QString begin = "File" + QString::number(counter) + "=";
- out.append(begin + f->path());
- begin = "Title" + QString::number(counter) + "=";
- out.append(begin + f->title());
- begin = "Length" + QString::number(counter) + "=";
- out.append(begin + QString::number(f->length()));
- counter ++;
- }
- out << "NumberOfEntries=" + QString::number(contents.count());
- return out.join("\n");
-}
-
-
-
-
-bool M3UPlaylistFormat::hasFormat(const QString & f)
-{
- foreach(QString s,m_supported_formats)
- if (f == s)
- return true;
-
- return false;
-}
-
-QStringList M3UPlaylistFormat::getExtensions() const
-{
- return m_supported_formats;
-}
-
-M3UPlaylistFormat::M3UPlaylistFormat()
-{
- m_supported_formats << "m3u";
-}
-
-QStringList M3UPlaylistFormat::decode(const QString & contents)
-{
- QStringList out;
- QStringList splitted = contents.split("\n");
- if (!splitted.isEmpty())
- {
- foreach(QString str, splitted)
- {
- str = str.trimmed ();
- if (str.startsWith("#EXTM3U") || str.startsWith("#EXTINF:") || str.isEmpty())
- ;//TODO: Let's skip it for now...
- else if (str.startsWith("http://"))
- out << str;
- else if (QFileInfo(str).exists())
- out << QFileInfo(str).absoluteFilePath();
- else
- qWarning("File %s does not exist", qPrintable(str));
- }
- return out;
- }
- else
- qWarning("Error parsing M3U format");
-
- return QStringList();
-}
-
-QString M3UPlaylistFormat::encode(const QList< PlayListItem * > & contents)
-{
- QStringList out;
- out << QString("#EXTM3U");
- foreach(PlayListItem* f,contents)
- {
- QString info = "#EXTINF:" + QString::number(f->length()) + "," + f->title();
- out.append(info);
- out.append(f->path());
- }
- return out.join("\n");
-}
-
-QString M3UPlaylistFormat::name() const
-{
- return "M3UPlaylistFormat";
-}
-
-
-// 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< PlayListItem * > & 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(PlayListItem* 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";
-}
-
-
-
-
-
diff --git a/src/ui/playlistformat.h b/src/ui/playlistformat.h
deleted file mode 100644
index 4e1de00f1..000000000
--- a/src/ui/playlistformat.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2006 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 _PALYLISTFORMAT_H
-#define _PALYLISTFORMAT_H
-#include <QStringList>
-
-
-class PlayListItem;
-/*!
- * Abstract interface for playlist formats.
- *
- * @author Vladimir Kuznetsov <vovanec@gmail.com>
- */
-class PlaylistFormat
-{
-public:
- virtual ~PlaylistFormat(){;}
- /*!
- * Takes raw contents of playlist file, should return string list of
- * ready file pathes to fill the playlist.
- */
- virtual QStringList decode(const QString& contents) = 0;
-
- /*!
- * Takes the list of PlayListItem objects, should return string of
- * encoded playlist file
- */
- virtual QString encode(const QList<PlayListItem*>& contents) = 0;
-
- /*!
- * Returns list of file extensions that current format supports
- */
- virtual QStringList getExtensions()const = 0;
-
- /*!
- * Verifies is the \b ext file extension supported by current playlist format.
- */
- virtual bool hasFormat(const QString& ext) = 0;
-
- /// Unique name of playlist format.
- virtual QString name()const = 0;
-};
-
-Q_DECLARE_INTERFACE(PlaylistFormat,"PlaylistFormatInterface/1.0");
-
-/*!
- * Class for PLS playlist format parsing
- */
-class PLSPlaylistFormat : public PlaylistFormat
-{
-public:
- PLSPlaylistFormat();
- virtual QStringList getExtensions()const;
- virtual bool hasFormat(const QString&);
- virtual QStringList decode(const QString& contents);
- virtual QString encode(const QList<PlayListItem*>& contents);
- virtual QString name()const;
-protected:
- QStringList m_supported_formats;
-
-};
-
-
-
-/*!
- * Class for M3U playlist format parsing
- */
-class M3UPlaylistFormat : public PlaylistFormat
-{
- public:
- M3UPlaylistFormat();
- virtual QStringList getExtensions()const;
- virtual bool hasFormat(const QString&);
- virtual QStringList decode(const QString& contents);
- virtual QString encode(const QList<PlayListItem*>& contents);
- virtual QString name()const;
-protected:
- QStringList m_supported_formats;
-};
-
-
-/*!
- * Class for XSPF playlist format parsing
- */
-class XSPFPlaylistFormat : public PlaylistFormat
-{
- public:
- XSPFPlaylistFormat();
- virtual QStringList getExtensions()const;
- virtual bool hasFormat(const QString&);
- virtual QStringList decode(const QString& contents);
- virtual QString encode(const QList<PlayListItem*>& contents);
- virtual QString name()const;
- protected:
- QStringList m_supported_formats;
-};
-
-#endif
diff --git a/src/ui/playlistmodel.cpp b/src/ui/playlistmodel.cpp
index 22371d283..f26f843d1 100644
--- a/src/ui/playlistmodel.cpp
+++ b/src/ui/playlistmodel.cpp
@@ -32,11 +32,12 @@
#include <qmmp/decoder.h>
#include <qmmp/decoderfactory.h>
+#include <qmmpui/playlistparser.h>
+#include <qmmpui/playlistformat.h>
#include "fileloader.h"
#include "playlistmodel.h"
#include "playlistitem.h"
-#include "playlistformat.h"
#include "playstate.h"
#include <QMetaType>
@@ -52,7 +53,7 @@ TagUpdater::TagUpdater(QObject* o,PlayListItem* item):m_observable(o),m_item(ite
void TagUpdater::updateTag()
{
- if(m_item->flag() == PlayListItem::SCHEDULED_FOR_DELETION)
+ if (m_item->flag() == PlayListItem::SCHEDULED_FOR_DELETION)
{
delete m_item;
m_item = NULL;
@@ -75,13 +76,6 @@ PlayListModel::PlayListModel ( QObject *parent )
is_repeatable_list = false;
m_play_state = new NormalPlayState(this);
//readSettings();
-
- registerPlaylistFormat( new PLSPlaylistFormat);
- registerPlaylistFormat( new M3UPlaylistFormat);
-#ifndef XSPF_PLUGIN
- registerPlaylistFormat( new XSPFPlaylistFormat);
-#endif
- loadExternalPlaylistFormats();
}
PlayListModel::~PlayListModel()
@@ -89,7 +83,7 @@ PlayListModel::~PlayListModel()
writeSettings();
clear();
delete m_play_state;
- qDeleteAll(m_registered_pl_formats);
+ //qDeleteAll(m_registered_pl_formats);
foreach(GuardedFileLoader l,m_running_loaders)
{
@@ -180,11 +174,11 @@ void PlayListModel::clear()
{
PlayListItem* mf = m_items.takeFirst();
- if(mf->flag() == PlayListItem::FREE)
+ if (mf->flag() == PlayListItem::FREE)
{
delete mf;
}
- else if(mf->flag() == PlayListItem::EDITING)
+ else if (mf->flag() == PlayListItem::EDITING)
{
mf->setFlag(PlayListItem::SCHEDULED_FOR_DELETION);
}
@@ -259,12 +253,12 @@ void PlayListModel::removeSelection(bool inverted)
if (m_total_length < 0)
m_total_length = 0;
- if(f->flag() == PlayListItem::FREE)
+ if (f->flag() == PlayListItem::FREE)
{
delete f;
f = NULL;
}
- else if(f->flag() == PlayListItem::EDITING)
+ else if (f->flag() == PlayListItem::EDITING)
f->setFlag(PlayListItem::SCHEDULED_FOR_DELETION);
select_after_delete = i;
@@ -313,7 +307,7 @@ void PlayListModel::showDetails()
if ( fact )
{
QObject* o = fact->showDetails ( 0, m_items.at ( i )->path() );
- if(o)
+ if (o)
{
TagUpdater *updater = new TagUpdater(o,m_items.at(i));
m_editing_items.append(m_items.at(i));
@@ -347,7 +341,7 @@ void PlayListModel::readSettings()
file.close ();
- if(m_current > files.count() - 1)
+ if (m_current > files.count() - 1)
m_current = 0;
int preload = (files.count() < 100) ? files.count() : 100;
@@ -814,76 +808,40 @@ void PlayListModel::setUpdatesEnabled(bool yes)
void PlayListModel::loadPlaylist(const QString & f_name)
{
-
- foreach(PlaylistFormat* prs,m_registered_pl_formats.values())
+ PlaylistFormat* prs = PlaylistParser::instance()->findByPath(f_name);
+ if (prs)
{
- if (prs->hasFormat(QFileInfo(f_name).suffix().toLower()))
+ QFile file(f_name);
+ if (file.open(QIODevice::ReadOnly))
{
- QFile file(f_name);
- if (file.open(QIODevice::ReadOnly))
- {
- clear();
- addFiles(prs->decode(QTextStream(&file).readAll()));
- file.close();
- }
- else
- qWarning("Error opening %s",f_name.toLocal8Bit().data());
+ clear();
+ addFiles(prs->decode(QTextStream(&file).readAll()));
+ file.close();
}
+ else
+ qWarning("Error opening %s",f_name.toLocal8Bit().data());
}
}
void PlayListModel::savePlaylist(const QString & f_name)
{
- foreach(PlaylistFormat* prs,m_registered_pl_formats.values())
+ PlaylistFormat* prs = PlaylistParser::instance()->findByPath(f_name);
+ if (prs)
{
- if (prs->hasFormat(QFileInfo(f_name).suffix().toLower()))
+ QFile file(f_name);
+ if (file.open(QIODevice::WriteOnly))
{
- QFile file(f_name);
- if (file.open(QIODevice::WriteOnly))
- {
- QTextStream ts(&file);
- ts << prs->encode(m_items);
- file.close();
- }
- else
- qWarning("Error opening %s",f_name.toLocal8Bit().data());
+ QTextStream ts(&file);
+ QList <SongInfo *> songs;
+ foreach(PlayListItem* item, m_items)
+ songs << item;
+ ts << prs->encode(songs);
+ file.close();
}
+ else
+ qWarning("Error opening %s",f_name.toLocal8Bit().data());
}
-}
-
-
-void PlayListModel::loadExternalPlaylistFormats()
-{
- QDir pluginsDir (QDir::homePath()+"/.qmmp/plugins/PlaylistFormats");
- //pluginsDir.cdUp();
- //pluginsDir.cd("plugins/PlaylistFormats");
- foreach (QString fileName, pluginsDir.entryList(QDir::Files))
- {
- QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
- QObject *plugin = loader.instance();
- if (loader.isLoaded())
- qDebug("PlaylistFormat: plugin loaded - %s", qPrintable(fileName));
-
- PlaylistFormat *fmt = 0;
- if (plugin)
- fmt = qobject_cast<PlaylistFormat *>(plugin);
-
- if (fmt)
- if (!registerPlaylistFormat(fmt))
- qDebug("Warning: Plugin with name %s is already registered...",
- qPrintable(fmt->name()));
- }
-}
-bool PlayListModel::registerPlaylistFormat(PlaylistFormat* p)
-{
- QString name = p->name();
- if (!m_registered_pl_formats.contains(name))
- {
- m_registered_pl_formats.insert(name,p);
- return true;
- }
- return false;
}
bool PlayListModel::isFileLoaderRunning() const
diff --git a/src/ui/playlistmodel.h b/src/ui/playlistmodel.h
index c8d826021..a5231b44f 100644
--- a/src/ui/playlistmodel.h
+++ b/src/ui/playlistmodel.h
@@ -177,29 +177,6 @@ public:
}
/*!
- * Registers playlist format parser.
- */
- bool registerPlaylistFormat(PlaylistFormat* p);
-
- /*!
- * Checks and loads external playlist format plugins
- */
- void loadExternalPlaylistFormats();
-
- /*!
- * Returns vector of reistered format parsers.
- */
- const QList<PlaylistFormat*> registeredPlaylistFormats()const
- {
- return m_registered_pl_formats.values();
- }
-
- const QStringList registeredPlaylistFormatNames()const
- {
- return m_registered_pl_formats.keys();
- }
-
- /*!
* Loads playlist with \b f_name name.
*/
void loadPlaylist(const QString& f_name);
@@ -349,8 +326,6 @@ private:
*/
QList<PlayListItem*>m_queued_songs;
- QMap<QString,PlaylistFormat* > m_registered_pl_formats;
-
/*!
* Is playlist repeatable?
*/
diff --git a/src/ui/ui.pro b/src/ui/ui.pro
index 51d23ede9..f01deb926 100644
--- a/src/ui/ui.pro
+++ b/src/ui/ui.pro
@@ -44,7 +44,6 @@ HEADERS += mainwindow.h \
balancebar.h \
playstate.h \
symboldisplay.h \
- playlistformat.h \
playlistcontrol.h \
version.h \
qmmpstarter.h \
@@ -98,7 +97,6 @@ SOURCES += mainwindow.cpp \
balancebar.cpp \
playstate.cpp \
symboldisplay.cpp \
- playlistformat.cpp \
playlistcontrol.cpp \
qmmpstarter.cpp \
eqpreset.cpp \
@@ -124,7 +122,7 @@ MOC_DIR =./.build/moc/
OBJECTS_DIR =./.build/obj
-QT += network xml
+QT += network
TARGET = ../../bin/qmmp
CONFIG += thread release \
warn_on