diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-11-17 21:32:21 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-11-17 21:32:21 +0000 |
| commit | e6b0d3e9a5c7f638e259e52a4ede439ae9a9d3ad (patch) | |
| tree | c847bbfb62708e011587a894a4120769fd8d7fa2 /src | |
| parent | 0d2454cadeb6798ef81d6cd6694b51876f6b84ad (diff) | |
| download | qmmp-e6b0d3e9a5c7f638e259e52a4ede439ae9a9d3ad.tar.gz qmmp-e6b0d3e9a5c7f638e259e52a4ede439ae9a9d3ad.tar.bz2 qmmp-e6b0d3e9a5c7f638e259e52a4ede439ae9a9d3ad.zip | |
added regexp for InputSourceFactory
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9103 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/qmmp/inputsource.cpp | 41 | ||||
| -rw-r--r-- | src/qmmp/inputsource.h | 1 | ||||
| -rw-r--r-- | src/qmmp/inputsourcefactory.h | 13 | ||||
| -rw-r--r-- | src/qmmp/metadatamanager.cpp | 2 |
4 files changed, 40 insertions, 17 deletions
diff --git a/src/qmmp/inputsource.cpp b/src/qmmp/inputsource.cpp index b4bbee466..c1dd59e16 100644 --- a/src/qmmp/inputsource.cpp +++ b/src/qmmp/inputsource.cpp @@ -99,24 +99,14 @@ QList<QmmpPluginCache*> *InputSource::m_cache = nullptr; InputSource *InputSource::create(const QString &url, QObject *parent) { loadPlugins(); - InputSourceFactory *factory = nullptr; if(!url.contains("://")) //local file path doesn't contain "://" { qDebug("InputSource: using file transport"); return new FileInputSource(url, parent); } - for(QmmpPluginCache *item : qAsConst(*m_cache)) - { - if(m_disabledNames.contains(item->shortName())) - continue; - factory = item->inputSourceFactory(); + InputSourceFactory *factory = findByUrl(url); - if(factory && factory->properties().protocols.contains(url.section("://", 0, 0))) - break; - else - factory = nullptr; - } if(factory) { qDebug("InputSource: using %s transport", qPrintable(url.section("://", 0, 0))); @@ -182,6 +172,35 @@ QStringList InputSource::protocols() return protocolsList; } +InputSourceFactory *InputSource::findByUrl(const QString &url) +{ + for(QmmpPluginCache *item : qAsConst(*m_cache)) + { + if(m_disabledNames.contains(item->shortName())) + continue; + + InputSourceFactory *factory = item->inputSourceFactory(); + for(const QRegularExpression &r : factory->properties().regExps) + { + if(r.match(url).hasMatch()) + return factory; + } + } + + for(QmmpPluginCache *item : qAsConst(*m_cache)) + { + if(m_disabledNames.contains(item->shortName())) + continue; + + InputSourceFactory *factory = item->inputSourceFactory(); + + if(factory && factory->properties().protocols.contains(url.section("://", 0, 0))) + return factory; + } + + return nullptr; +} + void InputSource::setEnabled(InputSourceFactory *factory, bool enable) { loadPlugins(); diff --git a/src/qmmp/inputsource.h b/src/qmmp/inputsource.h index fd87d102a..04885b8c7 100644 --- a/src/qmmp/inputsource.h +++ b/src/qmmp/inputsource.h @@ -135,6 +135,7 @@ public: * Returns a list of supported protocols. */ static QStringList protocols(); + static InputSourceFactory *findByUrl(const QString &url); /*! * Sets whether the input plugin is enabled. * @param factory Transport plugin factory. diff --git a/src/qmmp/inputsourcefactory.h b/src/qmmp/inputsourcefactory.h index b22734d42..d8b9ec4fd 100644 --- a/src/qmmp/inputsourcefactory.h +++ b/src/qmmp/inputsourcefactory.h @@ -22,6 +22,8 @@ #define INPUTSOURCEFACTORY_H #include <QObject> +#include <QRegularExpression> +#include <QList> #include "qmmp_export.h" class QStringList; @@ -32,11 +34,12 @@ class InputSource; */ struct QMMP_EXPORT InputSourceProperties { - QString name; /*!< Transport plugin full name */ - QString shortName; /*!< Transport plugin name for internal usage */ - QStringList protocols; /*!< A list of supported protocols. */ - bool hasAbout = false; /*!< Should be \b true if plugin has about dialog, otherwise \b false */ - bool hasSettings = false; /*!< Should be \b true if plugin has settings dialog, otherwise \b false */ + QString name; /*!< Transport plugin full name */ + QString shortName; /*!< Transport plugin name for internal usage */ + QList<QRegularExpression> regExps; /*!< A list of regular expressions for supported URLs (has highest priority). */ + QStringList protocols; /*!< A list of supported protocols. */ + bool hasAbout = false; /*!< Should be \b true if plugin has about dialog, otherwise \b false */ + bool hasSettings = false; /*!< Should be \b true if plugin has settings dialog, otherwise \b false */ }; diff --git a/src/qmmp/metadatamanager.cpp b/src/qmmp/metadatamanager.cpp index 8e291d1a7..ea7184b99 100644 --- a/src/qmmp/metadatamanager.cpp +++ b/src/qmmp/metadatamanager.cpp @@ -64,7 +64,7 @@ QList<TrackInfo *> MetaDataManager::createPlayList(const QString &path, TrackInf else { QString scheme = path.section("://",0,0); - if(InputSource::protocols().contains(scheme)) + if(InputSource::findByUrl(path)) { list << new TrackInfo(path); } |
