From 2f4bd7bb6981aa1eb6ad1e9b9e109878ed2947cf Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Tue, 21 Jan 2014 14:33:12 +0100 Subject: [PATCH] use qmetaenum in typeFromString --- src/core/plugins/plugincontainer.cpp | 38 +++++++------------ src/core/plugins/plugincontainer.h | 8 ++-- src/core/plugins/plugins.h | 2 + src/core/snore.cpp | 2 +- .../freedesktopnotificationfrontend.cpp | 6 +-- src/snorenotify.cpp | 2 +- 6 files changed, 25 insertions(+), 33 deletions(-) diff --git a/src/core/plugins/plugincontainer.cpp b/src/core/plugins/plugincontainer.cpp index c25277e..c693ae8 100644 --- a/src/core/plugins/plugincontainer.cpp +++ b/src/core/plugins/plugincontainer.cpp @@ -27,13 +27,14 @@ #include #include +#include using namespace Snore; QHash PluginContainer::s_pluginCache = QHash() ; -PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginType type): +PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type): m_pluginFile(fileName), m_pluginName(pluginName), m_pluginType(type), @@ -72,39 +73,28 @@ const QString & PluginContainer::name() return m_pluginName; } -SnorePlugin::PluginType PluginContainer::type() +SnorePlugin::PluginTypes PluginContainer::type() { return m_pluginType; } -SnorePlugin::PluginType PluginContainer::typeFromString(const QString &t) +SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t) { - SnorePlugin::PluginType type = SnorePlugin::PLUGIN; - if(t == QLatin1String("backend")) - { - type = SnorePlugin::BACKEND; - } - else if(t == QLatin1String("secondary_backend")) - { - type = SnorePlugin::SECONDARY_BACKEND; - } - else if(t == QLatin1String("frontend")) - { - type = SnorePlugin::FRONTEND; - } - return type; + return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1()); } const QStringList &PluginContainer::types() { - static QStringList list; - if(list.isEmpty()){ - list << "backend" - << "secondary_backend" - << "frontend" - << "plugin"; + static QStringList out; + if(out.isEmpty()) + { + QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")); + for(int i=0;i pluginCache(); - PluginContainer(QString fileName,QString pluginName,SnorePlugin::PluginType type); + PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type); ~PluginContainer(); SnorePlugin *load(); void unload(); const QString &file(); const QString &name(); - SnorePlugin::PluginType type(); + SnorePlugin::PluginTypes type(); - static SnorePlugin::PluginType typeFromString(const QString &t); + static SnorePlugin::PluginTypes typeFromString(const QString &t); static const QStringList &types(); private: @@ -69,7 +69,7 @@ private: QString m_pluginFile; QString m_pluginName; - SnorePlugin::PluginType m_pluginType; + SnorePlugin::PluginTypes m_pluginType; QPluginLoader m_loader; }; } diff --git a/src/core/plugins/plugins.h b/src/core/plugins/plugins.h index 408e444..6b9c267 100644 --- a/src/core/plugins/plugins.h +++ b/src/core/plugins/plugins.h @@ -45,6 +45,8 @@ public: PLUGIN = 0x8 }; Q_DECLARE_FLAGS(PluginTypes, PluginType) + Q_ENUMS(PluginType) + SnorePlugin ( const QString &name); virtual ~SnorePlugin(); diff --git a/src/core/snore.cpp b/src/core/snore.cpp index d95a7df..3ec4f66 100644 --- a/src/core/snore.cpp +++ b/src/core/snore.cpp @@ -57,7 +57,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types ) snoreDebug( SNORE_DEBUG ) << "PluginInfo" << PluginContainer::pluginCache().keys(); foreach ( PluginContainer *info, PluginContainer::pluginCache().values()) { - if(types == SnorePlugin::ALL || types.testFlag(info->type())) + if(types == SnorePlugin::ALL || types & info->type()) { switch(info->type()) { diff --git a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp index 18a6fd9..6033011 100644 --- a/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp +++ b/src/plugins/frontends/freedesktop/freedesktopnotificationfrontend.cpp @@ -171,8 +171,8 @@ QStringList FreedesktopFrontend::GetCapabilities() QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) { - vendor = "Snore"; + vendor = "SnoreNotify"; version = Version::version(); - specVersion = "0"; - return "Snore"; + specVersion = "0.9"; + return "SnoreNotify"; } diff --git a/src/snorenotify.cpp b/src/snorenotify.cpp index 4b13533..51c03e2 100644 --- a/src/snorenotify.cpp +++ b/src/snorenotify.cpp @@ -55,7 +55,7 @@ SnoreNotify::~SnoreNotify(){ } void SnoreNotify::load(){ - if(m_settings.contains("notificationBackend")) + if(m_settings.contains("notificationBackend") && !m_settings.value("notificationBackend").toString().isEmpty()) { m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString()); }