summaryrefslogtreecommitdiff
path: root/qmafwwatchlet
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-09-05 01:17:17 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-09-05 01:17:17 +0200
commit7bc076eda25c4c03648ba3dc021d0d0762e1be8d (patch)
tree28d75b31de4131385e98ea0013bac36aebf8a9f0 /qmafwwatchlet
parent2bb6b0e7b1a55b9e8ca5ffe7bd5b81b82e9a2933 (diff)
downloadsowatch-7bc076eda25c4c03648ba3dc021d0d0762e1be8d.tar.gz
sowatch-7bc076eda25c4c03648ba3dc021d0d0762e1be8d.zip
improve volume controlsowatch_0_4_3
Diffstat (limited to 'qmafwwatchlet')
-rw-r--r--qmafwwatchlet/metawatch-digital.qml5
-rw-r--r--qmafwwatchlet/qmafwwatchletvolumecontrol.cc41
-rw-r--r--qmafwwatchlet/qmafwwatchletvolumecontrol.h4
3 files changed, 36 insertions, 14 deletions
diff --git a/qmafwwatchlet/metawatch-digital.qml b/qmafwwatchlet/metawatch-digital.qml
index 02a5460..18a4ffc 100644
--- a/qmafwwatchlet/metawatch-digital.qml
+++ b/qmafwwatchlet/metawatch-digital.qml
@@ -78,8 +78,9 @@ Rectangle {
anchors.bottom: parent.bottom
anchors.margins: 4
- visible: volumeBar.visible
- height: (volumeControl.volume * (parent.height - anchors.margins*2)) / (volumeControl.max - volumeControl.min)
+ height: volumeBar.visible ?
+ (volumeControl.volume * (parent.height - anchors.margins*2)) / (volumeControl.max - volumeControl.min) :
+ 0; // Avoid unnecessary updates when not visible.
color: "white"
}
diff --git a/qmafwwatchlet/qmafwwatchletvolumecontrol.cc b/qmafwwatchlet/qmafwwatchletvolumecontrol.cc
index f4876a8..f839ce7 100644
--- a/qmafwwatchlet/qmafwwatchletvolumecontrol.cc
+++ b/qmafwwatchlet/qmafwwatchletvolumecontrol.cc
@@ -69,19 +69,34 @@ void QMafwWatchletVolumeControl::setVolume(int vol)
dbus_connection_send(_conn, msg, 0);
dbus_message_unref(msg);
+
+ if (vol != _curStep) {
+ _curStep = vol;
+ emit volumeChanged();
+ }
}
void QMafwWatchletVolumeControl::up()
{
- if (_curStep < _maxStep - 1) {
- setVolume(_curStep + 1);
+ int increment = _maxStep / 10;
+ int newStep = _curStep + increment;
+ if (newStep >= _maxStep) {
+ newStep = _maxStep - 1;
+ }
+ if (newStep != _curStep) {
+ setVolume(newStep);
}
}
void QMafwWatchletVolumeControl::down()
{
- if (_curStep > 0) {
- setVolume(_curStep - 1);
+ int increment = _maxStep / 10;
+ int newStep = _curStep - increment;
+ if (newStep < 0) {
+ newStep = 0;
+ }
+ if (newStep != _curStep) {
+ setVolume(newStep);
}
}
@@ -135,7 +150,7 @@ void QMafwWatchletVolumeControl::_listenForSignal()
void QMafwWatchletVolumeControl::_fetchValues()
{
- DBusMessage *msg, *reply;
+ DBusMessage *msg;
DBusError err;
dbus_error_init(&err);
@@ -205,12 +220,13 @@ void QMafwWatchletVolumeControl::handleFetchReply(DBusPendingCall *pending, void
quint32 value;
dbus_message_iter_get_basic(&iter_variant, &value);
- if (strcmp(prop_name, "StepCount")) {
+ qDebug() << "MainVolume" << prop_name << value;
+
+ if (strcmp(prop_name, "StepCount") == 0) {
self->_maxStep = value;
- } else if (strcmp(prop_name, "CurrentStep")) {
+ } else if (strcmp(prop_name, "CurrentStep") == 0) {
self->_curStep = value;
}
- qDebug() << prop_name << value;
}
dbus_message_iter_next(&iter_dict);
@@ -229,6 +245,7 @@ void QMafwWatchletVolumeControl::handleFetchReply(DBusPendingCall *pending, void
DBusHandlerResult QMafwWatchletVolumeControl::handleDBusSignal(DBusConnection *connection, DBusMessage *message, void *user_data)
{
QMafwWatchletVolumeControl *self = static_cast<QMafwWatchletVolumeControl*>(user_data);
+ Q_UNUSED(connection);
if (dbus_message_is_signal(message, VOLUME_IF, "StepsUpdated")) {
DBusError err;
quint32 curStep, maxStep;
@@ -238,14 +255,18 @@ DBusHandlerResult QMafwWatchletVolumeControl::handleDBusSignal(DBusConnection *c
DBUS_TYPE_UINT32, &maxStep,
DBUS_TYPE_UINT32, &curStep,
DBUS_TYPE_INVALID)) {
- if (self->_maxStep != maxStep) {
+ if (self->_maxStep != static_cast<int>(maxStep)) {
self->_maxStep = maxStep;
emit self->maxChanged();
}
- if (self->_curStep != curStep) {
+ if (self->_curStep != static_cast<int>(curStep)) {
self->_curStep = curStep;
emit self->volumeChanged();
}
}
+
+ return DBUS_HANDLER_RESULT_HANDLED;
}
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
diff --git a/qmafwwatchlet/qmafwwatchletvolumecontrol.h b/qmafwwatchlet/qmafwwatchletvolumecontrol.h
index 1e1261a..75b313a 100644
--- a/qmafwwatchlet/qmafwwatchletvolumecontrol.h
+++ b/qmafwwatchlet/qmafwwatchletvolumecontrol.h
@@ -44,8 +44,8 @@ private:
private:
DBusConnection *_conn;
- uint _curStep;
- uint _maxStep;
+ int _curStep;
+ int _maxStep;
};
}