use qmetaenum in typeFromString

This commit is contained in:
Patrick von Reth 2014-01-21 14:33:12 +01:00
parent 2ecbba5980
commit 2f4bd7bb69
6 changed files with 25 additions and 33 deletions

View File

@ -27,13 +27,14 @@
#include <QDir> #include <QDir>
#include <QDebug> #include <QDebug>
#include <QMetaEnum>
using namespace Snore; using namespace Snore;
QHash<QString,PluginContainer*> PluginContainer::s_pluginCache = QHash<QString,PluginContainer*>() ; QHash<QString,PluginContainer*> PluginContainer::s_pluginCache = QHash<QString,PluginContainer*>() ;
PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginType type): PluginContainer::PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type):
m_pluginFile(fileName), m_pluginFile(fileName),
m_pluginName(pluginName), m_pluginName(pluginName),
m_pluginType(type), m_pluginType(type),
@ -72,39 +73,28 @@ const QString & PluginContainer::name()
return m_pluginName; return m_pluginName;
} }
SnorePlugin::PluginType PluginContainer::type() SnorePlugin::PluginTypes PluginContainer::type()
{ {
return m_pluginType; return m_pluginType;
} }
SnorePlugin::PluginType PluginContainer::typeFromString(const QString &t) SnorePlugin::PluginTypes PluginContainer::typeFromString(const QString &t)
{ {
SnorePlugin::PluginType type = SnorePlugin::PLUGIN; return (SnorePlugin::PluginTypes)SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType")).keyToValue(t.toUpper().toLatin1());
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;
} }
const QStringList &PluginContainer::types() const QStringList &PluginContainer::types()
{ {
static QStringList list; static QStringList out;
if(list.isEmpty()){ if(out.isEmpty())
list << "backend" {
<< "secondary_backend" QMetaEnum e = SnorePlugin::staticMetaObject.enumerator(SnorePlugin::staticMetaObject.indexOfEnumerator("PluginType"));
<< "frontend" for(int i=0;i<e.keyCount();++i)
<< "plugin"; {
out << QString::fromLatin1(e.key(i)).toLower();
}
} }
return list; return out;
} }

View File

@ -40,16 +40,16 @@ class SNORE_EXPORT PluginContainer{
public: public:
static QHash<QString,PluginContainer*> pluginCache(); static QHash<QString,PluginContainer*> pluginCache();
PluginContainer(QString fileName,QString pluginName,SnorePlugin::PluginType type); PluginContainer(QString fileName, QString pluginName, SnorePlugin::PluginTypes type);
~PluginContainer(); ~PluginContainer();
SnorePlugin *load(); SnorePlugin *load();
void unload(); void unload();
const QString &file(); const QString &file();
const QString &name(); 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(); static const QStringList &types();
private: private:
@ -69,7 +69,7 @@ private:
QString m_pluginFile; QString m_pluginFile;
QString m_pluginName; QString m_pluginName;
SnorePlugin::PluginType m_pluginType; SnorePlugin::PluginTypes m_pluginType;
QPluginLoader m_loader; QPluginLoader m_loader;
}; };
} }

View File

@ -45,6 +45,8 @@ public:
PLUGIN = 0x8 PLUGIN = 0x8
}; };
Q_DECLARE_FLAGS(PluginTypes, PluginType) Q_DECLARE_FLAGS(PluginTypes, PluginType)
Q_ENUMS(PluginType)
SnorePlugin ( const QString &name); SnorePlugin ( const QString &name);
virtual ~SnorePlugin(); virtual ~SnorePlugin();

View File

@ -57,7 +57,7 @@ void SnoreCore::loadPlugins( SnorePlugin::PluginTypes types )
snoreDebug( SNORE_DEBUG ) << "PluginInfo" << PluginContainer::pluginCache().keys(); snoreDebug( SNORE_DEBUG ) << "PluginInfo" << PluginContainer::pluginCache().keys();
foreach ( PluginContainer *info, PluginContainer::pluginCache().values()) foreach ( PluginContainer *info, PluginContainer::pluginCache().values())
{ {
if(types == SnorePlugin::ALL || types.testFlag(info->type())) if(types == SnorePlugin::ALL || types & info->type())
{ {
switch(info->type()) switch(info->type())
{ {

View File

@ -171,8 +171,8 @@ QStringList FreedesktopFrontend::GetCapabilities()
QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion) QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
{ {
vendor = "Snore"; vendor = "SnoreNotify";
version = Version::version(); version = Version::version();
specVersion = "0"; specVersion = "0.9";
return "Snore"; return "SnoreNotify";
} }

View File

@ -55,7 +55,7 @@ SnoreNotify::~SnoreNotify(){
} }
void SnoreNotify::load(){ 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()); m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
} }