summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-09 04:03:20 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-09 04:03:20 +0200
commit406332eb6b3199d19388f359d04c9f184e6082b5 (patch)
tree0560e8dabcd715cdf1932b7ac6105df5d20025e5
parent3aa62b0543d978c1a01c5cf05a898fd8d805c44b (diff)
downloadsowatch-406332eb6b3199d19388f359d04c9f184e6082b5.tar.gz
sowatch-406332eb6b3199d19388f359d04c9f184e6082b5.zip
watch status UI
-rw-r--r--libsowatch/gconfkey.cpp1
-rw-r--r--libsowatch/sowatch_global.h2
-rw-r--r--libsowatch/watchserver.cpp26
-rw-r--r--libsowatch/watchserver.h16
-rw-r--r--sowatchd/daemon.cpp29
-rw-r--r--sowatchd/daemon.h8
-rw-r--r--sowatchd/daemonadaptor.cpp7
-rw-r--r--sowatchd/daemonadaptor.h9
-rw-r--r--sowatchui/daemonproxy.cpp26
-rw-r--r--sowatchui/daemonproxy.h63
-rw-r--r--sowatchui/main.cpp2
-rw-r--r--sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp5
-rw-r--r--sowatchui/qmlapplicationviewer/qmlapplicationviewer.h2
-rw-r--r--sowatchui/scannerproxy.cpp (renamed from sowatchui/scannerproxy.cc)0
-rw-r--r--sowatchui/scanwatchesmodel.cpp (renamed from sowatchui/scanwatchesmodel.cc)0
-rw-r--r--sowatchui/sowatchui.pro9
-rw-r--r--sowatchui/watchesmodel.cpp (renamed from sowatchui/watchesmodel.cc)38
-rw-r--r--sowatchui/watchesmodel.h6
18 files changed, 213 insertions, 36 deletions
diff --git a/libsowatch/gconfkey.cpp b/libsowatch/gconfkey.cpp
index b47deb5..c6becc4 100644
--- a/libsowatch/gconfkey.cpp
+++ b/libsowatch/gconfkey.cpp
@@ -11,6 +11,7 @@ static GConfClient* g_client = NULL;
static GConfClient* get_client() {
if (!g_client) {
+ g_type_init();
g_client = gconf_client_get_default();
}
return g_client;
diff --git a/libsowatch/sowatch_global.h b/libsowatch/sowatch_global.h
index 9c6cf73..b537930 100644
--- a/libsowatch/sowatch_global.h
+++ b/libsowatch/sowatch_global.h
@@ -10,7 +10,7 @@
# define SOWATCH_EXPORT Q_DECL_IMPORT
#endif
-#if defined(QT_SIMULATOR) || !defined(QT_NO_DEBUG)
+#if defined(QT_SIMULATOR) || (!defined(MEEGO_VERSION_MAJOR) && !defined(Q_WS_MAEMO_5) && !defined(QT_NO_DEBUG))
# define SOWATCH_PLUGINS_DIR ".."
# define SOWATCH_RESOURCES_DIR ".."
# define SOWATCH_QML_DIR ".."
diff --git a/libsowatch/watchserver.cpp b/libsowatch/watchserver.cpp
index 540eeea..d5db9da 100644
--- a/libsowatch/watchserver.cpp
+++ b/libsowatch/watchserver.cpp
@@ -14,10 +14,10 @@ WatchServer::WatchServer(Watch* watch, QObject* parent) :
_currentWatchlet(0), _currentWatchletActive(false), _currentWatchletIndex(-1),
_syncTimeTimer(new QTimer(this))
{
- connect(_watch, SIGNAL(connected()), SLOT(watchConnected()));
- connect(_watch, SIGNAL(disconnected()), SLOT(watchDisconnected()));
- connect(_watch, SIGNAL(idling()), SLOT(watchIdling()));
- connect(_watch, SIGNAL(buttonPressed(int)), SLOT(watchButtonPress(int)));
+ connect(_watch, SIGNAL(connected()), SLOT(handleWatchConnected()));
+ connect(_watch, SIGNAL(disconnected()), SLOT(handleWatchDisconnected()));
+ connect(_watch, SIGNAL(idling()), SLOT(handleWatchIdling()));
+ connect(_watch, SIGNAL(buttonPressed(int)), SLOT(handleWatchButtonPress(int)));
connect(_syncTimeTimer, SIGNAL(timeout()), SLOT(syncTime()));
_syncTimeTimer->setSingleShot(true);
@@ -165,7 +165,7 @@ void WatchServer::goToIdle()
_watch->displayIdleScreen();
}
-void WatchServer::watchConnected()
+void WatchServer::handleWatchConnected()
{
syncTime();
if (!_pendingNotifications.isEmpty()) {
@@ -175,18 +175,20 @@ void WatchServer::watchConnected()
} else {
goToIdle();
}
+ emit watchConnected();
}
-void WatchServer::watchDisconnected()
+void WatchServer::handleWatchDisconnected()
{
_syncTimeTimer->stop();
if (_currentWatchlet && _currentWatchletActive) {
deactivateCurrentWatchlet();
}
_pendingNotifications.clear();
+ emit watchDisconnected();
}
-void WatchServer::watchIdling()
+void WatchServer::handleWatchIdling()
{
qDebug() << "watch idling";
if (!_pendingNotifications.empty()) {
@@ -195,7 +197,7 @@ void WatchServer::watchIdling()
}
}
-void WatchServer::watchButtonPress(int button)
+void WatchServer::handleWatchButtonPress(int button)
{
if (button == _nextWatchletButton) {
qDebug() << "next watchlet button pressed";
@@ -216,8 +218,8 @@ void WatchServer::postNotification(Notification *notification)
_notifications[type].append(notification);
_notificationCounts[notification] = notification->count();
- connect(notification, SIGNAL(changed()), SLOT(notificationChanged()));
- connect(notification, SIGNAL(dismissed()), SLOT(notificationDismissed()));
+ connect(notification, SIGNAL(changed()), SLOT(handleNotificationChanged()));
+ connect(notification, SIGNAL(dismissed()), SLOT(handleNotificationDismissed()));
qDebug() << "notification received" << notification->title() << "(" << notification->count() << ")";
@@ -264,7 +266,7 @@ void WatchServer::nextNotification()
}
}
-void WatchServer::notificationChanged()
+void WatchServer::handleNotificationChanged()
{
QObject *obj = sender();
if (obj) {
@@ -307,7 +309,7 @@ void WatchServer::notificationChanged()
}
}
-void WatchServer::notificationDismissed()
+void WatchServer::handleNotificationDismissed()
{
QObject *obj = sender();
if (obj) {
diff --git a/libsowatch/watchserver.h b/libsowatch/watchserver.h
index 3995bc6..54d3dc1 100644
--- a/libsowatch/watchserver.h
+++ b/libsowatch/watchserver.h
@@ -49,6 +49,10 @@ public slots:
void syncTime();
+signals:
+ void watchConnected();
+ void watchDisconnected();
+
private:
Watch* _watch;
@@ -89,13 +93,13 @@ private:
void goToIdle();
private slots:
- void watchConnected();
- void watchDisconnected();
- void watchIdling();
- void watchButtonPress(int button);
+ void handleWatchConnected();
+ void handleWatchDisconnected();
+ void handleWatchIdling();
+ void handleWatchButtonPress(int button);
- void notificationChanged();
- void notificationDismissed();
+ void handleNotificationChanged();
+ void handleNotificationDismissed();
};
}
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
diff --git a/sowatchui/daemonproxy.cpp b/sowatchui/daemonproxy.cpp
new file mode 100644
index 0000000..6a4aee2
--- /dev/null
+++ b/sowatchui/daemonproxy.cpp
@@ -0,0 +1,26 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.7
+ * Command line was: qdbusxml2cpp -c DaemonProxy -p daemonproxy ../sowatchd/daemon.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * This file may have been hand-edited. Look for HAND-EDIT comments
+ * before re-generating it.
+ */
+
+#include "daemonproxy.h"
+
+/*
+ * Implementation of interface class DaemonProxy
+ */
+
+DaemonProxy::DaemonProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
+ : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
+{
+}
+
+DaemonProxy::~DaemonProxy()
+{
+}
+
diff --git a/sowatchui/daemonproxy.h b/sowatchui/daemonproxy.h
new file mode 100644
index 0000000..5083cf3
--- /dev/null
+++ b/sowatchui/daemonproxy.h
@@ -0,0 +1,63 @@
+/*
+ * This file was generated by qdbusxml2cpp version 0.7
+ * Command line was: qdbusxml2cpp -c DaemonProxy -p daemonproxy ../sowatchd/daemon.xml
+ *
+ * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This is an auto-generated file.
+ * Do not edit! All changes made to it will be lost.
+ */
+
+#ifndef DAEMONPROXY_H_1344472584
+#define DAEMONPROXY_H_1344472584
+
+#include <QtCore/QObject>
+#include <QtCore/QByteArray>
+#include <QtCore/QList>
+#include <QtCore/QMap>
+#include <QtCore/QString>
+#include <QtCore/QStringList>
+#include <QtCore/QVariant>
+#include <QtDBus/QtDBus>
+
+/*
+ * Proxy class for interface com.javispedro.sowatch.Daemon
+ */
+class DaemonProxy: public QDBusAbstractInterface
+{
+ Q_OBJECT
+public:
+ static inline const char *staticInterfaceName()
+ { return "com.javispedro.sowatch.Daemon"; }
+
+public:
+ DaemonProxy(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+
+ ~DaemonProxy();
+
+public Q_SLOTS: // METHODS
+ inline QDBusPendingReply<QString> GetWatchStatus(const QString &watch)
+ {
+ QList<QVariant> argumentList;
+ argumentList << qVariantFromValue(watch);
+ return asyncCallWithArgumentList(QLatin1String("GetWatchStatus"), argumentList);
+ }
+
+ inline QDBusPendingReply<> Terminate()
+ {
+ QList<QVariant> argumentList;
+ return asyncCallWithArgumentList(QLatin1String("Terminate"), argumentList);
+ }
+
+Q_SIGNALS: // SIGNALS
+ void WatchStatusChanged(const QString &watch, const QString &status);
+};
+
+namespace com {
+ namespace javispedro {
+ namespace sowatch {
+ typedef ::DaemonProxy Daemon;
+ }
+ }
+}
+#endif
diff --git a/sowatchui/main.cpp b/sowatchui/main.cpp
index f306fa9..ea4a172 100644
--- a/sowatchui/main.cpp
+++ b/sowatchui/main.cpp
@@ -19,6 +19,8 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
watches = new WatchesModel(app.data());
watchScanner = new ScanWatchesModel(app.data());
+ qDebug() << "Starting" << watches << endl;
+
viewer->rootContext()->setContextProperty("watches", watches);
viewer->rootContext()->setContextProperty("watchScanner", watchScanner);
diff --git a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp
index 8ba6e88..672abd8 100644
--- a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp
+++ b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.cpp
@@ -125,6 +125,11 @@ QmlApplicationViewer *QmlApplicationViewer::create()
#endif
}
+QDeclarativeContext * QmlApplicationViewer::rootContext()
+{
+ return d->view->rootContext();
+}
+
void QmlApplicationViewer::setMainQmlFile(const QString &file)
{
d->mainQmlFile = d->adjustPath(file);
diff --git a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h
index f8008f5..84fa3db 100644
--- a/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h
+++ b/sowatchui/qmlapplicationviewer/qmlapplicationviewer.h
@@ -29,6 +29,8 @@ public:
static QmlApplicationViewer *create();
+ QDeclarativeContext *rootContext();
+
void setMainQmlFile(const QString &file);
void addImportPath(const QString &path);
diff --git a/sowatchui/scannerproxy.cc b/sowatchui/scannerproxy.cpp
index cfa4365..cfa4365 100644
--- a/sowatchui/scannerproxy.cc
+++ b/sowatchui/scannerproxy.cpp
diff --git a/sowatchui/scanwatchesmodel.cc b/sowatchui/scanwatchesmodel.cpp
index 5b7c331..5b7c331 100644
--- a/sowatchui/scanwatchesmodel.cc
+++ b/sowatchui/scanwatchesmodel.cpp
diff --git a/sowatchui/sowatchui.pro b/sowatchui/sowatchui.pro
index e02afcc..53abe73 100644
--- a/sowatchui/sowatchui.pro
+++ b/sowatchui/sowatchui.pro
@@ -21,14 +21,17 @@ CONFIG += qdeclarative-boostable
LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch
INCLUDEPATH += $$PWD/../libsowatch
DEPENDPATH += $$PWD/../libsowatch
+!isEmpty(MEEGO_VERSION_MAJOR)|maemo5 {
+ QMAKE_RPATHDIR += /opt/sowatch/lib
+}
# Source files
SOURCES += main.cpp \
- watchesmodel.cc \
- scanwatchesmodel.cc scannerproxy.cc
+ watchesmodel.cpp daemonproxy.cpp \
+ scanwatchesmodel.cpp scannerproxy.cpp
HEADERS += \
- watchesmodel.h \
+ watchesmodel.h daemonproxy.h \
scanwatchesmodel.h scannerproxy.h
OTHER_FILES += qml/main.qml \
diff --git a/sowatchui/watchesmodel.cc b/sowatchui/watchesmodel.cpp
index d12e7db..4531544 100644
--- a/sowatchui/watchesmodel.cc
+++ b/sowatchui/watchesmodel.cpp
@@ -7,7 +7,8 @@ using namespace sowatch;
WatchesModel::WatchesModel(QObject *parent) :
QAbstractListModel(parent),
_config(new GConfKey("/apps/sowatch", this)),
- _active_watches(_config->getSubkey("active-watches", this))
+ _active_watches(_config->getSubkey("active-watches", this)),
+ _daemon(new DaemonProxy("com.javispedro.sowatchd", "/com/javispedro/sowatch/daemon", QDBusConnection::sessionBus()))
{
QHash<int, QByteArray> roles = roleNames();
roles[Qt::DisplayRole] = QByteArray("title");
@@ -19,7 +20,8 @@ WatchesModel::WatchesModel(QObject *parent) :
this, SLOT(handleConfigChanged()));
connect(_config, SIGNAL(subkeyChanged(QString)),
this, SLOT(handleSubkeyChanged(QString)));
- qDebug() << "connects";
+ connect(_daemon, SIGNAL(WatchStatusChanged(QString,QString)),
+ this, SLOT(handleWatchStatusChanged(QString,QString)));
reload();
}
@@ -37,18 +39,31 @@ QVariant WatchesModel::data(const QModelIndex &index, int role) const
{
qDebug() << "Asked for data" << index.row() << index.column() << role;
ConfigKey *config = _list[index.row()];
+ QString key = config->key();
+ QString id = key.mid(key.lastIndexOf('/') + 1);
switch (role) {
case Qt::DisplayRole:
return config->value("name");
case Qt::StatusTipRole:
- return QVariant(tr("Configured"));
+ if (isWatchIdActive(id)) {
+ QString status = _status[id];
+ if (status == "connected") {
+ return QVariant(tr("Connected"));
+ } else if (status == "enabled") {
+ return QVariant(tr("Searching..."));
+ } else {
+ return QVariant(tr("Enabled"));
+ }
+ } else {
+ return QVariant(tr("Disabled"));
+ }
}
return QVariant();
}
bool WatchesModel::removeRows(int row, int count, const QModelIndex &parent)
{
-
+ return false; // TODO
}
void WatchesModel::addFoundWatch(const QVariantMap &info)
@@ -124,6 +139,15 @@ void WatchesModel::handleSubkeyChanged(const QString &subkey)
}
}
+void WatchesModel::handleWatchStatusChanged(const QString &watch, const QString &status)
+{
+ _status[watch] = status;
+ int i = findRowByWatchId(watch);
+ if (i != -1) {
+ emit dataChanged(createIndex(i, 0), createIndex(i, 0));
+ }
+}
+
int WatchesModel::findRowByWatchId(const QString &id)
{
QString pattern(_config->key() + "/" + id);
@@ -134,3 +158,9 @@ int WatchesModel::findRowByWatchId(const QString &id)
}
return -1;
}
+
+bool WatchesModel::isWatchIdActive(const QString &id) const
+{
+ QStringList active = _active_watches->value().toStringList();
+ return active.contains(id);
+}
diff --git a/sowatchui/watchesmodel.h b/sowatchui/watchesmodel.h
index cc6c9af..4962725 100644
--- a/sowatchui/watchesmodel.h
+++ b/sowatchui/watchesmodel.h
@@ -5,6 +5,8 @@
#include <sowatch.h>
+#include "daemonproxy.h"
+
class WatchesModel : public QAbstractListModel
{
Q_OBJECT
@@ -27,14 +29,18 @@ private slots:
void reload();
void handleConfigChanged();
void handleSubkeyChanged(const QString& subkey);
+ void handleWatchStatusChanged(const QString& watch, const QString& status);
private:
int findRowByWatchId(const QString& id);
+ bool isWatchIdActive(const QString& id) const;
private:
sowatch::ConfigKey *_config;
sowatch::ConfigKey *_active_watches;
+ DaemonProxy *_daemon;
QList<sowatch::ConfigKey*> _list;
+ QMap<QString, QString> _status;
};
#endif // WATCHESMODEL_H