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.cpp | 128 |
1 files changed, 122 insertions, 6 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp index ded358c..8721a95 100644 --- a/core/settings/light-and-power/light.cpp +++ b/core/settings/light-and-power/light.cpp | |||
@@ -14,19 +14,23 @@ | |||
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 | |||
21 | // redone by Maximilian Reiss <harlekin@handhelds.org> | ||
22 | |||
20 | #include "settings.h" | 23 | #include "settings.h" |
21 | 24 | ||
22 | #include <qpe/global.h> | 25 | #include <qpe/global.h> |
23 | #include <qpe/fontmanager.h> | 26 | #include <qpe/fontmanager.h> |
24 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
25 | #include <qpe/applnk.h> | 28 | #include <qpe/applnk.h> |
26 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/power.h> | ||
27 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 31 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
28 | #include <qpe/qcopenvelope_qws.h> | 32 | #include <qpe/qcopenvelope_qws.h> |
29 | #endif | 33 | #endif |
30 | 34 | ||
31 | #include <qlabel.h> | 35 | #include <qlabel.h> |
32 | #include <qcheckbox.h> | 36 | #include <qcheckbox.h> |
@@ -35,12 +39,13 @@ | |||
35 | #include <qslider.h> | 39 | #include <qslider.h> |
36 | #include <qfile.h> | 40 | #include <qfile.h> |
37 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
38 | #include <qdatastream.h> | 42 | #include <qdatastream.h> |
39 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
40 | #include <qcombobox.h> | 44 | #include <qcombobox.h> |
45 | #include <qgroupbox.h> | ||
41 | #include <qspinbox.h> | 46 | #include <qspinbox.h> |
42 | #include <qlistbox.h> | 47 | #include <qlistbox.h> |
43 | #include <qdir.h> | 48 | #include <qdir.h> |
44 | #if QT_VERSION >= 300 | 49 | #if QT_VERSION >= 300 |
45 | #include <qstylefactory.h> | 50 | #include <qstylefactory.h> |
46 | #endif | 51 | #endif |
@@ -49,46 +54,106 @@ | |||
49 | 54 | ||
50 | using namespace Opie; | 55 | using namespace Opie; |
51 | 56 | ||
52 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags fl ) | 57 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags fl ) |
53 | : LightSettingsBase( parent, name, TRUE, fl ) | 58 | : LightSettingsBase( parent, name, TRUE, fl ) |
54 | { | 59 | { |
55 | // Not supported | 60 | |
56 | auto_brightness->hide(); | 61 | if ( ODevice::inst()->model() == Model_iPAQ_H31xx || |
62 | ODevice::inst()->model() == Model_iPAQ_H36xx || | ||
63 | ODevice::inst()->model() == Model_iPAQ_H37xx || | ||
64 | ODevice::inst()->model() == Model_iPAQ_H38xx ) { | ||
65 | // Not supported yet - hide until implemented | ||
66 | IpaqGroupBox->setEnabled( false ); | ||
67 | IpaqGroupBoxAC->setEnabled( false ); | ||
68 | LightSensorGroupBox->setEnabled( false ); | ||
69 | } else { | ||
70 | // if ipaq no need to show the sensor box | ||
71 | IpaqGroupBox->hide(); | ||
72 | IpaqGroupBoxAC->hide(); | ||
73 | LightSensorGroupBox->hide(); | ||
74 | } | ||
57 | 75 | ||
58 | Config config( "qpe" ); | 76 | Config config( "qpe" ); |
59 | 77 | ||
60 | config.setGroup( "Screensaver" ); | 78 | config.setGroup( "Screensaver" ); |
61 | 79 | ||
62 | int interval; | 80 | int interval; |
81 | |||
82 | // battery spinboxes | ||
63 | interval = config.readNumEntry( "Interval_Dim", 20 ); | 83 | interval = config.readNumEntry( "Interval_Dim", 20 ); |
64 | interval_dim->setValue( interval ); | 84 | interval_dim->setValue( interval ); |
65 | interval = config.readNumEntry( "Interval_LightOff", 30 ); | 85 | interval = config.readNumEntry( "Interval_LightOff", 30 ); |
66 | interval_lightoff->setValue( interval ); | 86 | interval_lightoff->setValue( interval ); |
67 | interval = config.readNumEntry( "Interval", 60 ); | 87 | interval = config.readNumEntry( "Interval", 60 ); |
68 | if ( interval > 3600 ) interval /= 1000; // compatibility (was millisecs) | 88 | if ( interval > 3600 ) interval /= 1000; // compatibility (was millisecs) |
69 | interval_suspend->setValue( interval ); | 89 | interval_suspend->setValue( interval ); |
70 | 90 | ||
91 | // ac spinboxes | ||
92 | interval = config.readNumEntry( "Interval_DimAC", 20 ); | ||
93 | interval_dim_ac_3->setValue( interval ); | ||
94 | interval = config.readNumEntry( "Interval_LightOffAC", 30 ); | ||
95 | interval_lightoff_ac_3->setValue( interval ); | ||
96 | interval = config.readNumEntry( "IntervalAC", 60 ); | ||
97 | if ( interval > 3600 ) { | ||
98 | interval /= 1000; // compatibility (was millisecs) | ||
99 | } | ||
100 | interval_suspend_ac_3->setValue( interval ); | ||
101 | |||
102 | |||
103 | // battery check and slider | ||
71 | screensaver_dim->setChecked( config.readNumEntry("Dim",1) != 0 ); | 104 | screensaver_dim->setChecked( config.readNumEntry("Dim",1) != 0 ); |
72 | screensaver_lightoff->setChecked( config.readNumEntry("LightOff",1) != 0 ); | 105 | screensaver_lightoff->setChecked( config.readNumEntry("LightOff",1) != 0 ); |
73 | LcdOffOnly->setChecked( config.readNumEntry("LcdOffOnly",0) != 0 ); | 106 | LcdOffOnly->setChecked( config.readNumEntry("LcdOffOnly",0) != 0 ); |
74 | int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( ); | 107 | int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( ); |
75 | initbright = config.readNumEntry("Brightness",255); | 108 | initbright = config.readNumEntry("Brightness",255); |
76 | brightness->setMaxValue( maxbright ); | 109 | brightness->setMaxValue( maxbright ); |
77 | brightness->setTickInterval( QMAX(1,maxbright/16) ); | 110 | brightness->setTickInterval( QMAX(1,maxbright/16) ); |
78 | brightness->setLineStep( QMAX(1,maxbright/16) ); | 111 | brightness->setLineStep( QMAX(1,maxbright/16) ); |
79 | brightness->setPageStep( QMAX(1,maxbright/16) ); | 112 | brightness->setPageStep( QMAX(1,maxbright/16) ); |
80 | brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); | 113 | brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); |
81 | 114 | ||
115 | // ac check and slider | ||
116 | screensaver_dim_ac_3->setChecked( config.readNumEntry("DimAC",1) != 0 ); | ||
117 | screensaver_lightoff_ac_3->setChecked( config.readNumEntry("LightOffAC",1) != 0 ); | ||
118 | LcdOffOnly_2_3->setChecked( config.readNumEntry("LcdOffOnlyAC",0) != 0 ); | ||
119 | int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( ); | ||
120 | initbright_ac = config.readNumEntry("BrightnessAC",255); | ||
121 | brightness_ac_3->setMaxValue( maxbright_ac ); | ||
122 | brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) ); | ||
123 | brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) ); | ||
124 | brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) ); | ||
125 | brightness_ac_3->setValue( (maxbright_ac*255 - initbright_ac*maxbright_ac)/255 ); | ||
126 | |||
127 | // advanced settings | ||
128 | config.setGroup( "APM" ); | ||
129 | warnintervalBox->setValue( config.readNumEntry("check_interval", 10000)/1000 ); | ||
130 | lowSpinBox->setValue( config.readNumEntry("power_verylow", 10 ) ); | ||
131 | criticalSpinBox->setValue( config.readNumEntry("power_critical", 5 ) ); | ||
132 | |||
133 | // ipaq sensor | ||
134 | config.setGroup( "Ipaq_light_sensor" ); | ||
135 | auto_brightness->setChecked( config.readNumEntry("LightSensor",1) != 0 ); | ||
136 | auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensorAC",1) != 0 ); | ||
137 | LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); | ||
138 | LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); | ||
139 | connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; | ||
140 | LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); | ||
141 | |||
82 | connect(brightness, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness())); | 142 | connect(brightness, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness())); |
143 | connect(brightness_ac_3, SIGNAL(valueChanged(int)), this, SLOT(applyBrightness())); | ||
83 | } | 144 | } |
84 | 145 | ||
85 | LightSettings::~LightSettings() | 146 | LightSettings::~LightSettings() |
86 | { | 147 | { |
87 | } | 148 | } |
88 | 149 | ||
150 | void LightSettings::slotSliderTicks( int steps ) { | ||
151 | LightMinValueSlider->setTickInterval( steps ); | ||
152 | } | ||
153 | |||
89 | static void set_fl(int bright) | 154 | static void set_fl(int bright) |
90 | { | 155 | { |
91 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | 156 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); |
92 | e << bright; | 157 | e << bright; |
93 | } | 158 | } |
94 | 159 | ||
@@ -99,44 +164,95 @@ void LightSettings::reject() | |||
99 | QDialog::reject(); | 164 | QDialog::reject(); |
100 | } | 165 | } |
101 | 166 | ||
102 | void LightSettings::accept() | 167 | void LightSettings::accept() |
103 | { | 168 | { |
104 | if ( qApp->focusWidget() ) | 169 | if ( qApp->focusWidget() ) |
105 | qApp->focusWidget()->clearFocus(); | 170 | qApp->focusWidget()->clearFocus(); |
106 | 171 | ||
107 | applyBrightness(); | 172 | applyBrightness(); |
108 | 173 | ||
174 | // bat | ||
109 | int i_dim = (screensaver_dim->isChecked() ? interval_dim->value() : 0); | 175 | int i_dim = (screensaver_dim->isChecked() ? interval_dim->value() : 0); |
110 | int i_lightoff = (screensaver_lightoff->isChecked() ? interval_lightoff->value() : 0); | 176 | int i_lightoff = (screensaver_lightoff->isChecked() ? interval_lightoff->value() : 0); |
111 | int i_suspend = interval_suspend->value(); | 177 | int i_suspend = interval_suspend->value(); |
112 | QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 178 | QCopEnvelope e("QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
113 | e << i_dim << i_lightoff << i_suspend; | 179 | e << i_dim << i_lightoff << i_suspend; |
114 | 180 | ||
181 | // ac | ||
182 | int i_dim_ac = (screensaver_dim_ac_3->isChecked() ? interval_dim_ac_3->value() : 0); | ||
183 | int i_lightoff_ac = (screensaver_lightoff_ac_3->isChecked() ? interval_lightoff_ac_3->value() : 0); | ||
184 | int i_suspend_ac = interval_suspend_ac_3->value(); | ||
185 | QCopEnvelope e_ac("QPE/System", "setScreenSaverIntervalsAC(int,int,int)" ); | ||
186 | e << i_dim_ac << i_lightoff_ac << i_suspend_ac; | ||
187 | |||
115 | Config config( "qpe" ); | 188 | Config config( "qpe" ); |
116 | config.setGroup( "Screensaver" ); | 189 | config.setGroup( "Screensaver" ); |
190 | |||
191 | // bat | ||
117 | config.writeEntry( "Dim", (int)screensaver_dim->isChecked() ); | 192 | config.writeEntry( "Dim", (int)screensaver_dim->isChecked() ); |
118 | config.writeEntry( "LightOff", (int)screensaver_lightoff->isChecked() ); | 193 | config.writeEntry( "LightOff", (int)screensaver_lightoff->isChecked() ); |
119 | config.writeEntry( "LcdOffOnly", (int)LcdOffOnly->isChecked() ); | 194 | config.writeEntry( "LcdOffOnly", (int)LcdOffOnly->isChecked() ); |
120 | config.writeEntry( "Interval_Dim", interval_dim->value() ); | 195 | config.writeEntry( "Interval_Dim", interval_dim->value() ); |
121 | config.writeEntry( "Interval_LightOff", interval_lightoff->value() ); | 196 | config.writeEntry( "Interval_LightOff", interval_lightoff->value() ); |
122 | config.writeEntry( "Interval", interval_suspend->value() ); | 197 | config.writeEntry( "Interval", interval_suspend->value() ); |
123 | config.writeEntry( "Brightness", | 198 | config.writeEntry( "Brightness", |
124 | (brightness->maxValue()-brightness->value())*255/brightness->maxValue() ); | 199 | (brightness->maxValue()-brightness->value())*255/brightness->maxValue() ); |
200 | |||
201 | // ac | ||
202 | config.writeEntry( "DimAC", (int)screensaver_dim_ac_3->isChecked() ); | ||
203 | config.writeEntry( "LightOffAC", (int)screensaver_lightoff_ac_3->isChecked() ); | ||
204 | config.writeEntry( "LcdOffOnlyAC", (int)LcdOffOnly_2_3->isChecked() ); | ||
205 | config.writeEntry( "Interval_DimAC", interval_dim_ac_3->value() ); | ||
206 | config.writeEntry( "Interval_LightOffAC", interval_lightoff_ac_3->value() ); | ||
207 | config.writeEntry( "IntervalAC", interval_suspend_ac_3->value() ); | ||
208 | config.writeEntry( "BrightnessAC", | ||
209 | (brightness_ac_3->maxValue() - brightness_ac_3->value())*255/brightness_ac_3->maxValue() ); | ||
210 | |||
211 | // advanced | ||
212 | config.setGroup( "APM" ); | ||
213 | config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); | ||
214 | config.writeEntry( "power_verylow", lowSpinBox->value() ); | ||
215 | config.writeEntry( "power_critical", criticalSpinBox->value() ); | ||
216 | QCopEnvelope e_warn("QPE/System", "reloadPowerWarnSettings()"); | ||
217 | |||
218 | |||
219 | // only make ipaq light sensor entries in config file if on an ipaq | ||
220 | if ( ODevice::inst()->model() == Model_iPAQ_H31xx || | ||
221 | ODevice::inst()->model() == Model_iPAQ_H36xx || | ||
222 | ODevice::inst()->model() == Model_iPAQ_H37xx || | ||
223 | ODevice::inst()->model() == Model_iPAQ_H38xx ) { | ||
224 | |||
225 | // ipaq sensor | ||
226 | config.setGroup( "Ipaq_light_sensor" ); | ||
227 | |||
228 | config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() ); | ||
229 | config.writeEntry( "LightSensorAC", (int)auto_brightness_ac_3->isChecked() ); | ||
230 | config.writeEntry( "Steps", LightStepSpin->value() ); | ||
231 | config.writeEntry( "MinValue", LightMinValueSlider->value() ); | ||
232 | config.writeEntry( "Shift", LightShiftSpin->value() ); | ||
233 | } | ||
234 | |||
125 | config.write(); | 235 | config.write(); |
126 | 236 | ||
127 | QDialog::accept(); | 237 | QDialog::accept(); |
128 | } | 238 | } |
129 | 239 | ||
130 | void LightSettings::applyBrightness() | 240 | void LightSettings::applyBrightness() |
131 | { | 241 | { |
132 | int bright = (brightness->maxValue()-brightness->value())*255 | 242 | // if ac is attached, set directly that sliders setting, else the "on battery" sliders setting |
133 | / brightness->maxValue(); | 243 | if ( PowerStatus::Online ) { |
134 | set_fl(bright); | 244 | int bright = (brightness_ac_3->maxValue() - brightness_ac_3->value())*255 / brightness_ac_3->maxValue(); |
245 | set_fl(bright); | ||
246 | } else { | ||
247 | int bright = (brightness->maxValue()-brightness->value())*255 / brightness->maxValue(); | ||
248 | set_fl(bright); | ||
249 | } | ||
135 | } | 250 | } |
136 | 251 | ||
137 | 252 | ||
253 | |||
138 | void LightSettings::done(int r) | 254 | void LightSettings::done(int r) |
139 | { | 255 | { |
140 | QDialog::done(r); | 256 | QDialog::done(r); |
141 | close ( ); | 257 | close ( ); |
142 | } | 258 | } |