1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20 #include "config.h"
21 #include "DeviceOrientationProviderQt.h"
22 
23 #include "DeviceOrientationClientMockQt.h"
24 
25 namespace WebCore {
26 
DeviceOrientationProviderQt()27 DeviceOrientationProviderQt::DeviceOrientationProviderQt()
28 {
29     m_rotation.addFilter(this);
30     m_orientation = DeviceOrientation::create();
31 
32     if (DeviceOrientationClientMockQt::mockIsActive)
33         activeClientMock();
34 }
35 
~DeviceOrientationProviderQt()36 DeviceOrientationProviderQt::~DeviceOrientationProviderQt()
37 {
38     disconnect();
39 }
40 
start()41 void DeviceOrientationProviderQt::start()
42 {
43     m_rotation.start();
44 }
45 
stop()46 void DeviceOrientationProviderQt::stop()
47 {
48     m_rotation.stop();
49 }
50 
filter(QRotationReading * reading)51 bool DeviceOrientationProviderQt::filter(QRotationReading* reading)
52 {
53     // Provide device orientation data according W3C spec:
54     // http://dev.w3.org/geo/api/spec-source-orientation.html
55     // Qt mobility provide these data via QRotationSensor using the
56     // QRotationReading class:
57     //  - the rotation around z axis (alpha) is given as z in QRotationReading;
58     //  - the rotation around x axis (beta) is given as x in QRotationReading;
59     //  - the rotation around y axis (gamma) is given as y in QRotationReading;
60     // See: http://doc.qt.nokia.com/qtmobility-1.0/qrotationreading.html
61     // The Z (alpha) rotation angle is checked via hasAlpha() private method,
62     // depending if the device is able do detect the alpha rotation. X (beta) and
63     // Y (gamma) axis are availble in this context.
64     m_orientation = DeviceOrientation::create(hasAlpha(), reading->z(),
65             /* x available */ true, reading->x(),
66             /* y available */ true, reading->y());
67     emit deviceOrientationChanged(m_orientation.get());
68 
69     return false;
70 }
71 
changeDeviceOrientation(DeviceOrientation * orientation)72 void DeviceOrientationProviderQt::changeDeviceOrientation(DeviceOrientation* orientation)
73 {
74     m_orientation = orientation;
75 }
76 
activeClientMock()77 void DeviceOrientationProviderQt::activeClientMock()
78 {
79     connect(DeviceOrientationClientMockQt::client(), SIGNAL(mockOrientationChanged(DeviceOrientation*)), SLOT(changeDeviceOrientation(DeviceOrientation*)));
80 }
81 
82 }
83 
84 #include "moc_DeviceOrientationProviderQt.cpp"
85