author | schurig <schurig> | 2003-06-06 08:28:34 (UTC) |
---|---|---|
committer | schurig <schurig> | 2003-06-06 08:28:34 (UTC) |
commit | bd0a37d78c1ba1f38b6fef144de584eff9dc2c1c (patch) (unidiff) | |
tree | ceb4ae77cb9d0a92f8738f3cd3b9a013b21cd148 /core | |
parent | b02b57cc34fdba0b3d9058ed263e283f0660ffb7 (diff) | |
download | opie-bd0a37d78c1ba1f38b6fef144de584eff9dc2c1c.zip opie-bd0a37d78c1ba1f38b6fef144de584eff9dc2c1c.tar.gz opie-bd0a37d78c1ba1f38b6fef144de584eff9dc2c1c.tar.bz2 |
added some doc-strings in an attempt to understand this beast
-rw-r--r-- | core/launcher/screensaver.cpp | 97 |
1 files changed, 77 insertions, 20 deletions
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index b9bb64c..182084d 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -41,29 +41,39 @@ OpieScreenSaver::OpieScreenSaver ( ) | |||
41 | m_level = -1; | 41 | m_level = -1; |
42 | 42 | ||
43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 43 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
44 | ODevice::inst ( )-> setDisplayStatus ( true ); | 44 | ODevice::inst ( )-> setDisplayStatus ( true ); |
45 | setBacklight ( -1 ); | 45 | setBacklight ( -1 ); |
46 | } | 46 | } |
47 | 47 | ||
48 | 48 | ||
49 | /** | ||
50 | * Stops the screen saver | ||
51 | */ | ||
49 | void OpieScreenSaver::restore() | 52 | void OpieScreenSaver::restore() |
50 | { | 53 | { |
51 | m_level = -1; | 54 | m_level = -1; |
52 | 55 | ||
53 | if ( !m_lcd_status ) { // We must have turned it off | 56 | if ( !m_lcd_status ) { // We must have turned it off |
54 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 57 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
55 | m_lcd_status = true; | 58 | m_lcd_status = true; |
56 | } | 59 | } |
57 | 60 | ||
58 | setBacklightInternal ( -1 ); | 61 | setBacklightInternal ( -1 ); |
59 | } | 62 | } |
60 | 63 | ||
61 | 64 | ||
65 | /** | ||
66 | * Starts the screen saver | ||
67 | * | ||
68 | * @param level what level of screen saving should happen (0=lowest non-off, 1=off, | ||
69 | * 2=suspend whole machine) | ||
70 | * @returns true on success | ||
71 | */ | ||
62 | bool OpieScreenSaver::save( int level ) | 72 | bool OpieScreenSaver::save( int level ) |
63 | { | 73 | { |
64 | m_level = level; | 74 | m_level = level; |
65 | 75 | ||
66 | switch ( level ) { | 76 | switch ( level ) { |
67 | case 0: | 77 | case 0: |
68 | if (( m_on_ac && m_enable_dim_ac ) || | 78 | if (( m_on_ac && m_enable_dim_ac ) || |
69 | ( !m_on_ac && m_enable_dim )) { | 79 | ( !m_on_ac && m_enable_dim )) { |
@@ -93,87 +103,116 @@ bool OpieScreenSaver::save( int level ) | |||
93 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 103 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
94 | m_lcd_status = false; | 104 | m_lcd_status = false; |
95 | return true; | 105 | return true; |
96 | } | 106 | } |
97 | 107 | ||
98 | // We're going to suspend the whole machine | 108 | // We're going to suspend the whole machine |
99 | 109 | ||
100 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | 110 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { |
111 | // TODO: why is this key F34 hard coded? -- schurig | ||
112 | // Does this now only work an devices with a ODevice::filter? | ||
101 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 113 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
102 | return true; | 114 | return true; |
103 | } | 115 | } |
104 | 116 | ||
105 | break; | 117 | break; |
106 | } | 118 | } |
107 | return false; | 119 | return false; |
108 | } | 120 | } |
109 | 121 | ||
110 | 122 | ||
111 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) | 123 | /** |
124 | * Set intervals in seconds for automatic dimming, light off and suspend | ||
125 | * | ||
126 | * This function also sets the member variables m_m_enable_dim[_ac], | ||
127 | * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] | ||
128 | * | ||
129 | * @param dim time in seconds to dim, -1 to read value from config file, | ||
130 | * 0 to disable | ||
131 | * @param lightoff time in seconds to turn LCD backlight off, -1 to | ||
132 | * read value from config file, 0 to disable | ||
133 | * @param suspend time in seconds to do an APM suspend, -1 to | ||
134 | * read value from config file, 0 to disable | ||
135 | */ | ||
136 | void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) | ||
112 | { | 137 | { |
113 | Config config ( "apm" ); | 138 | Config config ( "apm" ); |
114 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 139 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
115 | 140 | ||
116 | int v[ 4 ]; | 141 | int v[ 4 ]; |
117 | if ( i1 < 0 ) | 142 | if ( dim < 0 ) |
118 | i1 = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); | 143 | dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
119 | if ( i2 < 0 ) | 144 | if ( lightoff < 0 ) |
120 | i2 = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); | 145 | lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
121 | if ( i3 < 0 ) | 146 | if ( suspend < 0 ) |
122 | i3 = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); | 147 | suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
123 | 148 | ||
124 | if ( m_on_ac ) { | 149 | if ( m_on_ac ) { |
125 | m_enable_dim_ac = ( i1 > 0 ); | 150 | m_enable_dim_ac = ( dim > 0 ); |
126 | m_enable_lightoff_ac = ( i2 > 0 ); | 151 | m_enable_lightoff_ac = ( lightoff > 0 ); |
127 | m_enable_suspend_ac = ( i3 > 0 ); | 152 | m_enable_suspend_ac = ( suspend > 0 ); |
128 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); | 153 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
129 | } | 154 | } |
130 | else { | 155 | else { |
131 | m_enable_dim = ( i1 > 0 ); | 156 | m_enable_dim = ( dim > 0 ); |
132 | m_enable_lightoff = ( i2 > 0 ); | 157 | m_enable_lightoff = ( lightoff > 0 ); |
133 | m_enable_suspend = ( i3 > 0 ); | 158 | m_enable_suspend = ( suspend > 0 ); |
134 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); | 159 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
135 | } | 160 | } |
136 | 161 | ||
137 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 162 | //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); |
138 | 163 | ||
139 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 164 | v [ 0 ] = QMAX( 1000 * dim, 100 ); |
140 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 165 | v [ 1 ] = QMAX( 1000 * lightoff, 100 ); |
141 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 166 | v [ 2 ] = QMAX( 1000 * suspend, 100 ); |
142 | v [ 3 ] = 0; | 167 | v [ 3 ] = 0; |
143 | 168 | ||
144 | if ( !i1 && !i2 && !i3 ) | 169 | if ( !dim && !lightoff && !suspend ) |
145 | QWSServer::setScreenSaverInterval( 0 ); | 170 | QWSServer::setScreenSaverInterval( 0 ); |
146 | else | 171 | else |
147 | QWSServer::setScreenSaverIntervals( v ); | 172 | QWSServer::setScreenSaverIntervals( v ); |
148 | } | 173 | } |
149 | 174 | ||
150 | 175 | ||
176 | /** | ||
177 | * Set suspend time. Will read the dim and lcd-off times from the config file. | ||
178 | * | ||
179 | * @param suspend time in seconds to go into APM suspend, -1 to | ||
180 | * read value from config file, 0 to disable | ||
181 | */ | ||
151 | void OpieScreenSaver::setInterval ( int interval ) | 182 | void OpieScreenSaver::setInterval ( int interval ) |
152 | { | 183 | { |
153 | setIntervals ( -1, -1, interval ); | 184 | setIntervals ( -1, -1, interval ); |
154 | } | 185 | } |
155 | 186 | ||
156 | 187 | ||
157 | void OpieScreenSaver::setMode ( int mode ) | 188 | void OpieScreenSaver::setMode ( int mode ) |
158 | { | 189 | { |
159 | if ( mode > m_disable_suspend ) | 190 | if ( mode > m_disable_suspend ) |
160 | setInterval ( -1 ); | 191 | setInterval ( -1 ); |
161 | m_disable_suspend = mode; | 192 | m_disable_suspend = mode; |
162 | } | 193 | } |
163 | 194 | ||
164 | 195 | ||
196 | /** | ||
197 | * Set display brightness | ||
198 | * | ||
199 | * Get's default values for backlight and light sensor from config file. | ||
200 | * | ||
201 | * @param bright desired brighness (-1 to use automatic sensor data or value | ||
202 | * from config file, -2 to toggle backlight on and off, -3 to | ||
203 | * force backlight off) | ||
204 | */ | ||
165 | void OpieScreenSaver::setBacklight ( int bright ) | 205 | void OpieScreenSaver::setBacklight ( int bright ) |
166 | { | 206 | { |
167 | // Read from config | 207 | // Read from config |
168 | Config config ( "apm" ); | 208 | Config config ( "apm" ); |
169 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 209 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
170 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 210 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
171 | |||
172 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
173 | 212 | ||
174 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
175 | 214 | ||
176 | killTimers ( ); | 215 | killTimers ( ); |
177 | if (( bright < 0 ) && m_use_light_sensor ) { | 216 | if (( bright < 0 ) && m_use_light_sensor ) { |
178 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
179 | 218 | ||
@@ -194,16 +233,25 @@ void OpieScreenSaver::setBacklight ( int bright ) | |||
194 | timerEvent ( 0 ); | 233 | timerEvent ( 0 ); |
195 | startTimer ( m_sensordata [LS_Interval] ); | 234 | startTimer ( m_sensordata [LS_Interval] ); |
196 | } | 235 | } |
197 | 236 | ||
198 | setBacklightInternal ( bright ); | 237 | setBacklightInternal ( bright ); |
199 | } | 238 | } |
200 | 239 | ||
201 | 240 | ||
241 | /** | ||
242 | * Internal brightness setting method | ||
243 | * | ||
244 | * Get's default values for backlight and light sensor from config file. | ||
245 | * | ||
246 | * @param bright desired brighness (-1 to use automatic sensor data or value | ||
247 | * from config file, -2 to toggle backlight on and off, -3 to | ||
248 | * force backlight off) | ||
249 | */ | ||
202 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 250 | void OpieScreenSaver::setBacklightInternal ( int bright ) |
203 | { | 251 | { |
204 | if ( bright == -3 ) { | 252 | if ( bright == -3 ) { |
205 | // Forced on | 253 | // Forced on |
206 | m_backlight_forcedoff = false; | 254 | m_backlight_forcedoff = false; |
207 | bright = -1; | 255 | bright = -1; |
208 | } | 256 | } |
209 | if ( m_backlight_forcedoff && bright != -2 ) | 257 | if ( m_backlight_forcedoff && bright != -2 ) |
@@ -218,16 +266,20 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) | |||
218 | 266 | ||
219 | if ( bright != m_backlight_current ) { | 267 | if ( bright != m_backlight_current ) { |
220 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 268 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
221 | m_backlight_current = bright; | 269 | m_backlight_current = bright; |
222 | } | 270 | } |
223 | } | 271 | } |
224 | 272 | ||
225 | 273 | ||
274 | /** | ||
275 | * Timer event used for automatic setting the backlight according to a light sensor | ||
276 | * and to set the default brightness | ||
277 | */ | ||
226 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 278 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
227 | { | 279 | { |
228 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); | 280 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); |
229 | 281 | ||
230 | if ( s < m_sensordata [LS_SensorMin] ) | 282 | if ( s < m_sensordata [LS_SensorMin] ) |
231 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 283 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
232 | else if ( s >= m_sensordata [LS_SensorMax] ) | 284 | else if ( s >= m_sensordata [LS_SensorMax] ) |
233 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 285 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
@@ -242,29 +294,34 @@ void OpieScreenSaver::timerEvent ( QTimerEvent * ) | |||
242 | 294 | ||
243 | //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); | 295 | //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); |
244 | 296 | ||
245 | if ( m_level <= 0 ) | 297 | if ( m_level <= 0 ) |
246 | setBacklightInternal ( -1 ); | 298 | setBacklightInternal ( -1 ); |
247 | } | 299 | } |
248 | 300 | ||
249 | 301 | ||
302 | /** | ||
303 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. | ||
304 | */ | ||
250 | void OpieScreenSaver::setDisplayState ( bool on ) | 305 | void OpieScreenSaver::setDisplayState ( bool on ) |
251 | { | 306 | { |
252 | if ( m_lcd_status != on ) { | 307 | if ( m_lcd_status != on ) { |
253 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 308 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
254 | m_lcd_status = on; | 309 | m_lcd_status = on; |
255 | } | 310 | } |
256 | } | 311 | } |
257 | 312 | ||
258 | 313 | ||
314 | /** | ||
315 | * Set display to default ac/battery settings when power status changed. | ||
316 | */ | ||
259 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 317 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
260 | { | 318 | { |
261 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 319 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
262 | 320 | ||
263 | if ( newonac != m_on_ac ) { | 321 | if ( newonac != m_on_ac ) { |
264 | m_on_ac = newonac; | 322 | m_on_ac = newonac; |
265 | setInterval ( -1 ); | 323 | setInterval ( -1 ); |
266 | setBacklight ( -1 ); | 324 | setBacklight ( -1 ); |
267 | restore ( ); | 325 | restore ( ); |
268 | } | 326 | } |
269 | } | 327 | } |
270 | |||