From cbf8e3ad49917dc71e8c5f6413c55f266c1c4ad3 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 3 Dec 2011 00:00:07 +0100 Subject: change the way buttons work in declarativewatchlets --- libsowatch/declarativewatchwrapper.cpp | 39 +++++++++++++++++++++++++++++----- libsowatch/declarativewatchwrapper.h | 2 ++ 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'libsowatch') diff --git a/libsowatch/declarativewatchwrapper.cpp b/libsowatch/declarativewatchwrapper.cpp index d972d86..122545f 100644 --- a/libsowatch/declarativewatchwrapper.cpp +++ b/libsowatch/declarativewatchwrapper.cpp @@ -25,17 +25,27 @@ bool DeclarativeWatchWrapper::active() const QList DeclarativeWatchWrapper::notifications() const { - // TODO: Figure a better way for this; QAbstractListModel, etc. + // TODO: Figure out a better way for this; QAbstractListModel, etc. QList nl = _server->liveNotifications(); QList ol; foreach (Notification* n, nl) { QObject * o = n; ol.append(o); } - qDebug() << "notifications declarative: " << ol; + qDebug() << "notifications to declarative: " << ol; return ol; } +void DeclarativeWatchWrapper::useButton(int button) +{ + if (!_usedButtons.contains(button)) { + _usedButtons.insert(button); + if (_active) { + _watch->grabButton(button); + } + } +} + void DeclarativeWatchWrapper::vibrate(int msecs) { if (_active) { @@ -46,12 +56,22 @@ void DeclarativeWatchWrapper::vibrate(int msecs) void DeclarativeWatchWrapper::activate() { if (!_active) { + _active = true; + + // Grab all of the buttons used by this watchlet + foreach (int button, _usedButtons) { + _watch->grabButton(button); + } + + // Forward the button signals connect(_watch, SIGNAL(buttonPressed(int)), this, SIGNAL(buttonPressed(int))); connect(_watch, SIGNAL(buttonReleased(int)), this, SIGNAL(buttonReleased(int))); - _active = true; + + // Emit the active signal emit activeChanged(); + // Since a notification currently causes the active watchlet to be deactivated, - // we can assume notifications only change when we are deactivated. + // we can assume the notifications list only changes when we are deactivated. emit notificationsChanged(); } } @@ -59,8 +79,17 @@ void DeclarativeWatchWrapper::activate() void DeclarativeWatchWrapper::deactivate() { if (_active) { - disconnect(_watch, 0, this, 0); _active = false; + + // Stop forwarding button presses + disconnect(_watch, 0, this, 0); + + // Ungrab all the buttons used by this watchlet + foreach (int button, _usedButtons) { + _watch->ungrabButton(button); + } + + // Emit the deactivated signal emit activeChanged(); } } diff --git a/libsowatch/declarativewatchwrapper.h b/libsowatch/declarativewatchwrapper.h index 8d4fd7d..5a827ab 100644 --- a/libsowatch/declarativewatchwrapper.h +++ b/libsowatch/declarativewatchwrapper.h @@ -28,6 +28,7 @@ public: QList notifications() const; public slots: + void useButton(int button); void vibrate(int msecs); signals: @@ -41,6 +42,7 @@ private: WatchServer *_server; Watch* _watch; bool _active; + QSet _usedButtons; void activate(); void deactivate(); -- cgit v1.2.3