summaryrefslogtreecommitdiff
path: root/core/settings/light-and-power/light.cpp
Unidiff
Diffstat (limited to 'core/settings/light-and-power/light.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/light-and-power/light.cpp338
1 files changed, 160 insertions, 178 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp
index 572f8ea..2ea0356 100644
--- a/core/settings/light-and-power/light.cpp
+++ b/core/settings/light-and-power/light.cpp
@@ -1,24 +1,30 @@
1/********************************************************************** 1/*
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2 This file is part of the OPIE Project
3** 3               =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org>
4** This file is part of Qtopia Environment. 4             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
5** 5           .>+-=
6** This file may be distributed and/or modified under the terms of the 6 _;:,     .>    :=|. This file is free software; you can
7** GNU General Public License version 2 as published by the Free Software 7.> <`_,   >  .   <= redistribute it and/or modify it under
8** Foundation and appearing in the file LICENSE.GPL included in the 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9** packaging of this file. 9.="- .-=="i,     .._ License as published by the Free Software
10** 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11     ._= =}       : or (at your option) any later version.
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12    .%`+i>       _;_.
13** 13    .i_,=:_.      -<s. This file is distributed in the hope that
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15** 15    : ..    .:,     . . . without even the implied warranty of
16** Contact info@trolltech.com if any conditions of this licensing are 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17** not clear to you. 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18** 18..}^=.=       =       ; Public License for more details.
19**********************************************************************/ 19++=   -.     .`     .:
20 20 :     =  ...= . :.=- You should have received a copy of the GNU
21// redone by Maximilian Reiss <harlekin@handhelds.org> 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
22 28
23#include "settings.h" 29#include "settings.h"
24 30
@@ -53,159 +59,152 @@
53 59
54#include <opie/odevice.h> 60#include <opie/odevice.h>
55 61
62#include "sensor.h"
63
56using namespace Opie; 64using namespace Opie;
57 65
58LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) 66LightSettings::LightSettings( QWidget* parent, const char* name, WFlags )
59 : LightSettingsBase( parent, name, TRUE, WStyle_ContextHelp ) 67 : LightSettingsBase( parent, name, true, WStyle_ContextHelp )
60{ 68{
61 int res = ODevice::inst ( )-> displayBrightnessResolution ( ); 69 m_res = ODevice::inst ( )-> displayBrightnessResolution ( );
62 70
63 if ( ODevice::inst()->hasLightSensor() ) { 71 if ( !ODevice::inst ( )-> hasLightSensor ( )) {
64 // Not supported yet - hide until implemented 72 auto_brightness-> hide ( );
65 CalibrateLightSensor->setEnabled( false ); 73 CalibrateLightSensor-> hide ( );
66 CalibrateLightSensorAC->setEnabled( false ); 74 auto_brightness_ac_3-> hide ( );
67 } else { 75 CalibrateLightSensorAC-> hide ( );
68 // if ipaq no need to show the sensor box 76 }
69 auto_brightness->hide(); 77
70 CalibrateLightSensor->hide(); 78 Config config ( "apm" );
71 auto_brightness_ac_3->hide(); 79 config. setGroup ( "Battery" );
72 CalibrateLightSensorAC->hide(); 80
73 } 81 // battery spinboxes
74 82 interval_dim-> setValue ( config. readNumEntry ( "Dim", 20 ));
75 Config config( "apm" ); 83 interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 ));
76 config.setGroup( "Battery" ); 84 interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 ));
77 85
78 // battery spinboxes 86 // battery check and slider
79 interval_dim->setValue( config.readNumEntry( "Dim", 20 )); 87 LcdOffOnly-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
80 interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 )); 88
81 interval_suspend->setValue( config.readNumEntry( "Suspend", 60 )); 89 int bright = config. readNumEntry ( "Brightness", 255 );
82 90 brightness-> setMaxValue ( m_res - 1 );
83 // battery check and slider 91 brightness-> setTickInterval ( QMAX( 1, m_res / 16 ));
84 LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); 92 brightness-> setLineStep ( QMAX( 1, m_res / 16 ));
85 93 brightness-> setPageStep ( QMAX( 1, m_res / 16 ));
86 initbright = config. readNumEntry ( "Brightness", 255 ); 94 brightness-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 );
87 brightness-> setMaxValue ( res - 1 ); 95
88 brightness-> setTickInterval ( QMAX( 1, res / 16 )); 96 // light sensor
89 brightness-> setLineStep ( QMAX( 1, res / 16 )); 97 auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
90 brightness-> setPageStep ( QMAX( 1, res / 16 )); 98 m_sensordata = config. readListEntry ( "LightSensorData", ';' );
91 brightness-> setValue (( initbright * ( res - 1 ) + 127 ) / 255 ); 99
92 100 config. setGroup ( "AC" );
93 // light sensor 101
94 auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 102 // ac spinboxes
95 103 interval_dim_ac_3-> setValue ( config. readNumEntry ( "Dim", 20 ));
96 config.setGroup( "AC" ); 104 interval_lightoff_ac_3-> setValue ( config. readNumEntry ( "LightOff", 30 ));
97 // ac spinboxes 105 interval_suspend_ac_3-> setValue ( config. readNumEntry ( "Suspend", 60 ));
98 interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); 106
99 interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); 107 // ac check and slider
100 interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 )); 108 LcdOffOnly_2_3-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
101 109
102 // ac check and slider 110 bright = config. readNumEntry ( "Brightness", 255 );
103 LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); 111 brightness_ac_3-> setMaxValue ( m_res - 1 );
104 112 brightness_ac_3-> setTickInterval ( QMAX( 1, m_res / 16 ));
105 initbright_ac = config. readNumEntry ( "Brightness", 255 ); 113 brightness_ac_3-> setLineStep ( QMAX( 1, m_res / 16 ));
106 brightness_ac_3-> setMaxValue ( res - 1 ); 114 brightness_ac_3-> setPageStep ( QMAX( 1, m_res / 16 ));
107 brightness_ac_3-> setTickInterval ( QMAX( 1, res / 16 )); 115 brightness_ac_3-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 );
108 brightness_ac_3-> setLineStep ( QMAX( 1, res / 16 )); 116
109 brightness_ac_3-> setPageStep ( QMAX( 1, res / 16 )); 117 // light sensor
110 brightness_ac_3-> setValue (( initbright_ac * ( res - 1 ) + 127 ) / 255 ); 118 auto_brightness_ac_3-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
111 119 m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' );
112 // light sensor 120
113 auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 121 // advanced settings
114 122 config. setGroup ( "Warnings" );
115 123 warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 );
116 //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); 124 lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) );
117 //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); 125 criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) );
118 //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; 126
119 //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); 127 if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online )
120 128 connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
121 // advanced settings 129 else
122 config.setGroup( "Warnings" ); 130 connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
123 warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 );
124 lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) );
125 criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) );
126
127 connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) );
128 connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) );
129} 131}
130 132
131LightSettings::~LightSettings() { 133LightSettings::~LightSettings ( )
134{
132} 135}
133 136
134void LightSettings::slotSliderTicks( int steps ) { 137
135// LightMinValueSlider->setTickInterval( steps ); 138void LightSettings::calibrateSensor ( )
139{
140 Sensor *s = new Sensor ( m_sensordata, this );
141 s-> showMaximized ( );
142 s-> exec ( );
143 delete s;
136} 144}
137 145
138static void set_fl(int bright) 146void LightSettings::calibrateSensorAC ( )
139{ 147{
140 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 148 Sensor *s = new Sensor ( m_sensordata_ac, this );
141 e << bright; 149 s-> showMaximized ( );
150 s-> exec ( );
151 delete s;
142} 152}
143 153
144void LightSettings::reject() 154void LightSettings::setBacklight ( int bright )
145{ 155{
146 set_fl(initbright); 156 bright = bright * 255 / ( m_res - 1 );
147 QDialog::reject(); 157 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
158 e << bright;
159}
160
161void LightSettings::reject ( )
162{
163 {
164 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
165 e << -1;
166 }
167 QDialog::reject ( );
148} 168}
149 169
150void LightSettings::accept() 170void LightSettings::accept ( )
151{ 171{
152 if ( qApp->focusWidget() ) { 172 Config config ( "apm" );
153 qApp->focusWidget()->clearFocus(); 173
154 } 174 // bat
155 175 config. setGroup ( "Battery" );
156 applyBrightness(); 176 config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( ));
157 177 config. writeEntry ( "Dim", interval_dim-> value ( ));
158 // bat 178 config. writeEntry ( "LightOff", interval_lightoff-> value ( ));
159 int i_dim = interval_dim->value(); 179 config. writeEntry ( "Suspend", interval_suspend-> value ( ));
160 int i_lightoff = interval_lightoff->value(); 180 config. writeEntry ( "Brightness", brightness-> value ( ) * 255 / ( m_res - 1 ) );
161 int i_suspend = interval_suspend->value(); 181
162 182 // ac
163 // ac 183 config. setGroup ( "AC" );
164 int i_dim_ac = interval_dim_ac_3->value(); 184 config. writeEntry ( "LcdOffOnly", LcdOffOnly_2_3-> isChecked ( ));
165 int i_lightoff_ac = interval_lightoff_ac_3->value(); 185 config. writeEntry ( "Dim", interval_dim_ac_3-> value ( ));
166 int i_suspend_ac = interval_suspend_ac_3->value(); 186 config. writeEntry ( "LightOff", interval_lightoff_ac_3-> value ( ));
167 187 config. writeEntry ( "Suspend", interval_suspend_ac_3-> value ( ));
168 Config config( "apm" ); 188 config. writeEntry ( "Brightness", brightness_ac_3-> value ( ) * 255 / ( m_res - 1 ));
169 189
170 config.setGroup( "Battery" ); 190 // only make light sensor stuff appear if the unit has a sensor
171 191 if ( ODevice::inst ( )-> hasLightSensor ( )) {
172 // bat 192 config. setGroup ( "Battery" );
173 config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); 193 config. writeEntry ( "LightSensor", auto_brightness->isChecked() );
174 config.writeEntry( "Dim", i_dim ); 194 config. writeEntry ( "LightSensorData", m_sensordata, ';' );
175 config.writeEntry( "LightOff", i_lightoff ); 195 config. setGroup ( "AC" );
176 config.writeEntry( "Suspend", i_suspend ); 196 config. writeEntry ( "LightSensor", auto_brightness_ac_3->isChecked() );
177 config.writeEntry( "Brightness", 197 config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' );
178 ( brightness->value() ) * 255 / brightness->maxValue() ); 198 }
179 199
180 // ac 200 // advanced
181 config.setGroup( "AC" ); 201 config. setGroup ( "Warnings" );
182 config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); 202 config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 );
183 config.writeEntry( "Dim", i_dim_ac ); 203 config. writeEntry ( "power_verylow", lowSpinBox-> value ( ));
184 config.writeEntry( "LightOff", i_lightoff_ac ); 204 config. writeEntry ( "power_critical", criticalSpinBox-> value ( ));
185 config.writeEntry( "Suspend", i_suspend_ac ); 205 config. write ( );
186 config.writeEntry( "Brightness",
187 ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() );
188
189
190 // only make light sensor stuff appear if the unit has a sensor
191 if ( ODevice::inst()->hasLightSensor() ) {
192 config.setGroup( "Battery" );
193 config.writeEntry( "LightSensor", auto_brightness->isChecked() );
194 config.setGroup( "AC" );
195 config.writeEntry( "LightSensor", auto_brightness_ac_3->isChecked() );
196 //config.writeEntry( "Steps", LightStepSpin->value() );
197 //onfig.writeEntry( "MinValue", LightMinValueSlider->value() );
198 //config.writeEntry( "Shift", LightShiftSpin->value() );
199 }
200
201
202 // advanced
203 config.setGroup( "Warnings" );
204 config.writeEntry( "check_interval", warnintervalBox->value()*1000 );
205 config.writeEntry( "power_verylow", lowSpinBox->value() );
206 config.writeEntry( "power_critical", criticalSpinBox->value() );
207 config.write();
208 206
207 // notify the launcher
209 { 208 {
210 QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); 209 QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" );
211 } 210 }
@@ -217,29 +216,12 @@ void LightSettings::accept()
217 QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); 216 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
218 e << -1; 217 e << -1;
219 } 218 }
220 219
221 QDialog::accept(); 220 QDialog::accept ( );
222}
223
224void LightSettings::applyBrightness()
225{
226 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
227 int bright = ( brightness->value() ) * 255 / brightness->maxValue();
228 set_fl(bright);
229 }
230}
231
232void LightSettings::applyBrightnessAC()
233{
234 // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting
235 if ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ) {
236 int bright = ( brightness_ac_3->value() ) * 255 / brightness_ac_3->maxValue();
237 set_fl(bright);
238 }
239} 221}
240 222
241void LightSettings::done(int r) 223void LightSettings::done ( int r )
242{ 224{
243 QDialog::done(r); 225 QDialog::done ( r );
244 close(); 226 close ( );
245} 227}