aboutsummaryrefslogtreecommitdiff
path: root/src/qmmpui
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmmpui')
-rw-r--r--src/qmmpui/CMakeLists.txt2
-rw-r--r--src/qmmpui/configdialog.cpp2
-rw-r--r--src/qmmpui/general.cpp127
-rw-r--r--src/qmmpui/general.h18
-rw-r--r--src/qmmpui/qmmpui.pro6
-rw-r--r--src/qmmpui/qmmpuiplugincache.cpp155
-rw-r--r--src/qmmpui/qmmpuiplugincache_p.h57
-rw-r--r--src/qmmpui/uihelper.cpp6
8 files changed, 305 insertions, 68 deletions
diff --git a/src/qmmpui/CMakeLists.txt b/src/qmmpui/CMakeLists.txt
index ae500bc83..4a4a4bdd4 100644
--- a/src/qmmpui/CMakeLists.txt
+++ b/src/qmmpui/CMakeLists.txt
@@ -52,6 +52,7 @@ SET(libqmmpui_SRCS
radioitemdelegate.cpp
playlistdownloader.cpp
addurldialog.cpp
+ qmmpuiplugincache.cpp
)
SET(libqmmpui_HDRS
@@ -68,6 +69,7 @@ SET(libqmmpui_HDRS
pluginitem_p.h
general.h
playlistparser.h
+ qmmpuiplugincache_p.h
)
SET(libqmmpui_MOC_HDRS
diff --git a/src/qmmpui/configdialog.cpp b/src/qmmpui/configdialog.cpp
index 8fc747cb0..e1a9f25d8 100644
--- a/src/qmmpui/configdialog.cpp
+++ b/src/qmmpui/configdialog.cpp
@@ -222,7 +222,7 @@ void ConfigDialog::loadPluginsInfo()
load general plugin information
*/
item = new QTreeWidgetItem (m_ui->treeWidget, QStringList() << tr("General"));
- foreach(GeneralFactory *factory, *General::factories())
+ foreach(GeneralFactory *factory, General::factories())
{
new PluginItem (item, factory, General::file(factory));
}
diff --git a/src/qmmpui/general.cpp b/src/qmmpui/general.cpp
index c78df7b0e..3b3c65a8b 100644
--- a/src/qmmpui/general.cpp
+++ b/src/qmmpui/general.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2012 by Ilya Kotov *
+ * Copyright (C) 2008-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -18,47 +18,39 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <QtGui>
-#include <QObject>
#include <QList>
-#include <QApplication>
+#include <QDir>
+#include <QDialog>
#include <qmmp/qmmp.h>
+#include "qmmpuiplugincache_p.h"
#include "general.h"
-QList<GeneralFactory*> *General::m_factories = 0;
-QHash <GeneralFactory*, QString> *General::m_files = 0;
+QList<QmmpUiPluginCache*> *General::m_cache = 0;
+QStringList General::m_enabledNames;
QHash <GeneralFactory*, QObject*> *General::m_generals = 0;
QObject *General::m_parent = 0;
-void General::checkFactories()
+void General::loadPlugins()
{
- if (!m_factories)
+ if (m_cache)
+ return;
+
+ m_cache = new QList<QmmpUiPluginCache*>;
+ QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
+ QDir pluginsDir (Qmmp::pluginsPath());
+ pluginsDir.cd("General");
+ foreach (QString fileName, pluginsDir.entryList(QDir::Files))
{
- m_factories = new QList<GeneralFactory *>;
- m_files = new QHash <GeneralFactory*, QString>;
- QDir pluginsDir (Qmmp::pluginsPath());
- pluginsDir.cd("General");
- foreach (QString fileName, pluginsDir.entryList(QDir::Files))
+ QmmpUiPluginCache *item = new QmmpUiPluginCache(pluginsDir.absoluteFilePath(fileName), &settings);
+ if(item->hasError())
{
- QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
- QObject *plugin = loader.instance();
- if (loader.isLoaded())
- qDebug("General: loaded plugin %s", qPrintable(fileName));
- else
- qWarning("General: %s", qPrintable(loader.errorString ()));
-
- GeneralFactory *factory = 0;
- if (plugin)
- factory = qobject_cast<GeneralFactory *>(plugin);
-
- if (factory)
- {
- m_factories->append(factory);
- m_files->insert(factory, pluginsDir.absoluteFilePath(fileName));
- qApp->installTranslator(factory->createTranslator(qApp));
- }
+ delete item;
+ continue;
}
+ m_cache->append(item);
}
+ m_enabledNames = settings.value("General/enabled_plugins").toStringList();
+ QmmpUiPluginCache::cleanup(&settings);
}
void General::create(QObject *parent)
@@ -67,10 +59,13 @@ void General::create(QObject *parent)
return;
m_generals = new QHash <GeneralFactory*, QObject*>();
m_parent = parent;
- checkFactories();
- foreach(GeneralFactory* factory, *General::factories())
+ loadPlugins();
+ foreach(QmmpUiPluginCache* item, *m_cache)
{
- if (General::isEnabled(factory))
+ if(!m_enabledNames.contains(item->shortName()))
+ continue;
+ GeneralFactory *factory = item->generalFactory();
+ if (factory)
{
QObject *general = factory->create(parent);
m_generals->insert(factory, general);
@@ -78,40 +73,64 @@ void General::create(QObject *parent)
}
}
-QList<GeneralFactory*> *General::factories()
+QList<GeneralFactory *> General::factories()
{
- checkFactories();
- return m_factories;
+ loadPlugins();
+ QList<GeneralFactory *> list;
+ foreach (QmmpUiPluginCache *item, *m_cache)
+ {
+ if(item->generalFactory())
+ list.append(item->generalFactory());
+ }
+ return list;
+}
+
+QList<GeneralFactory *> General::enabledFactories()
+{
+ loadPlugins();
+ QList<GeneralFactory *> list;
+ foreach (QmmpUiPluginCache *item, *m_cache)
+ {
+ if(!m_enabledNames.contains(item->shortName()))
+ continue;
+ if(item->generalFactory())
+ list.append(item->generalFactory());
+ }
+ return list;
}
QString General::file(GeneralFactory *factory)
{
- checkFactories();
- return m_files->value(factory);
+ loadPlugins();
+ foreach(QmmpUiPluginCache *item, *m_cache)
+ {
+ if(item->shortName() == factory->properties().shortName)
+ return item->file();
+ }
+ return QString();
}
void General::setEnabled(GeneralFactory* factory, bool enable)
{
- checkFactories();
- if (!m_factories->contains(factory))
+ loadPlugins();
+ if (!factories().contains(factory))
+ return;
+
+ if(enable == isEnabled(factory))
return;
- QString name = factory->properties().shortName;
- QSettings settings ( Qmmp::configFile(), QSettings::IniFormat );
- QStringList genList = settings.value("General/enabled_plugins").toStringList();
+ QSettings settings (Qmmp::configFile(), QSettings::IniFormat);
if (enable)
- {
- if (!genList.contains(name))
- genList << name;
- }
+ m_enabledNames << factory->properties().shortName;
else
- genList.removeAll(name);
- settings.setValue("General/enabled_plugins", genList);
+ m_enabledNames.removeAll(factory->properties().shortName);
+ m_enabledNames.removeDuplicates();
+ settings.setValue("General/enabled_plugins", m_enabledNames);
+
if(!m_generals)
return;
-
if (enable == m_generals->keys().contains(factory))
return;
if (enable)
@@ -143,10 +162,6 @@ void General::showSettings(GeneralFactory* factory, QWidget* parentWidget)
bool General::isEnabled(GeneralFactory* factory)
{
- checkFactories();
- if (!m_factories->contains(factory))
- return false;
- QSettings settings (Qmmp::configFile(), QSettings::IniFormat );
- QStringList genList = settings.value("General/enabled_plugins").toStringList();
- return genList.contains(factory->properties().shortName);
+ loadPlugins();
+ return m_enabledNames.contains(factory->properties().shortName);
}
diff --git a/src/qmmpui/general.h b/src/qmmpui/general.h
index ba15da292..4c2f4879d 100644
--- a/src/qmmpui/general.h
+++ b/src/qmmpui/general.h
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2012 by Ilya Kotov *
+ * Copyright (C) 2008-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -25,6 +25,8 @@
#include <QHash>
#include "generalfactory.h"
+class QmmpUiPluginCache;
+
/*! @brief The General class provides simple access to general plugins
* @author Ilya Kotov <forkotov02@hotmail.ru>
*/
@@ -37,9 +39,13 @@ public:
*/
static void create(QObject *parent);
/*!
- * Returns a list of the loaded general plugin factories.
+ * Returns a list of the general plugin factories.
+ */
+ static QList<GeneralFactory *> factories();
+ /*!
+ * Returns a list of the enabled general plugin factories.
*/
- static QList<GeneralFactory*> *factories();
+ static QList<GeneralFactory *> enabledFactories();
/*!
* Returns plugin file path.
* @param factory General plugin factory.
@@ -64,11 +70,11 @@ public:
static bool isEnabled(GeneralFactory* factory);
private:
- static void checkFactories();
- static QList<GeneralFactory*> *m_factories;
+ static void loadPlugins();
static QHash <GeneralFactory*, QObject*> *m_generals;
- static QHash <GeneralFactory*, QString> *m_files;
static QObject *m_parent;
+ static QList<QmmpUiPluginCache*> *m_cache;
+ static QStringList m_enabledNames;
};
#endif
diff --git a/src/qmmpui/qmmpui.pro b/src/qmmpui/qmmpui.pro
index 15c324398..0ae9e0843 100644
--- a/src/qmmpui/qmmpui.pro
+++ b/src/qmmpui/qmmpui.pro
@@ -47,7 +47,8 @@ HEADERS += general.h \
qmmpuisettings.h \
radioitemdelegate_p.h \
playlistdownloader.h \
- addurldialog_p.h
+ addurldialog_p.h \
+ qmmpuiplugincache_p.h
SOURCES += general.cpp \
playlistparser.cpp \
commandlinemanager.cpp \
@@ -72,7 +73,8 @@ SOURCES += general.cpp \
qmmpuisettings.cpp \
radioitemdelegate.cpp \
playlistdownloader.cpp \
- addurldialog.cpp
+ addurldialog.cpp \
+ qmmpuiplugincache.cpp
FORMS += forms/detailsdialog.ui \
forms/tageditor.ui \
forms/templateeditor.ui \
diff --git a/src/qmmpui/qmmpuiplugincache.cpp b/src/qmmpui/qmmpuiplugincache.cpp
new file mode 100644
index 000000000..ff804c131
--- /dev/null
+++ b/src/qmmpui/qmmpuiplugincache.cpp
@@ -0,0 +1,155 @@
+/***************************************************************************
+ * 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 <QStringList>
+#include <QDateTime>
+#include <QFileInfo>
+#include <QPluginLoader>
+#include <QApplication>
+#include <QTranslator>
+#include "generalfactory.h"
+#include "qmmpuiplugincache_p.h"
+
+QmmpUiPluginCache::QmmpUiPluginCache(const QString &file, QSettings *settings)
+{
+ m_error = false;
+ m_instance = 0;
+ m_generalFactory = 0;
+ m_priority = 0;
+ bool update = false;
+ QFileInfo info(file);
+ m_path = info.QFileInfo::canonicalFilePath();
+
+ settings->beginGroup("PluginCache");
+ QString key = m_path;
+#ifndef Q_OS_WIN
+ key.remove(0,1);
+#endif
+ if(settings->allKeys().contains(key))
+
+ {
+ 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(GeneralFactory *factory = generalFactory())
+ {
+ m_shortName = factory->properties().shortName;
+ m_priority = 0;
+ }
+ else
+ {
+ qWarning("QmmpUiPluginCache: 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("QmmpUiPluginCache: added cache item \"%s=%s\"",
+ qPrintable(info.fileName()), qPrintable(values.join(",")));
+ }
+ }
+ settings->endGroup();
+}
+
+const QString QmmpUiPluginCache::shortName() const
+{
+ return m_shortName;
+}
+
+const QString QmmpUiPluginCache::file() const
+{
+ return m_path;
+}
+
+int QmmpUiPluginCache::priority() const
+{
+ return m_priority;
+}
+
+bool QmmpUiPluginCache::hasError() const
+{
+ return m_error;
+}
+
+GeneralFactory *QmmpUiPluginCache::generalFactory()
+{
+ if(!m_generalFactory)
+ {
+ m_generalFactory = qobject_cast<GeneralFactory *> (instance());
+ if(m_generalFactory)
+ qApp->installTranslator(m_generalFactory->createTranslator(qApp));
+ }
+ return m_generalFactory;
+}
+
+QObject *QmmpUiPluginCache::instance()
+{
+ if(m_error)
+ return 0;
+ if(m_instance)
+ return m_instance;
+ QPluginLoader loader(m_path);
+ m_instance = loader.instance();
+ if (loader.isLoaded())
+ qDebug("QmmpUiPluginCache: loaded plugin %s", qPrintable(QFileInfo(m_path).fileName()));
+ else
+ {
+ m_error = true;
+ qWarning("QmmpUiPluginCache: error: %s", qPrintable(loader.errorString ()));
+ }
+ return m_instance;
+}
+
+void QmmpUiPluginCache::cleanup(QSettings *settings)
+{
+ settings->beginGroup("PluginCache");
+
+ foreach (QString key, settings->allKeys())
+ {
+#ifdef Q_OS_WIN
+ if(!QFile::exists(key))
+#else
+ if(!QFile::exists("/" + key))
+#endif
+ {
+ settings->remove(key);
+ qDebug("QmmpUiPluginCache: removed key %s", qPrintable(key));
+ }
+ }
+ settings->endGroup();
+}
diff --git a/src/qmmpui/qmmpuiplugincache_p.h b/src/qmmpui/qmmpuiplugincache_p.h
new file mode 100644
index 000000000..c5e3186f6
--- /dev/null
+++ b/src/qmmpui/qmmpuiplugincache_p.h
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * 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 QMMPUIPLUGINCACHE_P_H
+#define QMMPUIPLUGINCACHE_P_H
+
+#include <QString>
+#include <QObject>
+#include <QSettings>
+
+class GeneralFactory;
+
+/*! @internal
+ * @author Ilya Kotov <forkotov02@hotmail.ru>
+ */
+class QmmpUiPluginCache
+{
+public:
+ QmmpUiPluginCache(const QString &file, QSettings *settings);
+
+ const QString shortName() const;
+ const QString file() const;
+ int priority() const;
+ bool hasError() const;
+
+ GeneralFactory *generalFactory();
+
+ static void cleanup(QSettings *settings);
+
+private:
+ QObject *instance();
+ QString m_path;
+ QString m_shortName;
+ bool m_error;
+ QObject *m_instance;
+ GeneralFactory *m_generalFactory;
+ int m_priority;
+};
+
+#endif // QMMPUIPLUGINCACHE_P_H
diff --git a/src/qmmpui/uihelper.cpp b/src/qmmpui/uihelper.cpp
index e2984619f..48d827618 100644
--- a/src/qmmpui/uihelper.cpp
+++ b/src/qmmpui/uihelper.cpp
@@ -1,5 +1,5 @@
/***************************************************************************
- * Copyright (C) 2008-2012 by Ilya Kotov *
+ * Copyright (C) 2008-2013 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -57,9 +57,9 @@ UiHelper::~UiHelper()
bool UiHelper::visibilityControl()
{
GeneralFactory* factory;
- foreach(factory, *General::factories())
+ foreach(factory, General::enabledFactories())
{
- if (General::isEnabled(factory) && factory->properties().visibilityControl)
+ if (factory->properties().visibilityControl)
return true;
}
return false;