Public feed
#724706
/****************************************************************************
**
**
** This file is part of the Phone Edition of the Qtopia Toolkit.
**
** This software is licensed under the terms of the GNU General Public
** License (GPL) version 2.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include <qtopianamespace.h>
#include <qwindowsystem_qws.h>
#include <QStringList>
#include <QDir>
#include <qtopialog.h>
#include <qvaluespace.h>
#define CLASS_BACKLIGHT "/sys/class/backlight/"
QTOPIA_EXPORT int qpe_sysBrightnessSteps()
{
int nMax = 0;
// List backlight class subdirectories
QDir iClassBacklight( CLASS_BACKLIGHT );
QStringList iDirectory( iClassBacklight.entryList() );
QDir iDeviceBacklight;
// if a directory is set then backlight module is loaded
if (iDirectory.count()==0)
return -1;
QString szPath( CLASS_BACKLIGHT );
szPath.append( iDirectory.at(2).toLocal8Bit().constData() );
szPath.append( "/" );
iDeviceBacklight.setPath( szPath );
if (iDeviceBacklight.exists("max_brightness")) {
//Read and return value
QFile file;
QString szFile( CLASS_BACKLIGHT );
szFile.append( iDirectory.at(2).toLocal8Bit().constData() );
szFile.append( "/" );
szFile.append( "max_brightness" );
file.setFileName( szFile );
file.open( QIODevice::ReadOnly | QIODevice::Text);
//qWarning( file.readLine().toLatin1() );
QString szRead( file.readLine() );
//nMax = 64; //file.readLine().toInt();
file.close();
}
return 255;
}
QTOPIA_EXPORT void qpe_setBrightness(int value)
{
int nMax = 0;
QString szvalue;
if(value <= 1) {
system("apm -s");
}
else {
// List backlight class subdirectories
QDir iClassBacklight( CLASS_BACKLIGHT );
QStringList iDirectory( iClassBacklight.entryList() );
QDir iDeviceBacklight;
QString szPath( CLASS_BACKLIGHT );
szPath.append( iDirectory.at(2).toLocal8Bit().constData() );
szPath.append( "/" );
iDeviceBacklight.setPath( szPath );
if (iDeviceBacklight.exists("brightness")) {
//Read and return value
QFile file;
QString szFile( CLASS_BACKLIGHT );
szFile.append( iDirectory.at(2).toLocal8Bit().constData() );
szFile.append( "/" );
szFile.append( "brightness" );
file.setFileName( szFile );
file.open( QIODevice::ReadWrite | QIODevice::Text);
value = value * 64 / 255;
file.write( szvalue.number(value,10).toLatin1() , szvalue.number(value,10).size() );
file.close();
}
}
}