diff options
Diffstat (limited to 'sowatchd')
-rw-r--r-- | sowatchd/daemon.cpp | 29 | ||||
-rw-r--r-- | sowatchd/daemon.h | 8 | ||||
-rw-r--r-- | sowatchd/daemonadaptor.cpp | 7 | ||||
-rw-r--r-- | sowatchd/daemonadaptor.h | 9 |
4 files changed, 43 insertions, 10 deletions
diff --git a/sowatchd/daemon.cpp b/sowatchd/daemon.cpp index f8cfa00..2a6c84f 100644 --- a/sowatchd/daemon.cpp +++ b/sowatchd/daemon.cpp @@ -7,9 +7,14 @@ using namespace sowatch; Daemon::Daemon(QObject *parent) : QObject(parent), _registry(Registry::registry()), - _settings(new GConfKey("/apps/sowatch", this)) + _settings(new GConfKey("/apps/sowatch", this)), + _status_mapper(new QSignalMapper(this)) { - connect(_settings, SIGNAL(subkeyChanged(QString)), SLOT(settingsChanged(QString))); + connect(_settings, SIGNAL(subkeyChanged(QString)), + SLOT(handleSettingsChanged(QString))); + connect(_status_mapper, SIGNAL(mapped(QString)), + SLOT(handleWatchStatusChange(QString))); + QStringList activeWatches = _settings->value("active-watches").toStringList(); foreach (const QString& s, activeWatches) { startWatch(s); @@ -63,6 +68,13 @@ void Daemon::startWatch(const QString &name) WatchServer* server = new WatchServer(watch, this); _servers[name] = server; + // Connect watch status signals + _status_mapper->setMapping(watch, name); + connect(watch, SIGNAL(connected()), + _status_mapper, SLOT(map())); + connect(watch, SIGNAL(disconnected()), + _status_mapper, SLOT(map())); + // Configure the server server->setNextWatchletButton(watchSettings->value("next-watchlet-button").toString()); @@ -101,7 +113,7 @@ void Daemon::stopWatch(const QString &name) qDebug() << "Stopping watch" << name; } -void Daemon::settingsChanged(const QString &subkey) +void Daemon::handleSettingsChanged(const QString &subkey) { qDebug() << "Daemon settings changed" << subkey; if (subkey == "active-watches") { @@ -117,3 +129,14 @@ void Daemon::settingsChanged(const QString &subkey) } } } + +void Daemon::handleWatchStatusChange(const QString &name) +{ + WatchServer* server = _servers[name]; + Watch* watch = server->watch(); + if (watch->isConnected()) { + emit WatchStatusChanged(name, QLatin1String("connected")); + } else { + emit WatchStatusChanged(name, QLatin1String("enabled")); + } +} diff --git a/sowatchd/daemon.h b/sowatchd/daemon.h index ba62585..338eb2a 100644 --- a/sowatchd/daemon.h +++ b/sowatchd/daemon.h @@ -3,6 +3,7 @@ #include <QtCore/QObject> #include <QtCore/QMap> +#include <QtCore/QSignalMapper> #include <sowatch.h> @@ -20,16 +21,21 @@ public: public slots: void terminate(); +signals: + void WatchStatusChanged(const QString &watch, const QString &status); + private: Registry* _registry; ConfigKey* _settings; QMap<QString, WatchServer*> _servers; + QSignalMapper *_status_mapper; void startWatch(const QString& name); void stopWatch(const QString& name); private slots: - void settingsChanged(const QString& subkey); + void handleSettingsChanged(const QString& subkey); + void handleWatchStatusChange(const QString& watch); }; } diff --git a/sowatchd/daemonadaptor.cpp b/sowatchd/daemonadaptor.cpp index c8a322a..d8a4260 100644 --- a/sowatchd/daemonadaptor.cpp +++ b/sowatchd/daemonadaptor.cpp @@ -16,6 +16,7 @@ #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QVariant> +#include "daemon.h" /* * Implementation of adaptor class DaemonAdaptor @@ -36,14 +37,12 @@ DaemonAdaptor::~DaemonAdaptor() QString DaemonAdaptor::GetWatchStatus(const QString &watch) { // handle method call com.javispedro.sowatch.Daemon.GetWatchStatus - QString status; - QMetaObject::invokeMethod(parent(), "getWatchStatus", Q_RETURN_ARG(QString, status), Q_ARG(QString, watch)); - return status; + return static_cast<sowatch::Daemon*>(parent())->getWatchStatus(watch); } void DaemonAdaptor::Terminate() { // handle method call com.javispedro.sowatch.Daemon.Terminate - QMetaObject::invokeMethod(parent(), "terminate"); + static_cast<sowatch::Daemon*>(parent())->terminate(); } diff --git a/sowatchd/daemonadaptor.h b/sowatchd/daemonadaptor.h index d16cb99..71640ba 100644 --- a/sowatchd/daemonadaptor.h +++ b/sowatchd/daemonadaptor.h @@ -9,8 +9,8 @@ * before re-generating it. */ -#ifndef DAEMONADAPTOR_H_1335395583 -#define DAEMONADAPTOR_H_1335395583 +#ifndef DAEMONADAPTOR_H_1344470120 +#define DAEMONADAPTOR_H_1344470120 #include <QtCore/QObject> #include <QtDBus/QtDBus> @@ -35,6 +35,10 @@ class DaemonAdaptor: public QDBusAbstractAdaptor " <arg direction=\"out\" type=\"s\" name=\"status\"/>\n" " </method>\n" " <method name=\"Terminate\"/>\n" +" <signal name=\"WatchStatusChanged\">\n" +" <arg type=\"s\" name=\"watch\"/>\n" +" <arg type=\"s\" name=\"status\"/>\n" +" </signal>\n" " </interface>\n" "") public: @@ -46,6 +50,7 @@ public Q_SLOTS: // METHODS QString GetWatchStatus(const QString &watch); void Terminate(); Q_SIGNALS: // SIGNALS + void WatchStatusChanged(const QString &watch, const QString &status); }; #endif |