48 class MaemoOrientation : public DeviceOrientation |
48 class MaemoOrientation : public DeviceOrientation |
49 { |
49 { |
50 Q_OBJECT |
50 Q_OBJECT |
51 public: |
51 public: |
52 MaemoOrientation() |
52 MaemoOrientation() |
53 : o(UnknownOrientation) |
53 : o(UnknownOrientation), sensorEnabled(false) |
54 { |
54 { |
55 // enable the orientation sensor |
55 resumeListening(); |
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 |
56 // connect to the orientation change signal |
71 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, |
57 QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, |
72 MCE_DEVICE_ORIENTATION_SIG, |
58 MCE_DEVICE_ORIENTATION_SIG, |
73 this, |
59 this, |
74 SLOT(deviceOrientationChanged(QString))); |
60 SLOT(deviceOrientationChanged(QString))); |
87 return o; |
73 return o; |
88 } |
74 } |
89 |
75 |
90 void setOrientation(Orientation o) |
76 void setOrientation(Orientation o) |
91 { |
77 { |
|
78 } |
|
79 |
|
80 void pauseListening() { |
|
81 if (sensorEnabled) { |
|
82 // disable the orientation sensor |
|
83 QDBusConnection::systemBus().call( |
|
84 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
85 MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); |
|
86 sensorEnabled = false; |
|
87 } |
|
88 } |
|
89 |
|
90 void resumeListening() { |
|
91 if (!sensorEnabled) { |
|
92 // enable the orientation sensor |
|
93 QDBusConnection::systemBus().call( |
|
94 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
95 MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); |
|
96 |
|
97 QDBusMessage reply = QDBusConnection::systemBus().call( |
|
98 QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, |
|
99 MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET)); |
|
100 |
|
101 if (reply.type() == QDBusMessage::ErrorMessage) { |
|
102 qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage())); |
|
103 } else { |
|
104 Orientation orientation = toOrientation(reply.arguments().value(0).toString()); |
|
105 if (o != orientation) { |
|
106 o = orientation; |
|
107 emit orientationChanged(); |
|
108 } |
|
109 sensorEnabled = true; |
|
110 } |
|
111 } |
92 } |
112 } |
93 |
113 |
94 private Q_SLOTS: |
114 private Q_SLOTS: |
95 void deviceOrientationChanged(const QString &newOrientation) |
115 void deviceOrientationChanged(const QString &newOrientation) |
96 { |
116 { |