use qmetaenum in typeFromString
This commit is contained in:
parent
2ecbba5980
commit
2f4bd7bb69
|
@ -27,13 +27,14 @@
|
|||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QMetaEnum>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
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_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<e.keyCount();++i)
|
||||
{
|
||||
out << QString::fromLatin1(e.key(i)).toLower();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,16 +40,16 @@ class SNORE_EXPORT PluginContainer{
|
|||
public:
|
||||
static QHash<QString,PluginContainer*> 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;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public:
|
|||
PLUGIN = 0x8
|
||||
};
|
||||
Q_DECLARE_FLAGS(PluginTypes, PluginType)
|
||||
Q_ENUMS(PluginType)
|
||||
|
||||
|
||||
SnorePlugin ( const QString &name);
|
||||
virtual ~SnorePlugin();
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue