Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

light.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the OPIE Project
00003                =.            Copyright (c)  2002 Maximilian Reiss <harlekin@handhelds.org>
00004              .=l.            Copyright (c)  2002 Robert Griebl <sandman@handhelds.org>
00005            .>+-=
00006  _;:,     .>    :=|.         This file is free software; you can
00007 .> <`_,   >  .   <=          redistribute it and/or modify it under
00008 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00009 .="- .-=="i,     .._         License as published by the Free Software
00010  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00011      ._= =}       :          or (at your option) any later version.
00012     .%`+i>       _;_.
00013     .i_,=:_.      -<s.       This file is distributed in the hope that
00014      +  .  -:.       =       it will be useful, but WITHOUT ANY WARRANTY;
00015     : ..    .:,     . . .    without even the implied warranty of
00016     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU General
00018 ..}^=.=       =       ;      Public License for more details.
00019 ++=   -.     .`     .:
00020  :     =  ...= . :.=-        You should have received a copy of the GNU
00021  -.   .:....=;==+<;          General Public License along with this file;
00022   -_. . .   )=.  =           see the file COPYING. If not, write to the
00023     --        :-=`           Free Software Foundation, Inc.,
00024                              59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 #include "light.h"
00030 #include "sensor.h"
00031 
00032 /* OPIE */
00033 #include <opie2/odevice.h>
00034 #include <opie2/odebug.h>
00035 
00036 #include <qpe/config.h>
00037 #include <qpe/power.h>
00038 #if defined(Q_WS_QWS) && !defined(QT_NO_COP)
00039 #include <qpe/qcopenvelope_qws.h>
00040 #endif
00041 
00042 /* QT */
00043 #include <qlabel.h>
00044 #include <qcheckbox.h>
00045 #include <qtabwidget.h>
00046 #include <qslider.h>
00047 #include <qspinbox.h>
00048 #include <qpushbutton.h>
00049 #include <qgroupbox.h>
00050 #include <qcombobox.h>
00051 
00052 
00053 
00054 using namespace Opie::Core;
00055 
00056 LightSettings::LightSettings( QWidget* parent,  const char* name, WFlags )
00057     : LightSettingsBase( parent, name, false, WStyle_ContextHelp )
00058 {
00059     m_bres = ODevice::inst ( )-> displayBrightnessResolution ( );
00060     m_cres = ODevice::inst ( )-> displayContrastResolution ( );
00061 
00062     // check whether to show the light sensor stuff
00063 
00064     if ( !ODevice::inst ( )-> hasLightSensor ( )) {
00065         auto_brightness-> hide ( );
00066         CalibrateLightSensor-> hide ( );
00067         auto_brightness_ac-> hide ( );
00068         CalibrateLightSensor_ac-> hide ( );
00069     }
00070 
00071     // check whether to show the contrast stuff
00072 
00073     if (m_cres) {
00074         GroupLight->setTitle(tr("Backlight && Contrast"));
00075         GroupLight_ac->setTitle(GroupLight->title());
00076     } else {
00077         contrast->hide();
00078         contrast_ac->hide();
00079     }
00080 
00081     // check whether to show the cpu frequency stuff
00082 
00083     QStrList freq = ODevice::inst()->allowedCpuFrequencies();
00084     if ( freq.count() ) {
00085         frequency->insertStrList( freq );
00086         frequency_ac->insertStrList( freq );
00087     } else {
00088         frequencyLabel->hide();
00089         frequency->hide();
00090         frequencyLabel_ac->hide();
00091         frequency_ac->hide();
00092     }
00093 
00094     // check whether to show the hinge action stuff
00095 
00096     if ( !ODevice::inst()->hasHingeSensor() ) {
00097         closeHingeLabel->hide();
00098         closeHingeAction->hide();
00099         closeHingeLabel_ac->hide();
00100         closeHingeAction_ac->hide();
00101     }
00102 
00103     Config config ( "apm" );
00104     config. setGroup ( "Battery" );
00105 
00106     // battery spinboxes
00107     interval_dim->      setValue ( config. readNumEntry ( "Dim", 20 ));
00108     interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 ));
00109     interval_suspend->  setValue ( config. readNumEntry ( "Suspend", 60 ));
00110 
00111     // battery check and slider
00112     LcdOffOnly->setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
00113 
00114     // CPU frequency
00115     frequency->setCurrentItem( config.readNumEntry("Freq", 0) );
00116 
00117     // hinge action
00118     closeHingeAction->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) );
00119 
00120     int bright = config. readNumEntry ( "Brightness", 127 );
00121     int contr  = m_oldcontrast = config. readNumEntry ( "Contrast", 127 );
00122     brightness-> setTickInterval ( QMAX( 16, 256 / m_bres ));
00123     brightness-> setLineStep ( QMAX( 1, 256 / m_bres ));
00124     brightness-> setPageStep ( QMAX( 1, 256 / m_bres ));
00125     brightness-> setValue ( bright );
00126 
00127 //
00128     if (m_cres) {
00129         contrast-> setTickInterval ( QMAX( 16, 256 / m_cres ));
00130         contrast-> setLineStep ( QMAX( 1, 256 / m_cres ));
00131         contrast-> setPageStep ( QMAX( 1, 256 / m_cres ));
00132         contrast-> setValue ( contr );
00133     }
00134 
00135     // light sensor
00136     auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
00137     m_sensordata = config. readListEntry ( "LightSensorData", ';' );
00138 
00139     config. setGroup ( "AC" );
00140 
00141     // ac spinboxes
00142     interval_dim_ac->      setValue ( config. readNumEntry ( "Dim", 60 ));
00143     interval_lightoff_ac-> setValue ( config. readNumEntry ( "LightOff", 120 ));
00144     interval_suspend_ac->  setValue ( config. readNumEntry ( "Suspend", 0 ));
00145 
00146     // ac check and slider
00147     LcdOffOnly_ac-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
00148 
00149     // CPU frequency
00150     frequency_ac->setCurrentItem( config.readNumEntry("Freq", 0) );
00151 
00152     // hinge action
00153     closeHingeAction_ac->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) );
00154 
00155     bright = config. readNumEntry ( "Brightness", 255 );
00156     brightness_ac-> setTickInterval ( QMAX( 16, 256 / m_bres ));
00157     brightness_ac-> setLineStep ( QMAX( 1, 256 / m_bres ));
00158     brightness_ac-> setPageStep ( QMAX( 1, 256 / m_bres ));
00159     brightness_ac-> setValue ( bright );
00160 
00161     if (m_cres) {
00162         contr = config. readNumEntry ( "Contrast", 127);
00163         contrast_ac-> setTickInterval ( QMAX( 16, 256 / m_cres ));
00164         contrast_ac-> setLineStep ( QMAX( 1, 256 / m_cres ));
00165         contrast_ac-> setPageStep ( QMAX( 1, 256 / m_cres ));
00166         contrast_ac-> setValue ( contr );
00167     }
00168 
00169     // light sensor
00170     auto_brightness_ac-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
00171     m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' );
00172 
00173     // warnings
00174     config. setGroup ( "Warnings" );
00175     warnintervalBox-> setValue ( config. readNumEntry ( "check_interval", 10000 ) / 1000 );
00176     lowSpinBox->      setValue ( config. readNumEntry ( "power_verylow", 10 ) );
00177     criticalSpinBox-> setValue ( config. readNumEntry ( "power_critical", 5 ) );
00178 
00179     m_resettimer = new QTimer ( this );
00180     connect ( m_resettimer, SIGNAL( timeout()), this, SLOT( resetBacklight()));
00181 
00182     if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) {
00183         tabs-> setCurrentPage ( 0 );
00184         brightness->setFocus();
00185     }
00186     else {
00187         tabs-> setCurrentPage ( 1 );
00188         brightness_ac->setFocus();
00189     }
00190 
00191     connect ( brightness, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int)));
00192     connect ( brightness_ac, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int)));
00193     if (m_cres) {
00194         connect ( contrast,    SIGNAL( valueChanged(int)), this, SLOT( setContrast(int)));
00195         connect ( contrast_ac, SIGNAL( valueChanged(int)), this, SLOT( setContrast(int)));
00196     }
00197     connect( frequency, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) );
00198     connect( frequency_ac, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) );
00199     connect( closeHingeAction, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) );
00200     connect( closeHingeAction_ac, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) );
00201 }
00202 
00203 LightSettings::~LightSettings ( )
00204 {
00205 }
00206 
00207 void LightSettings::calibrateSensor ( )
00208 {
00209     Sensor *s = new Sensor ( m_sensordata, this );
00210     connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int)));
00211     QPEApplication::execDialog( s );
00212     delete s;
00213 }
00214 
00215 void LightSettings::calibrateSensorAC ( )
00216 {
00217     Sensor *s = new Sensor ( m_sensordata_ac, this );
00218     connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int)));
00219     QPEApplication::execDialog ( s );
00220     delete s;
00221 }
00222 
00223 void LightSettings::setBacklight ( int bright )
00224 {
00225     QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
00226     e << bright;
00227 
00228     if ( bright != -1 ) {
00229         m_resettimer-> stop ( );
00230         m_resettimer-> start ( 4000, true );
00231     }
00232 }
00233 
00234 void LightSettings::setContrast ( int contr )
00235 {
00236     if (contr == -1) contr = m_oldcontrast;
00237     ODevice::inst ( )-> setDisplayContrast(contr);
00238 }
00239 
00240 void LightSettings::setFrequency ( int index )
00241 {
00242     owarn << "LightSettings::setFrequency(" << index << ")" << oendl;
00243     ODevice::inst ( )-> setCurrentCpuFrequency(index);
00244 }
00245 
00246 void LightSettings::resetBacklight ( )
00247 {
00248     setBacklight ( -1 );
00249     setContrast ( -1 );
00250 }
00251 
00252 void LightSettings::setCloseHingeAction ( int index )
00253 {
00254     owarn << "LightSettings::setCloseHingeStatus(" << index << ")" << oendl;
00255 }
00256 
00257 void LightSettings::accept ( )
00258 {
00259     Config config ( "apm" );
00260 
00261     // bat
00262     config. setGroup ( "Battery" );
00263     config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( ));
00264     config. writeEntry ( "Dim",        interval_dim-> value ( ));
00265     config. writeEntry ( "LightOff",   interval_lightoff-> value ( ));
00266     config. writeEntry ( "Suspend",    interval_suspend-> value ( ));
00267     config. writeEntry ( "Brightness", brightness-> value () );
00268     if (m_cres)
00269     config. writeEntry ( "Contrast",   contrast-> value () );
00270     config. writeEntry ( "Freq",       frequency->currentItem() );
00271     config. writeEntry ( "CloseHingeAction", closeHingeAction->currentItem() );
00272 
00273     // ac
00274     config. setGroup ( "AC" );
00275     config. writeEntry ( "LcdOffOnly", LcdOffOnly_ac-> isChecked ( ));
00276     config. writeEntry ( "Dim",        interval_dim_ac-> value ( ));
00277     config. writeEntry ( "LightOff",   interval_lightoff_ac-> value ( ));
00278     config. writeEntry ( "Suspend",    interval_suspend_ac-> value ( ));
00279     config. writeEntry ( "Brightness", brightness_ac-> value () );
00280     if (m_cres)
00281     config. writeEntry ( "Contrast",   contrast_ac-> value () );
00282     config. writeEntry ( "Freq",       frequency_ac->currentItem() );
00283     config. writeEntry ( "CloseHingeAction", closeHingeAction_ac->currentItem() );
00284 
00285     // only make light sensor stuff appear if the unit has a sensor
00286     if ( ODevice::inst ( )-> hasLightSensor ( )) {
00287         config. setGroup ( "Battery" );
00288         config. writeEntry ( "LightSensor", auto_brightness->isChecked() );
00289         config. writeEntry ( "LightSensorData", m_sensordata, ';' );
00290         config. setGroup ( "AC" );
00291         config. writeEntry ( "LightSensor", auto_brightness_ac->isChecked() );
00292         config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' );
00293     }
00294 
00295     // advanced
00296     config. setGroup ( "Warnings" );
00297     config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 );
00298     config. writeEntry ( "power_verylow",  lowSpinBox-> value ( ));
00299     config. writeEntry ( "power_critical", criticalSpinBox-> value ( ));
00300     config. write ( );
00301 
00302     // notify the launcher
00303     {
00304         QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" );
00305     }
00306     {
00307         QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" );
00308         e << -1;
00309     }
00310     LightSettingsBase::accept ( );
00311 }
00312 
00313 void LightSettings::done ( int r )
00314 {
00315     m_resettimer-> stop ( );
00316     resetBacklight ( );
00317 
00318     LightSettingsBase::done ( r );
00319     close ( );
00320 }

Generated on Sat Nov 5 16:15:57 2005 for OPIE by  doxygen 1.4.2