use qt5 json magic to load plugins

This commit is contained in:
Patrick von Reth 2014-09-22 09:54:09 +02:00
parent f19e50d6f5
commit 0178f5ea1d
24 changed files with 32 additions and 31 deletions

View File

@ -54,7 +54,9 @@ SnorePlugin *PluginContainer::load()
snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << m_loader.errorString();
return NULL;
}
return qobject_cast<SnorePlugin *> (m_loader.instance());
SnorePlugin *plugin = qobject_cast<SnorePlugin *> (m_loader.instance());
Q_ASSERT_X(m_pluginName == plugin->name(),Q_FUNC_INFO, "The plugin name is different to the one in the meta data.");
return plugin;
}
void PluginContainer::unload()
@ -121,21 +123,14 @@ void PluginContainer::updatePluginCache()
QStringList(pluginFileFilters(type)), QDir::Files)) {
snoreDebug(SNORE_DEBUG) << "adding" << file.absoluteFilePath();
QPluginLoader loader(file.absoluteFilePath());
QObject *plugin = loader.instance();
if (plugin == NULL) { //TODO: Qt5 json stuff
snoreDebug(SNORE_WARNING) << "Failed loading plugin: " << file.absoluteFilePath() << loader.errorString();
continue;
QJsonObject data = loader.metaData()["MetaData"].toObject();
QString name = data.value("name").toString();
if (!name.isEmpty()) {
PluginContainer *info = new PluginContainer(file.fileName(), name, type);
s_pluginCache[type].insert(name, info);
plugins << info;
snoreDebug(SNORE_DEBUG) << "added" << name << "to cache";
}
SnorePlugin *sp = qobject_cast<SnorePlugin *>(plugin);
if (sp == NULL) {
snoreDebug(SNORE_WARNING) << "Error:" << file.absoluteFilePath() << " is not a Snore plugin" ;
loader.unload();
continue;
}
PluginContainer *info = new PluginContainer(file.fileName(), sp->name() , type);
s_pluginCache[type].insert(info->name(), info);
plugins << info;
snoreDebug(SNORE_DEBUG) << "added" << info->name() << "to cache";
}
}
}

View File

@ -12,10 +12,8 @@
using namespace Snore;
Q_EXPORT_PLUGIN2(libsnore_backend_freedesktop, FreedesktopBackend)
FreedesktopBackend::FreedesktopBackend() :
SnoreBackend("FreedesktopNotification", true, true, true)
SnoreBackend("Freedesktop Notification", true, true, true)
{
}

View File

@ -7,7 +7,7 @@ class FreedesktopBackend: public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
FreedesktopBackend();
virtual bool initialize(Snore::SnoreCore *snore);

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "Freedesktop Notification" }

View File

@ -27,7 +27,7 @@ class GrowlBackend: public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
GrowlBackend();

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "Growl" }

View File

@ -25,7 +25,7 @@ class OSXNotificationCenter : public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
OSXNotificationCenter();

View File

@ -7,8 +7,6 @@
#import <QThread.h>
#import <QApplication.h>
Q_EXPORT_PLUGIN2(libsnore_backend_osxnotificationcenter, OSXNotificationCenter)
using namespace Snore;
// store some variables that are needed (since obj-c++ does not allow having obj-c classes as c++ members)

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "OSX Notification Center" }

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "Snarl" }

View File

@ -25,7 +25,7 @@ class SnarlBackend: public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnarlBackend();
~SnarlBackend();

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "Snore" }

View File

@ -27,7 +27,7 @@ class SnoreNotifier : public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnoreNotifier();
~SnoreNotifier();

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "Windows 8" }

View File

@ -8,7 +8,7 @@ class SnoreToast : public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnoreToast();
~SnoreToast();

View File

@ -0,0 +1 @@
{ "type" : "backend", "name" : "System Tray Icon" }

View File

@ -10,7 +10,7 @@
using namespace Snore;
TrayIconNotifer::TrayIconNotifer() :
SnoreBackend("SystemTray", true, false),
SnoreBackend("System Tray Icon", true, false),
m_trayIcon(NULL),
m_displayed(-1),
m_currentlyDisplaying(false)

View File

@ -14,7 +14,7 @@ class TrayIconNotifer: public Snore::SnoreBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
TrayIconNotifer();
virtual ~TrayIconNotifer();

View File

@ -28,7 +28,7 @@ class FreedesktopFrontend : public Snore::SnoreFrontend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreFrontend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json")
public:
FreedesktopFrontend();
~FreedesktopFrontend();

View File

@ -0,0 +1 @@
{ "type" : "frontend", "name" : "Freedesktop" }

View File

@ -0,0 +1 @@
{ "type" : "frontend", "name" : "SnarlNetwork" }

View File

@ -30,7 +30,7 @@ class SnarlNetworkFrontend : public Snore::SnoreFrontend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreFrontend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json")
friend class Parser;
public:
static const int port = 9887;

View File

@ -0,0 +1 @@
{ "type" : "secondary_backend", "name" : "Toasty" }

View File

@ -9,7 +9,7 @@ class Toasty : public Snore::SnoreSecondaryBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0")
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
Toasty();
~Toasty();