diff options
author | David Boddie <david.boddie@nokia.com> | 2011-04-28 17:39:11 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2011-04-28 17:39:11 (GMT) |
commit | 3abaecc3aec4e46f1c5969c33875fd45aa542385 (patch) | |
tree | 58613c5d2b765018c31d0b189e9c5a34d8adde69 /examples/widgets/maemovibration/mcevibrator.cpp | |
parent | ddb22795641253a026b72f752ebc769745dd41be (diff) | |
download | Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.zip Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.tar.gz Qt-3abaecc3aec4e46f1c5969c33875fd45aa542385.tar.bz2 |
Squashed commit of the changes from the mobile-examples repository
(4.7-generated-declarative branch).
Diffstat (limited to 'examples/widgets/maemovibration/mcevibrator.cpp')
-rw-r--r-- | examples/widgets/maemovibration/mcevibrator.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/examples/widgets/maemovibration/mcevibrator.cpp b/examples/widgets/maemovibration/mcevibrator.cpp new file mode 100644 index 0000000..be6415f --- /dev/null +++ b/examples/widgets/maemovibration/mcevibrator.cpp @@ -0,0 +1,79 @@ + +#include "mcevibrator.h" + +#include <QStringList> +#include <QDebug> +#include <QDBusConnection> +#include <QDBusMessage> + +#include <mce/dbus-names.h> + +const char MceVibrator::defaultMceFilePath[] = "/etc/mce/mce.ini"; + +//! [5] +static void checkError(QDBusMessage &msg) +{ + if (msg.type() == QDBusMessage::ErrorMessage) + qDebug() << msg.errorName() << msg.errorMessage(); +} +//! [5] + +//! [0] +MceVibrator::MceVibrator(QObject *parent) : + QObject(parent), + mceInterface(MCE_SERVICE, MCE_REQUEST_PATH, MCE_REQUEST_IF, + QDBusConnection::systemBus()) +{ + QDBusMessage reply = mceInterface.call(MCE_ENABLE_VIBRATOR); + checkError(reply); +} +//! [0] + +//! [3] +MceVibrator::~MceVibrator() +{ + deactivate(lastPatternName); + QDBusMessage reply = mceInterface.call(MCE_DISABLE_VIBRATOR); + checkError(reply); +} +//! [3] + +//! [1] +void MceVibrator::vibrate(const QString &patternName) +{ + deactivate(lastPatternName); + lastPatternName = patternName; + QDBusMessage reply = mceInterface.call(MCE_ACTIVATE_VIBRATOR_PATTERN, patternName); + checkError(reply); +} +//! [1] + +//! [2] +void MceVibrator::deactivate(const QString &patternName) +{ + if (!patternName.isNull()) { + QDBusMessage reply = mceInterface.call(MCE_DEACTIVATE_VIBRATOR_PATTERN, patternName); + checkError(reply); + } +} +//! [2] + +//! [4] +QStringList MceVibrator::parsePatternNames(QTextStream &stream) +{ + QStringList result; + QString line; + + do { + line = stream.readLine(); + if (line.startsWith(QLatin1String("VibratorPatterns="))) { + QString values = line.section('=', 1); + result = values.split(';'); + break; + } + } while (!line.isNull()); + + return result; +} +//! [4] + |