summaryrefslogtreecommitdiff
path: root/sowatchd
diff options
context:
space:
mode:
Diffstat (limited to 'sowatchd')
-rw-r--r--sowatchd/daemon.cpp71
-rw-r--r--sowatchd/daemon.h9
2 files changed, 73 insertions, 7 deletions
diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp
index a2d7b5a..3d9c05c 100644
--- a/sowatchd/daemon.cpp
+++ b/sowatchd/daemon.cpp
@@ -11,14 +11,18 @@ Daemon::Daemon(QObject *parent) :
QObject(parent)
{
loadDrivers();
- loadWatches();
- loadWatchlets();
+ loadProviders();
+ initWatches();
}
void Daemon::loadDrivers()
{
QDir dir(SOWATCH_DRIVERS_DIR);
foreach (QString file, dir.entryList(QDir::Files)) {
+#if defined(Q_OS_UNIX)
+ // Temporary workaround for QtC deploy plugin issues
+ if (!file.endsWith(".so")) continue;
+#endif
QPluginLoader loader(dir.absoluteFilePath(file));
QObject *pluginObj = loader.instance();
if (pluginObj) {
@@ -28,16 +32,50 @@ void Daemon::loadDrivers()
foreach (const QString& driver, drivers) {
_drivers[driver] = plugin;
}
+ } else {
+ qWarning() << "Invalid plugin" << file;
+ loader.unload();
}
} else {
qWarning() << "Invalid plugin" << file;
+ loader.unload();
}
}
qDebug() << "loaded drivers" << _drivers.keys();
}
-void Daemon::loadWatches()
+void Daemon::loadProviders()
+{
+ QDir dir(SOWATCH_NOTIFICATIONS_DIR);
+ foreach (QString file, dir.entryList(QDir::Files)) {
+#if defined(Q_OS_UNIX)
+ // Temporary workaround for QtC deploy plugin issues
+ if (!file.endsWith(".so")) continue;
+#endif
+ QPluginLoader loader(dir.absoluteFilePath(file));
+ QObject *pluginObj = loader.instance();
+ if (pluginObj) {
+ NotificationPluginInterface *plugin = qobject_cast<NotificationPluginInterface*>(pluginObj);
+ if (plugin) {
+ QStringList providers = plugin->providers();
+ foreach (const QString& provider, providers) {
+ _providers[provider] = plugin;
+ }
+ } else {
+ qWarning() << "Invalid plugin" << file;
+ loader.unload();
+ }
+ } else {
+ qWarning() << "Invalid plugin" << file;
+ loader.unload();
+ }
+ }
+
+ qDebug() << "loaded providers" << _providers;
+}
+
+void Daemon::initWatches()
{
QSettings settings;
int size = settings.beginReadArray("watches");
@@ -49,7 +87,7 @@ void Daemon::loadWatches()
if (plugin) {
Watch *watch = plugin->getWatch(driver, settings, this);
if (watch) {
- _watches.append(watch);
+ initWatch(watch, settings);
} else {
qWarning() << "Driver" << driver << "refused to getWatch";
}
@@ -59,7 +97,30 @@ void Daemon::loadWatches()
}
settings.endArray();
- qDebug() << "handling" << _watches.size() << "watches";
+ qDebug() << "handling" << _servers.size() << "watches";
+}
+
+void Daemon::initWatch(Watch* watch, QSettings& settings)
+{
+ int size;
+
+ // Create the server
+ WatchServer* server = new WatchServer(watch, this);
+ _servers.append(server);
+
+ // Initialize providers
+ size = settings.beginReadArray("notifications");
+ for (int i = 0; i < size; i++) {
+ settings.setArrayIndex(i);
+ QString id = settings.value("provider").toString().toLower();
+ NotificationPluginInterface *plugin = _providers[id];
+ if (plugin) {
+ NotificationProvider *provider = plugin->getProvider(id, settings, server);
+ server->addProvider(provider);
+ }
+ }
+
+ settings.endArray();
}
void Daemon::loadWatchlets()
diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h
index 9346a41..607e887 100644
--- a/sowatchd/daemon.h
+++ b/sowatchd/daemon.h
@@ -4,6 +4,7 @@
#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtCore/QMap>
+#include <QtCore/QSettings>
#include <sowatch.h>
@@ -18,11 +19,15 @@ public:
protected:
QMap<QString, WatchPluginInterface*> _drivers;
- QList<Watch*> _watches;
+ QMap<QString, NotificationPluginInterface*> _providers;
+ QList<WatchServer*> _servers;
void loadDrivers();
- void loadWatches();
+ void loadProviders();
void loadWatchlets();
+
+ void initWatches();
+ void initWatch(Watch* watch, QSettings& settings);
};
}