Changed the default configuration file path
[harmattan/cameraplus] / src / orientation.cpp
1 #include "orientation.h"
2 #include <qmorientation.h>
3 #include <QDebug>
4
5 Orientation::Orientation(QObject *parent) :
6   QObject(parent),
7   m_orientation(new MeeGo::QmOrientation(this)),
8   m_direction(Unknown) {
9
10   QObject::connect(m_orientation, SIGNAL(orientationChanged(const MeeGo::QmOrientationReading&)),
11                    this, SLOT(orientationChanged(const MeeGo::QmOrientationReading&)));
12
13   if (m_orientation->requestSession(MeeGo::QmSensor::SessionTypeListen)
14       == MeeGo::QmSensor::SessionTypeNone) {
15     qDebug() << "Failed to get listen session:" << m_orientation->lastError();
16   }
17 }
18
19 Orientation::~Orientation() {
20   m_orientation->stop();
21 }
22
23 bool Orientation::isActive() const {
24   return m_orientation->isRunning();
25 }
26
27 void Orientation::setActive(bool active) {
28   if (active == isActive()) {
29     return;
30   }
31
32   if (active) {
33     m_orientation->start();
34     orientationChanged(m_orientation->orientation());
35   }
36   else {
37     m_orientation->stop();
38     m_direction = Unknown;
39
40     emit orientationChanged();
41   }
42
43   emit activeChanged();
44 }
45
46 Orientation::OrientationDirection Orientation::orientation() const {
47   return m_direction;
48 }
49
50 void Orientation::orientationChanged(const MeeGo::QmOrientationReading& value) {
51   OrientationDirection direction = Unknown;
52
53   switch (value.value) {
54   case MeeGo::QmOrientation::BottomUp:
55     direction = InvertedLandscape;
56     break;
57
58   case MeeGo::QmOrientation::BottomDown:
59     direction = Landscape;
60     break;
61
62   case MeeGo::QmOrientation::LeftUp:
63     direction = Portrait;
64     break;
65
66   case MeeGo::QmOrientation::RightUp:
67     direction = InvertedPortrait;
68     break;
69
70   default:
71     direction = Unknown;
72     break;
73   }
74
75   if (direction != m_direction) {
76     m_direction = direction;
77     emit orientationChanged();
78   }
79 }