1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
9 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
14 ** Please review the following information to ensure the GNU Lesser General
15 ** Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
24 ** Alternatively, this file may be used in accordance with the terms and
25 ** conditions contained in a signed written agreement between you and Nokia.
27 ** If you have questions regarding the use of this file, please contact
28 ** Nokia at qt-info@nokia.com.
30 **************************************************************************/
32 #include "deviceorientation.h"
35 #include <mce/mode-names.h>
36 #include <mce/dbus-names.h>
38 class MaemoOrientation : public DeviceOrientation
43 : o(UnknownOrientation), sensorEnabled(false)
46 // connect to the orientation change signal
47 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
48 MCE_DEVICE_ORIENTATION_SIG,
50 SLOT(deviceOrientationChanged(QString)));
55 // disable the orientation sensor
56 QDBusConnection::systemBus().call(
57 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
58 MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
61 inline Orientation orientation() const
66 void setOrientation(Orientation o)
70 void pauseListening() {
72 // disable the orientation sensor
73 QDBusConnection::systemBus().call(
74 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
75 MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ));
76 sensorEnabled = false;
80 void resumeListening() {
82 // enable the orientation sensor
83 QDBusConnection::systemBus().call(
84 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
85 MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ));
87 QDBusMessage reply = QDBusConnection::systemBus().call(
88 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH,
89 MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET));
91 if (reply.type() == QDBusMessage::ErrorMessage) {
92 qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage()));
94 Orientation orientation = toOrientation(reply.arguments().value(0).toString());
95 if (o != orientation) {
97 emit orientationChanged();
105 void deviceOrientationChanged(const QString &newOrientation)
107 o = toOrientation(newOrientation);
109 emit orientationChanged();
110 // printf("%d\n", o);
114 static Orientation toOrientation(const QString &nativeOrientation)
116 if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE)
118 else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED)
119 return LandscapeInverted;
120 else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT)
122 else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED)
123 return PortraitInverted;
124 return UnknownOrientation;
132 DeviceOrientation* DeviceOrientation::instance()
134 static MaemoOrientation *o = new MaemoOrientation;
138 #include "deviceorientation_maemo5.moc"