diff options
author | Javier S. Pedro <maemo@javispedro.com> | 2011-10-16 04:42:30 +0200 |
---|---|---|
committer | Javier S. Pedro <maemo@javispedro.com> | 2011-10-16 04:42:30 +0200 |
commit | 4da9bced6a27b92d49b9fc9392946510b8519d82 (patch) | |
tree | 7a2417a932a6463e3e6f6ec4d3799e24de917306 /sowatchd/daemon.cpp | |
parent | bde4bde8ec9d6d09874d5ae9e0ba6dc9431859b6 (diff) | |
download | sowatch-4da9bced6a27b92d49b9fc9392946510b8519d82.tar.gz sowatch-4da9bced6a27b92d49b9fc9392946510b8519d82.zip |
Initial implementation of weather
Diffstat (limited to 'sowatchd/daemon.cpp')
-rw-r--r-- | sowatchd/daemon.cpp | 105 |
1 files changed, 5 insertions, 100 deletions
diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp index 0cc6c05..3cbfb64 100644 --- a/sowatchd/daemon.cpp +++ b/sowatchd/daemon.cpp @@ -1,81 +1,16 @@ #include <QtCore/QDebug> -#include <QtCore/QPluginLoader> -#include <QtCore/QSettings> -#include <QtCore/QDir> #include <sowatch.h> #include "daemon.h" using namespace sowatch; Daemon::Daemon(QObject *parent) : - QObject(parent) + QObject(parent), + _registry(Registry::registry()) { - loadDrivers(); - loadProviders(); - loadWatchlets(); 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) { - WatchPluginInterface *plugin = qobject_cast<WatchPluginInterface*>(pluginObj); - if (plugin) { - QStringList drivers = plugin->drivers(); - foreach (const QString& driver, drivers) { - _drivers[driver] = plugin; - } - } else { - qWarning() << "Invalid plugin" << file; - loader.unload(); - } - } else { - qWarning() << "Invalid plugin" << file << loader.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded drivers" << _drivers.keys(); -} - -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.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded providers" << _providers.keys(); -} - void Daemon::initWatches() { QSettings settings; @@ -84,7 +19,7 @@ void Daemon::initWatches() for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString driver = settings.value("driver").toString().toLower(); - WatchPluginInterface *plugin = _drivers[driver]; + WatchPluginInterface *plugin = _registry->getWatchPlugin(driver); if (plugin) { Watch *watch = plugin->getWatch(driver, settings, this); if (watch) { @@ -117,7 +52,7 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString id = settings.value("provider").toString().toLower(); - NotificationPluginInterface *plugin = _providers[id]; + NotificationPluginInterface *plugin = _registry->getNotificationPlugin(id); if (plugin) { NotificationProvider *provider = plugin->getProvider(id, settings, server); server->addProvider(provider); @@ -132,7 +67,7 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) for (int i = 0; i < size; i++) { settings.setArrayIndex(i); QString id = settings.value("id").toString().toLower(); - WatchletPluginInterface *plugin = _watchlets[id]; + WatchletPluginInterface *plugin = _registry->getWatchletPlugin(id); if (plugin) { plugin->getWatchlet(id, settings, server); // Watchlets are associated to server via parent-child relationship. @@ -142,33 +77,3 @@ void Daemon::initWatch(Watch* watch, QSettings& settings) } settings.endArray(); } - -void Daemon::loadWatchlets() -{ - QDir dir(SOWATCH_WATCHLETS_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) { - WatchletPluginInterface *plugin = qobject_cast<WatchletPluginInterface*>(pluginObj); - if (plugin) { - QStringList watchlets = plugin->watchlets(); - foreach (const QString& watchlet, watchlets) { - _watchlets[watchlet] = plugin; - } - } else { - qWarning() << "Invalid plugin" << file; - loader.unload(); - } - } else { - qWarning() << "Invalid plugin" << file << loader.errorString(); - loader.unload(); - } - } - - qDebug() << "loaded watchlets" << _watchlets.keys(); -} |