00001 /************************************************************************** 00002 ScreenLitKeeper 00003 00004 Copyright (C) 2010 Heli Hyvättinen 00005 00006 This file is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 **************************************************************************/ 00020 00021 00022 00023 00024 00025 #include "screenlitkeeper.h" 00026 00027 ScreenLitKeeper::ScreenLitKeeper(QObject *parent) : 00028 QObject(parent) 00029 { 00030 p_screensaver_ = NULL; 00031 isKeptLit_ = false; 00032 } 00033 00034 void ScreenLitKeeper::keepScreenLit(bool keepLit) 00035 { 00036 00037 //If the requested state is the same as the current state do nothing. 00038 if (keepLit == isKeptLit_) 00039 return; 00040 00041 00042 00043 if (keepLit == true ) 00044 { 00045 //a new screensaver is created, parent is given so that it is automatically destroyed when this object is destroyed 00046 p_screensaver_ = new QSystemScreenSaver(this); 00047 //screensaver is disabled, which keeps the screen lit on N900 00048 p_screensaver_->setScreenSaverInhibit(); 00049 isKeptLit_ = true; 00050 00051 } 00052 00053 else if (p_screensaver_ != NULL) //just to be on the safe side, it should never be NULL if this line is reached 00054 { 00055 delete p_screensaver_; //The object must be deleted to reverse the effect of setScreenSaverInhibit() 00056 p_screensaver_ = NULL; 00057 isKeptLit_ = false; 00058 00059 } 00060 00061 return; 00062 00063 }