a2c05c2b4eac499dea01518b17e04bde488c07a6
[harmattan/cameraplus] / src / displaystate.cpp
1 #include "displaystate.h"
2 #include <qmsystem2/qmdisplaystate.h>
3 #include <QTimer>
4 #include <QDebug>
5
6 DisplayState::DisplayState(QObject *parent) :
7   QObject(parent), m_state(new MeeGo::QmDisplayState(this)), m_timer(new QTimer(this)) {
8
9   m_timer->setSingleShot(false);
10   m_timer->setInterval(50 * 1000);
11
12   QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
13 }
14
15 DisplayState::~DisplayState() {
16   setInhibitDim(false);
17 }
18
19 bool DisplayState::isDimInhibited() const {
20   return m_timer->isActive();
21 }
22
23 void DisplayState::setInhibitDim(bool inhibit) {
24   if (m_timer->isActive() == inhibit) {
25     return;
26   }
27
28   if (!inhibit) {
29     if (!m_state->cancelBlankingPause()) {
30       qWarning() << "Failed to cancel display dimming!";
31     }
32
33     m_timer->stop();
34   }
35   else {
36     if (!m_state->setBlankingPause()) {
37       qWarning() << "Failed to inhibit display dimming!";
38       return;
39     }
40
41     m_timer->start();
42   }
43
44   emit inhibitDimChanged();
45 }
46
47 void DisplayState::timeout() {
48   if (!m_state->setBlankingPause()) {
49     qWarning() << "Failed to inhibit display dimming!";
50   }
51 }