summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-27 19:36:57 (UTC)
committer sandman <sandman>2002-10-27 19:36:57 (UTC)
commitc1f70789d18145743fd71464c091612788cc5e3f (patch) (unidiff)
treea2e90d73149f638d155d3e28990fe77ea83de96e
parent63894d36a26675655a4f74721ea1c19fb5e3e84c (diff)
downloadopie-c1f70789d18145743fd71464c091612788cc5e3f.zip
opie-c1f70789d18145743fd71464c091612788cc5e3f.tar.gz
opie-c1f70789d18145743fd71464c091612788cc5e3f.tar.bz2
some cleanup regarding config:
replaced all the foo/foo_Interval configs with a single foo config (a 0 value means off)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/light-and-power/light.cpp86
1 files changed, 20 insertions, 66 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp
index bf94a21..c021ad4 100644
--- a/core/settings/light-and-power/light.cpp
+++ b/core/settings/light-and-power/light.cpp
@@ -1,288 +1,242 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21// redone by Maximilian Reiss <harlekin@handhelds.org> 21// redone by Maximilian Reiss <harlekin@handhelds.org>
22 22
23#include "settings.h" 23#include "settings.h"
24 24
25#include <qpe/global.h> 25#include <qpe/global.h>
26#include <qpe/fontmanager.h> 26#include <qpe/fontmanager.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/applnk.h> 28#include <qpe/applnk.h>
29#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30#include <qpe/power.h> 30#include <qpe/power.h>
31#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 31#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
32#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33#endif 33#endif
34 34
35#include <qlabel.h> 35#include <qlabel.h>
36#include <qcheckbox.h> 36#include <qcheckbox.h>
37#include <qradiobutton.h> 37#include <qradiobutton.h>
38#include <qtabwidget.h> 38#include <qtabwidget.h>
39#include <qslider.h> 39#include <qslider.h>
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42#include <qdatastream.h> 42#include <qdatastream.h>
43#include <qmessagebox.h> 43#include <qmessagebox.h>
44#include <qcombobox.h> 44#include <qcombobox.h>
45#include <qgroupbox.h> 45#include <qgroupbox.h>
46#include <qspinbox.h> 46#include <qspinbox.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qlistbox.h> 48#include <qlistbox.h>
49#include <qdir.h> 49#include <qdir.h>
50#if QT_VERSION >= 300 50#if QT_VERSION >= 300
51#include <qstylefactory.h> 51#include <qstylefactory.h>
52#endif 52#endif
53 53
54#include <opie/odevice.h> 54#include <opie/odevice.h>
55 55
56using namespace Opie; 56using namespace Opie;
57 57
58LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) 58LightSettings::LightSettings( QWidget* parent, const char* name, WFlags )
59 : LightSettingsBase( parent, name, TRUE, WStyle_ContextHelp ) 59 : LightSettingsBase( parent, name, TRUE, WStyle_ContextHelp )
60{ 60{
61 61
62 if ( ODevice::inst()->hasLightSensor() ) { 62 if ( ODevice::inst()->hasLightSensor() ) {
63 // Not supported yet - hide until implemented 63 // Not supported yet - hide until implemented
64 CalibrateLightSensor->setEnabled( false ); 64 CalibrateLightSensor->setEnabled( false );
65 CalibrateLightSensorAC->setEnabled( false ); 65 CalibrateLightSensorAC->setEnabled( false );
66 } else { 66 } else {
67 // if ipaq no need to show the sensor box 67 // if ipaq no need to show the sensor box
68 auto_brightness->hide(); 68 auto_brightness->hide();
69 CalibrateLightSensor->hide(); 69 CalibrateLightSensor->hide();
70 auto_brightness_ac_3->hide(); 70 auto_brightness_ac_3->hide();
71 CalibrateLightSensorAC->hide(); 71 CalibrateLightSensorAC->hide();
72 } 72 }
73 73
74 Config config( "apm" ); 74 Config config( "apm" );
75 config.setGroup( "Battery" ); 75 config.setGroup( "Battery" );
76 76
77 int interval;
78 // battery spinboxes 77 // battery spinboxes
79 interval = config.readNumEntry( "Interval_Dim", 20 ); 78 interval_dim->setValue( config.readNumEntry( "Dim", 20 ));
80 if ( config.readNumEntry("Dim",1) == 0 ) { 79 interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 ));
81 interval_dim->setValue( 0 ); 80 interval_suspend->setValue( config.readNumEntry( "Suspend", 60 ));
82 } else {
83 interval_dim->setValue( interval );
84 }
85
86 interval = config.readNumEntry( "Interval_LightOff", 30 );
87 if ( config.readNumEntry("LightOff",1) == 0 ) {
88 interval_lightoff->setValue( 0 );
89 } else {
90 interval_lightoff->setValue( interval );
91 }
92
93 interval = config.readNumEntry( "Interval", 60 );
94 if ( interval > 3600 ) interval /= 1000; // compatibility (was millisecs)
95
96 if ( config.readNumEntry("NoApm", 0 ) == 1 ) {
97 interval_suspend->setValue( 0 );
98 } else {
99 interval_suspend->setValue( interval );
100 }
101 81
102 // battery check and slider 82 // battery check and slider
103 LcdOffOnly->setChecked( config.readNumEntry("LcdOffOnly",0) != 0 ); 83 LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false));
104 int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( ); 84 int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( );
105 initbright = config.readNumEntry("Brightness",255); 85 initbright = config.readNumEntry("Brightness",255);
106 brightness->setMaxValue( maxbright ); 86 brightness->setMaxValue( maxbright );
107 brightness->setTickInterval( QMAX(1,maxbright/16) ); 87 brightness->setTickInterval( QMAX(1,maxbright/16) );
108 brightness->setLineStep( QMAX(1,maxbright/16) ); 88 brightness->setLineStep( QMAX(1,maxbright/16) );
109 brightness->setPageStep( QMAX(1,maxbright/16) ); 89 brightness->setPageStep( QMAX(1,maxbright/16) );
110 brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); 90 brightness->setValue( (maxbright*255 - initbright*maxbright)/255 );
111 91
112 // light sensor 92 // light sensor
113 auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 93 auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 );
114 94
115 95
116 96
117 config.setGroup( "AC" ); 97 config.setGroup( "AC" );
118 // ac spinboxes 98 // ac spinboxes
119 interval = config.readNumEntry( "Interval_Dim", 20 ); 99 interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 ));
120 if ( config.readNumEntry("Dim",1) == 0 ) { 100 interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 ));
121 interval_dim_ac_3->setValue( 0 ); 101 interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 ));
122 } else {
123 interval_dim_ac_3->setValue( interval );
124 }
125
126 interval = config.readNumEntry( "Interval_LightOff", 30 );
127 if ( config.readNumEntry("LightOff",1) == 0 ) {
128 interval_lightoff_ac_3->setValue( 0 );
129 } else {
130 interval_lightoff_ac_3->setValue( interval );
131 }
132
133 interval = config.readNumEntry( "Interval", 60 );
134 if ( interval > 3600 ) {
135 interval /= 1000; // compatibility (was millisecs)
136 }
137 if ( config.readNumEntry("NoApm", 1) == 1 ) {
138 interval_suspend_ac_3->setValue( 0 );
139 } else {
140 interval_suspend_ac_3->setValue( interval );
141 }
142 102
143 // ac check and slider 103 // ac check and slider
144 LcdOffOnly_2_3->setChecked( config.readNumEntry("LcdOffOnly",0) != 0 ); 104 LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false));
145 int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( ); 105 int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( );
146 initbright_ac = config.readNumEntry("Brightness",255); 106 initbright_ac = config.readNumEntry("Brightness",255);
147 brightness_ac_3->setMaxValue( maxbright_ac ); 107 brightness_ac_3->setMaxValue( maxbright_ac );
148 brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) ); 108 brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) );
149 brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) ); 109 brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) );
150 brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) ); 110 brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) );
151 brightness_ac_3->setValue( (maxbright_ac*255 - initbright_ac*maxbright_ac)/255 ); 111 brightness_ac_3->setValue( (maxbright_ac*255 - initbright_ac*maxbright_ac)/255 );
152 112
153 // light sensor 113 // light sensor
154 auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 114 auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 );
155 115
156 116
157 //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); 117 //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) );
158 //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); 118 //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) );
159 //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; 119 //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ;
160 //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); 120 //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) );
161 121
162 // advanced settings 122 // advanced settings
163 config.setGroup( "Warnings" ); 123 config.setGroup( "Warnings" );
164 warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 ); 124 warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 );
165 lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); 125 lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) );
166 criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); 126 criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) );
167 127
168 connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) ); 128 connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) );
169 connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) ); 129 connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) );
170} 130}
171 131
172LightSettings::~LightSettings() { 132LightSettings::~LightSettings() {
173} 133}
174 134
175void LightSettings::slotSliderTicks( int steps ) { 135void LightSettings::slotSliderTicks( int steps ) {
176// LightMinValueSlider->setTickInterval( steps ); 136// LightMinValueSlider->setTickInterval( steps );
177} 137}
178 138
179static void set_fl(int bright) 139static void set_fl(int bright)
180{ 140{
181 qDebug ( QString( "Brightness" ).arg( bright ) ); 141 qDebug ( QString( "Brightness" ).arg( bright ) );
182 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 142 QCopEnvelope e("QPE/System", "setBacklight(int)" );
183 e << bright; 143 e << bright;
184} 144}
185 145
186void LightSettings::reject() 146void LightSettings::reject()
187{ 147{
188 set_fl(initbright); 148 set_fl(initbright);
189 QDialog::reject(); 149 QDialog::reject();
190} 150}
191 151
192void LightSettings::accept() 152void LightSettings::accept()
193{ 153{
194 if ( qApp->focusWidget() ) { 154 if ( qApp->focusWidget() ) {
195 qApp->focusWidget()->clearFocus(); 155 qApp->focusWidget()->clearFocus();
196 } 156 }
197 157
198 applyBrightness(); 158 applyBrightness();
199 159
200 // bat 160 // bat
201 int i_dim = ( !( interval_dim->specialValueText() == tr("never") ) ? interval_dim->value() : 0); 161 int i_dim = interval_dim->value();
202 int i_lightoff = ( !( interval_lightoff->specialValueText() == tr("never") ) ? interval_lightoff->value() : 0); 162 int i_lightoff = interval_lightoff->value();
203 int i_suspend = interval_suspend->value(); 163 int i_suspend = interval_suspend->value();
204 QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" ); 164 QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" );
205 e << i_dim << i_lightoff << i_suspend; 165 e << i_dim << i_lightoff << i_suspend;
206 166
207 // ac 167 // ac
208 int i_dim_ac = ( !( interval_dim_ac_3->specialValueText() == tr("never") ) ? interval_dim_ac_3->value() : 0); 168 int i_dim_ac = interval_dim_ac_3->value();
209 int i_lightoff_ac = ( !( interval_lightoff_ac_3->specialValueText() == tr("never") ) ? interval_lightoff_ac_3->value() : 0); 169 int i_lightoff_ac = interval_lightoff_ac_3->value();
210 int i_suspend_ac = interval_suspend_ac_3->value(); 170 int i_suspend_ac = interval_suspend_ac_3->value();
211 QCopEnvelope e_ac("QPE/System", "setScreenSaverIntervalsAC(int,int,int)" ); 171 QCopEnvelope e_ac("QPE/System", "setScreenSaverIntervalsAC(int,int,int)" );
212 e << i_dim_ac << i_lightoff_ac << i_suspend_ac; 172 e << i_dim_ac << i_lightoff_ac << i_suspend_ac;
213 173
214 Config config( "apm" ); 174 Config config( "apm" );
215 175
216 config.setGroup( "Battery" ); 176 config.setGroup( "Battery" );
217 177
218 // bat 178 // bat
219 config.writeEntry( "Dim", interval_dim->specialValueText() == tr("never") ); 179 config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() );
220 config.writeEntry( "LightOff", interval_lightoff->specialValueText() == tr("never") ); 180 config.writeEntry( "Dim", interval_dim->value() );
221 config.writeEntry( "LcdOffOnly", (int)LcdOffOnly->isChecked() ); 181 config.writeEntry( "LightOff", interval_lightoff->value() );
222 config.writeEntry( "NoAPm", interval_suspend->specialValueText() == tr("never") ); 182 config.writeEntry( "Suspend", interval_suspend->value() );
223 config.writeEntry( "Interval_Dim", interval_dim->value() );
224 config.writeEntry( "Interval_LightOff", interval_lightoff->value() );
225 config.writeEntry( "Interval", interval_suspend->value() );
226 config.writeEntry( "Brightness", 183 config.writeEntry( "Brightness",
227 ( brightness->value() ) * 255 / brightness->maxValue() ); 184 ( brightness->value() ) * 255 / brightness->maxValue() );
228 185
229 // ac 186 // ac
230 config.setGroup( "AC" ); 187 config.setGroup( "AC" );
231 config.writeEntry( "Dim", interval_dim_ac_3->specialValueText() == tr("never") ); 188 config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() );
232 config.writeEntry( "LightOff", interval_lightoff_ac_3->specialValueText() == tr("never") ); 189 config.writeEntry( "Dim", interval_dim_ac_3->value() );
233 config.writeEntry( "LcdOffOnly", (int)LcdOffOnly_2_3->isChecked() ); 190 config.writeEntry( "LightOff", interval_lightoff_ac_3->value() );
234 config.writeEntry( "NoAPm", interval_suspend_ac_3->specialValueText() == tr("never") ); 191 config.writeEntry( "Suspend", interval_suspend_ac_3->value() );
235 config.writeEntry( "Interval_Dim", interval_dim_ac_3->value() );
236 config.writeEntry( "Interval_LightOff", interval_lightoff_ac_3->value() );
237 config.writeEntry( "Interval", interval_suspend_ac_3->value() );
238 config.writeEntry( "Brightness", 192 config.writeEntry( "Brightness",
239 ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() ); 193 ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() );
240 194
241 195
242 // only make light sensor stuff appear if the unit has a sensor 196 // only make light sensor stuff appear if the unit has a sensor
243 if ( ODevice::inst()->hasLightSensor() ) { 197 if ( ODevice::inst()->hasLightSensor() ) {
244 config.setGroup( "lightsensor" ); 198 config.setGroup( "lightsensor" );
245 config.setGroup( "Battery" ); 199 config.setGroup( "Battery" );
246 config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() ); 200 config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() );
247 config.setGroup( "AC" ); 201 config.setGroup( "AC" );
248 config.writeEntry( "LightSensor", (int)auto_brightness_ac_3->isChecked() ); 202 config.writeEntry( "LightSensor", (int)auto_brightness_ac_3->isChecked() );
249 //config.writeEntry( "Steps", LightStepSpin->value() ); 203 //config.writeEntry( "Steps", LightStepSpin->value() );
250 //onfig.writeEntry( "MinValue", LightMinValueSlider->value() ); 204 //onfig.writeEntry( "MinValue", LightMinValueSlider->value() );
251 //config.writeEntry( "Shift", LightShiftSpin->value() ); 205 //config.writeEntry( "Shift", LightShiftSpin->value() );
252 } 206 }
253 207
254 208
255 // advanced 209 // advanced
256 config.setGroup( "Warnings" ); 210 config.setGroup( "Warnings" );
257 config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); 211 config.writeEntry( "check_interval", warnintervalBox->value()*1000 );
258 config.writeEntry( "power_verylow", lowSpinBox->value() ); 212 config.writeEntry( "power_verylow", lowSpinBox->value() );
259 config.writeEntry( "power_critical", criticalSpinBox->value() ); 213 config.writeEntry( "power_critical", criticalSpinBox->value() );
260 QCopEnvelope e_warn("QPE/System", "reloadPowerWarnSettings()"); 214 QCopEnvelope e_warn("QPE/System", "reloadPowerWarnSettings()");
261 215
262 config.write(); 216 config.write();
263 217
264 QDialog::accept(); 218 QDialog::accept();
265} 219}
266 220
267void LightSettings::applyBrightness() 221void LightSettings::applyBrightness()
268{ 222{
269 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 223 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
270 int bright = ( brightness->value() ) * 255 / brightness->maxValue(); 224 int bright = ( brightness->value() ) * 255 / brightness->maxValue();
271 set_fl(bright); 225 set_fl(bright);
272 } 226 }
273} 227}
274 228
275void LightSettings::applyBrightnessAC() 229void LightSettings::applyBrightnessAC()
276{ 230{
277 // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting 231 // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting
278 if ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ) { 232 if ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ) {
279 int bright = ( brightness_ac_3->value() ) * 255 / brightness_ac_3->maxValue(); 233 int bright = ( brightness_ac_3->value() ) * 255 / brightness_ac_3->maxValue();
280 set_fl(bright); 234 set_fl(bright);
281 } 235 }
282} 236}
283 237
284void LightSettings::done(int r) 238void LightSettings::done(int r)
285{ 239{
286 QDialog::done(r); 240 QDialog::done(r);
287 close(); 241 close();
288} 242}