-rw-r--r-- | core/settings/light-and-power/light.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp index aa36e06..572f8ea 100644 --- a/core/settings/light-and-power/light.cpp +++ b/core/settings/light-and-power/light.cpp | |||
@@ -37,129 +37,127 @@ | |||
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 | ||
56 | using namespace Opie; | 56 | using namespace Opie; |
57 | 57 | ||
58 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) | 58 | LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) |
59 | : LightSettingsBase( parent, name, TRUE, WStyle_ContextHelp ) | 59 | : LightSettingsBase( parent, name, TRUE, WStyle_ContextHelp ) |
60 | { | 60 | { |
61 | int res = ODevice::inst ( )-> displayBrightnessResolution ( ); | ||
61 | 62 | ||
62 | if ( ODevice::inst()->hasLightSensor() ) { | 63 | if ( ODevice::inst()->hasLightSensor() ) { |
63 | // Not supported yet - hide until implemented | 64 | // Not supported yet - hide until implemented |
64 | CalibrateLightSensor->setEnabled( false ); | 65 | CalibrateLightSensor->setEnabled( false ); |
65 | CalibrateLightSensorAC->setEnabled( false ); | 66 | CalibrateLightSensorAC->setEnabled( false ); |
66 | } else { | 67 | } else { |
67 | // if ipaq no need to show the sensor box | 68 | // if ipaq no need to show the sensor box |
68 | auto_brightness->hide(); | 69 | auto_brightness->hide(); |
69 | CalibrateLightSensor->hide(); | 70 | CalibrateLightSensor->hide(); |
70 | auto_brightness_ac_3->hide(); | 71 | auto_brightness_ac_3->hide(); |
71 | CalibrateLightSensorAC->hide(); | 72 | CalibrateLightSensorAC->hide(); |
72 | } | 73 | } |
73 | 74 | ||
74 | Config config( "apm" ); | 75 | Config config( "apm" ); |
75 | config.setGroup( "Battery" ); | 76 | config.setGroup( "Battery" ); |
76 | 77 | ||
77 | // battery spinboxes | 78 | // battery spinboxes |
78 | interval_dim->setValue( config.readNumEntry( "Dim", 20 )); | 79 | interval_dim->setValue( config.readNumEntry( "Dim", 20 )); |
79 | interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 )); | 80 | interval_lightoff->setValue( config.readNumEntry( "LightOff", 30 )); |
80 | interval_suspend->setValue( config.readNumEntry( "Suspend", 60 )); | 81 | interval_suspend->setValue( config.readNumEntry( "Suspend", 60 )); |
81 | 82 | ||
82 | // battery check and slider | 83 | // battery check and slider |
83 | LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); | 84 | LcdOffOnly->setChecked( config.readBoolEntry("LcdOffOnly",false)); |
84 | int maxbright = ODevice::inst ( )-> displayBrightnessResolution ( ); | 85 | |
85 | initbright = config.readNumEntry("Brightness",255); | 86 | initbright = config. readNumEntry ( "Brightness", 255 ); |
86 | brightness->setMaxValue( maxbright ); | 87 | brightness-> setMaxValue ( res - 1 ); |
87 | brightness->setTickInterval( QMAX(1,maxbright/16) ); | 88 | brightness-> setTickInterval ( QMAX( 1, res / 16 )); |
88 | brightness->setLineStep( QMAX(1,maxbright/16) ); | 89 | brightness-> setLineStep ( QMAX( 1, res / 16 )); |
89 | brightness->setPageStep( QMAX(1,maxbright/16) ); | 90 | brightness-> setPageStep ( QMAX( 1, res / 16 )); |
90 | brightness->setValue( (maxbright*255 - initbright*maxbright)/255 ); | 91 | brightness-> setValue (( initbright * ( res - 1 ) + 127 ) / 255 ); |
91 | 92 | ||
92 | // light sensor | 93 | // light sensor |
93 | auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); | 94 | auto_brightness->setChecked( config.readNumEntry("LightSensor",0) != 0 ); |
94 | 95 | ||
95 | |||
96 | |||
97 | config.setGroup( "AC" ); | 96 | config.setGroup( "AC" ); |
98 | // ac spinboxes | 97 | // ac spinboxes |
99 | interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); | 98 | interval_dim_ac_3->setValue( config.readNumEntry( "Dim", 20 )); |
100 | interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); | 99 | interval_lightoff_ac_3->setValue( config.readNumEntry( "LightOff", 30 )); |
101 | interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 )); | 100 | interval_suspend_ac_3->setValue( config.readNumEntry( "Suspend", 60 )); |
102 | 101 | ||
103 | // ac check and slider | 102 | // ac check and slider |
104 | LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); | 103 | LcdOffOnly_2_3->setChecked( config.readBoolEntry("LcdOffOnly",false)); |
105 | int maxbright_ac = ODevice::inst ( )-> displayBrightnessResolution ( ); | 104 | |
106 | initbright_ac = config.readNumEntry("Brightness",255); | 105 | initbright_ac = config. readNumEntry ( "Brightness", 255 ); |
107 | brightness_ac_3->setMaxValue( maxbright_ac ); | 106 | brightness_ac_3-> setMaxValue ( res - 1 ); |
108 | brightness_ac_3->setTickInterval( QMAX(1,maxbright_ac/16) ); | 107 | brightness_ac_3-> setTickInterval ( QMAX( 1, res / 16 )); |
109 | brightness_ac_3->setLineStep( QMAX(1,maxbright_ac/16) ); | 108 | brightness_ac_3-> setLineStep ( QMAX( 1, res / 16 )); |
110 | brightness_ac_3->setPageStep( QMAX(1,maxbright_ac/16) ); | 109 | brightness_ac_3-> setPageStep ( QMAX( 1, res / 16 )); |
111 | brightness_ac_3->setValue( (maxbright_ac*255 - initbright_ac*maxbright_ac)/255 ); | 110 | brightness_ac_3-> setValue (( initbright_ac * ( res - 1 ) + 127 ) / 255 ); |
112 | 111 | ||
113 | // light sensor | 112 | // light sensor |
114 | auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); | 113 | auto_brightness_ac_3->setChecked( config.readNumEntry("LightSensor",0) != 0 ); |
115 | 114 | ||
116 | 115 | ||
117 | //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); | 116 | //LightStepSpin->setValue( config.readNumEntry("Steps", 10 ) ); |
118 | //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); | 117 | //LightMinValueSlider->setValue( config.readNumEntry("MinValue", 70 ) ); |
119 | //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; | 118 | //connect( LightStepSpin, SIGNAL( valueChanged( int ) ), this, SLOT( slotSliderTicks( int ) ) ) ; |
120 | //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); | 119 | //LightShiftSpin->setValue( config.readNumEntry("Shift", 0 ) ); |
121 | 120 | ||
122 | // advanced settings | 121 | // advanced settings |
123 | config.setGroup( "Warnings" ); | 122 | config.setGroup( "Warnings" ); |
124 | warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 ); | 123 | warnintervalBox->setValue( config.readNumEntry("checkinterval", 10000)/1000 ); |
125 | lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); | 124 | lowSpinBox->setValue( config.readNumEntry("powerverylow", 10 ) ); |
126 | criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); | 125 | criticalSpinBox->setValue( config.readNumEntry("powercritical", 5 ) ); |
127 | 126 | ||
128 | connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) ); | 127 | connect( brightness, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightness() ) ); |
129 | connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) ); | 128 | connect( brightness_ac_3, SIGNAL( valueChanged(int) ), this, SLOT( applyBrightnessAC() ) ); |
130 | } | 129 | } |
131 | 130 | ||
132 | LightSettings::~LightSettings() { | 131 | LightSettings::~LightSettings() { |
133 | } | 132 | } |
134 | 133 | ||
135 | void LightSettings::slotSliderTicks( int steps ) { | 134 | void LightSettings::slotSliderTicks( int steps ) { |
136 | // LightMinValueSlider->setTickInterval( steps ); | 135 | // LightMinValueSlider->setTickInterval( steps ); |
137 | } | 136 | } |
138 | 137 | ||
139 | static void set_fl(int bright) | 138 | static void set_fl(int bright) |
140 | { | 139 | { |
141 | qDebug ( QString( "Brightness" ).arg( bright ) ); | ||
142 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | 140 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); |
143 | e << bright; | 141 | e << bright; |
144 | } | 142 | } |
145 | 143 | ||
146 | void LightSettings::reject() | 144 | void LightSettings::reject() |
147 | { | 145 | { |
148 | set_fl(initbright); | 146 | set_fl(initbright); |
149 | QDialog::reject(); | 147 | QDialog::reject(); |
150 | } | 148 | } |
151 | 149 | ||
152 | void LightSettings::accept() | 150 | void LightSettings::accept() |
153 | { | 151 | { |
154 | if ( qApp->focusWidget() ) { | 152 | if ( qApp->focusWidget() ) { |
155 | qApp->focusWidget()->clearFocus(); | 153 | qApp->focusWidget()->clearFocus(); |
156 | } | 154 | } |
157 | 155 | ||
158 | applyBrightness(); | 156 | applyBrightness(); |
159 | 157 | ||
160 | // bat | 158 | // bat |
161 | int i_dim = interval_dim->value(); | 159 | int i_dim = interval_dim->value(); |
162 | int i_lightoff = interval_lightoff->value(); | 160 | int i_lightoff = interval_lightoff->value(); |
163 | int i_suspend = interval_suspend->value(); | 161 | int i_suspend = interval_suspend->value(); |
164 | 162 | ||
165 | // ac | 163 | // ac |
@@ -171,51 +169,51 @@ void LightSettings::accept() | |||
171 | 169 | ||
172 | config.setGroup( "Battery" ); | 170 | config.setGroup( "Battery" ); |
173 | 171 | ||
174 | // bat | 172 | // bat |
175 | config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); | 173 | config.writeEntry( "LcdOffOnly", LcdOffOnly->isChecked() ); |
176 | config.writeEntry( "Dim", i_dim ); | 174 | config.writeEntry( "Dim", i_dim ); |
177 | config.writeEntry( "LightOff", i_lightoff ); | 175 | config.writeEntry( "LightOff", i_lightoff ); |
178 | config.writeEntry( "Suspend", i_suspend ); | 176 | config.writeEntry( "Suspend", i_suspend ); |
179 | config.writeEntry( "Brightness", | 177 | config.writeEntry( "Brightness", |
180 | ( brightness->value() ) * 255 / brightness->maxValue() ); | 178 | ( brightness->value() ) * 255 / brightness->maxValue() ); |
181 | 179 | ||
182 | // ac | 180 | // ac |
183 | config.setGroup( "AC" ); | 181 | config.setGroup( "AC" ); |
184 | config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); | 182 | config.writeEntry( "LcdOffOnly", LcdOffOnly_2_3->isChecked() ); |
185 | config.writeEntry( "Dim", i_dim_ac ); | 183 | config.writeEntry( "Dim", i_dim_ac ); |
186 | config.writeEntry( "LightOff", i_lightoff_ac ); | 184 | config.writeEntry( "LightOff", i_lightoff_ac ); |
187 | config.writeEntry( "Suspend", i_suspend_ac ); | 185 | config.writeEntry( "Suspend", i_suspend_ac ); |
188 | config.writeEntry( "Brightness", | 186 | config.writeEntry( "Brightness", |
189 | ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() ); | 187 | ( brightness_ac_3->value()) * 255 / brightness_ac_3->maxValue() ); |
190 | 188 | ||
191 | 189 | ||
192 | // 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 |
193 | if ( ODevice::inst()->hasLightSensor() ) { | 191 | if ( ODevice::inst()->hasLightSensor() ) { |
194 | config.setGroup( "Battery" ); | 192 | config.setGroup( "Battery" ); |
195 | config.writeEntry( "LightSensor", (int)auto_brightness->isChecked() ); | 193 | config.writeEntry( "LightSensor", auto_brightness->isChecked() ); |
196 | config.setGroup( "AC" ); | 194 | config.setGroup( "AC" ); |
197 | config.writeEntry( "LightSensor", (int)auto_brightness_ac_3->isChecked() ); | 195 | config.writeEntry( "LightSensor", auto_brightness_ac_3->isChecked() ); |
198 | //config.writeEntry( "Steps", LightStepSpin->value() ); | 196 | //config.writeEntry( "Steps", LightStepSpin->value() ); |
199 | //onfig.writeEntry( "MinValue", LightMinValueSlider->value() ); | 197 | //onfig.writeEntry( "MinValue", LightMinValueSlider->value() ); |
200 | //config.writeEntry( "Shift", LightShiftSpin->value() ); | 198 | //config.writeEntry( "Shift", LightShiftSpin->value() ); |
201 | } | 199 | } |
202 | 200 | ||
203 | 201 | ||
204 | // advanced | 202 | // advanced |
205 | config.setGroup( "Warnings" ); | 203 | config.setGroup( "Warnings" ); |
206 | config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); | 204 | config.writeEntry( "check_interval", warnintervalBox->value()*1000 ); |
207 | config.writeEntry( "power_verylow", lowSpinBox->value() ); | 205 | config.writeEntry( "power_verylow", lowSpinBox->value() ); |
208 | config.writeEntry( "power_critical", criticalSpinBox->value() ); | 206 | config.writeEntry( "power_critical", criticalSpinBox->value() ); |
209 | config.write(); | 207 | config.write(); |
210 | 208 | ||
211 | { | 209 | { |
212 | QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); | 210 | QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); |
213 | } | 211 | } |
214 | { | 212 | { |
215 | QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); | 213 | QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); |
216 | e << -1; | 214 | e << -1; |
217 | } | 215 | } |
218 | { | 216 | { |
219 | QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); | 217 | QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); |
220 | e << -1; | 218 | e << -1; |
221 | } | 219 | } |