diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-22 10:46:29 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2012-12-22 10:46:29 +0000 |
| commit | 954146ff9b69591f0cf3895e96922bb55ad88502 (patch) | |
| tree | b495690d6ed2a6b5251fd1e8a428b550354a0cba /src | |
| parent | 2b286b3f3713a224839b9444579046556b608c58 (diff) | |
| download | qmmp-954146ff9b69591f0cf3895e96922bb55ad88502.tar.gz qmmp-954146ff9b69591f0cf3895e96922bb55ad88502.tar.bz2 qmmp-954146ff9b69591f0cf3895e96922bb55ad88502.zip | |
playlist format api cleanup
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3088 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp | 24 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/m3u/m3uplaylistformat.h | 14 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/pls/plsplaylistformat.cpp | 30 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/pls/plsplaylistformat.h | 12 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp | 37 | ||||
| -rw-r--r-- | src/plugins/PlayListFormats/xspf/xspfplaylistformat.h | 13 | ||||
| -rw-r--r-- | src/qmmpui/playlistformat.h | 33 | ||||
| -rw-r--r-- | src/qmmpui/playlistparser.cpp | 29 | ||||
| -rw-r--r-- | src/qmmpui/playlistparser.h | 4 | ||||
| -rw-r--r-- | src/qmmpui/uihelper.cpp | 59 |
10 files changed, 97 insertions, 158 deletions
diff --git a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp index 8349f1274..3f1270eec 100644 --- a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp +++ b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -22,19 +22,12 @@ #include <QtPlugin> #include "m3uplaylistformat.h" -bool M3UPlaylistFormat::hasFormat(const QString &f) +const PlayListFormatProperties M3UPlaylistFormat::properties() const { - return m_supported_formats.contains(f); -} - -QStringList M3UPlaylistFormat::getExtensions() const -{ - return m_supported_formats; -} - -M3UPlaylistFormat::M3UPlaylistFormat() -{ - m_supported_formats << "m3u"; + PlayListFormatProperties p; + p.filters << "*.m3u"; + p.shortName = "m3u"; + return p; } QStringList M3UPlaylistFormat::decode(const QString & contents) @@ -70,9 +63,4 @@ QString M3UPlaylistFormat::encode(const QList<PlayListItem*> & contents) return out.join("\n"); } -QString M3UPlaylistFormat::name() const -{ - return "M3UPlaylistFormat"; -} - Q_EXPORT_PLUGIN2(m3uplaylistformat,M3UPlaylistFormat) diff --git a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h index 4a5414894..4c2405abf 100644 --- a/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h +++ b/src/plugins/PlayListFormats/m3u/m3uplaylistformat.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -35,14 +35,10 @@ 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<PlayListItem*>& contents); - virtual QString name()const; -protected: - QStringList m_supported_formats; + const PlayListFormatProperties properties() const; + QStringList decode(const QString& contents); + QString encode(const QList<PlayListItem*>& contents); + }; #endif diff --git a/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp b/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp index a251276d0..602e29199 100644 --- a/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp +++ b/src/plugins/PlayListFormats/pls/plsplaylistformat.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,34 +20,16 @@ #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 +const PlayListFormatProperties PLSPlaylistFormat::properties() const { - return "PLSPlaylistFormat"; + PlayListFormatProperties p; + p.filters << "*.pls"; + p.shortName = "pls"; + return p; } - QStringList PLSPlaylistFormat::decode(const QString & contents) { QStringList out; diff --git a/src/plugins/PlayListFormats/pls/plsplaylistformat.h b/src/plugins/PlayListFormats/pls/plsplaylistformat.h index 4d770ee74..42fbb48f6 100644 --- a/src/plugins/PlayListFormats/pls/plsplaylistformat.h +++ b/src/plugins/PlayListFormats/pls/plsplaylistformat.h @@ -35,14 +35,10 @@ 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<PlayListItem*>& contents); - virtual QString name()const; -protected: - QStringList m_supported_formats; + const PlayListFormatProperties properties() const; + QStringList decode(const QString& contents); + QString encode(const QList<PlayListItem*>& contents); + }; #endif diff --git a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp index 2e1296b48..4e6c2a349 100644 --- a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp +++ b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008-2009 by Ilya Kotov * + * Copyright (C) 2008-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -23,13 +23,19 @@ #include <QFileInfo> #include <QUrl> #include <QtPlugin> - #include <qmmp/qmmp.h> - #include "xspfplaylistformat.h" // Needs more work - it's better use libSpiff there and put it as plugin. +const PlayListFormatProperties XSPFPlaylistFormat::XSPFPlaylistFormat::properties() const +{ + PlayListFormatProperties p; + p.filters << "*.xspf"; + p.shortName = "xspf"; + return p; +} + QStringList XSPFPlaylistFormat::decode(const QString & contents) { QStringList out; @@ -138,29 +144,4 @@ QString XSPFPlaylistFormat::encode(const QList<PlayListItem*> & files) 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_PLUGIN2(xspfplaylistformat,XSPFPlaylistFormat) diff --git a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h index 2b72c8613..4570c041d 100644 --- a/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h +++ b/src/plugins/PlayListFormats/xspf/xspfplaylistformat.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Ilya Kotov * + * Copyright (C) 2008-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -35,14 +35,9 @@ 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<PlayListItem*>& contents); - virtual QString name()const; -protected: - QStringList m_supported_formats; + const PlayListFormatProperties properties() const; + QStringList decode(const QString& contents); + QString encode(const QList<PlayListItem*>& contents); }; #endif diff --git a/src/qmmpui/playlistformat.h b/src/qmmpui/playlistformat.h index 4c152d786..a2dd2ee10 100644 --- a/src/qmmpui/playlistformat.h +++ b/src/qmmpui/playlistformat.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2009 by Ilya Kotov * + * Copyright (C) 2006-2012 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -24,6 +24,16 @@ class PlayListItem; +/*! @brief Helper structure to store playlist format properies. + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +struct PlayListFormatProperties +{ + QString shortName; /*!< Unique name of the playlist format for internal usage */ + QStringList filters; /*!< File filters (example: "*.m3u") */ + QStringList contentTypes; /*!< Supported content types */ +}; + /*! @brief Abstract interface for playlist formats. * @author Vladimir Kuznetsov <vovanec@gmail.com> */ @@ -33,10 +43,11 @@ public: /*! * Object destructor */ - virtual ~PlayListFormat() - { - ; - } + virtual ~PlayListFormat() {} + /*! + * Returns playlist format properties. + */ + virtual const PlayListFormatProperties properties() const = 0; /*! * Takes raw contents of playlist file, should return string list of * ready file pathes to fill the playlist. @@ -47,18 +58,6 @@ public: * 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") diff --git a/src/qmmpui/playlistparser.cpp b/src/qmmpui/playlistparser.cpp index aa14ec214..7f14901a5 100644 --- a/src/qmmpui/playlistparser.cpp +++ b/src/qmmpui/playlistparser.cpp @@ -18,9 +18,10 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#include <QtGui> -#include <QObject> +#include <QPluginLoader> +#include <QRegExp> #include <QList> +#include <QDir> #include <QApplication> #include <qmmp/qmmp.h> #include "playlistformat.h" @@ -34,22 +35,28 @@ QList<PlayListFormat*> *PlayListParser::formats() return m_formats; } -PlayListFormat *PlayListParser::findByPath(const QString &filePath) +QStringList PlayListParser::nameFilters() { checkFormats(); - QString ext; - if(filePath.contains("://")) //is it url? + QStringList filters; + foreach(PlayListFormat* format, *m_formats) { - QString p = QUrl(filePath).encodedPath(); - ext = QFileInfo(p).suffix().toLower(); + filters << format->properties().filters; } - else - ext = QFileInfo(filePath).suffix().toLower(); + return filters; +} +PlayListFormat *PlayListParser::findByPath(const QString &filePath) +{ + checkFormats(); foreach(PlayListFormat* format, *m_formats) { - if (format->hasFormat(ext)) - return format; + foreach(QString filter, format->properties().filters) + { + QRegExp r(filter, Qt::CaseInsensitive, QRegExp::Wildcard); + if(r.exactMatch(filePath)) + return format; + } } return 0; } diff --git a/src/qmmpui/playlistparser.h b/src/qmmpui/playlistparser.h index c75b9412d..d78e3ad7d 100644 --- a/src/qmmpui/playlistparser.h +++ b/src/qmmpui/playlistparser.h @@ -33,6 +33,10 @@ public: */ static QList<PlayListFormat*> *formats(); /*! + * Returns a list of the supported files name filters, i.e. "*.m3u *.pls" + */ + static QStringList nameFilters(); + /*! * Finds playlist format by file path \b filePath * Returns \b 0 if file \b filePath is unsupported. */ diff --git a/src/qmmpui/uihelper.cpp b/src/qmmpui/uihelper.cpp index c9247640e..2dfb7b9e8 100644 --- a/src/qmmpui/uihelper.cpp +++ b/src/qmmpui/uihelper.cpp @@ -147,51 +147,42 @@ void UiHelper::addDirectory(QWidget *parent, PlayListModel *model) void UiHelper::loadPlayList(QWidget *parent, PlayListModel *model) { - QStringList l; - QList<PlayListFormat*> *p_list = PlayListParser::formats(); - if (!p_list->isEmpty()) + if(PlayListParser::nameFilters().isEmpty()) { - foreach(PlayListFormat* fmt, *p_list) - l << fmt->getExtensions(); - - QString mask = tr("Playlist Files")+" (" + l.join(" *.").prepend("*.") + ")"; - //TODO use nonmodal dialog and multiplier playlists - QString f_name = FileDialog::getOpenFileName(parent ,tr("Open Playlist"),m_lastDir,mask); - if (!f_name.isEmpty()) - { - model->clear(); - model->loadPlaylist(f_name); - model->setName(QFileInfo(f_name).baseName()); - m_lastDir = QFileInfo(f_name).absoluteDir().path(); - } + qWarning("UiHelper: There is no registered playlist parsers"); + return; } - else + + QString mask = tr("Playlist Files") + " (" + PlayListParser::nameFilters().join(" ") + ")"; + //TODO use nonmodal dialog and multiplier playlists + QString f_name = FileDialog::getOpenFileName(parent ,tr("Open Playlist"), m_lastDir, mask); + if (!f_name.isEmpty()) { - qWarning("Error: There is no registered playlist parsers"); + model->clear(); + model->loadPlaylist(f_name); + model->setName(QFileInfo(f_name).baseName()); + m_lastDir = QFileInfo(f_name).absoluteDir().path(); } } void UiHelper::savePlayList(QWidget *parent, PlayListModel *model) { - QStringList l; - QList<PlayListFormat*> *p_list = PlayListParser::formats(); - if (!p_list->isEmpty()) + if(PlayListParser::nameFilters().isEmpty()) { - foreach(PlayListFormat* fmt,*p_list) - l << fmt->getExtensions(); - - QString mask = tr("Playlist Files")+" (" + l.join(" *.").prepend("*.") + ")"; - QString f_name = FileDialog::getSaveFileName(parent, tr("Save Playlist"),m_lastDir + "/" + - model->name() + "." + l[0],mask); + qWarning("UiHelper: There is no registered playlist parsers"); + return; + } + QString ext = PlayListParser::nameFilters().at(0); + ext.replace("*.", "."); //extract extension from name filter + QString mask = tr("Playlist Files") + " (" + PlayListParser::nameFilters().join(" ") + ")"; + QString f_name = FileDialog::getSaveFileName(parent, tr("Save Playlist"),m_lastDir + "/" + + model->name() + ext,mask); - if (!f_name.isEmpty()) - { - model->savePlaylist(f_name); - m_lastDir = QFileInfo(f_name).absoluteDir().path(); - } + if (!f_name.isEmpty()) + { + model->savePlaylist(f_name); + m_lastDir = QFileInfo(f_name).absoluteDir().path(); } - else - qWarning("Error: There is no registered playlist parsers"); } void UiHelper::jumpToTrack(QWidget *parent, PlayListModel *model) |
