Diffstat (limited to 'core/settings/light-and-power/light.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/settings/light-and-power/light.cpp | 194 |
1 files changed, 88 insertions, 106 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,19 +59,16 @@ | |||
53 | 59 | ||
54 | #include <opie/odevice.h> | 60 | #include <opie/odevice.h> |
55 | 61 | ||
62 | #include "sensor.h" | ||
63 | |||
56 | using namespace Opie; | 64 | using namespace Opie; |
57 | 65 | ||
58 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) | 66 | LightSettings::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 | ||
65 | CalibrateLightSensor->setEnabled( false ); | ||
66 | CalibrateLightSensorAC->setEnabled( false ); | ||
67 | } else { | ||
68 | // if ipaq no need to show the sensor box | ||
69 | auto_brightness->hide(); | 72 | auto_brightness->hide(); |
70 | CalibrateLightSensor->hide(); | 73 | CalibrateLightSensor->hide(); |
71 | auto_brightness_ac_3->hide(); | 74 | auto_brightness_ac_3->hide(); |
@@ -83,17 +86,19 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) | |||
83 | // battery check and slider | 86 | // battery check and slider |
84 | LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); | 87 | LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); |
85 | 88 | ||
86 | initbright = config. readNumEntry ( "Brightness", 255 ); | 89 | int bright = config. readNumEntry ( "Brightness", 255 ); |
87 | brightness-> setMaxValue ( res - 1 ); | 90 | brightness-> setMaxValue ( m_res - 1 ); |
88 | brightness-> setTickInterval ( QMAX( 1, res / 16 )); | 91 | brightness-> setTickInterval ( QMAX( 1, m_res / 16 )); |
89 | brightness-> setLineStep ( QMAX( 1, res / 16 )); | 92 | brightness-> setLineStep ( QMAX( 1, m_res / 16 )); |
90 | brightness-> setPageStep ( QMAX( 1, res / 16 )); | 93 | brightness-> setPageStep ( QMAX( 1, m_res / 16 )); |
91 | brightness-> setValue (( initbright * ( res - 1 ) + 127 ) / 255 ); | 94 | brightness-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); |
92 | 95 | ||
93 | // light sensor | 96 | // light sensor |
94 | auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); | 97 | auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false )); |
98 | m_sensordata = config. readListEntry ( "LightSensorData", ';' ); | ||
95 | 99 | ||
96 | config.setGroup( "AC" ); | 100 | config.setGroup( "AC" ); |
101 | |||
97 | // ac spinboxes | 102 | // ac spinboxes |
98 | interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); | 103 | interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); |
99 | interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); | 104 | interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); |
@@ -102,21 +107,16 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) | |||
102 | // ac check and slider | 107 | // ac check and slider |
103 | LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); | 108 | LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); |
104 | 109 | ||
105 | initbright_ac = config. readNumEntry ( "Brightness", 255 ); | 110 | bright = config. readNumEntry ( "Brightness", 255 ); |
106 | brightness_ac_3-> setMaxValue ( res - 1 ); | 111 | brightness_ac_3-> setMaxValue ( m_res - 1 ); |
107 | brightness_ac_3-> setTickInterval ( QMAX( 1, res / 16 )); | 112 | brightness_ac_3-> setTickInterval ( QMAX( 1, m_res / 16 )); |
108 | brightness_ac_3-> setLineStep ( QMAX( 1, res / 16 )); | 113 | brightness_ac_3-> setLineStep ( QMAX( 1, m_res / 16 )); |
109 | brightness_ac_3-> setPageStep ( QMAX( 1, res / 16 )); | 114 | brightness_ac_3-> setPageStep ( QMAX( 1, m_res / 16 )); |
110 | brightness_ac_3-> setValue (( initbright_ac * ( res - 1 ) + 127 ) / 255 ); | 115 | brightness_ac_3-> setValue (( bright * ( m_res - 1 ) + 127 ) / 255 ); |
111 | 116 | ||
112 | // light sensor | 117 | // light sensor |
113 | auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); | 118 | auto_brightness_ac_3-> setChecked ( config. readBoolEntry ( "LightSensor", false )); |
114 | 119 | m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' ); | |
115 | |||
116 | //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); | ||
117 | //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); | ||
118 | //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; | ||
119 | //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); | ||
120 | 120 | ||
121 | // advanced settings | 121 | // advanced settings |
122 | config.setGroup( "Warnings" ); | 122 | config.setGroup( "Warnings" ); |
@@ -124,81 +124,79 @@ LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) | |||
124 | lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); | 124 | lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); |
125 | criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); | 125 | criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); |
126 | 126 | ||
127 | connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) ); | 127 | if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) |
128 | connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) ); | 128 | connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); |
129 | else | ||
130 | connect ( brightness_ac_3, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int ))); | ||
129 | } | 131 | } |
130 | 132 | ||
131 | LightSettings::~LightSettings() { | 133 | LightSettings::~LightSettings ( ) |
134 | { | ||
135 | } | ||
136 | |||
137 | |||
138 | void LightSettings::calibrateSensor ( ) | ||
139 | { | ||
140 | Sensor *s = new Sensor ( m_sensordata, this ); | ||
141 | s-> showMaximized ( ); | ||
142 | s-> exec ( ); | ||
143 | delete s; | ||
132 | } | 144 | } |
133 | 145 | ||
134 | void LightSettings::slotSliderTicks( int steps ) { | 146 | void LightSettings::calibrateSensorAC ( ) |
135 | // LightMinValueSlider->setTickInterval( steps ); | 147 | { |
148 | Sensor *s = new Sensor ( m_sensordata_ac, this ); | ||
149 | s-> showMaximized ( ); | ||
150 | s-> exec ( ); | ||
151 | delete s; | ||
136 | } | 152 | } |
137 | 153 | ||
138 | static void set_fl(int bright) | 154 | void LightSettings::setBacklight ( int bright ) |
139 | { | 155 | { |
156 | bright = bright * 255 / ( m_res - 1 ); | ||
140 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | 157 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); |
141 | e << bright; | 158 | e << bright; |
142 | } | 159 | } |
143 | 160 | ||
144 | void LightSettings::reject() | 161 | void LightSettings::reject() |
145 | { | 162 | { |
146 | set_fl(initbright); | 163 | { |
164 | QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); | ||
165 | e << -1; | ||
166 | } | ||
147 | QDialog::reject(); | 167 | QDialog::reject(); |
148 | } | 168 | } |
149 | 169 | ||
150 | void LightSettings::accept() | 170 | void LightSettings::accept() |
151 | { | 171 | { |
152 | if ( qApp->focusWidget() ) { | ||
153 | qApp->focusWidget()->clearFocus(); | ||
154 | } | ||
155 | |||
156 | applyBrightness(); | ||
157 | |||
158 | // bat | ||
159 | int i_dim = interval_dim->value(); | ||
160 | int i_lightoff = interval_lightoff->value(); | ||
161 | int i_suspend = interval_suspend->value(); | ||
162 | |||
163 | // ac | ||
164 | int i_dim_ac = interval_dim_ac_3->value(); | ||
165 | int i_lightoff_ac = interval_lightoff_ac_3->value(); | ||
166 | int i_suspend_ac = interval_suspend_ac_3->value(); | ||
167 | |||
168 | Config config( "apm" ); | 172 | Config config( "apm" ); |
169 | 173 | ||
170 | config.setGroup( "Battery" ); | ||
171 | |||
172 | // bat | 174 | // bat |
175 | config. setGroup ( "Battery" ); | ||
173 | config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); | 176 | config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); |
174 | config.writeEntry( "Dim", i_dim ); | 177 | config. writeEntry ( "Dim", interval_dim-> value ( )); |
175 | config.writeEntry( "LightOff", i_lightoff ); | 178 | config. writeEntry ( "LightOff", interval_lightoff-> value ( )); |
176 | config.writeEntry( "Suspend", i_suspend ); | 179 | config. writeEntry ( "Suspend", interval_suspend-> value ( )); |
177 | config.writeEntry( "Brightness", | 180 | config. writeEntry ( "Brightness", brightness-> value ( ) * 255 / ( m_res - 1 ) ); |
178 | ( brightness->value() ) * 255 / brightness->maxValue() ); | ||
179 | 181 | ||
180 | // ac | 182 | // ac |
181 | config.setGroup( "AC" ); | 183 | config.setGroup( "AC" ); |
182 | config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); | 184 | config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); |
183 | config.writeEntry( "Dim", i_dim_ac ); | 185 | config. writeEntry ( "Dim", interval_dim_ac_3-> value ( )); |
184 | config.writeEntry( "LightOff", i_lightoff_ac ); | 186 | config. writeEntry ( "LightOff", interval_lightoff_ac_3-> value ( )); |
185 | config.writeEntry( "Suspend", i_suspend_ac ); | 187 | config. writeEntry ( "Suspend", interval_suspend_ac_3-> value ( )); |
186 | config.writeEntry( "Brightness", | 188 | config. writeEntry ( "Brightness", brightness_ac_3-> value ( ) * 255 / ( m_res - 1 )); |
187 | ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() ); | ||
188 | |||
189 | 189 | ||
190 | // only make light sensor stuff appear if the unit has a sensor | 190 | // only make light sensor stuff appear if the unit has a sensor |
191 | if ( ODevice::inst()->hasLightSensor() ) { | 191 | if ( ODevice::inst()->hasLightSensor() ) { |
192 | config.setGroup( "Battery" ); | 192 | config.setGroup( "Battery" ); |
193 | config.writeEntry( "LightSensor", auto_brightness->isChecked() ); | 193 | config.writeEntry( "LightSensor", auto_brightness->isChecked() ); |
194 | config. writeEntry ( "LightSensorData", m_sensordata, ';' ); | ||
194 | config.setGroup( "AC" ); | 195 | config.setGroup( "AC" ); |
195 | config.writeEntry( "LightSensor", auto_brightness_ac_3->isChecked() ); | 196 | config.writeEntry( "LightSensor", auto_brightness_ac_3->isChecked() ); |
196 | //config.writeEntry( "Steps", LightStepSpin->value() ); | 197 | config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' ); |
197 | //onfig.writeEntry( "MinValue", LightMinValueSlider->value() ); | ||
198 | //config.writeEntry( "Shift", LightShiftSpin->value() ); | ||
199 | } | 198 | } |
200 | 199 | ||
201 | |||
202 | // advanced | 200 | // advanced |
203 | config.setGroup( "Warnings" ); | 201 | config.setGroup( "Warnings" ); |
204 | config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); | 202 | config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); |
@@ -206,6 +204,7 @@ void LightSettings::accept() | |||
206 | config.writeEntry( "power_critical", criticalSpinBox->value() ); | 204 | config.writeEntry( "power_critical", criticalSpinBox->value() ); |
207 | config.write(); | 205 | config.write(); |
208 | 206 | ||
207 | // notify the launcher | ||
209 | { | 208 | { |
210 | QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); | 209 | QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); |
211 | } | 210 | } |
@@ -221,23 +220,6 @@ void LightSettings::accept() | |||
221 | QDialog::accept(); | 220 | QDialog::accept(); |
222 | } | 221 | } |
223 | 222 | ||
224 | void 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 | |||
232 | void 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 | } | ||
240 | |||
241 | void LightSettings::done(int r) | 223 | void LightSettings::done(int r) |
242 | { | 224 | { |
243 | QDialog::done(r); | 225 | QDialog::done(r); |