|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the tools applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "deviceorientation.h" |
|
43 #include <QtDBus> |
|
44 |
|
45 #include <mce/mode-names.h> |
|
46 #include <mce/dbus-names.h> |
|
47 |
|
48 class MaemoOrientation : public DeviceOrientation |
|
49 { |
|
50 Q_OBJECT |
|
51 public: |
|
52 MaemoOrientation() |
|
53 : o(UnknownOrientation) |
|
54 { |
|
55 // enable the orientation sensor |
|
56 QDBusConnection::systemBus().call( |
|
57 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
58 MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); |
|
59 |
|
60 // query the initial orientation |
|
61 QDBusMessage reply = QDBusConnection::systemBus().call( |
|
62 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
63 MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET)); |
|
64 if (reply.type() == QDBusMessage::ErrorMessage) { |
|
65 qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage())); |
|
66 } else { |
|
67 o = toOrientation(reply.arguments().value(0).toString()); |
|
68 } |
|
69 |
|
70 // connect to the orientation change signal |
|
71 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, |
|
72 MCE_DEVICE_ORIENTATION_SIG, |
|
73 this, |
|
74 SLOT(deviceOrientationChanged(QString))); |
|
75 } |
|
76 |
|
77 ~MaemoOrientation() |
|
78 { |
|
79 // disable the orientation sensor |
|
80 QDBusConnection::systemBus().call( |
|
81 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
82 MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); |
|
83 } |
|
84 |
|
85 inline Orientation orientation() const |
|
86 { |
|
87 return o; |
|
88 } |
|
89 |
|
90 void setOrientation(Orientation o) |
|
91 { |
|
92 } |
|
93 |
|
94 private Q_SLOTS: |
|
95 void deviceOrientationChanged(const QString &newOrientation) |
|
96 { |
|
97 o = toOrientation(newOrientation); |
|
98 |
|
99 emit orientationChanged(); |
|
100 // printf("%d\n", o); |
|
101 } |
|
102 |
|
103 private: |
|
104 static Orientation toOrientation(const QString &nativeOrientation) |
|
105 { |
|
106 if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE) |
|
107 return Landscape; |
|
108 else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED) |
|
109 return LandscapeInverted; |
|
110 else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT) |
|
111 return Portrait; |
|
112 else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED) |
|
113 return PortraitInverted; |
|
114 return UnknownOrientation; |
|
115 } |
|
116 |
|
117 private: |
|
118 Orientation o; |
|
119 }; |
|
120 |
|
121 DeviceOrientation* DeviceOrientation::instance() |
|
122 { |
|
123 static MaemoOrientation *o = new MaemoOrientation; |
|
124 return o; |
|
125 } |
|
126 |
|
127 #include "deviceorientation_maemo5.moc" |