From a1eccaf2c22bf4743a65e17c91bc2f5ab3a276a1 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 12 May 2013 10:58:45 +0000 Subject: plugin cache: added decoder priority support git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3443 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmp/CMakeLists.txt | 3 + src/qmmp/decoder.cpp | 9 +-- src/qmmp/plugincache.cpp | 125 --------------------------------------- src/qmmp/plugincache.h | 57 ------------------ src/qmmp/qmmp.pro | 4 +- src/qmmp/qmmpplugincache.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++ src/qmmp/qmmpplugincache_p.h | 59 ++++++++++++++++++ 7 files changed, 207 insertions(+), 188 deletions(-) delete mode 100644 src/qmmp/plugincache.cpp delete mode 100644 src/qmmp/plugincache.h create mode 100644 src/qmmp/qmmpplugincache.cpp create mode 100644 src/qmmp/qmmpplugincache_p.h (limited to 'src') diff --git a/src/qmmp/CMakeLists.txt b/src/qmmp/CMakeLists.txt index 325fec452..4710e15e0 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -57,6 +57,7 @@ SET(libqmmp_SRCS audioconverter.cpp eqsettings.cpp qmmpevents.cpp + qmmpplugincache.cpp ) SET(libqmmp_HDRS @@ -75,6 +76,7 @@ SET(libqmmp_HDRS replaygain_p.h fileinfo.h audioconverter_p.h + qmmpplugincache_p.h eqsettings.h decoder.h tagmodel.h @@ -84,6 +86,7 @@ SET(libqmmp_HDRS metadatamanager.h volume.h output.h + ) SET(libqmmp_MOC_HDRS diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 197ba3569..a41efacdd 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -10,7 +10,7 @@ #include #include #include -#include "plugincache.h" +#include "qmmpplugincache_p.h" #include "buffer.h" #include "output.h" #include "visual.h" @@ -87,10 +87,10 @@ DecoderFactory *Decoder::m_lastFactory = 0; QList *Decoder::m_cache = 0; //sort cache items by priority -/*static bool _decoderLessComparator(DecoderFactory* f1, DecoderFactory* f2) +static bool _pluginCacheLessComparator(QmmpPluginCache* f1, QmmpPluginCache* f2) { - return f1->properties().priority < f2->properties().priority; -}*/ + return f1->priority() < f2->priority(); +} void Decoder::checkFactories() { @@ -112,6 +112,7 @@ void Decoder::checkFactories() m_cache->append(item); } m_disabledNames = settings.value("Decoder/disabled_plugins").toStringList(); + qSort(m_cache->begin(), m_cache->end(), _pluginCacheLessComparator); } QString Decoder::file(DecoderFactory *factory) diff --git a/src/qmmp/plugincache.cpp b/src/qmmp/plugincache.cpp deleted file mode 100644 index a1eed8621..000000000 --- a/src/qmmp/plugincache.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2013 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include "decoderfactory.h" -#include "outputfactory.h" -#include "plugincache.h" - -QmmpPluginCache::QmmpPluginCache(const QString &file, QSettings *settings) -{ - m_error = false; - m_instance = 0; - m_decoderFactory = 0; - bool update = false; - QFileInfo info(file); - m_path = info.QFileInfo::canonicalFilePath(); - - settings->beginGroup("PluginCache"); - QString copy = m_path; - if(settings->allKeys().contains(copy.remove(0,1))) - { - QStringList values = settings->value(m_path).toStringList(); - if(values.count() != 2) - update = true; - else - { - m_shortName = values.at(0); - update = (info.lastModified().toString(Qt::ISODate) != values.at(1)); - } - } - else - update = true; - - - if(update) - { - if(DecoderFactory *factory = decoderFactory()) - { - m_shortName = factory->properties().shortName; - } - /*else if(OutputFactory *factory = outputFactory()) - { - m_shortName = factory->properties().shortName; - }*/ - else - m_error = true; - - if (!m_error) - { - QStringList values; - values << m_shortName; - values << info.lastModified().toString(Qt::ISODate); - settings->setValue(m_path, values); - qDebug("PluginCache: added to cache: %s", qPrintable(m_path)); - } - } - - settings->endGroup(); -} - -const QString QmmpPluginCache::shortName() const -{ - return m_shortName; -} - -const QString QmmpPluginCache::file() const -{ - return m_path; -} - -DecoderFactory *QmmpPluginCache::decoderFactory() -{ - if(!m_decoderFactory) - { - m_decoderFactory = qobject_cast (instance()); - if(m_decoderFactory) - qApp->installTranslator(m_decoderFactory->createTranslator(qApp)); - } - return m_decoderFactory; -} - -bool QmmpPluginCache::hasError() const -{ - return m_error; -} - -QObject *QmmpPluginCache::instance() -{ - if(m_error) - return 0; - if(m_instance) - return m_instance; - QPluginLoader loader(m_path); - m_instance = loader.instance(); - if (loader.isLoaded()) - qDebug("PluginCache: loaded plugin %s", qPrintable(QFileInfo(m_path).fileName())); - else - { - m_error = true; - qWarning("PluginCache: %s", qPrintable(loader.errorString ())); - } - return m_instance; -} diff --git a/src/qmmp/plugincache.h b/src/qmmp/plugincache.h deleted file mode 100644 index b258fd5e2..000000000 --- a/src/qmmp/plugincache.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2013 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef PLUGINCACHE_H -#define PLUGINCACHE_H - -#include -#include -#include - -class DecoderFactory; - -/*! @internal - * @author Ilya Kotov - */ -class QmmpPluginCache -{ -public: - QmmpPluginCache(const QString &file, QSettings *settings); - - const QString shortName() const; - const QString file() const; - bool hasError() const; - - - DecoderFactory *decoderFactory(); - - //OutputFactory *outputFactory(); - //EngineFactory *engineFactory(); - -private: - QObject *instance(); - QString m_path; - QString m_shortName; - bool m_error; - QObject *m_instance; - DecoderFactory *m_decoderFactory; -}; - -#endif // PLUGINCACHE_H diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index 41191d798..ee1188005 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -37,7 +37,7 @@ HEADERS += \ volumecontrol_p.h \ outputwriter_p.h \ recycler_p.h \ - plugincache.h + qmmpplugincache_p.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -66,7 +66,7 @@ SOURCES += recycler.cpp \ eqsettings.cpp \ qmmpevents.cpp \ outputwriter.cpp \ - plugincache.cpp + qmmpplugincache.cpp FORMS += unix:TARGET = ../../lib/qmmp win32:TARGET = ../../../bin/qmmp diff --git a/src/qmmp/qmmpplugincache.cpp b/src/qmmp/qmmpplugincache.cpp new file mode 100644 index 000000000..bc8b7b395 --- /dev/null +++ b/src/qmmp/qmmpplugincache.cpp @@ -0,0 +1,138 @@ +/*************************************************************************** + * Copyright (C) 2013 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include "decoderfactory.h" +#include "outputfactory.h" +#include "qmmpplugincache_p.h" + +QmmpPluginCache::QmmpPluginCache(const QString &file, QSettings *settings) +{ + m_error = false; + m_instance = 0; + m_decoderFactory = 0; + m_priority = 0; + bool update = false; + QFileInfo info(file); + m_path = info.QFileInfo::canonicalFilePath(); + + settings->beginGroup("PluginCache"); + QString copy = m_path; + if(settings->allKeys().contains(copy.remove(0,1))) + { + QStringList values = settings->value(m_path).toStringList(); + if(values.count() != 3) + update = true; + else + { + m_shortName = values.at(0); + m_priority = values.at(1).toInt(); + update = (info.lastModified().toString(Qt::ISODate) != values.at(2)); + } + } + else + update = true; + + + if(update) + { + if(DecoderFactory *factory = decoderFactory()) + { + m_shortName = factory->properties().shortName; + m_priority = factory->properties().priority; + } + /*else if(OutputFactory *factory = outputFactory()) + { + m_shortName = factory->properties().shortName; + m_priority = 0; + }*/ + else + { + qWarning("QmmpPluginCache: unknown plugin type: %s", qPrintable(m_path)); + m_error = true; + } + + if (!m_error) + { + QStringList values; + values << m_shortName; + values << QString::number(m_priority); + values << info.lastModified().toString(Qt::ISODate); + settings->setValue(m_path, values); + qDebug("QmmpPluginCache: added cache item \"%s=%s\"", + qPrintable(info.fileName()), qPrintable(values.join(","))); + } + } + settings->endGroup(); +} + +const QString QmmpPluginCache::shortName() const +{ + return m_shortName; +} + +const QString QmmpPluginCache::file() const +{ + return m_path; +} + +int QmmpPluginCache::priority() const +{ + return m_priority; +} + +DecoderFactory *QmmpPluginCache::decoderFactory() +{ + if(!m_decoderFactory) + { + m_decoderFactory = qobject_cast (instance()); + if(m_decoderFactory) + qApp->installTranslator(m_decoderFactory->createTranslator(qApp)); + } + return m_decoderFactory; +} + +bool QmmpPluginCache::hasError() const +{ + return m_error; +} + +QObject *QmmpPluginCache::instance() +{ + if(m_error) + return 0; + if(m_instance) + return m_instance; + QPluginLoader loader(m_path); + m_instance = loader.instance(); + if (loader.isLoaded()) + qDebug("QmmpPluginCache: loaded plugin %s", qPrintable(QFileInfo(m_path).fileName())); + else + { + m_error = true; + qWarning("QmmpPluginCache: error: %s", qPrintable(loader.errorString ())); + } + return m_instance; +} diff --git a/src/qmmp/qmmpplugincache_p.h b/src/qmmp/qmmpplugincache_p.h new file mode 100644 index 000000000..028e1f561 --- /dev/null +++ b/src/qmmp/qmmpplugincache_p.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2013 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef QMMPPLUGINCACHE_P_H +#define QMMPPLUGINCACHE_P_H + +#include +#include +#include + +class DecoderFactory; + +/*! @internal + * @author Ilya Kotov + */ +class QmmpPluginCache +{ +public: + QmmpPluginCache(const QString &file, QSettings *settings); + + const QString shortName() const; + const QString file() const; + int priority() const; + bool hasError() const; + + + DecoderFactory *decoderFactory(); + + //OutputFactory *outputFactory(); + //EngineFactory *engineFactory(); + +private: + QObject *instance(); + QString m_path; + QString m_shortName; + bool m_error; + QObject *m_instance; + DecoderFactory *m_decoderFactory; + int m_priority; +}; + +#endif // QMMPPLUGINCACHE_P_H -- cgit v1.2.3-13-gbd6f