Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "deviceorientation.h"
43#include <QtDBus>
44#include <QDebug>
45
46#define ORIENTATION_SERVICE QLatin1String("com.nokia.SensorService")
47#define ORIENTATION_PATH QLatin1String("/org/maemo/contextkit/Screen/TopEdge")
48#define CONTEXT_INTERFACE QLatin1String("org.maemo.contextkit.Property")
49#define CONTEXT_CHANGED QLatin1String("ValueChanged")
50#define CONTEXT_SUBSCRIBE QLatin1String("Subscribe")
51#define CONTEXT_UNSUBSCRIBE QLatin1String("Unsubscribe")
52#define CONTEXT_GET QLatin1String("Get")
53
54
55class HarmattanOrientation : public DeviceOrientation
56{
57 Q_OBJECT
58public:
59 HarmattanOrientation()
60 : o(UnknownOrientation), sensorEnabled(false)
61 {
62 resumeListening();
63 // connect to the orientation change signal
64 bool ok = QDBusConnection::systemBus().connect(ORIENTATION_SERVICE, ORIENTATION_PATH,
65 CONTEXT_INTERFACE,
66 CONTEXT_CHANGED,
67 this,
68 SLOT(deviceOrientationChanged(QList<QVariant>,quint64)));
69// qDebug() << "connection OK" << ok;
70 QDBusMessage reply = QDBusConnection::systemBus().call(
71 QDBusMessage::createMethodCall(ORIENTATION_SERVICE, ORIENTATION_PATH,
72 CONTEXT_INTERFACE, CONTEXT_GET));
73 if (reply.type() != QDBusMessage::ErrorMessage) {
74 QList<QVariant> args;
75 qvariant_cast<QDBusArgument>(reply.arguments().at(0)) >> args;
76 deviceOrientationChanged(args, 0);
77 }
78 }
79
80 ~HarmattanOrientation()
81 {
82 // unsubscribe from the orientation sensor
83 if (sensorEnabled)
84 QDBusConnection::systemBus().call(
85 QDBusMessage::createMethodCall(ORIENTATION_SERVICE, ORIENTATION_PATH,
86 CONTEXT_INTERFACE, CONTEXT_UNSUBSCRIBE));
87 }
88
89 inline Orientation orientation() const
90 {
91 return o;
92 }
93
94 void setOrientation(Orientation)
95 {
96 }
97
98 void pauseListening() {
99 if (sensorEnabled) {
100 // unsubscribe from the orientation sensor
101 QDBusConnection::systemBus().call(
102 QDBusMessage::createMethodCall(ORIENTATION_SERVICE, ORIENTATION_PATH,
103 CONTEXT_INTERFACE, CONTEXT_UNSUBSCRIBE));
104 sensorEnabled = false;
105 }
106 }
107
108 void resumeListening() {
109 if (!sensorEnabled) {
110 // subscribe to the orientation sensor
111 QDBusMessage reply = QDBusConnection::systemBus().call(
112 QDBusMessage::createMethodCall(ORIENTATION_SERVICE, ORIENTATION_PATH,
113 CONTEXT_INTERFACE, CONTEXT_SUBSCRIBE));
114
115 if (reply.type() == QDBusMessage::ErrorMessage) {
116 qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage()));
117 } else {
118 sensorEnabled = true;
119 }
120 }
121 }
122
123private Q_SLOTS:
124 void deviceOrientationChanged(QList<QVariant> args,quint64)
125 {
126 if (args.count() == 0)
127 return;
128 Orientation newOrientation = toOrientation(args.at(0).toString());
129 if (newOrientation != o) {
130 o = newOrientation;
131 emit orientationChanged();
132 }
133// qDebug() << "orientation" << args.at(0).toString();
134 }
135
136private:
137 static Orientation toOrientation(const QString &nativeOrientation)
138 {
139 if (nativeOrientation == QLatin1String("top"))
140 return Landscape;
141 else if (nativeOrientation == QLatin1String("left"))
142 return Portrait;
143 else if (nativeOrientation == QLatin1String("bottom"))
144 return LandscapeInverted;
145 else if (nativeOrientation == QLatin1String("right"))
146 return PortraitInverted;
147 return UnknownOrientation;
148 }
149
150private:
151 Orientation o;
152 bool sensorEnabled;
153};
154
155DeviceOrientation* DeviceOrientation::instance()
156{
157 static HarmattanOrientation *o = new HarmattanOrientation;
158 return o;
159}
160
161#include "deviceorientation_harmattan.moc"
162

Warning: That file was not part of the compilation database. It may have many parsing errors.