-rw-r--r-- | core/launcher/desktop.cpp | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 387650b..d2bd8ae 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -122,250 +122,254 @@ public: | |||
122 | parent, name, FALSE ) | 122 | parent, name, FALSE ) |
123 | { | 123 | { |
124 | currentPriority = INT_MAX; | 124 | currentPriority = INT_MAX; |
125 | alertCount = 0; | 125 | alertCount = 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void alert( const QString &text, int priority ); | 128 | void alert( const QString &text, int priority ); |
129 | void hideEvent( QHideEvent * ); | 129 | void hideEvent( QHideEvent * ); |
130 | private: | 130 | private: |
131 | int currentPriority; | 131 | int currentPriority; |
132 | int alertCount; | 132 | int alertCount; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
136 | { | 136 | { |
137 | alertCount++; | 137 | alertCount++; |
138 | if ( alertCount < priority ) | 138 | if ( alertCount < priority ) |
139 | return ; | 139 | return ; |
140 | if ( priority > currentPriority ) | 140 | if ( priority > currentPriority ) |
141 | return ; | 141 | return ; |
142 | currentPriority = priority; | 142 | currentPriority = priority; |
143 | setText( text ); | 143 | setText( text ); |
144 | show(); | 144 | show(); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
149 | { | 149 | { |
150 | QMessageBox::hideEvent( e ); | 150 | QMessageBox::hideEvent( e ); |
151 | alertCount = 0; | 151 | alertCount = 0; |
152 | currentPriority = INT_MAX; | 152 | currentPriority = INT_MAX; |
153 | } | 153 | } |
154 | 154 | ||
155 | class QPEScreenSaver : public QWSScreenSaver | 155 | class QPEScreenSaver : public QWSScreenSaver |
156 | { | 156 | { |
157 | private: | 157 | private: |
158 | int LcdOn; | 158 | int LcdOn; |
159 | 159 | ||
160 | public: | 160 | public: |
161 | QPEScreenSaver() | 161 | QPEScreenSaver() |
162 | { | 162 | { |
163 | m_disable_suspend = 100; | 163 | m_disable_suspend = 100; |
164 | m_enable_dim = false; | 164 | m_enable_dim = false; |
165 | m_enable_lightoff = false; | 165 | m_enable_lightoff = false; |
166 | m_enable_onlylcdoff = false; | 166 | m_enable_onlylcdoff = false; |
167 | 167 | ||
168 | m_lcd_status = true; | 168 | m_lcd_status = true; |
169 | 169 | ||
170 | m_backlight_bright = -1; | 170 | m_backlight_normal = -1; |
171 | m_backlight_current = -1; | ||
171 | m_backlight_forcedoff = false; | 172 | m_backlight_forcedoff = false; |
172 | 173 | ||
173 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 174 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
174 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 175 | ODevice::inst ( )-> setDisplayStatus ( true ); |
176 | setBacklight ( -1 ); | ||
175 | } | 177 | } |
176 | void restore() | 178 | void restore() |
177 | { | 179 | { |
178 | if ( !m_lcd_status ) { // We must have turned it off | 180 | if ( !m_lcd_status ) { // We must have turned it off |
179 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 181 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
180 | m_lcd_status = true; | 182 | m_lcd_status = true; |
181 | } | 183 | } |
182 | 184 | ||
183 | setBacklight ( -1 ); | 185 | setBacklightInternal ( -1 ); |
184 | } | 186 | } |
185 | bool save( int level ) | 187 | bool save( int level ) |
186 | { | 188 | { |
187 | switch ( level ) { | 189 | switch ( level ) { |
188 | case 0: | 190 | case 0: |
189 | if ( m_disable_suspend > 0 && m_enable_dim ) { | 191 | if ( m_disable_suspend > 0 && m_enable_dim ) { |
190 | if ( backlight() > 1 ) | 192 | if ( m_backlight_current > 1 ) |
191 | setBacklight( 1 ); // lowest non-off | 193 | setBacklightInternal ( 1 ); // lowest non-off |
192 | } | 194 | } |
193 | return true; | 195 | return true; |
194 | break; | 196 | break; |
195 | case 1: | 197 | case 1: |
196 | if ( m_disable_suspend > 1 && m_enable_lightoff ) { | 198 | if ( m_disable_suspend > 1 && m_enable_lightoff ) { |
197 | setBacklight( 0 ); // off | 199 | setBacklightInternal ( 0 ); // off |
198 | } | 200 | } |
199 | return true; | 201 | return true; |
200 | break; | 202 | break; |
201 | case 2: | 203 | case 2: |
202 | if ( m_enable_onlylcdoff ) { | 204 | if ( m_enable_onlylcdoff ) { |
203 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 205 | ODevice::inst ( )-> setDisplayStatus ( false ); |
204 | m_lcd_status = false; | 206 | m_lcd_status = false; |
205 | return true; | 207 | return true; |
206 | } | 208 | } |
207 | else // We're going to suspend the whole machine | 209 | else // We're going to suspend the whole machine |
208 | { | 210 | { |
209 | if ( ( m_disable_suspend > 2 ) && | 211 | if ( ( m_disable_suspend > 2 ) && |
210 | ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && | 212 | ( PowerStatusManager::readStatus().acStatus() != PowerStatus::Online ) && |
211 | ( !Network::networkOnline ( ) ) ) { | 213 | ( !Network::networkOnline ( ) ) ) { |
212 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 214 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
213 | return true; | 215 | return true; |
214 | } | 216 | } |
215 | } | 217 | } |
216 | break; | 218 | break; |
217 | } | 219 | } |
218 | return false; | 220 | return false; |
219 | } | 221 | } |
220 | 222 | ||
221 | private: | 223 | private: |
222 | static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) | 224 | static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) |
223 | { | 225 | { |
224 | if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) | 226 | if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) |
225 | return 0; | 227 | return 0; |
226 | 228 | ||
227 | if ( interval < 0 ) { | 229 | if ( interval < 0 ) { |
228 | // Restore screen blanking and power saving state | 230 | // Restore screen blanking and power saving state |
229 | interval = config.readNumEntry( value, def ); | 231 | interval = config.readNumEntry( value, def ); |
230 | } | 232 | } |
231 | return interval; | 233 | return interval; |
232 | } | 234 | } |
233 | 235 | ||
234 | public: | 236 | public: |
235 | void setIntervals( int i1, int i2, int i3 ) | 237 | void setIntervals( int i1, int i2, int i3 ) |
236 | { | 238 | { |
237 | Config config( "qpe" ); | 239 | Config config( "qpe" ); |
238 | config.setGroup( "Screensaver" ); | 240 | config.setGroup( "Screensaver" ); |
239 | 241 | ||
240 | int v[ 4 ]; | 242 | int v[ 4 ]; |
241 | i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); | 243 | i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); |
242 | i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); | 244 | i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); |
243 | i3 = ssi( i3, config, "", "Interval", 60 ); | 245 | i3 = ssi( i3, config, "", "Interval", 60 ); |
244 | 246 | ||
245 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | 247 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); |
246 | 248 | ||
247 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | 249 | v [ 0 ] = QMAX( 1000 * i1, 100 ); |
248 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | 250 | v [ 1 ] = QMAX( 1000 * i2, 100 ); |
249 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | 251 | v [ 2 ] = QMAX( 1000 * i3, 100 ); |
250 | v [ 3 ] = 0; | 252 | v [ 3 ] = 0; |
251 | m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); | 253 | m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); |
252 | m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); | 254 | m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); |
253 | m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); | 255 | m_enable_onlylcdoff = config. readNumEntry ( "LcdOffOnly", 0 ); |
254 | 256 | ||
255 | if ( !i1 && !i2 && !i3 ) | 257 | if ( !i1 && !i2 && !i3 ) |
256 | QWSServer::setScreenSaverInterval( 0 ); | 258 | QWSServer::setScreenSaverInterval( 0 ); |
257 | else | 259 | else |
258 | QWSServer::setScreenSaverIntervals( v ); | 260 | QWSServer::setScreenSaverIntervals( v ); |
259 | } | 261 | } |
260 | 262 | ||
261 | void setInterval ( int interval ) | 263 | void setInterval ( int interval ) |
262 | { | 264 | { |
263 | setIntervals ( -1, -1, interval ); | 265 | setIntervals ( -1, -1, interval ); |
264 | } | 266 | } |
265 | 267 | ||
266 | void setMode ( int mode ) | 268 | void setMode ( int mode ) |
267 | { | 269 | { |
268 | if ( mode > m_disable_suspend ) | 270 | if ( mode > m_disable_suspend ) |
269 | setInterval( -1 ); | 271 | setInterval( -1 ); |
270 | m_disable_suspend = mode; | 272 | m_disable_suspend = mode; |
271 | } | 273 | } |
272 | 274 | ||
273 | int backlight ( ) | 275 | void setBacklight ( int bright ) |
274 | { | 276 | { |
275 | if ( m_backlight_bright == -1 ) { | 277 | // Read from config |
276 | // Read from config | 278 | Config config ( "qpe" ); |
277 | Config config ( "qpe" ); | 279 | config. setGroup ( "Screensaver" ); |
278 | config. setGroup ( "Screensaver" ); | 280 | m_backlight_normal = config. readNumEntry ( "Brightness", 255 ); |
279 | m_backlight_bright = config. readNumEntry ( "Brightness", 255 ); | 281 | |
280 | } | 282 | setBacklightInternal ( bright ); |
281 | return m_backlight_bright; | ||
282 | } | 283 | } |
283 | 284 | ||
284 | void setBacklight ( int bright ) | 285 | private: |
286 | void setBacklightInternal ( int bright ) | ||
285 | { | 287 | { |
286 | if ( bright == -3 ) { | 288 | if ( bright == -3 ) { |
287 | // Forced on | 289 | // Forced on |
288 | m_backlight_forcedoff = false; | 290 | m_backlight_forcedoff = false; |
289 | bright = -1; | 291 | bright = -1; |
290 | } | 292 | } |
291 | if ( m_backlight_forcedoff && bright != -2 ) | 293 | if ( m_backlight_forcedoff && bright != -2 ) |
292 | return ; | 294 | return ; |
293 | if ( bright == -2 ) { | 295 | if ( bright == -2 ) { |
294 | // Toggle between off and on | 296 | // Toggle between off and on |
295 | bright = m_backlight_bright ? 0 : -1; | 297 | bright = m_backlight_current ? 0 : -1; |
296 | m_backlight_forcedoff = !bright; | 298 | m_backlight_forcedoff = !bright; |
297 | } | 299 | } |
298 | 300 | if ( bright == -1 ) | |
299 | m_backlight_bright = bright; | 301 | bright = m_backlight_normal; |
300 | 302 | ||
301 | bright = backlight ( ); | 303 | if ( bright != m_backlight_current ) { |
302 | ODevice::inst ( ) -> setDisplayBrightness ( bright ); | 304 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
303 | 305 | m_backlight_current = bright; | |
304 | m_backlight_bright = bright; | 306 | } |
305 | } | 307 | } |
306 | 308 | ||
309 | public: | ||
307 | void setDisplayState ( bool on ) | 310 | void setDisplayState ( bool on ) |
308 | { | 311 | { |
309 | if ( m_lcd_status != on ) { | 312 | if ( m_lcd_status != on ) { |
310 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 313 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
311 | m_lcd_status = on; | 314 | m_lcd_status = on; |
312 | } | 315 | } |
313 | } | 316 | } |
314 | 317 | ||
315 | private: | 318 | private: |
316 | int m_disable_suspend; | 319 | int m_disable_suspend; |
317 | bool m_enable_dim; | 320 | bool m_enable_dim; |
318 | bool m_enable_lightoff; | 321 | bool m_enable_lightoff; |
319 | bool m_enable_onlylcdoff; | 322 | bool m_enable_onlylcdoff; |
320 | 323 | ||
321 | bool m_lcd_status; | 324 | bool m_lcd_status; |
322 | 325 | ||
323 | int m_backlight_bright; | 326 | int m_backlight_normal; |
327 | int m_backlight_current; | ||
324 | bool m_backlight_forcedoff; | 328 | bool m_backlight_forcedoff; |
325 | }; | 329 | }; |
326 | 330 | ||
327 | void DesktopApplication::switchLCD ( bool on ) | 331 | void DesktopApplication::switchLCD ( bool on ) |
328 | { | 332 | { |
329 | if ( qApp ) { | 333 | if ( qApp ) { |
330 | DesktopApplication *dapp = (DesktopApplication *) qApp; | 334 | DesktopApplication *dapp = (DesktopApplication *) qApp; |
331 | 335 | ||
332 | if ( dapp-> m_screensaver ) { | 336 | if ( dapp-> m_screensaver ) { |
333 | if ( on ) { | 337 | if ( on ) { |
334 | dapp-> m_screensaver-> setDisplayState ( true ); | 338 | dapp-> m_screensaver-> setDisplayState ( true ); |
335 | dapp-> m_screensaver-> setBacklight ( -3 ); | 339 | dapp-> m_screensaver-> setBacklight ( -3 ); |
336 | } | 340 | } |
337 | else { | 341 | else { |
338 | dapp-> m_screensaver-> setDisplayState ( false ); | 342 | dapp-> m_screensaver-> setDisplayState ( false ); |
339 | } | 343 | } |
340 | } | 344 | } |
341 | } | 345 | } |
342 | } | 346 | } |
343 | 347 | ||
344 | 348 | ||
345 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | 349 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
346 | : QPEApplication( argc, argv, appType ) | 350 | : QPEApplication( argc, argv, appType ) |
347 | { | 351 | { |
348 | 352 | ||
349 | QTimer * t = new QTimer( this ); | 353 | QTimer * t = new QTimer( this ); |
350 | connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); | 354 | connect( t, SIGNAL( timeout() ), this, SLOT( psTimeout() ) ); |
351 | t->start( 10000 ); | 355 | t->start( 10000 ); |
352 | ps = new PowerStatus; | 356 | ps = new PowerStatus; |
353 | pa = new DesktopPowerAlerter( 0 ); | 357 | pa = new DesktopPowerAlerter( 0 ); |
354 | 358 | ||
355 | channel = new QCopChannel( "QPE/Desktop", this ); | 359 | channel = new QCopChannel( "QPE/Desktop", this ); |
356 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 360 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
357 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | 361 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); |
358 | 362 | ||
359 | channel = new QCopChannel( "QPE/System", this ); | 363 | channel = new QCopChannel( "QPE/System", this ); |
360 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 364 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
361 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 365 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
362 | 366 | ||
363 | m_screensaver = new QPEScreenSaver; | 367 | m_screensaver = new QPEScreenSaver; |
364 | 368 | ||
365 | m_screensaver-> setInterval ( -1 ); | 369 | m_screensaver-> setInterval ( -1 ); |
366 | QWSServer::setScreenSaver( m_screensaver ); | 370 | QWSServer::setScreenSaver( m_screensaver ); |
367 | } | 371 | } |
368 | 372 | ||
369 | 373 | ||
370 | DesktopApplication::~DesktopApplication() | 374 | DesktopApplication::~DesktopApplication() |
371 | { | 375 | { |