use qt5 json magic to load plugins
This commit is contained in:
parent
f19e50d6f5
commit
0178f5ea1d
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "Freedesktop Notification" }
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "Growl" }
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "OSX Notification Center" }
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "Snarl" }
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "Snore" }
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "Windows 8" }
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "backend", "name" : "System Tray Icon" }
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "frontend", "name" : "Freedesktop" }
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "frontend", "name" : "SnarlNetwork" }
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{ "type" : "secondary_backend", "name" : "Toasty" }
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue