summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/light-and-power/light.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp
index c021ad4..aa36e06 100644
--- a/core/settings/light-and-power/light.cpp
+++ b/core/settings/light-and-power/light.cpp
@@ -1,242 +1,247 @@
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 // battery spinboxes 77 // battery spinboxes
78 interval_dim->setValue( config.readNumEntry( "Dim", 20 )); 78 interval_dim->setValue( config.readNumEntry( "Dim", 20 ));
79 interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 )); 79 interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 ));
80 interval_suspend->setValue( config.readNumEntry( "Suspend", 60 )); 80 interval_suspend->setValue( config.readNumEntry( "Suspend", 60 ));
81 81
82 // battery check and slider 82 // battery check and slider
83 LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); 83 LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false));
84 int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( ); 84 int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( );
85 initbright = config.readNumEntry("Brightness",255); 85 initbright = config.readNumEntry("Brightness",255);
86 brightness->setMaxValue( maxbright ); 86 brightness->setMaxValue( maxbright );
87 brightness->setTickInterval( QMAX(1,maxbright/16) ); 87 brightness->setTickInterval( QMAX(1,maxbright/16) );
88 brightness->setLineStep( QMAX(1,maxbright/16) ); 88 brightness->setLineStep( QMAX(1,maxbright/16) );
89 brightness->setPageStep( QMAX(1,maxbright/16) ); 89 brightness->setPageStep( QMAX(1,maxbright/16) );
90 brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); 90 brightness->setValue( (maxbright*255 - initbright*maxbright)/255 );
91 91
92 // light sensor 92 // light sensor
93 auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 93 auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 );
94 94
95 95
96 96
97 config.setGroup( "AC" ); 97 config.setGroup( "AC" );
98 // ac spinboxes 98 // ac spinboxes
99 interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); 99 interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 ));
100 interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); 100 interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 ));
101 interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 )); 101 interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 ));
102 102
103 // ac check and slider 103 // ac check and slider
104 LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); 104 LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false));
105 int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( ); 105 int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( );
106 initbright_ac = config.readNumEntry("Brightness",255); 106 initbright_ac = config.readNumEntry("Brightness",255);
107 brightness_ac_3->setMaxValue( maxbright_ac ); 107 brightness_ac_3->setMaxValue( maxbright_ac );
108 brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) ); 108 brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) );
109 brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) ); 109 brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) );
110 brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) ); 110 brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) );
111 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 );
112 112
113 // light sensor 113 // light sensor
114 auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); 114 auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 );
115 115
116 116
117 //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); 117 //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) );
118 //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); 118 //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) );
119 //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; 119 //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ;
120 //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); 120 //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) );
121 121
122 // advanced settings 122 // advanced settings
123 config.setGroup( "Warnings" ); 123 config.setGroup( "Warnings" );
124 warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 ); 124 warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 );
125 lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); 125 lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) );
126 criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); 126 criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) );
127 127
128 connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) ); 128 connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) );
129 connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) ); 129 connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) );
130} 130}
131 131
132LightSettings::~LightSettings() { 132LightSettings::~LightSettings() {
133} 133}
134 134
135void LightSettings::slotSliderTicks( int steps ) { 135void LightSettings::slotSliderTicks( int steps ) {
136// LightMinValueSlider->setTickInterval( steps ); 136// LightMinValueSlider->setTickInterval( steps );
137} 137}
138 138
139static void set_fl(int bright) 139static void set_fl(int bright)
140{ 140{
141 qDebug ( QString( "Brightness" ).arg( bright ) ); 141 qDebug ( QString( "Brightness" ).arg( bright ) );
142 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 142 QCopEnvelope e("QPE/System", "setBacklight(int)" );
143 e << bright; 143 e << bright;
144} 144}
145 145
146void LightSettings::reject() 146void LightSettings::reject()
147{ 147{
148 set_fl(initbright); 148 set_fl(initbright);
149 QDialog::reject(); 149 QDialog::reject();
150} 150}
151 151
152void LightSettings::accept() 152void LightSettings::accept()
153{ 153{
154 if ( qApp->focusWidget() ) { 154 if ( qApp->focusWidget() ) {
155 qApp->focusWidget()->clearFocus(); 155 qApp->focusWidget()->clearFocus();
156 } 156 }
157 157
158 applyBrightness(); 158 applyBrightness();
159 159
160 // bat 160 // bat
161 int i_dim = interval_dim->value(); 161 int i_dim = interval_dim->value();
162 int i_lightoff = interval_lightoff->value(); 162 int i_lightoff = interval_lightoff->value();
163 int i_suspend = interval_suspend->value(); 163 int i_suspend = interval_suspend->value();
164 QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" );
165 e << i_dim << i_lightoff << i_suspend;
166 164
167 // ac 165 // ac
168 int i_dim_ac = interval_dim_ac_3->value(); 166 int i_dim_ac = interval_dim_ac_3->value();
169 int i_lightoff_ac = interval_lightoff_ac_3->value(); 167 int i_lightoff_ac = interval_lightoff_ac_3->value();
170 int i_suspend_ac = interval_suspend_ac_3->value(); 168 int i_suspend_ac = interval_suspend_ac_3->value();
171 QCopEnvelope e_ac("QPE/System", "setScreenSaverIntervalsAC(int,int,int)" );
172 e << i_dim_ac << i_lightoff_ac << i_suspend_ac;
173 169
174 Config config( "apm" ); 170 Config config( "apm" );
175 171
176 config.setGroup( "Battery" ); 172 config.setGroup( "Battery" );
177 173
178 // bat 174 // bat
179 config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); 175 config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() );
180 config.writeEntry( "Dim", interval_dim->value() ); 176 config.writeEntry( "Dim", i_dim );
181 config.writeEntry( "LightOff", interval_lightoff->value() ); 177 config.writeEntry( "LightOff", i_lightoff );
182 config.writeEntry( "Suspend", interval_suspend->value() ); 178 config.writeEntry( "Suspend", i_suspend );
183 config.writeEntry( "Brightness", 179 config.writeEntry( "Brightness",
184 ( brightness->value() ) * 255 / brightness->maxValue() ); 180 ( brightness->value() ) * 255 / brightness->maxValue() );
185 181
186 // ac 182 // ac
187 config.setGroup( "AC" ); 183 config.setGroup( "AC" );
188 config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); 184 config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() );
189 config.writeEntry( "Dim", interval_dim_ac_3->value() ); 185 config.writeEntry( "Dim", i_dim_ac );
190 config.writeEntry( "LightOff", interval_lightoff_ac_3->value() ); 186 config.writeEntry( "LightOff", i_lightoff_ac );
191 config.writeEntry( "Suspend", interval_suspend_ac_3->value() ); 187 config.writeEntry( "Suspend", i_suspend_ac );
192 config.writeEntry( "Brightness", 188 config.writeEntry( "Brightness",
193 ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() ); 189 ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() );
194 190
195 191
196 // only make light sensor stuff appear if the unit has a sensor 192 // only make light sensor stuff appear if the unit has a sensor
197 if ( ODevice::inst()->hasLightSensor() ) { 193 if ( ODevice::inst()->hasLightSensor() ) {
198 config.setGroup( "lightsensor" );
199 config.setGroup( "Battery" ); 194 config.setGroup( "Battery" );
200 config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() ); 195 config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() );
201 config.setGroup( "AC" ); 196 config.setGroup( "AC" );
202 config.writeEntry( "LightSensor", (int)auto_brightness_ac_3->isChecked() ); 197 config.writeEntry( "LightSensor", (int)auto_brightness_ac_3->isChecked() );
203 //config.writeEntry( "Steps", LightStepSpin->value() ); 198 //config.writeEntry( "Steps", LightStepSpin->value() );
204 //onfig.writeEntry( "MinValue", LightMinValueSlider->value() ); 199 //onfig.writeEntry( "MinValue", LightMinValueSlider->value() );
205 //config.writeEntry( "Shift", LightShiftSpin->value() ); 200 //config.writeEntry( "Shift", LightShiftSpin->value() );
206 } 201 }
207 202
208 203
209 // advanced 204 // advanced
210 config.setGroup( "Warnings" ); 205 config.setGroup( "Warnings" );
211 config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); 206 config.writeEntry( "check_interval", warnintervalBox->value()*1000 );
212 config.writeEntry( "power_verylow", lowSpinBox->value() ); 207 config.writeEntry( "power_verylow", lowSpinBox->value() );
213 config.writeEntry( "power_critical", criticalSpinBox->value() ); 208 config.writeEntry( "power_critical", criticalSpinBox->value() );
214 QCopEnvelope e_warn("QPE/System", "reloadPowerWarnSettings()");
215
216 config.write(); 209 config.write();
217 210
211 {
212 QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" );
213 }
214 {
215 QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" );
216 e << -1;
217 }
218 {
219 QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
220 e << -1;
221 }
222
218 QDialog::accept(); 223 QDialog::accept();
219} 224}
220 225
221void LightSettings::applyBrightness() 226void LightSettings::applyBrightness()
222{ 227{
223 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) { 228 if ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) {
224 int bright = ( brightness->value() ) * 255 / brightness->maxValue(); 229 int bright = ( brightness->value() ) * 255 / brightness->maxValue();
225 set_fl(bright); 230 set_fl(bright);
226 } 231 }
227} 232}
228 233
229void LightSettings::applyBrightnessAC() 234void LightSettings::applyBrightnessAC()
230{ 235{
231 // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting 236 // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting
232 if ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ) { 237 if ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ) {
233 int bright = ( brightness_ac_3->value() ) * 255 / brightness_ac_3->maxValue(); 238 int bright = ( brightness_ac_3->value() ) * 255 / brightness_ac_3->maxValue();
234 set_fl(bright); 239 set_fl(bright);
235 } 240 }
236} 241}
237 242
238void LightSettings::done(int r) 243void LightSettings::done(int r)
239{ 244{
240 QDialog::done(r); 245 QDialog::done(r);
241 close(); 246 close();
242} 247}