Updated the web pages
[chessclock] / classes / screenlitkeeper.cpp
1 /**************************************************************************
2         ScreenLitKeeper
3
4         Copyright (C) 2010  Heli Hyvättinen
5         
6         This file is free software: you can redistribute it and/or modify
7         it under the terms of the GNU General Public License as published by
8         the Free Software Foundation, either version 3 of the License, or
9         (at your option) any later version.
10
11         This program is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14         GNU General Public License for more details.
15
16         You should have received a copy of the GNU General Public License
17         along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 **************************************************************************/
20
21
22
23
24
25 #include "screenlitkeeper.h"
26
27 ScreenLitKeeper::ScreenLitKeeper(QObject *parent) :
28     QObject(parent)
29 {
30     p_screensaver_ = NULL;
31     isKeptLit_ = false;
32 }
33
34 void ScreenLitKeeper::keepScreenLit(bool keepLit)
35 {
36
37     //If the requested state is the same as the current state do nothing.
38     if (keepLit == isKeptLit_)
39         return;
40
41
42
43     if (keepLit == true )
44     {
45         //a new screensaver is created, parent is given so that it is automatically destroyed when this object is destroyed
46         p_screensaver_ = new QSystemScreenSaver(this);
47         //screensaver is disabled, which keeps the screen lit on N900
48         p_screensaver_->setScreenSaverInhibit();
49         isKeptLit_ = true;
50
51     }
52
53     else if (p_screensaver_ != NULL) //just to be on the safe side, it should never be NULL if this line is reached
54     {
55       delete p_screensaver_; //The object must be deleted to reverse the effect of setScreenSaverInhibit()
56       p_screensaver_ = NULL;
57       isKeptLit_ = false;
58
59     }
60
61     return;
62
63 }