-rw-r--r-- | core/launcher/desktop.cpp | 345 | ||||
-rw-r--r-- | core/launcher/desktop.h | 7 | ||||
-rw-r--r-- | core/launcher/launcher.pro | 2 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 237 | ||||
-rw-r--r-- | core/launcher/screensaver.h | 61 |
5 files changed, 354 insertions, 298 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp index 2ea6d27..bc43475 100644 --- a/core/launcher/desktop.cpp +++ b/core/launcher/desktop.cpp | |||
@@ -1,1058 +1,815 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
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 | 20 | ||
21 | #include "desktop.h" | 21 | #include "desktop.h" |
22 | #include "info.h" | 22 | #include "info.h" |
23 | #include "launcher.h" | 23 | #include "launcher.h" |
24 | #include "qcopbridge.h" | 24 | #include "qcopbridge.h" |
25 | #include "shutdownimpl.h" | 25 | #include "shutdownimpl.h" |
26 | #include "startmenu.h" | 26 | #include "startmenu.h" |
27 | #include "taskbar.h" | 27 | #include "taskbar.h" |
28 | #include "transferserver.h" | 28 | #include "transferserver.h" |
29 | #include "irserver.h" | 29 | #include "irserver.h" |
30 | #include "packageslave.h" | 30 | #include "packageslave.h" |
31 | #include "screensaver.h" | ||
31 | 32 | ||
32 | #include <qpe/applnk.h> | 33 | #include <qpe/applnk.h> |
33 | #include <qpe/mimetype.h> | 34 | #include <qpe/mimetype.h> |
34 | #include <qpe/password.h> | 35 | #include <qpe/password.h> |
35 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
36 | #include <qpe/power.h> | 37 | #include <qpe/power.h> |
37 | #include <qpe/timeconversion.h> | 38 | #include <qpe/timeconversion.h> |
38 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
39 | #include <qpe/network.h> | 40 | #include <qpe/network.h> |
40 | #include <qpe/global.h> | 41 | #include <qpe/global.h> |
41 | 42 | ||
42 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) | 43 | #if defined( QT_QWS_CUSTOM ) || defined( QT_QWS_IPAQ ) |
43 | #include <qpe/custom.h> | 44 | #include <qpe/custom.h> |
44 | #endif | 45 | #endif |
45 | 46 | ||
46 | #include <opie/odevice.h> | 47 | #include <opie/odevice.h> |
47 | 48 | ||
48 | #include <qgfx_qws.h> | 49 | #include <qgfx_qws.h> |
49 | #include <qmainwindow.h> | 50 | #include <qmainwindow.h> |
50 | #include <qmessagebox.h> | 51 | #include <qmessagebox.h> |
51 | #include <qtimer.h> | 52 | #include <qtimer.h> |
52 | #include <qwindowsystem_qws.h> | 53 | #include <qwindowsystem_qws.h> |
53 | 54 | ||
54 | #include <qvaluelist.h> | 55 | #include <qvaluelist.h> |
55 | 56 | ||
56 | #include <stdlib.h> | 57 | #include <stdlib.h> |
57 | #include <unistd.h> | 58 | #include <unistd.h> |
58 | #include <fcntl.h> | 59 | #include <fcntl.h> |
59 | 60 | ||
60 | using namespace Opie; | 61 | using namespace Opie; |
61 | 62 | ||
62 | class QCopKeyRegister | 63 | class QCopKeyRegister |
63 | { | 64 | { |
64 | public: | 65 | public: |
65 | QCopKeyRegister() : keyCode( 0 ) | 66 | QCopKeyRegister() : keyCode( 0 ) |
66 | { } | 67 | { } |
67 | QCopKeyRegister( int k, const QString &c, const QString &m ) | 68 | QCopKeyRegister( int k, const QString &c, const QString &m ) |
68 | : keyCode( k ), channel( c ), message( m ) | 69 | : keyCode( k ), channel( c ), message( m ) |
69 | { } | 70 | { } |
70 | 71 | ||
71 | int getKeyCode() const | 72 | int getKeyCode() const |
72 | { | 73 | { |
73 | return keyCode; | 74 | return keyCode; |
74 | } | 75 | } |
75 | QString getChannel() const | 76 | QString getChannel() const |
76 | { | 77 | { |
77 | return channel; | 78 | return channel; |
78 | } | 79 | } |
79 | QString getMessage() const | 80 | QString getMessage() const |
80 | { | 81 | { |
81 | return message; | 82 | return message; |
82 | } | 83 | } |
83 | 84 | ||
84 | private: | 85 | private: |
85 | int keyCode; | 86 | int keyCode; |
86 | QString channel, message; | 87 | QString channel, message; |
87 | }; | 88 | }; |
88 | 89 | ||
89 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | 90 | typedef QValueList<QCopKeyRegister> KeyRegisterList; |
90 | KeyRegisterList keyRegisterList; | 91 | KeyRegisterList keyRegisterList; |
91 | 92 | ||
92 | static Desktop* qpedesktop = 0; | 93 | static Desktop* qpedesktop = 0; |
93 | static int loggedin = 0; | 94 | static int loggedin = 0; |
94 | static void login( bool at_poweron ) | 95 | static void login( bool at_poweron ) |
95 | { | 96 | { |
96 | if ( !loggedin ) { | 97 | if ( !loggedin ) { |
97 | Global::terminateBuiltin( "calibrate" ); | 98 | Global::terminateBuiltin( "calibrate" ); |
98 | Password::authenticate( at_poweron ); | 99 | Password::authenticate( at_poweron ); |
99 | loggedin = 1; | 100 | loggedin = 1; |
100 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 101 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
101 | } | 102 | } |
102 | } | 103 | } |
103 | 104 | ||
104 | bool Desktop::screenLocked() | 105 | bool Desktop::screenLocked() |
105 | { | 106 | { |
106 | return loggedin == 0; | 107 | return loggedin == 0; |
107 | } | 108 | } |
108 | 109 | ||
109 | /* | 110 | /* |
110 | Priority is number of alerts that are needed to pop up | 111 | Priority is number of alerts that are needed to pop up |
111 | alert. | 112 | alert. |
112 | */ | 113 | */ |
113 | class DesktopPowerAlerter : public QMessageBox | 114 | class DesktopPowerAlerter : public QMessageBox |
114 | { | 115 | { |
115 | public: | 116 | public: |
116 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 117 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
117 | : QMessageBox( tr( "Battery Status" ), "Low Battery", | 118 | : QMessageBox( tr( "Battery Status" ), "Low Battery", |
118 | QMessageBox::Critical, | 119 | QMessageBox::Critical, |
119 | QMessageBox::Ok | QMessageBox::Default, | 120 | QMessageBox::Ok | QMessageBox::Default, |
120 | QMessageBox::NoButton, QMessageBox::NoButton, | 121 | QMessageBox::NoButton, QMessageBox::NoButton, |
121 | parent, name, FALSE ) | 122 | parent, name, FALSE ) |
122 | { | 123 | { |
123 | currentPriority = INT_MAX; | 124 | currentPriority = INT_MAX; |
124 | alertCount = 0; | 125 | alertCount = 0; |
125 | } | 126 | } |
126 | 127 | ||
127 | void alert( const QString &text, int priority ); | 128 | void alert( const QString &text, int priority ); |
128 | void hideEvent( QHideEvent * ); | 129 | void hideEvent( QHideEvent * ); |
129 | private: | 130 | private: |
130 | int currentPriority; | 131 | int currentPriority; |
131 | int alertCount; | 132 | int alertCount; |
132 | }; | 133 | }; |
133 | 134 | ||
134 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 135 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
135 | { | 136 | { |
136 | alertCount++; | 137 | alertCount++; |
137 | if ( alertCount < priority ) | 138 | if ( alertCount < priority ) |
138 | return ; | 139 | return ; |
139 | if ( priority > currentPriority ) | 140 | if ( priority > currentPriority ) |
140 | return ; | 141 | return ; |
141 | currentPriority = priority; | 142 | currentPriority = priority; |
142 | setText( text ); | 143 | setText( text ); |
143 | show(); | 144 | show(); |
144 | } | 145 | } |
145 | 146 | ||
146 | 147 | ||
147 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 148 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
148 | { | 149 | { |
149 | QMessageBox::hideEvent( e ); | 150 | QMessageBox::hideEvent( e ); |
150 | alertCount = 0; | 151 | alertCount = 0; |
151 | currentPriority = INT_MAX; | 152 | currentPriority = INT_MAX; |
152 | } | 153 | } |
153 | 154 | ||
154 | class QPEScreenSaver : public QWSScreenSaver | ||
155 | { | ||
156 | private: | ||
157 | int LcdOn; | ||
158 | |||
159 | public: | ||
160 | QPEScreenSaver() | ||
161 | { | ||
162 | m_disable_suspend = 100; | ||
163 | m_enable_dim = false; | ||
164 | m_enable_lightoff = false; | ||
165 | m_enable_onlylcdoff = false; | ||
166 | |||
167 | m_disable_suspend_ac = 100; | ||
168 | m_enable_dim_ac = false; | ||
169 | m_enable_lightoff_ac = false; | ||
170 | m_enable_onlylcdoff_ac = false; | ||
171 | m_disable_apm_ac = false; | ||
172 | |||
173 | m_lcd_status = true; | ||
174 | |||
175 | m_backlight_normal = -1; | ||
176 | m_backlight_current = -1; | ||
177 | m_backlight_forcedoff = false; | ||
178 | |||
179 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | ||
180 | ODevice::inst ( )-> setDisplayStatus ( true ); | ||
181 | setBacklight ( -1 ); | ||
182 | } | ||
183 | void restore() | ||
184 | { | ||
185 | if ( !m_lcd_status ) { // We must have turned it off | ||
186 | ODevice::inst ( ) -> setDisplayStatus ( true ); | ||
187 | m_lcd_status = true; | ||
188 | } | ||
189 | |||
190 | setBacklightInternal ( -1 ); | ||
191 | } | ||
192 | bool save( int level ) | ||
193 | { | ||
194 | bool onAC = ( PowerStatusManager::readStatus().acStatus() == PowerStatus::Online ); | ||
195 | |||
196 | switch ( level ) { | ||
197 | case 0: | ||
198 | |||
199 | if ( m_disable_suspend_ac > 0 && m_enable_dim_ac && onAC ) { | ||
200 | if ( m_backlight_current > 1 ) | ||
201 | setBacklight( 1 ); // lowest non-off | ||
202 | } else if ( !onAC && m_disable_suspend > 0 && m_enable_dim ) { | ||
203 | if ( m_backlight_current > 1 ) | ||
204 | setBacklightInternal( 1 ); // lowest non-off | ||
205 | } | ||
206 | return true; | ||
207 | break; | ||
208 | case 1: | ||
209 | |||
210 | if ( m_disable_suspend_ac > 1 && m_enable_lightoff_ac && onAC ) { | ||
211 | setBacklightInternal( 0 ); // off | ||
212 | } else if ( !onAC && m_disable_suspend > 1 && m_enable_lightoff ) { | ||
213 | setBacklightInternal( 0 ); // off | ||
214 | } | ||
215 | return true; | ||
216 | break; | ||
217 | case 2: | ||
218 | if ( m_disable_apm_ac && onAC ) { | ||
219 | return true; | ||
220 | } | ||
221 | |||
222 | if ( m_enable_onlylcdoff_ac && onAC ) { | ||
223 | ODevice::inst ( ) -> setDisplayStatus ( false ); | ||
224 | m_lcd_status = false; | ||
225 | return true; | ||
226 | } | ||
227 | else if ( !onAC && m_enable_onlylcdoff ) { | ||
228 | ODevice::inst ( ) -> setDisplayStatus ( false ); | ||
229 | m_lcd_status = false; | ||
230 | return true; | ||
231 | } | ||
232 | else // We're going to suspend the whole machine | ||
233 | { | ||
234 | if ( ( m_disable_suspend_ac > 2 && onAC ) && ( !Network::networkOnline ( ) ) ) { | ||
235 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
236 | return true; | ||
237 | } | ||
238 | if ( !onAC && ( m_disable_suspend > 2 ) && ( !Network::networkOnline ( ) ) ) { | ||
239 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
240 | return true; | ||
241 | } | ||
242 | } | ||
243 | break; | ||
244 | } | ||
245 | return false; | ||
246 | } | ||
247 | |||
248 | private: | ||
249 | static int ssi( int interval, Config & config, const QString & enable, const QString & value, int def ) | ||
250 | { | ||
251 | if ( !enable.isEmpty() && config.readNumEntry( enable, 0 ) == 0 ) | ||
252 | return 0; | ||
253 | |||
254 | if ( interval < 0 ) { | ||
255 | // Restore screen blanking and power saving state | ||
256 | interval = config.readNumEntry( value, def ); | ||
257 | } | ||
258 | return interval; | ||
259 | } | ||
260 | |||
261 | public: | ||
262 | void setIntervals( int i1, int i2, int i3 ) | ||
263 | { | ||
264 | Config config( "qpe" ); | ||
265 | config.setGroup( "Screensaver" ); | ||
266 | |||
267 | int v[ 4 ]; | ||
268 | i1 = ssi( i1, config, "Dim", "Interval_Dim", 30 ); | ||
269 | i2 = ssi( i2, config, "LightOff", "Interval_LightOff", 20 ); | ||
270 | i3 = ssi( i3, config, "", "Interval", 60 ); | ||
271 | |||
272 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | ||
273 | |||
274 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | ||
275 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | ||
276 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | ||
277 | v [ 3 ] = 0; | ||
278 | m_enable_dim = ( ( i1 != 0 ) ? config. readNumEntry ( "Dim", 1 ) : false ); | ||
279 | m_enable_lightoff = ( ( i2 != 0 ) ? config. readNumEntry ( "LightOff", 1 ) : false ); | ||
280 | m_enable_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 ); | ||
281 | |||
282 | if ( !i1 && !i2 && !i3 ) | ||
283 | QWSServer::setScreenSaverInterval( 0 ); | ||
284 | else | ||
285 | QWSServer::setScreenSaverIntervals( v ); | ||
286 | } | ||
287 | |||
288 | void setIntervalsAC( int i1, int i2, int i3 ) | ||
289 | { | ||
290 | Config config( "qpe" ); | ||
291 | config.setGroup( "Screensaver" ); | ||
292 | |||
293 | int v[ 4 ]; | ||
294 | i1 = ssi( i1, config, "DimAC", "Interval_DimAC", 30 ); | ||
295 | i2 = ssi( i2, config, "LightOffAC", "Interval_LightOffAC", 20 ); | ||
296 | i3 = ssi( i3, config, "", "IntervalAC", 60 ); | ||
297 | |||
298 | //qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | ||
299 | |||
300 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | ||
301 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | ||
302 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | ||
303 | v [ 3 ] = 0; | ||
304 | m_enable_dim_ac = ( ( i1 != 0 ) ? config.readNumEntry ( "DimAC", 1 ) : false ); | ||
305 | m_enable_lightoff_ac = ( ( i2 != 0 ) ? config.readNumEntry ( "LightOffAC", 1 ) : false ); | ||
306 | m_enable_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnlyAC", 0 ); | ||
307 | m_disable_apm_ac = config.readNumEntry ( "NoApmAC", 0 ); | ||
308 | |||
309 | if ( !i1 && !i2 && !i3 ) | ||
310 | QWSServer::setScreenSaverInterval( 0 ); | ||
311 | else | ||
312 | QWSServer::setScreenSaverIntervals( v ); | ||
313 | } | ||
314 | |||
315 | void setInterval ( int interval ) | ||
316 | { | ||
317 | setIntervals ( -1, -1, interval ); | ||
318 | setIntervalsAC ( -1, -1, interval ); | ||
319 | } | ||
320 | |||
321 | void setMode ( int mode ) | ||
322 | { | ||
323 | if ( mode > m_disable_suspend ) | ||
324 | setInterval( -1 ); | ||
325 | m_disable_suspend = mode; | ||
326 | } | ||
327 | |||
328 | void setBacklight ( int bright ) | ||
329 | { | ||
330 | // Read from config | ||
331 | Config config ( "qpe" ); | ||
332 | config. setGroup ( "Screensaver" ); | ||
333 | m_backlight_normal = config. readNumEntry ( "Brightness", 255 ); | ||
334 | |||
335 | setBacklightInternal ( bright ); | ||
336 | } | ||
337 | |||
338 | private: | ||
339 | void setBacklightInternal ( int bright ) | ||
340 | { | ||
341 | if ( bright == -3 ) { | ||
342 | // Forced on | ||
343 | m_backlight_forcedoff = false; | ||
344 | bright = -1; | ||
345 | } | ||
346 | if ( m_backlight_forcedoff && bright != -2 ) | ||
347 | return ; | ||
348 | if ( bright == -2 ) { | ||
349 | // Toggle between off and on | ||
350 | bright = m_backlight_current ? 0 : -1; | ||
351 | m_backlight_forcedoff = !bright; | ||
352 | } | ||
353 | if ( bright == -1 ) | ||
354 | bright = m_backlight_normal; | ||
355 | |||
356 | if ( bright != m_backlight_current ) { | ||
357 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | ||
358 | m_backlight_current = bright; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | public: | ||
363 | void setDisplayState ( bool on ) | ||
364 | { | ||
365 | if ( m_lcd_status != on ) { | ||
366 | ODevice::inst ( ) -> setDisplayStatus ( on ); | ||
367 | m_lcd_status = on; | ||
368 | } | ||
369 | } | ||
370 | |||
371 | private: | ||
372 | int m_disable_suspend; | ||
373 | bool m_enable_dim; | ||
374 | bool m_enable_lightoff; | ||
375 | bool m_enable_onlylcdoff; | ||
376 | |||
377 | int m_disable_suspend_ac; | ||
378 | bool m_enable_dim_ac; | ||
379 | bool m_enable_lightoff_ac; | ||
380 | bool m_enable_onlylcdoff_ac; | ||
381 | bool m_disable_apm_ac; | ||
382 | |||
383 | bool m_lcd_status; | ||
384 | |||
385 | int m_backlight_normal; | ||
386 | int m_backlight_current; | ||
387 | bool m_backlight_forcedoff; | ||
388 | }; | ||
389 | 155 | ||
390 | void DesktopApplication::switchLCD ( bool on ) | 156 | void DesktopApplication::switchLCD ( bool on ) |
391 | { | 157 | { |
392 | if ( qApp ) { | 158 | if ( qApp ) { |
393 | DesktopApplication *dapp = (DesktopApplication *) qApp; | 159 | DesktopApplication *dapp = (DesktopApplication *) qApp; |
394 | 160 | ||
395 | if ( dapp-> m_screensaver ) { | 161 | if ( dapp-> m_screensaver ) { |
396 | if ( on ) { | 162 | if ( on ) { |
397 | dapp-> m_screensaver-> setDisplayState ( true ); | 163 | dapp-> m_screensaver-> setDisplayState ( true ); |
398 | dapp-> m_screensaver-> setBacklight ( -3 ); | 164 | dapp-> m_screensaver-> setBacklight ( -3 ); |
399 | } | 165 | } |
400 | else { | 166 | else { |
401 | dapp-> m_screensaver-> setDisplayState ( false ); | 167 | dapp-> m_screensaver-> setDisplayState ( false ); |
402 | } | 168 | } |
403 | } | 169 | } |
404 | } | 170 | } |
405 | } | 171 | } |
406 | 172 | ||
407 | 173 | ||
408 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | 174 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) |
409 | : QPEApplication( argc, argv, appType ) | 175 | : QPEApplication( argc, argv, appType ) |
410 | { | 176 | { |
411 | 177 | ||
412 | m_timer = new QTimer( this ); | 178 | Config cfg( "apm" ); |
413 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); | 179 | cfg.setGroup( "Warnings" ); |
414 | Config cfg( "apm" ); | ||
415 | cfg.setGroup( "Warnings" ); | ||
416 | m_timer->start( 5000 ); | ||
417 | //cfg.readNumEntry( "checkinterval", 10000 ) | 180 | //cfg.readNumEntry( "checkinterval", 10000 ) |
418 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); | 181 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); |
419 | m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); | 182 | m_powerCritical = cfg.readNumEntry( "powercritical", 5 ); |
420 | ps = new PowerStatus; | 183 | |
421 | pa = new DesktopPowerAlerter( 0 ); | 184 | m_ps = new PowerStatus; |
185 | m_ps_last = new PowerStatus; | ||
186 | pa = new DesktopPowerAlerter( 0 ); | ||
422 | 187 | ||
423 | channel = new QCopChannel( "QPE/Desktop", this ); | 188 | m_timer = new QTimer( this ); |
424 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 189 | connect( m_timer, SIGNAL( timeout() ), this, SLOT( apmTimeout() ) ); |
425 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | 190 | m_timer->start( 5000 ); |
191 | |||
192 | channel = new QCopChannel( "QPE/Desktop", this ); | ||
193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | ||
194 | this, SLOT( desktopMessage( const QCString&, const QByteArray& ) ) ); | ||
426 | 195 | ||
427 | channel = new QCopChannel( "QPE/System", this ); | 196 | channel = new QCopChannel( "QPE/System", this ); |
428 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | 197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), |
429 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | 198 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); |
430 | 199 | ||
431 | m_screensaver = new QPEScreenSaver; | 200 | m_screensaver = new OpieScreenSaver ( ); |
432 | 201 | m_screensaver-> setInterval ( -1 ); | |
433 | m_screensaver-> setInterval ( -1 ); | 202 | QWSServer::setScreenSaver( m_screensaver ); |
434 | QWSServer::setScreenSaver( m_screensaver ); | 203 | |
204 | apmTimeout ( ); | ||
435 | } | 205 | } |
436 | 206 | ||
437 | 207 | ||
438 | DesktopApplication::~DesktopApplication() | 208 | DesktopApplication::~DesktopApplication() |
439 | { | 209 | { |
440 | delete ps; | 210 | delete m_ps; |
441 | delete pa; | 211 | delete m_ps_last; |
212 | delete pa; | ||
213 | } | ||
214 | |||
215 | void DesktopApplication::apmTimeout() | ||
216 | { | ||
217 | qpedesktop->checkMemory(); // in case no events are being generated | ||
218 | |||
219 | *m_ps_last = *m_ps; | ||
220 | *m_ps = PowerStatusManager::readStatus(); | ||
221 | |||
222 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) | ||
223 | m_screensaver-> powerStatusChanged ( *m_ps ); | ||
224 | |||
225 | int bat = m_ps-> batteryPercentRemaining ( ); | ||
226 | |||
227 | if ( m_ps_last-> batteryPercentRemaining ( ) != bat ) { | ||
228 | if ( bat <= m_powerCritical ) | ||
229 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); | ||
230 | else if ( bat <= m_powerVeryLow ) | ||
231 | pa->alert( tr( "Battery is running very low." ), 2 ); | ||
232 | |||
233 | |||
234 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) | ||
235 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); | ||
236 | } | ||
442 | } | 237 | } |
443 | 238 | ||
444 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) | 239 | void DesktopApplication::desktopMessage( const QCString &msg, const QByteArray &data ) |
445 | { | 240 | { |
446 | QDataStream stream( data, IO_ReadOnly ); | 241 | QDataStream stream( data, IO_ReadOnly ); |
447 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { | 242 | if ( msg == "keyRegister(int key, QString channel, QString message)" ) { |
448 | int k; | 243 | int k; |
449 | QString c, m; | 244 | QString c, m; |
450 | stream >> k; | 245 | stream >> k; |
451 | stream >> c; | 246 | stream >> c; |
452 | stream >> m; | 247 | stream >> m; |
453 | 248 | ||
454 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); | 249 | qWarning( "KeyRegisterReceived: %i, %s, %s", k, ( const char* ) c, ( const char * ) m ); |
455 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); | 250 | keyRegisterList.append( QCopKeyRegister( k, c, m ) ); |
456 | } | 251 | } |
457 | } | 252 | } |
458 | 253 | ||
459 | 254 | ||
460 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) | 255 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) |
461 | { | 256 | { |
462 | QDataStream stream ( data, IO_ReadOnly ); | 257 | QDataStream stream ( data, IO_ReadOnly ); |
463 | 258 | ||
464 | if ( msg == "setScreenSaverInterval(int)" ) { | 259 | if ( msg == "setScreenSaverInterval(int)" ) { |
465 | int time; | 260 | int time; |
466 | stream >> time; | 261 | stream >> time; |
467 | m_screensaver-> setInterval( time ); | 262 | m_screensaver-> setInterval( time ); |
468 | } | 263 | } |
469 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 264 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
470 | int t1, t2, t3; | 265 | int t1, t2, t3; |
471 | stream >> t1 >> t2 >> t3; | 266 | stream >> t1 >> t2 >> t3; |
472 | m_screensaver-> setIntervals( t1, t2, t3 ); | 267 | m_screensaver-> setIntervals( t1, t2, t3 ); |
473 | } | 268 | } |
474 | else if ( msg == "setScreenSaverIntervalsAC(int,int,int)" ) { | ||
475 | int t1, t2, t3; | ||
476 | stream >> t1 >> t2 >> t3; | ||
477 | m_screensaver-> setIntervalsAC( t1, t2, t3 ); | ||
478 | } | ||
479 | else if ( msg == "setBacklight(int)" ) { | 269 | else if ( msg == "setBacklight(int)" ) { |
480 | int bright; | 270 | int bright; |
481 | stream >> bright; | 271 | stream >> bright; |
482 | m_screensaver-> setBacklight( bright ); | 272 | m_screensaver-> setBacklight( bright ); |
483 | } | 273 | } |
484 | else if ( msg == "setScreenSaverMode(int)" ) { | 274 | else if ( msg == "setScreenSaverMode(int)" ) { |
485 | int mode; | 275 | int mode; |
486 | stream >> mode; | 276 | stream >> mode; |
487 | m_screensaver-> setMode ( mode ); | 277 | m_screensaver-> setMode ( mode ); |
488 | } | 278 | } |
489 | else if ( msg == "reloadPowerWarnSettings()" ) { | 279 | else if ( msg == "reloadPowerWarnSettings()" ) { |
490 | reloadPowerWarnSettings(); | 280 | reloadPowerWarnSettings(); |
491 | } | 281 | } |
492 | else if ( msg == "setDisplayState(int)" ) { | 282 | else if ( msg == "setDisplayState(int)" ) { |
493 | int state; | 283 | int state; |
494 | stream >> state; | 284 | stream >> state; |
495 | m_screensaver-> setDisplayState ( state != 0 ); | 285 | m_screensaver-> setDisplayState ( state != 0 ); |
496 | } | 286 | } |
497 | else if ( msg == "suspend()" ) { | 287 | else if ( msg == "suspend()" ) { |
498 | emit power(); | 288 | emit power(); |
499 | } | 289 | } |
500 | } | 290 | } |
501 | 291 | ||
502 | void DesktopApplication::reloadPowerWarnSettings() { | 292 | void DesktopApplication::reloadPowerWarnSettings() { |
503 | Config cfg( "apm" ); | 293 | Config cfg( "apm" ); |
504 | cfg.setGroup( "Warnings" ); | 294 | cfg.setGroup( "Warnings" ); |
505 | 295 | ||
506 | // m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); | 296 | // m_timer->changeInterval( cfg.readNumEntry( "checkinterval", 10000 ) ); |
507 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); | 297 | m_powerVeryLow = cfg.readNumEntry( "powerverylow", 10 ); |
508 | m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); | 298 | m_powerCritical = cfg.readNumEntry( "powervcritical", 5 ); |
509 | } | 299 | } |
510 | 300 | ||
511 | 301 | ||
512 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | 302 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; |
513 | 303 | ||
514 | #ifdef Q_WS_QWS | 304 | #ifdef Q_WS_QWS |
515 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | 305 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) |
516 | { | 306 | { |
517 | qpedesktop->checkMemory(); | 307 | qpedesktop->checkMemory(); |
518 | 308 | ||
519 | if ( e->type == QWSEvent::Key ) { | 309 | if ( e->type == QWSEvent::Key ) { |
520 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; | 310 | QWSKeyEvent * ke = ( QWSKeyEvent * ) e; |
521 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) | 311 | if ( !loggedin && ke->simpleData.keycode != Key_F34 ) |
522 | return TRUE; | 312 | return TRUE; |
523 | bool press = ke->simpleData.is_press; | 313 | bool press = ke->simpleData.is_press; |
524 | bool autoRepeat = ke->simpleData.is_auto_repeat; | 314 | bool autoRepeat = ke->simpleData.is_auto_repeat; |
525 | 315 | ||
526 | /* | 316 | /* |
527 | app that registers key/message to be sent back to the app, when it doesn't have focus, | 317 | app that registers key/message to be sent back to the app, when it doesn't have focus, |
528 | when user presses key, unless keyboard has been requested from app. | 318 | when user presses key, unless keyboard has been requested from app. |
529 | will not send multiple repeats if user holds key | 319 | will not send multiple repeats if user holds key |
530 | i.e. one shot | 320 | i.e. one shot |
531 | */ | 321 | */ |
532 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { | 322 | if ( !keyRegisterList.isEmpty() && ke->simpleData.keycode !=0 && press) { |
533 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); | 323 | // qDebug("<<<<<<<<<<<<<keycode %d", ke->simpleData.keycode); |
534 | KeyRegisterList::Iterator it; | 324 | KeyRegisterList::Iterator it; |
535 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | 325 | for ( it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { |
536 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { | 326 | if ( ( *it ).getKeyCode() == ke->simpleData.keycode && !autoRepeat && !keyboardGrabbed() ) { |
537 | if ( press ) | 327 | if ( press ) |
538 | qDebug( "press" ); | 328 | qDebug( "press" ); |
539 | else | 329 | else |
540 | qDebug( "release" ); | 330 | qDebug( "release" ); |
541 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); | 331 | QCopEnvelope( ( *it ).getChannel().utf8(), ( *it ).getMessage().utf8() ); |
542 | } | 332 | } |
543 | } | 333 | } |
544 | } | 334 | } |
545 | 335 | ||
546 | if ( !keyboardGrabbed() ) { | 336 | if ( !keyboardGrabbed() ) { |
547 | if ( ke->simpleData.keycode == Key_F9 ) { | 337 | if ( ke->simpleData.keycode == Key_F9 ) { |
548 | if ( press ) | 338 | if ( press ) |
549 | emit datebook(); | 339 | emit datebook(); |
550 | return TRUE; | 340 | return TRUE; |
551 | } | 341 | } |
552 | if ( ke->simpleData.keycode == Key_F10 ) { | 342 | if ( ke->simpleData.keycode == Key_F10 ) { |
553 | if ( !press && cardSendTimer ) { | 343 | if ( !press && cardSendTimer ) { |
554 | emit contacts(); | 344 | emit contacts(); |
555 | delete cardSendTimer; | 345 | delete cardSendTimer; |
556 | } | 346 | } |
557 | else if ( press ) { | 347 | else if ( press ) { |
558 | cardSendTimer = new QTimer(); | 348 | cardSendTimer = new QTimer(); |
559 | cardSendTimer->start( 2000, TRUE ); | 349 | cardSendTimer->start( 2000, TRUE ); |
560 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); | 350 | connect( cardSendTimer, SIGNAL( timeout() ), this, SLOT( sendCard() ) ); |
561 | } | 351 | } |
562 | return TRUE; | 352 | return TRUE; |
563 | } | 353 | } |
564 | 354 | ||
565 | // if ( ke->simpleData.keycode == Key_F11 ) { | 355 | // if ( ke->simpleData.keycode == Key_F11 ) { |
566 | // if ( press ) emit menu(); | 356 | // if ( press ) emit menu(); |
567 | // return TRUE; | 357 | // return TRUE; |
568 | // } | 358 | // } |
569 | 359 | ||
570 | if ( ke->simpleData.keycode == Key_F12 ) { | 360 | if ( ke->simpleData.keycode == Key_F12 ) { |
571 | while ( activePopupWidget() ) | 361 | while ( activePopupWidget() ) |
572 | activePopupWidget() ->close(); | 362 | activePopupWidget() ->close(); |
573 | if ( press ) | 363 | if ( press ) |
574 | emit launch(); | 364 | emit launch(); |
575 | return TRUE; | 365 | return TRUE; |
576 | } | 366 | } |
577 | if ( ke->simpleData.keycode == Key_F13 ) { | 367 | if ( ke->simpleData.keycode == Key_F13 ) { |
578 | if ( press ) | 368 | if ( press ) |
579 | emit email(); | 369 | emit email(); |
580 | return TRUE; | 370 | return TRUE; |
581 | } | 371 | } |
582 | } | 372 | } |
583 | 373 | ||
584 | if ( ke->simpleData.keycode == Key_F34 ) { | 374 | if ( ke->simpleData.keycode == Key_F34 ) { |
585 | if ( press ) | 375 | if ( press ) |
586 | emit power(); | 376 | emit power(); |
587 | return TRUE; | 377 | return TRUE; |
588 | } | 378 | } |
589 | // This was used for the iPAQ PowerButton | 379 | // This was used for the iPAQ PowerButton |
590 | // See main.cpp for new KeyboardFilter | 380 | // See main.cpp for new KeyboardFilter |
591 | // | 381 | // |
592 | // if ( ke->simpleData.keycode == Key_SysReq ) { | 382 | // if ( ke->simpleData.keycode == Key_SysReq ) { |
593 | // if ( press ) emit power(); | 383 | // if ( press ) emit power(); |
594 | // return TRUE; | 384 | // return TRUE; |
595 | // } | 385 | // } |
596 | if ( ke->simpleData.keycode == Key_F35 ) { | 386 | if ( ke->simpleData.keycode == Key_F35 ) { |
597 | if ( press ) | 387 | if ( press ) |
598 | emit backlight(); | 388 | emit backlight(); |
599 | return TRUE; | 389 | return TRUE; |
600 | } | 390 | } |
601 | if ( ke->simpleData.keycode == Key_F32 ) { | 391 | if ( ke->simpleData.keycode == Key_F32 ) { |
602 | if ( press ) | 392 | if ( press ) |
603 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 393 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
604 | return TRUE; | 394 | return TRUE; |
605 | } | 395 | } |
606 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { | 396 | if ( ke->simpleData.keycode == Key_F31 && !ke->simpleData.modifiers ) { |
607 | if ( press ) | 397 | if ( press ) |
608 | emit symbol(); | 398 | emit symbol(); |
609 | return TRUE; | 399 | return TRUE; |
610 | } | 400 | } |
611 | if ( ke->simpleData.keycode == Key_NumLock ) { | 401 | if ( ke->simpleData.keycode == Key_NumLock ) { |
612 | if ( press ) | 402 | if ( press ) |
613 | emit numLockStateToggle(); | 403 | emit numLockStateToggle(); |
614 | } | 404 | } |
615 | if ( ke->simpleData.keycode == Key_CapsLock ) { | 405 | if ( ke->simpleData.keycode == Key_CapsLock ) { |
616 | if ( press ) | 406 | if ( press ) |
617 | emit capsLockStateToggle(); | 407 | emit capsLockStateToggle(); |
618 | } | 408 | } |
619 | if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) | 409 | if ( ( press && !autoRepeat ) || ( !press && autoRepeat ) ) |
620 | qpedesktop->keyClick(); | 410 | qpedesktop->keyClick(); |
621 | } | 411 | } |
622 | else { | 412 | else { |
623 | if ( e->type == QWSEvent::Mouse ) { | 413 | if ( e->type == QWSEvent::Mouse ) { |
624 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | 414 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; |
625 | static bool up = TRUE; | 415 | static bool up = TRUE; |
626 | if ( me->simpleData.state & LeftButton ) { | 416 | if ( me->simpleData.state & LeftButton ) { |
627 | if ( up ) { | 417 | if ( up ) { |
628 | up = FALSE; | 418 | up = FALSE; |
629 | qpedesktop->screenClick(); | 419 | qpedesktop->screenClick(); |
630 | } | 420 | } |
631 | } | 421 | } |
632 | else { | 422 | else { |
633 | up = TRUE; | 423 | up = TRUE; |
634 | } | 424 | } |
635 | } | 425 | } |
636 | } | 426 | } |
637 | 427 | ||
638 | return QPEApplication::qwsEventFilter( e ); | 428 | return QPEApplication::qwsEventFilter( e ); |
639 | } | 429 | } |
640 | #endif | 430 | #endif |
641 | 431 | ||
642 | void DesktopApplication::psTimeout( int batRemaining ) | ||
643 | { | ||
644 | *ps = PowerStatusManager::readStatus(); | ||
645 | |||
646 | // maybe now since its triggered by apm change there might be to few warnings | ||
647 | // if ( ( ps->batteryStatus() == PowerStatus::VeryLow ) ) { | ||
648 | if ( ( batRemaining == m_powerVeryLow ) ) { | ||
649 | pa->alert( tr( "Battery is running very low." ), 2 ); | ||
650 | } | ||
651 | |||
652 | // if ( ps->batteryStatus() == PowerStatus::Critical ) { | ||
653 | if ( batRemaining == m_powerCritical ) { | ||
654 | pa->alert( tr( "Battery level is critical!\n" | ||
655 | "Keep power off until power restored!" ), 1 ); | ||
656 | } | ||
657 | |||
658 | if ( ps->backupBatteryStatus() == PowerStatus::VeryLow ) { | ||
659 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); | ||
660 | } | ||
661 | } | ||
662 | |||
663 | void DesktopApplication::apmTimeout() | ||
664 | { | ||
665 | qpedesktop->checkMemory(); // in case no events are being generated | ||
666 | |||
667 | *ps = PowerStatusManager::readStatus(); | ||
668 | |||
669 | if ( m_currentPowerLevel != ps->batteryPercentRemaining() ) { | ||
670 | // not very nice, since psTimeout parses the again | ||
671 | m_currentPowerLevel = ps->batteryPercentRemaining(); | ||
672 | psTimeout( m_currentPowerLevel ); | ||
673 | } | ||
674 | } | ||
675 | 432 | ||
676 | void DesktopApplication::sendCard() | 433 | void DesktopApplication::sendCard() |
677 | { | 434 | { |
678 | delete cardSendTimer; | 435 | delete cardSendTimer; |
679 | cardSendTimer = 0; | 436 | cardSendTimer = 0; |
680 | QString card = getenv( "HOME" ); | 437 | QString card = getenv( "HOME" ); |
681 | card += "/Applications/addressbook/businesscard.vcf"; | 438 | card += "/Applications/addressbook/businesscard.vcf"; |
682 | 439 | ||
683 | if ( QFile::exists( card ) ) { | 440 | if ( QFile::exists( card ) ) { |
684 | QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); | 441 | QCopEnvelope e( "QPE/Obex", "send(QString,QString,QString)" ); |
685 | QString mimetype = "text/x-vCard"; | 442 | QString mimetype = "text/x-vCard"; |
686 | e << tr( "business card" ) << card << mimetype; | 443 | e << tr( "business card" ) << card << mimetype; |
687 | } | 444 | } |
688 | } | 445 | } |
689 | 446 | ||
690 | #if defined(QPE_HAVE_MEMALERTER) | 447 | #if defined(QPE_HAVE_MEMALERTER) |
691 | QPE_MEMALERTER_IMPL | 448 | QPE_MEMALERTER_IMPL |
692 | #endif | 449 | #endif |
693 | 450 | ||
694 | //=========================================================================== | 451 | //=========================================================================== |
695 | 452 | ||
696 | Desktop::Desktop() : | 453 | Desktop::Desktop() : |
697 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 454 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
698 | qcopBridge( 0 ), | 455 | qcopBridge( 0 ), |
699 | transferServer( 0 ), | 456 | transferServer( 0 ), |
700 | packageSlave( 0 ) | 457 | packageSlave( 0 ) |
701 | { | 458 | { |
702 | qpedesktop = this; | 459 | qpedesktop = this; |
703 | 460 | ||
704 | // bg = new Info( this ); | 461 | // bg = new Info( this ); |
705 | tb = new TaskBar; | 462 | tb = new TaskBar; |
706 | 463 | ||
707 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); | 464 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); |
708 | 465 | ||
709 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); | 466 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); |
710 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); | 467 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); |
711 | 468 | ||
712 | int displayw = qApp->desktop() ->width(); | 469 | int displayw = qApp->desktop() ->width(); |
713 | int displayh = qApp->desktop() ->height(); | 470 | int displayh = qApp->desktop() ->height(); |
714 | 471 | ||
715 | 472 | ||
716 | QSize sz = tb->sizeHint(); | 473 | QSize sz = tb->sizeHint(); |
717 | 474 | ||
718 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 475 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
719 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 476 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
720 | 477 | ||
721 | tb->show(); | 478 | tb->show(); |
722 | launcher->showMaximized(); | 479 | launcher->showMaximized(); |
723 | launcher->show(); | 480 | launcher->show(); |
724 | launcher->raise(); | 481 | launcher->raise(); |
725 | #if defined(QPE_HAVE_MEMALERTER) | 482 | #if defined(QPE_HAVE_MEMALERTER) |
726 | 483 | ||
727 | initMemalerter(); | 484 | initMemalerter(); |
728 | #endif | 485 | #endif |
729 | // start services | 486 | // start services |
730 | startTransferServer(); | 487 | startTransferServer(); |
731 | ( void ) new IrServer( this ); | 488 | ( void ) new IrServer( this ); |
732 | rereadVolumes(); | 489 | rereadVolumes(); |
733 | 490 | ||
734 | packageSlave = new PackageSlave( this ); | 491 | packageSlave = new PackageSlave( this ); |
735 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); | 492 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); |
736 | 493 | ||
737 | qApp->installEventFilter( this ); | 494 | qApp->installEventFilter( this ); |
738 | 495 | ||
739 | qApp-> setMainWidget ( launcher ); | 496 | qApp-> setMainWidget ( launcher ); |
740 | } | 497 | } |
741 | 498 | ||
742 | void Desktop::show() | 499 | void Desktop::show() |
743 | { | 500 | { |
744 | login( TRUE ); | 501 | login( TRUE ); |
745 | QWidget::show(); | 502 | QWidget::show(); |
746 | } | 503 | } |
747 | 504 | ||
748 | Desktop::~Desktop() | 505 | Desktop::~Desktop() |
749 | { | 506 | { |
750 | delete launcher; | 507 | delete launcher; |
751 | delete tb; | 508 | delete tb; |
752 | delete qcopBridge; | 509 | delete qcopBridge; |
753 | delete transferServer; | 510 | delete transferServer; |
754 | } | 511 | } |
755 | 512 | ||
756 | bool Desktop::recoverMemory() | 513 | bool Desktop::recoverMemory() |
757 | { | 514 | { |
758 | return tb->recoverMemory(); | 515 | return tb->recoverMemory(); |
759 | } | 516 | } |
760 | 517 | ||
761 | void Desktop::checkMemory() | 518 | void Desktop::checkMemory() |
762 | { | 519 | { |
763 | #if defined(QPE_HAVE_MEMALERTER) | 520 | #if defined(QPE_HAVE_MEMALERTER) |
764 | static bool ignoreNormal = FALSE; | 521 | static bool ignoreNormal = FALSE; |
765 | static bool existingMessage = FALSE; | 522 | static bool existingMessage = FALSE; |
766 | 523 | ||
767 | if ( existingMessage ) | 524 | if ( existingMessage ) |
768 | return ; // don't show a second message while still on first | 525 | return ; // don't show a second message while still on first |
769 | 526 | ||
770 | existingMessage = TRUE; | 527 | existingMessage = TRUE; |
771 | switch ( memstate ) { | 528 | switch ( memstate ) { |
772 | case Unknown: | 529 | case Unknown: |
773 | break; | 530 | break; |
774 | case Low: | 531 | case Low: |
775 | memstate = Unknown; | 532 | memstate = Unknown; |
776 | if ( recoverMemory() ) | 533 | if ( recoverMemory() ) |
777 | ignoreNormal = TRUE; | 534 | ignoreNormal = TRUE; |
778 | else | 535 | else |
779 | QMessageBox::warning( 0 , "Memory Status", | 536 | QMessageBox::warning( 0 , "Memory Status", |
780 | "The memory smacks of shortage. \n" | 537 | "The memory smacks of shortage. \n" |
781 | "Please save data. " ); | 538 | "Please save data. " ); |
782 | break; | 539 | break; |
783 | case Normal: | 540 | case Normal: |
784 | memstate = Unknown; | 541 | memstate = Unknown; |
785 | if ( ignoreNormal ) | 542 | if ( ignoreNormal ) |
786 | ignoreNormal = FALSE; | 543 | ignoreNormal = FALSE; |
787 | // else | 544 | // else |
788 | // QMessageBox::information ( 0 , "Memory Status", | 545 | // QMessageBox::information ( 0 , "Memory Status", |
789 | // "There is enough memory again." ); | 546 | // "There is enough memory again." ); |
790 | break; | 547 | break; |
791 | case VeryLow: | 548 | case VeryLow: |
792 | memstate = Unknown; | 549 | memstate = Unknown; |
793 | QMessageBox::critical( 0 , "Memory Status", | 550 | QMessageBox::critical( 0 , "Memory Status", |
794 | "The memory is very low. \n" | 551 | "The memory is very low. \n" |
795 | "Please end this application \n" | 552 | "Please end this application \n" |
796 | "immediately." ); | 553 | "immediately." ); |
797 | recoverMemory(); | 554 | recoverMemory(); |
798 | } | 555 | } |
799 | existingMessage = FALSE; | 556 | existingMessage = FALSE; |
800 | #endif | 557 | #endif |
801 | } | 558 | } |
802 | 559 | ||
803 | static bool isVisibleWindow( int wid ) | 560 | static bool isVisibleWindow( int wid ) |
804 | { | 561 | { |
805 | #ifdef QWS | 562 | #ifdef QWS |
806 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 563 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
807 | QWSWindow* w; | 564 | QWSWindow* w; |
808 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 565 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
809 | if ( w->winId() == wid ) | 566 | if ( w->winId() == wid ) |
810 | return !w->isFullyObscured(); | 567 | return !w->isFullyObscured(); |
811 | } | 568 | } |
812 | #endif | 569 | #endif |
813 | return FALSE; | 570 | return FALSE; |
814 | } | 571 | } |
815 | 572 | ||
816 | static bool hasVisibleWindow( const QString& clientname ) | 573 | static bool hasVisibleWindow( const QString& clientname ) |
817 | { | 574 | { |
818 | #ifdef QWS | 575 | #ifdef QWS |
819 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 576 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
820 | QWSWindow* w; | 577 | QWSWindow* w; |
821 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | 578 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { |
822 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) | 579 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) |
823 | return TRUE; | 580 | return TRUE; |
824 | } | 581 | } |
825 | #endif | 582 | #endif |
826 | return FALSE; | 583 | return FALSE; |
827 | } | 584 | } |
828 | 585 | ||
829 | void Desktop::raiseLauncher() | 586 | void Desktop::raiseLauncher() |
830 | { | 587 | { |
831 | Config cfg( "qpe" ); //F12 'Home' | 588 | Config cfg( "qpe" ); //F12 'Home' |
832 | cfg.setGroup( "AppsKey" ); | 589 | cfg.setGroup( "AppsKey" ); |
833 | QString tempItem; | 590 | QString tempItem; |
834 | tempItem = cfg.readEntry( "Middle", "Home" ); | 591 | tempItem = cfg.readEntry( "Middle", "Home" ); |
835 | if ( tempItem == "Home" || tempItem.isEmpty() ) { | 592 | if ( tempItem == "Home" || tempItem.isEmpty() ) { |
836 | home ( ); | 593 | home ( ); |
837 | } | 594 | } |
838 | else { | 595 | else { |
839 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 596 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
840 | e << tempItem; | 597 | e << tempItem; |
841 | } | 598 | } |
842 | } | 599 | } |
843 | 600 | ||
844 | void Desktop::home ( ) | 601 | void Desktop::home ( ) |
845 | { | 602 | { |
846 | if ( isVisibleWindow( launcher->winId() ) ) | 603 | if ( isVisibleWindow( launcher->winId() ) ) |
847 | launcher->nextView(); | 604 | launcher->nextView(); |
848 | else | 605 | else |
849 | launcher->raise(); | 606 | launcher->raise(); |
850 | } | 607 | } |
851 | 608 | ||
852 | void Desktop::executeOrModify( const QString& appLnkFile ) | 609 | void Desktop::executeOrModify( const QString& appLnkFile ) |
853 | { | 610 | { |
854 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); | 611 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); |
855 | if ( lnk.isValid() ) { | 612 | if ( lnk.isValid() ) { |
856 | QCString app = lnk.exec().utf8(); | 613 | QCString app = lnk.exec().utf8(); |
857 | Global::terminateBuiltin( "calibrate" ); | 614 | Global::terminateBuiltin( "calibrate" ); |
858 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { | 615 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { |
859 | // MRUList::addTask( &lnk ); | 616 | // MRUList::addTask( &lnk ); |
860 | if ( hasVisibleWindow( app ) ) | 617 | if ( hasVisibleWindow( app ) ) |
861 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); | 618 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); |
862 | else | 619 | else |
863 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); | 620 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); |
864 | } | 621 | } |
865 | else { | 622 | else { |
866 | lnk.execute(); | 623 | lnk.execute(); |
867 | } | 624 | } |
868 | } | 625 | } |
869 | } | 626 | } |
870 | 627 | ||
871 | void Desktop::raiseDatebook() | 628 | void Desktop::raiseDatebook() |
872 | { | 629 | { |
873 | Config cfg( "qpe" ); //F9 'Activity' | 630 | Config cfg( "qpe" ); //F9 'Activity' |
874 | cfg.setGroup( "AppsKey" ); | 631 | cfg.setGroup( "AppsKey" ); |
875 | QString tempItem; | 632 | QString tempItem; |
876 | tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); | 633 | tempItem = cfg.readEntry( "LeftEnd" , "Calendar" ); |
877 | if ( tempItem == "Calendar" || tempItem.isEmpty() ) { | 634 | if ( tempItem == "Calendar" || tempItem.isEmpty() ) { |
878 | tempItem = "datebook"; | 635 | tempItem = "datebook"; |
879 | } | 636 | } |
880 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 637 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
881 | e << tempItem; | 638 | e << tempItem; |
882 | } | 639 | } |
883 | 640 | ||
884 | void Desktop::raiseContacts() | 641 | void Desktop::raiseContacts() |
885 | { | 642 | { |
886 | Config cfg( "qpe" ); //F10, 'Contacts' | 643 | Config cfg( "qpe" ); //F10, 'Contacts' |
887 | cfg.setGroup( "AppsKey" ); | 644 | cfg.setGroup( "AppsKey" ); |
888 | QString tempItem; | 645 | QString tempItem; |
889 | tempItem = cfg.readEntry( "Left2nd", "Address Book" ); | 646 | tempItem = cfg.readEntry( "Left2nd", "Address Book" ); |
890 | if ( tempItem == "Address Book" || tempItem.isEmpty() ) { | 647 | if ( tempItem == "Address Book" || tempItem.isEmpty() ) { |
891 | tempItem = "addressbook"; | 648 | tempItem = "addressbook"; |
892 | } | 649 | } |
893 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 650 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
894 | e << tempItem; | 651 | e << tempItem; |
895 | } | 652 | } |
896 | 653 | ||
897 | void Desktop::raiseMenu() | 654 | void Desktop::raiseMenu() |
898 | { | 655 | { |
899 | Config cfg( "qpe" ); //F11, 'Menu | 656 | Config cfg( "qpe" ); //F11, 'Menu |
900 | cfg.setGroup( "AppsKey" ); | 657 | cfg.setGroup( "AppsKey" ); |
901 | QString tempItem; | 658 | QString tempItem; |
902 | tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); | 659 | tempItem = cfg.readEntry( "Right2nd" , "Popup Menu" ); |
903 | if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { | 660 | if ( tempItem == "Popup Menu" || tempItem.isEmpty() ) { |
904 | Global::terminateBuiltin( "calibrate" ); | 661 | Global::terminateBuiltin( "calibrate" ); |
905 | tb->startMenu() ->launch(); | 662 | tb->startMenu() ->launch(); |
906 | } | 663 | } |
907 | else { | 664 | else { |
908 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 665 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
909 | e << tempItem; | 666 | e << tempItem; |
910 | } | 667 | } |
911 | } | 668 | } |
912 | 669 | ||
913 | void Desktop::raiseEmail() | 670 | void Desktop::raiseEmail() |
914 | { | 671 | { |
915 | Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 | 672 | Config cfg( "qpe" ); //F13, 'Mail' // only in zaurus, on ipaq mail key is F11 |
916 | cfg.setGroup( "AppsKey" ); | 673 | cfg.setGroup( "AppsKey" ); |
917 | QString tempItem; | 674 | QString tempItem; |
918 | tempItem = cfg.readEntry( "RightEnd", "Mail" ); | 675 | tempItem = cfg.readEntry( "RightEnd", "Mail" ); |
919 | if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { | 676 | if ( tempItem == "Mail" || tempItem == "qtmail" || tempItem.isEmpty() ) { |
920 | tempItem = "mail"; | 677 | tempItem = "mail"; |
921 | } | 678 | } |
922 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 679 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
923 | e << tempItem; | 680 | e << tempItem; |
924 | } | 681 | } |
925 | 682 | ||
926 | // autoStarts apps on resume and start | 683 | // autoStarts apps on resume and start |
927 | void Desktop::execAutoStart() | 684 | void Desktop::execAutoStart() |
928 | { | 685 | { |
929 | QString appName; | 686 | QString appName; |
930 | int delay; | 687 | int delay; |
931 | QDateTime now = QDateTime::currentDateTime(); | 688 | QDateTime now = QDateTime::currentDateTime(); |
932 | Config cfg( "autostart" ); | 689 | Config cfg( "autostart" ); |
933 | cfg.setGroup( "AutoStart" ); | 690 | cfg.setGroup( "AutoStart" ); |
934 | appName = cfg.readEntry( "Apps", "" ); | 691 | appName = cfg.readEntry( "Apps", "" ); |
935 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); | 692 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); |
936 | // If the time between suspend and resume was longer then the | 693 | // If the time between suspend and resume was longer then the |
937 | // value saved as delay, start the app | 694 | // value saved as delay, start the app |
938 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 695 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
939 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 696 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
940 | e << QString( appName ); | 697 | e << QString( appName ); |
941 | } | 698 | } |
942 | } | 699 | } |
943 | 700 | ||
944 | #if defined(QPE_HAVE_TOGGLELIGHT) | 701 | #if defined(QPE_HAVE_TOGGLELIGHT) |
945 | #include <qpe/config.h> | 702 | #include <qpe/config.h> |
946 | 703 | ||
947 | #include <sys/ioctl.h> | 704 | #include <sys/ioctl.h> |
948 | #include <sys/types.h> | 705 | #include <sys/types.h> |
949 | #include <fcntl.h> | 706 | #include <fcntl.h> |
950 | #include <unistd.h> | 707 | #include <unistd.h> |
951 | #include <errno.h> | 708 | #include <errno.h> |
952 | #include <linux/ioctl.h> | 709 | #include <linux/ioctl.h> |
953 | #include <time.h> | 710 | #include <time.h> |
954 | #endif | 711 | #endif |
955 | 712 | ||
956 | 713 | ||
957 | void Desktop::togglePower() | 714 | void Desktop::togglePower() |
958 | { | 715 | { |
959 | static bool excllock = false; | 716 | static bool excllock = false; |
960 | 717 | ||
961 | qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); | 718 | qDebug ( "togglePower (locked == %d)", excllock ? 1 : 0 ); |
962 | 719 | ||
963 | if ( excllock ) | 720 | if ( excllock ) |
964 | return; | 721 | return; |
965 | 722 | ||
966 | excllock = true; | 723 | excllock = true; |
967 | 724 | ||
968 | bool wasloggedin = loggedin; | 725 | bool wasloggedin = loggedin; |
969 | loggedin = 0; | 726 | loggedin = 0; |
970 | suspendTime = QDateTime::currentDateTime(); | 727 | suspendTime = QDateTime::currentDateTime(); |
971 | 728 | ||
972 | #ifdef QWS | 729 | #ifdef QWS |
973 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { | 730 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { |
974 | // Should use a big black window instead. | 731 | // Should use a big black window instead. |
975 | // But this would not show up fast enough | 732 | // But this would not show up fast enough |
976 | QGfx *g = qt_screen-> screenGfx ( ); | 733 | QGfx *g = qt_screen-> screenGfx ( ); |
977 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 734 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
978 | delete g; | 735 | delete g; |
979 | } | 736 | } |
980 | #endif | 737 | #endif |
981 | 738 | ||
982 | ODevice::inst ( )-> suspend ( ); | 739 | ODevice::inst ( )-> suspend ( ); |
983 | 740 | ||
984 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call | 741 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call |
985 | QWSServer::screenSaverActivate ( false ); | 742 | QWSServer::screenSaverActivate ( false ); |
986 | 743 | ||
987 | { | 744 | { |
988 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 745 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
989 | } | 746 | } |
990 | 747 | ||
991 | if ( wasloggedin ) | 748 | if ( wasloggedin ) |
992 | login ( true ); | 749 | login ( true ); |
993 | 750 | ||
994 | execAutoStart(); | 751 | execAutoStart(); |
995 | //qcopBridge->closeOpenConnections(); | 752 | //qcopBridge->closeOpenConnections(); |
996 | 753 | ||
997 | excllock = false; | 754 | excllock = false; |
998 | } | 755 | } |
999 | 756 | ||
1000 | void Desktop::toggleLight() | 757 | void Desktop::toggleLight() |
1001 | { | 758 | { |
1002 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); | 759 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); |
1003 | e << -2; // toggle | 760 | e << -2; // toggle |
1004 | } | 761 | } |
1005 | 762 | ||
1006 | void Desktop::toggleSymbolInput() | 763 | void Desktop::toggleSymbolInput() |
1007 | { | 764 | { |
1008 | tb->toggleSymbolInput(); | 765 | tb->toggleSymbolInput(); |
1009 | } | 766 | } |
1010 | 767 | ||
1011 | void Desktop::toggleNumLockState() | 768 | void Desktop::toggleNumLockState() |
1012 | { | 769 | { |
1013 | tb->toggleNumLockState(); | 770 | tb->toggleNumLockState(); |
1014 | } | 771 | } |
1015 | 772 | ||
1016 | void Desktop::toggleCapsLockState() | 773 | void Desktop::toggleCapsLockState() |
1017 | { | 774 | { |
1018 | tb->toggleCapsLockState(); | 775 | tb->toggleCapsLockState(); |
1019 | } | 776 | } |
1020 | 777 | ||
1021 | void Desktop::styleChange( QStyle &s ) | 778 | void Desktop::styleChange( QStyle &s ) |
1022 | { | 779 | { |
1023 | QWidget::styleChange( s ); | 780 | QWidget::styleChange( s ); |
1024 | int displayw = qApp->desktop() ->width(); | 781 | int displayw = qApp->desktop() ->width(); |
1025 | int displayh = qApp->desktop() ->height(); | 782 | int displayh = qApp->desktop() ->height(); |
1026 | 783 | ||
1027 | QSize sz = tb->sizeHint(); | 784 | QSize sz = tb->sizeHint(); |
1028 | 785 | ||
1029 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | 786 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); |
1030 | } | 787 | } |
1031 | 788 | ||
1032 | void DesktopApplication::shutdown() | 789 | void DesktopApplication::shutdown() |
1033 | { | 790 | { |
1034 | if ( type() != GuiServer ) | 791 | if ( type() != GuiServer ) |
1035 | return ; | 792 | return ; |
1036 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 793 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
1037 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), | 794 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), |
1038 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); | 795 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); |
1039 | sd->showMaximized(); | 796 | sd->showMaximized(); |
1040 | } | 797 | } |
1041 | 798 | ||
1042 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) | 799 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) |
1043 | { | 800 | { |
1044 | switch ( t ) { | 801 | switch ( t ) { |
1045 | case ShutdownImpl::ShutdownSystem: | 802 | case ShutdownImpl::ShutdownSystem: |
1046 | execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); | 803 | execlp( "shutdown", "shutdown", "-h", "now", ( void* ) 0 ); |
1047 | break; | 804 | break; |
1048 | case ShutdownImpl::RebootSystem: | 805 | case ShutdownImpl::RebootSystem: |
1049 | execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); | 806 | execlp( "shutdown", "shutdown", "-r", "now", ( void* ) 0 ); |
1050 | break; | 807 | break; |
1051 | case ShutdownImpl::RestartDesktop: | 808 | case ShutdownImpl::RestartDesktop: |
1052 | restart(); | 809 | restart(); |
1053 | break; | 810 | break; |
1054 | case ShutdownImpl::TerminateDesktop: | 811 | case ShutdownImpl::TerminateDesktop: |
1055 | prepareForTermination( FALSE ); | 812 | prepareForTermination( FALSE ); |
1056 | 813 | ||
1057 | // This is a workaround for a Qt bug | 814 | // This is a workaround for a Qt bug |
1058 | // clipboard applet has to stop its poll timer, or Qt/E | 815 | // clipboard applet has to stop its poll timer, or Qt/E |
diff --git a/core/launcher/desktop.h b/core/launcher/desktop.h index 8308811..f6059b8 100644 --- a/core/launcher/desktop.h +++ b/core/launcher/desktop.h | |||
@@ -1,154 +1,153 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
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 | 20 | ||
21 | #ifndef __DESKTOP_H__ | 21 | #ifndef __DESKTOP_H__ |
22 | #define __DESKTOP_H__ | 22 | #define __DESKTOP_H__ |
23 | 23 | ||
24 | 24 | ||
25 | #include "shutdownimpl.h" | 25 | #include "shutdownimpl.h" |
26 | 26 | ||
27 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
28 | 28 | ||
29 | #include <qwidget.h> | 29 | #include <qwidget.h> |
30 | #include <qdatetime.h> | 30 | #include <qdatetime.h> |
31 | 31 | ||
32 | class Background; | 32 | class Background; |
33 | class Launcher; | 33 | class Launcher; |
34 | class TaskBar; | 34 | class TaskBar; |
35 | class PowerStatus; | 35 | class PowerStatus; |
36 | class QCopBridge; | 36 | class QCopBridge; |
37 | class TransferServer; | 37 | class TransferServer; |
38 | class DesktopPowerAlerter; | 38 | class DesktopPowerAlerter; |
39 | class PackageSlave; | 39 | class PackageSlave; |
40 | class QPEScreenSaver; | 40 | class OpieScreenSaver; |
41 | 41 | ||
42 | class DesktopApplication : public QPEApplication | 42 | class DesktopApplication : public QPEApplication |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | public: | 45 | public: |
46 | DesktopApplication( int& argc, char **argv, Type t ); | 46 | DesktopApplication( int& argc, char **argv, Type t ); |
47 | ~DesktopApplication(); | 47 | ~DesktopApplication(); |
48 | 48 | ||
49 | static void switchLCD ( bool on ); // only for togglePower in Desktop | 49 | static void switchLCD ( bool on ); // only for togglePower in Desktop |
50 | 50 | ||
51 | signals: | 51 | signals: |
52 | void menu(); | 52 | void menu(); |
53 | void home(); | 53 | void home(); |
54 | void datebook(); | 54 | void datebook(); |
55 | void contacts(); | 55 | void contacts(); |
56 | void launch(); | 56 | void launch(); |
57 | void email(); | 57 | void email(); |
58 | void backlight(); | 58 | void backlight(); |
59 | void power(); | 59 | void power(); |
60 | void symbol(); | 60 | void symbol(); |
61 | void numLockStateToggle(); | 61 | void numLockStateToggle(); |
62 | void capsLockStateToggle(); | 62 | void capsLockStateToggle(); |
63 | void prepareForRestart(); | 63 | void prepareForRestart(); |
64 | 64 | ||
65 | protected: | 65 | protected: |
66 | #ifdef Q_WS_QWS | 66 | #ifdef Q_WS_QWS |
67 | 67 | ||
68 | bool qwsEventFilter( QWSEvent * ); | 68 | bool qwsEventFilter( QWSEvent * ); |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | void shutdown(); | 71 | void shutdown(); |
72 | void restart(); | 72 | void restart(); |
73 | 73 | ||
74 | public slots: | 74 | public slots: |
75 | virtual void desktopMessage ( const QCString &msg, const QByteArray &data ); | 75 | virtual void desktopMessage ( const QCString &msg, const QByteArray &data ); |
76 | virtual void systemMessage ( const QCString &msg, const QByteArray &data ); | 76 | virtual void systemMessage ( const QCString &msg, const QByteArray &data ); |
77 | 77 | ||
78 | protected slots: | 78 | protected slots: |
79 | void shutdown( ShutdownImpl::Type ); | 79 | void shutdown( ShutdownImpl::Type ); |
80 | void psTimeout( int ); | ||
81 | void apmTimeout(); | 80 | void apmTimeout(); |
82 | void sendCard(); | 81 | void sendCard(); |
83 | private: | 82 | private: |
84 | void reloadPowerWarnSettings(); | 83 | void reloadPowerWarnSettings(); |
85 | DesktopPowerAlerter *pa; | 84 | DesktopPowerAlerter *pa; |
86 | PowerStatus *ps; | 85 | PowerStatus *m_ps, *m_ps_last; |
87 | QTimer *cardSendTimer; | 86 | QTimer *cardSendTimer; |
88 | QCopChannel *channel; | 87 | QCopChannel *channel; |
89 | QPEScreenSaver *m_screensaver; | 88 | OpieScreenSaver *m_screensaver; |
90 | QTimer * m_timer; | 89 | QTimer * m_timer; |
91 | int m_powerVeryLow; | 90 | int m_powerVeryLow; |
92 | int m_powerCritical; | 91 | int m_powerCritical; |
93 | int m_currentPowerLevel; | 92 | int m_currentPowerLevel; |
94 | }; | 93 | }; |
95 | 94 | ||
96 | 95 | ||
97 | class Desktop : public QWidget | 96 | class Desktop : public QWidget |
98 | { | 97 | { |
99 | Q_OBJECT | 98 | Q_OBJECT |
100 | public: | 99 | public: |
101 | Desktop(); | 100 | Desktop(); |
102 | ~Desktop(); | 101 | ~Desktop(); |
103 | 102 | ||
104 | static bool screenLocked(); | 103 | static bool screenLocked(); |
105 | 104 | ||
106 | void show(); | 105 | void show(); |
107 | void checkMemory(); | 106 | void checkMemory(); |
108 | 107 | ||
109 | void keyClick(); | 108 | void keyClick(); |
110 | void screenClick(); | 109 | void screenClick(); |
111 | static void soundAlarm(); | 110 | static void soundAlarm(); |
112 | 111 | ||
113 | public slots: | 112 | public slots: |
114 | void raiseDatebook(); | 113 | void raiseDatebook(); |
115 | void raiseContacts(); | 114 | void raiseContacts(); |
116 | void raiseMenu(); | 115 | void raiseMenu(); |
117 | void raiseLauncher(); | 116 | void raiseLauncher(); |
118 | void raiseEmail(); | 117 | void raiseEmail(); |
119 | void execAutoStart(); | 118 | void execAutoStart(); |
120 | void togglePower(); | 119 | void togglePower(); |
121 | void toggleLight(); | 120 | void toggleLight(); |
122 | void toggleNumLockState(); | 121 | void toggleNumLockState(); |
123 | void toggleCapsLockState(); | 122 | void toggleCapsLockState(); |
124 | void toggleSymbolInput(); | 123 | void toggleSymbolInput(); |
125 | void terminateServers(); | 124 | void terminateServers(); |
126 | void rereadVolumes(); | 125 | void rereadVolumes(); |
127 | 126 | ||
128 | void home ( ); | 127 | void home ( ); |
129 | 128 | ||
130 | protected: | 129 | protected: |
131 | void executeOrModify( const QString& appLnkFile ); | 130 | void executeOrModify( const QString& appLnkFile ); |
132 | void styleChange( QStyle & ); | 131 | void styleChange( QStyle & ); |
133 | void timerEvent( QTimerEvent *e ); | 132 | void timerEvent( QTimerEvent *e ); |
134 | bool eventFilter( QObject *, QEvent * ); | 133 | bool eventFilter( QObject *, QEvent * ); |
135 | 134 | ||
136 | QWidget *bg; | 135 | QWidget *bg; |
137 | Launcher *launcher; | 136 | Launcher *launcher; |
138 | TaskBar *tb; | 137 | TaskBar *tb; |
139 | 138 | ||
140 | private: | 139 | private: |
141 | void startTransferServer(); | 140 | void startTransferServer(); |
142 | bool recoverMemory(); | 141 | bool recoverMemory(); |
143 | 142 | ||
144 | QCopBridge *qcopBridge; | 143 | QCopBridge *qcopBridge; |
145 | TransferServer *transferServer; | 144 | TransferServer *transferServer; |
146 | PackageSlave *packageSlave; | 145 | PackageSlave *packageSlave; |
147 | 146 | ||
148 | QDateTime suspendTime; | 147 | QDateTime suspendTime; |
149 | bool keyclick, touchclick, alarmsound; | 148 | bool keyclick, touchclick, alarmsound; |
150 | }; | 149 | }; |
151 | 150 | ||
152 | 151 | ||
153 | #endif // __DESKTOP_H__ | 152 | #endif // __DESKTOP_H__ |
154 | 153 | ||
diff --git a/core/launcher/launcher.pro b/core/launcher/launcher.pro index 95642af..83f8b5c 100644 --- a/core/launcher/launcher.pro +++ b/core/launcher/launcher.pro | |||
@@ -1,118 +1,120 @@ | |||
1 | TEMPLATE= app | 1 | TEMPLATE= app |
2 | CONFIG = qt warn_on release | 2 | CONFIG = qt warn_on release |
3 | DESTDIR = ../../bin | 3 | DESTDIR = ../../bin |
4 | HEADERS = background.h \ | 4 | HEADERS = background.h \ |
5 | desktop.h \ | 5 | desktop.h \ |
6 | screensaver.h \ | ||
6 | qprocess.h \ | 7 | qprocess.h \ |
7 | mediummountgui.h \ | 8 | mediummountgui.h \ |
8 | info.h \ | 9 | info.h \ |
9 | appicons.h \ | 10 | appicons.h \ |
10 | taskbar.h \ | 11 | taskbar.h \ |
11 | sidething.h \ | 12 | sidething.h \ |
12 | runningappbar.h \ | 13 | runningappbar.h \ |
13 | stabmon.h \ | 14 | stabmon.h \ |
14 | inputmethods.h \ | 15 | inputmethods.h \ |
15 | systray.h \ | 16 | systray.h \ |
16 | wait.h \ | 17 | wait.h \ |
17 | shutdownimpl.h \ | 18 | shutdownimpl.h \ |
18 | launcher.h \ | 19 | launcher.h \ |
19 | launcherview.h \ | 20 | launcherview.h \ |
20 | ../../core/apps/calibrate/calibrate.h \ | 21 | ../../core/apps/calibrate/calibrate.h \ |
21 | startmenu.h \ | 22 | startmenu.h \ |
22 | transferserver.h \ | 23 | transferserver.h \ |
23 | qcopbridge.h \ | 24 | qcopbridge.h \ |
24 | packageslave.h \ | 25 | packageslave.h \ |
25 | irserver.h \ | 26 | irserver.h \ |
26 | ../../rsync/buf.h \ | 27 | ../../rsync/buf.h \ |
27 | ../../rsync/checksum.h \ | 28 | ../../rsync/checksum.h \ |
28 | ../../rsync/command.h \ | 29 | ../../rsync/command.h \ |
29 | ../../rsync/emit.h \ | 30 | ../../rsync/emit.h \ |
30 | ../../rsync/job.h \ | 31 | ../../rsync/job.h \ |
31 | ../../rsync/netint.h \ | 32 | ../../rsync/netint.h \ |
32 | ../../rsync/protocol.h \ | 33 | ../../rsync/protocol.h \ |
33 | ../../rsync/prototab.h \ | 34 | ../../rsync/prototab.h \ |
34 | ../../rsync/rsync.h \ | 35 | ../../rsync/rsync.h \ |
35 | ../../rsync/search.h \ | 36 | ../../rsync/search.h \ |
36 | ../../rsync/stream.h \ | 37 | ../../rsync/stream.h \ |
37 | ../../rsync/sumset.h \ | 38 | ../../rsync/sumset.h \ |
38 | ../../rsync/trace.h \ | 39 | ../../rsync/trace.h \ |
39 | ../../rsync/types.h \ | 40 | ../../rsync/types.h \ |
40 | ../../rsync/util.h \ | 41 | ../../rsync/util.h \ |
41 | ../../rsync/whole.h \ | 42 | ../../rsync/whole.h \ |
42 | ../../rsync/config_rsync.h \ | 43 | ../../rsync/config_rsync.h \ |
43 | ../../rsync/qrsync.h \ | 44 | ../../rsync/qrsync.h \ |
44 | quicklauncher.h | 45 | quicklauncher.h |
45 | SOURCES = background.cpp \ | 46 | SOURCES = background.cpp \ |
46 | desktop.cpp \ | 47 | desktop.cpp \ |
48 | screensaver.cpp \ | ||
47 | mediummountgui.cpp \ | 49 | mediummountgui.cpp \ |
48 | qprocess.cpp qprocess_unix.cpp \ | 50 | qprocess.cpp qprocess_unix.cpp \ |
49 | info.cpp \ | 51 | info.cpp \ |
50 | appicons.cpp \ | 52 | appicons.cpp \ |
51 | taskbar.cpp \ | 53 | taskbar.cpp \ |
52 | sidething.cpp \ | 54 | sidething.cpp \ |
53 | runningappbar.cpp \ | 55 | runningappbar.cpp \ |
54 | stabmon.cpp \ | 56 | stabmon.cpp \ |
55 | inputmethods.cpp \ | 57 | inputmethods.cpp \ |
56 | systray.cpp \ | 58 | systray.cpp \ |
57 | wait.cpp \ | 59 | wait.cpp \ |
58 | shutdownimpl.cpp \ | 60 | shutdownimpl.cpp \ |
59 | launcher.cpp \ | 61 | launcher.cpp \ |
60 | launcherview.cpp \ | 62 | launcherview.cpp \ |
61 | ../../core/apps/calibrate/calibrate.cpp \ | 63 | ../../core/apps/calibrate/calibrate.cpp \ |
62 | transferserver.cpp \ | 64 | transferserver.cpp \ |
63 | packageslave.cpp \ | 65 | packageslave.cpp \ |
64 | irserver.cpp \ | 66 | irserver.cpp \ |
65 | qcopbridge.cpp \ | 67 | qcopbridge.cpp \ |
66 | startmenu.cpp \ | 68 | startmenu.cpp \ |
67 | main.cpp \ | 69 | main.cpp \ |
68 | ../../rsync/base64.c \ | 70 | ../../rsync/base64.c \ |
69 | ../../rsync/buf.c \ | 71 | ../../rsync/buf.c \ |
70 | ../../rsync/checksum.c \ | 72 | ../../rsync/checksum.c \ |
71 | ../../rsync/command.c \ | 73 | ../../rsync/command.c \ |
72 | ../../rsync/delta.c \ | 74 | ../../rsync/delta.c \ |
73 | ../../rsync/emit.c \ | 75 | ../../rsync/emit.c \ |
74 | ../../rsync/hex.c \ | 76 | ../../rsync/hex.c \ |
75 | ../../rsync/job.c \ | 77 | ../../rsync/job.c \ |
76 | ../../rsync/mdfour.c \ | 78 | ../../rsync/mdfour.c \ |
77 | ../../rsync/mksum.c \ | 79 | ../../rsync/mksum.c \ |
78 | ../../rsync/msg.c \ | 80 | ../../rsync/msg.c \ |
79 | ../../rsync/netint.c \ | 81 | ../../rsync/netint.c \ |
80 | ../../rsync/patch.c \ | 82 | ../../rsync/patch.c \ |
81 | ../../rsync/prototab.c \ | 83 | ../../rsync/prototab.c \ |
82 | ../../rsync/readsums.c \ | 84 | ../../rsync/readsums.c \ |
83 | ../../rsync/scoop.c \ | 85 | ../../rsync/scoop.c \ |
84 | ../../rsync/search.c \ | 86 | ../../rsync/search.c \ |
85 | ../../rsync/stats.c \ | 87 | ../../rsync/stats.c \ |
86 | ../../rsync/stream.c \ | 88 | ../../rsync/stream.c \ |
87 | ../../rsync/sumset.c \ | 89 | ../../rsync/sumset.c \ |
88 | ../../rsync/trace.c \ | 90 | ../../rsync/trace.c \ |
89 | ../../rsync/tube.c \ | 91 | ../../rsync/tube.c \ |
90 | ../../rsync/util.c \ | 92 | ../../rsync/util.c \ |
91 | ../../rsync/version.c \ | 93 | ../../rsync/version.c \ |
92 | ../../rsync/whole.c \ | 94 | ../../rsync/whole.c \ |
93 | ../../rsync/qrsync.cpp | 95 | ../../rsync/qrsync.cpp |
94 | INTERFACES= syncdialog.ui | 96 | INTERFACES= syncdialog.ui |
95 | INCLUDEPATH += ../../include | 97 | INCLUDEPATH += ../../include |
96 | DEPENDPATH+= ../../include . | 98 | DEPENDPATH+= ../../include . |
97 | INCLUDEPATH += ../../core/apps/calibrate | 99 | INCLUDEPATH += ../../core/apps/calibrate |
98 | DEPENDPATH+= ../../core/apps/calibrate | 100 | DEPENDPATH+= ../../core/apps/calibrate |
99 | INCLUDEPATH += ../../rsync | 101 | INCLUDEPATH += ../../rsync |
100 | DEPENDPATH+= ../../rsync | 102 | DEPENDPATH+= ../../rsync |
101 | TARGET = qpe | 103 | TARGET = qpe |
102 | LIBS += -lqpe -lcrypt -lopie | 104 | LIBS += -lqpe -lcrypt -lopie |
103 | 105 | ||
104 | TRANSLATIONS = ../../i18n/de/qpe.ts \ | 106 | TRANSLATIONS = ../../i18n/de/qpe.ts \ |
105 | ../../i18n/en/qpe.ts \ | 107 | ../../i18n/en/qpe.ts \ |
106 | ../../i18n/es/qpe.ts \ | 108 | ../../i18n/es/qpe.ts \ |
107 | ../../i18n/fr/qpe.ts \ | 109 | ../../i18n/fr/qpe.ts \ |
108 | ../../i18n/hu/qpe.ts \ | 110 | ../../i18n/hu/qpe.ts \ |
109 | ../../i18n/ja/qpe.ts \ | 111 | ../../i18n/ja/qpe.ts \ |
110 | ../../i18n/ko/qpe.ts \ | 112 | ../../i18n/ko/qpe.ts \ |
111 | ../../i18n/no/qpe.ts \ | 113 | ../../i18n/no/qpe.ts \ |
112 | ../../i18n/pl/qpe.ts \ | 114 | ../../i18n/pl/qpe.ts \ |
113 | ../../i18n/pt/qpe.ts \ | 115 | ../../i18n/pt/qpe.ts \ |
114 | ../../i18n/pt_BR/qpe.ts \ | 116 | ../../i18n/pt_BR/qpe.ts \ |
115 | ../../i18n/sl/qpe.ts \ | 117 | ../../i18n/sl/qpe.ts \ |
116 | ../../i18n/zh_CN/qpe.ts \ | 118 | ../../i18n/zh_CN/qpe.ts \ |
117 | ../../i18n/it/qpe.ts \ | 119 | ../../i18n/it/qpe.ts \ |
118 | ../../i18n/zh_TW/qpe.ts | 120 | ../../i18n/zh_TW/qpe.ts |
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp new file mode 100644 index 0000000..9e823ff --- a/dev/null +++ b/core/launcher/screensaver.cpp | |||
@@ -0,0 +1,237 @@ | |||
1 | |||
2 | #include "screensaver.h" | ||
3 | |||
4 | #include <qpe/config.h> | ||
5 | #include <qpe/power.h> | ||
6 | #include <qpe/network.h> | ||
7 | |||
8 | #include <opie/odevice.h> | ||
9 | |||
10 | |||
11 | using namespace Opie; | ||
12 | |||
13 | |||
14 | OpieScreenSaver::OpieScreenSaver ( ) | ||
15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | ||
16 | { | ||
17 | m_disable_suspend = 100; | ||
18 | m_enable_dim = false; | ||
19 | m_enable_lightoff = false; | ||
20 | m_enable_suspend = false; | ||
21 | m_onlylcdoff = false; | ||
22 | |||
23 | m_enable_dim_ac = false; | ||
24 | m_enable_lightoff_ac = false; | ||
25 | m_enable_suspend_ac = false; | ||
26 | m_onlylcdoff_ac = false; | ||
27 | |||
28 | m_use_light_sensor = false; | ||
29 | m_backlight_sensor = -1; | ||
30 | |||
31 | m_lcd_status = true; | ||
32 | |||
33 | m_backlight_normal = -1; | ||
34 | m_backlight_current = -1; | ||
35 | m_backlight_forcedoff = false; | ||
36 | |||
37 | m_on_ac = false; | ||
38 | |||
39 | m_level = -1; | ||
40 | |||
41 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | ||
42 | ODevice::inst ( )-> setDisplayStatus ( true ); | ||
43 | setBacklight ( -1 ); | ||
44 | } | ||
45 | |||
46 | |||
47 | void OpieScreenSaver::restore() | ||
48 | { | ||
49 | m_level = -1; | ||
50 | |||
51 | if ( !m_lcd_status ) { // We must have turned it off | ||
52 | ODevice::inst ( ) -> setDisplayStatus ( true ); | ||
53 | m_lcd_status = true; | ||
54 | } | ||
55 | |||
56 | setBacklightInternal ( -1 ); | ||
57 | } | ||
58 | |||
59 | |||
60 | bool OpieScreenSaver::save( int level ) | ||
61 | { | ||
62 | m_level = level; | ||
63 | |||
64 | switch ( level ) { | ||
65 | case 0: | ||
66 | if (( m_on_ac && m_enable_dim_ac ) || | ||
67 | ( !m_on_ac && m_enable_dim )) { | ||
68 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) | ||
69 | setBacklightInternal ( 1 ); // lowest non-off | ||
70 | } | ||
71 | return true; | ||
72 | break; | ||
73 | |||
74 | case 1: | ||
75 | if (( m_on_ac && m_enable_lightoff_ac ) || | ||
76 | ( !m_on_ac && m_enable_lightoff )) { | ||
77 | if ( m_disable_suspend > 1 ) | ||
78 | setBacklightInternal ( 0 ); // off | ||
79 | } | ||
80 | return true; | ||
81 | break; | ||
82 | |||
83 | case 2: | ||
84 | if (( m_on_ac && !m_enable_suspend_ac ) || | ||
85 | ( !m_on_ac && !m_enable_suspend )) { | ||
86 | return true; | ||
87 | } | ||
88 | |||
89 | if (( m_on_ac && m_onlylcdoff_ac ) || | ||
90 | ( !m_on_ac && m_onlylcdoff )) { | ||
91 | ODevice::inst ( ) -> setDisplayStatus ( false ); | ||
92 | m_lcd_status = false; | ||
93 | return true; | ||
94 | } | ||
95 | |||
96 | // We're going to suspend the whole machine | ||
97 | |||
98 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | ||
99 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | ||
100 | return true; | ||
101 | } | ||
102 | |||
103 | break; | ||
104 | } | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | |||
109 | void OpieScreenSaver::setIntervals ( int i1, int i2, int i3 ) | ||
110 | { | ||
111 | Config config ( "apm" ); | ||
112 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | ||
113 | |||
114 | int v[ 4 ]; | ||
115 | if ( i1 < 0 ) | ||
116 | i1 = config. readNumEntry ( "Dim", 30 ); | ||
117 | if ( i2 < 0 ) | ||
118 | i2 = config. readNumEntry ( "LightOff", 20 ); | ||
119 | if ( i3 < 0 ) | ||
120 | i3 = config. readNumEntry ( "Suspend", 60 ); | ||
121 | |||
122 | if ( m_on_ac ) { | ||
123 | m_enable_dim_ac = ( i1 > 0 ); | ||
124 | m_enable_lightoff_ac = ( i2 > 0 ); | ||
125 | m_enable_suspend_ac = ( i3 > 0 ); | ||
126 | m_onlylcdoff_ac = config.readNumEntry ( "LcdOffOnly", 0 ); | ||
127 | } | ||
128 | else { | ||
129 | m_enable_dim = ( i1 > 0 ); | ||
130 | m_enable_lightoff = ( i2 > 0 ); | ||
131 | m_enable_suspend = ( i3 > 0 ); | ||
132 | m_onlylcdoff = config.readNumEntry ( "LcdOffOnly", 0 ); | ||
133 | } | ||
134 | |||
135 | qDebug("screen saver intervals: %d %d %d", i1, i2, i3); | ||
136 | |||
137 | v [ 0 ] = QMAX( 1000 * i1, 100 ); | ||
138 | v [ 1 ] = QMAX( 1000 * i2, 100 ); | ||
139 | v [ 2 ] = QMAX( 1000 * i3, 100 ); | ||
140 | v [ 3 ] = 0; | ||
141 | |||
142 | if ( !i1 && !i2 && !i3 ) | ||
143 | QWSServer::setScreenSaverInterval( 0 ); | ||
144 | else | ||
145 | QWSServer::setScreenSaverIntervals( v ); | ||
146 | } | ||
147 | |||
148 | |||
149 | void OpieScreenSaver::setInterval ( int interval ) | ||
150 | { | ||
151 | setIntervals ( -1, -1, interval ); | ||
152 | } | ||
153 | |||
154 | |||
155 | void OpieScreenSaver::setMode ( int mode ) | ||
156 | { | ||
157 | if ( mode > m_disable_suspend ) | ||
158 | setInterval ( -1 ); | ||
159 | m_disable_suspend = mode; | ||
160 | } | ||
161 | |||
162 | |||
163 | void OpieScreenSaver::setBacklight ( int bright ) | ||
164 | { | ||
165 | // Read from config | ||
166 | Config config ( "apm" ); | ||
167 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | ||
168 | m_backlight_normal = config. readNumEntry ( "Brightness", 255 ); | ||
169 | |||
170 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | ||
171 | |||
172 | qDebug ( "setBacklight: %d (ls: %d)", m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | ||
173 | |||
174 | killTimers ( ); | ||
175 | if ( m_use_light_sensor ) { | ||
176 | timerEvent ( 0 ); | ||
177 | startTimer ( 2000 ); | ||
178 | } | ||
179 | |||
180 | setBacklightInternal ( bright ); | ||
181 | } | ||
182 | |||
183 | |||
184 | void OpieScreenSaver::setBacklightInternal ( int bright ) | ||
185 | { | ||
186 | if ( bright == -3 ) { | ||
187 | // Forced on | ||
188 | m_backlight_forcedoff = false; | ||
189 | bright = -1; | ||
190 | } | ||
191 | if ( m_backlight_forcedoff && bright != -2 ) | ||
192 | return ; | ||
193 | if ( bright == -2 ) { | ||
194 | // Toggle between off and on | ||
195 | bright = m_backlight_current ? 0 : -1; | ||
196 | m_backlight_forcedoff = !bright; | ||
197 | } | ||
198 | if ( bright == -1 ) | ||
199 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | ||
200 | |||
201 | if ( bright != m_backlight_current ) { | ||
202 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | ||
203 | m_backlight_current = bright; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | |||
208 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | ||
209 | { | ||
210 | m_backlight_sensor = (( 255 - ODevice::inst ( )-> readLightSensor ( )) * m_backlight_normal ) / 255; | ||
211 | |||
212 | if ( m_level <= 0 ) | ||
213 | setBacklightInternal ( -1 ); | ||
214 | } | ||
215 | |||
216 | |||
217 | void OpieScreenSaver::setDisplayState ( bool on ) | ||
218 | { | ||
219 | if ( m_lcd_status != on ) { | ||
220 | ODevice::inst ( ) -> setDisplayStatus ( on ); | ||
221 | m_lcd_status = on; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | |||
226 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | ||
227 | { | ||
228 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | ||
229 | |||
230 | if ( newonac != m_on_ac ) { | ||
231 | m_on_ac = newonac; | ||
232 | setInterval ( -1 ); | ||
233 | setBacklight ( -1 ); | ||
234 | restore ( ); | ||
235 | } | ||
236 | } | ||
237 | |||
diff --git a/core/launcher/screensaver.h b/core/launcher/screensaver.h new file mode 100644 index 0000000..9126f33 --- a/dev/null +++ b/core/launcher/screensaver.h | |||
@@ -0,0 +1,61 @@ | |||
1 | #ifndef __LAUNCHER_SCREENSAVER_H__ | ||
2 | #define __LAUNCHER_SCREENSAVER_H__ | ||
3 | |||
4 | #include <qwindowsystem_qws.h> | ||
5 | #include <qobject.h> | ||
6 | |||
7 | #include <qpe/power.h> | ||
8 | |||
9 | class OpieScreenSaver : public QObject, public QWSScreenSaver | ||
10 | { | ||
11 | public: | ||
12 | OpieScreenSaver ( ); | ||
13 | |||
14 | void restore ( ); | ||
15 | bool save ( int level ); | ||
16 | |||
17 | void setIntervals( int i1, int i2, int i3 ); | ||
18 | void setIntervalsAC( int i1, int i2, int i3 ); | ||
19 | |||
20 | void setInterval ( int interval ); | ||
21 | |||
22 | void setMode ( int mode ); | ||
23 | |||
24 | void setBacklight ( int bright ); | ||
25 | void setDisplayState ( bool on ); | ||
26 | |||
27 | void powerStatusChanged ( PowerStatus ps ); | ||
28 | |||
29 | private: | ||
30 | void setBacklightInternal ( int bright ); | ||
31 | |||
32 | protected: | ||
33 | virtual void timerEvent ( QTimerEvent * ); | ||
34 | |||
35 | private: | ||
36 | int m_disable_suspend; | ||
37 | bool m_enable_dim; | ||
38 | bool m_enable_lightoff; | ||
39 | bool m_enable_suspend; | ||
40 | bool m_onlylcdoff; | ||
41 | |||
42 | bool m_enable_dim_ac; | ||
43 | bool m_enable_lightoff_ac; | ||
44 | bool m_enable_suspend_ac; | ||
45 | bool m_onlylcdoff_ac; | ||
46 | |||
47 | bool m_use_light_sensor; | ||
48 | int m_backlight_sensor; | ||
49 | |||
50 | bool m_lcd_status; | ||
51 | |||
52 | int m_backlight_normal; | ||
53 | int m_backlight_current; | ||
54 | bool m_backlight_forcedoff; | ||
55 | |||
56 | bool m_on_ac; | ||
57 | |||
58 | int m_level; | ||
59 | }; | ||
60 | |||
61 | #endif | ||