~ken-vandine/ubuntu-system-settings/no_s_i_d

« back to all changes in this revision

Viewing changes to plugins/sound/sound.cpp

merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "sound.h"
22
22
 
 
23
#include <QDebug>
23
24
#include <QDir>
24
25
#include <QFile>
25
26
#include <QStandardPaths>
 
27
#include <QDBusReply>
 
28
#include <QDBusVariant>
26
29
#include <unistd.h>
27
30
 
28
31
#define AS_INTERFACE "com.ubuntu.touch.AccountsService.Sound"
 
32
#define US_INTERFACE "com.canonical.usensord"
 
33
#define US_PATH "/com/canonical/usensord/haptic"
29
34
 
30
35
Sound::Sound(QObject *parent) :
31
 
    QObject(parent)
 
36
    QObject(parent),
 
37
    m_usensordIface (US_INTERFACE,
 
38
                     US_PATH,
 
39
                     "org.freedesktop.DBus.Properties",
 
40
                     QDBusConnection::sessionBus())
32
41
{
33
42
    connect (&m_accountsService,
34
43
             SIGNAL (propertyChanged (QString, QString)),
42
51
}
43
52
 
44
53
void Sound::slotChanged(QString interface,
45
 
                                  QString property)
 
54
                        QString property)
46
55
{
47
56
    if (interface != AS_INTERFACE)
48
57
        return;
59
68
        Q_EMIT incomingCallVibrateSilentModeChanged();
60
69
    } else if (property == "IncomingMessageVibrateSilentMode") {
61
70
        Q_EMIT incomingMessageVibrateSilentModeChanged();
62
 
    } else if (property == "OtherVibrate") {
63
 
        Q_EMIT otherVibrateChanged();
64
71
    } else if (property == "DialpadSoundsEnabled") {
65
72
        Q_EMIT dialpadSoundsEnabledChanged();
66
73
    }
75
82
    Q_EMIT incomingMessageVibrateChanged();
76
83
    Q_EMIT incomingCallVibrateSilentModeChanged();
77
84
    Q_EMIT incomingMessageVibrateSilentModeChanged();
78
 
    Q_EMIT otherVibrateChanged();
79
85
    Q_EMIT dialpadSoundsEnabledChanged();
80
86
}
81
87
 
198
204
 
199
205
bool Sound::getOtherVibrate()
200
206
{
201
 
    return m_accountsService.getUserProperty(AS_INTERFACE,
202
 
                                             "OtherVibrate").toBool();
 
207
    QDBusReply<QDBusVariant> reply = m_usensordIface.call("Get", "com.canonical.usensord.haptic", "OtherVibrate");
 
208
 
 
209
    if (reply.isValid()) {
 
210
      return reply.value().variant().toBool();
 
211
    } else {
 
212
        qWarning() << "no value from sensor service" << reply.error();
 
213
        return false;
 
214
    }
203
215
}
204
216
 
205
217
void Sound::setOtherVibrate(bool enabled)
206
218
{
207
 
    if (enabled == getOtherVibrate())
208
 
        return;
209
 
 
210
 
    m_accountsService.setUserProperty(AS_INTERFACE,
211
 
                                      "OtherVibrate",
212
 
                                      QVariant::fromValue(enabled));
213
 
    Q_EMIT(otherVibrateChanged());
 
219
    quint32 result = enabled ? 1 : 0;
 
220
    m_usensordIface.call("Set", "com.canonical.usensord.haptic", "OtherVibrate", result);
214
221
}
215
222
 
216
223
bool Sound::getDialpadSoundsEnabled()