author | zecke <zecke> | 2003-08-28 14:55:46 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-08-28 14:55:46 (UTC) |
commit | d687b15c95f022bd46a23758577a4816bd372505 (patch) (unidiff) | |
tree | 402a286cef17d0f1d47a58e41c429267cb5c9b1b /core/launcher/desktop.cpp | |
parent | fa605085c3f966aa2897cacea03b24025c5c23a3 (diff) | |
download | opie-d687b15c95f022bd46a23758577a4816bd372505.zip opie-d687b15c95f022bd46a23758577a4816bd372505.tar.gz opie-d687b15c95f022bd46a23758577a4816bd372505.tar.bz2 |
Add license
remove old unneeded files
-rw-r--r-- | core/launcher/desktop.cpp | 878 |
1 files changed, 0 insertions, 878 deletions
diff --git a/core/launcher/desktop.cpp b/core/launcher/desktop.cpp deleted file mode 100644 index 067a167..0000000 --- a/core/launcher/desktop.cpp +++ b/dev/null | |||
@@ -1,878 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <syslog.h> | ||
22 | |||
23 | #include "desktop.h" | ||
24 | #include "info.h" | ||
25 | #include "launcher.h" | ||
26 | #include "qcopbridge.h" | ||
27 | #include "shutdownimpl.h" | ||
28 | #include "startmenu.h" | ||
29 | #include "taskbar.h" | ||
30 | #include "transferserver.h" | ||
31 | #include "irserver.h" | ||
32 | #include "packageslave.h" | ||
33 | #include "screensaver.h" | ||
34 | |||
35 | #include <qpe/applnk.h> | ||
36 | #include <qpe/mimetype.h> | ||
37 | #include <qpe/password.h> | ||
38 | #include <qpe/config.h> | ||
39 | #include <qpe/power.h> | ||
40 | #include <qpe/timeconversion.h> | ||
41 | #include <qpe/qcopenvelope_qws.h> | ||
42 | #include <qpe/network.h> | ||
43 | #include <qpe/global.h> | ||
44 | |||
45 | #if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) || defined(QT_QWS_RAMSES) | ||
46 | #include <qpe/custom.h> | ||
47 | #endif | ||
48 | |||
49 | #include <opie/odevice.h> | ||
50 | |||
51 | #include <qgfx_qws.h> | ||
52 | #include <qmainwindow.h> | ||
53 | #include <qmessagebox.h> | ||
54 | #include <qtimer.h> | ||
55 | #include <qwindowsystem_qws.h> | ||
56 | |||
57 | #include <qvaluelist.h> | ||
58 | |||
59 | #include <stdlib.h> | ||
60 | #include <unistd.h> | ||
61 | #include <fcntl.h> | ||
62 | |||
63 | |||
64 | using namespace Opie; | ||
65 | |||
66 | class QCopKeyRegister | ||
67 | { | ||
68 | public: | ||
69 | QCopKeyRegister() : keyCode( 0 ) | ||
70 | { } | ||
71 | QCopKeyRegister( int k, const QCString &c, const QCString &m ) | ||
72 | : keyCode( k ), channel( c ), message( m ) | ||
73 | { } | ||
74 | |||
75 | int getKeyCode() const | ||
76 | { | ||
77 | return keyCode; | ||
78 | } | ||
79 | QCString getChannel() const | ||
80 | { | ||
81 | return channel; | ||
82 | } | ||
83 | QCString getMessage() const | ||
84 | { | ||
85 | return message; | ||
86 | } | ||
87 | |||
88 | private: | ||
89 | int keyCode; | ||
90 | QCString channel, message; | ||
91 | }; | ||
92 | |||
93 | typedef QValueList<QCopKeyRegister> KeyRegisterList; | ||
94 | KeyRegisterList keyRegisterList; | ||
95 | |||
96 | static Desktop* qpedesktop = 0; | ||
97 | static int loggedin = 0; | ||
98 | static void login( bool at_poweron ) | ||
99 | { | ||
100 | if ( !loggedin ) { | ||
101 | Global::terminateBuiltin( "calibrate" ); | ||
102 | Password::authenticate( at_poweron ); | ||
103 | loggedin = 1; | ||
104 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | bool Desktop::screenLocked() | ||
109 | { | ||
110 | return loggedin == 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | Priority is number of alerts that are needed to pop up | ||
115 | alert. | ||
116 | */ | ||
117 | class DesktopPowerAlerter : public QMessageBox | ||
118 | { | ||
119 | public: | ||
120 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | ||
121 | : QMessageBox( tr( "Battery Status" ), "Low Battery", | ||
122 | QMessageBox::Critical, | ||
123 | QMessageBox::Ok | QMessageBox::Default, | ||
124 | QMessageBox::NoButton, QMessageBox::NoButton, | ||
125 | parent, name, FALSE ) | ||
126 | { | ||
127 | currentPriority = INT_MAX; | ||
128 | alertCount = 0; | ||
129 | } | ||
130 | |||
131 | void alert( const QString &text, int priority ); | ||
132 | void hideEvent( QHideEvent * ); | ||
133 | private: | ||
134 | int currentPriority; | ||
135 | int alertCount; | ||
136 | }; | ||
137 | |||
138 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | ||
139 | { | ||
140 | alertCount++; | ||
141 | if ( alertCount < priority ) | ||
142 | return ; | ||
143 | if ( priority > currentPriority ) | ||
144 | return ; | ||
145 | currentPriority = priority; | ||
146 | setText( text ); | ||
147 | show(); | ||
148 | } | ||
149 | |||
150 | |||
151 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | ||
152 | { | ||
153 | QMessageBox::hideEvent( e ); | ||
154 | alertCount = 0; | ||
155 | currentPriority = INT_MAX; | ||
156 | } | ||
157 | |||
158 | |||
159 | void DesktopApplication::switchLCD ( bool on ) | ||
160 | { | ||
161 | if ( qApp ) { | ||
162 | DesktopApplication *dapp = (DesktopApplication *) qApp; | ||
163 | |||
164 | if ( dapp-> m_screensaver ) { | ||
165 | if ( on ) { | ||
166 | dapp-> m_screensaver-> setDisplayState ( true ); | ||
167 | dapp-> m_screensaver-> setBacklight ( -3 ); | ||
168 | } | ||
169 | else { | ||
170 | dapp-> m_screensaver-> setDisplayState ( false ); | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | |||
177 | DesktopApplication::DesktopApplication( int& argc, char **argv, Type appType ) | ||
178 | : QPEApplication( argc, argv, appType ) | ||
179 | { | ||
180 | m_ps = new PowerStatus; | ||
181 | m_ps_last = new PowerStatus; | ||
182 | pa = new DesktopPowerAlerter( 0 ); | ||
183 | |||
184 | m_apm_timer = new QTimer ( this ); | ||
185 | connect ( m_apm_timer, SIGNAL( timeout ( )), this, SLOT( apmTimeout ( ))); | ||
186 | reloadPowerWarnSettings ( ); | ||
187 | |||
188 | m_last_button = 0; | ||
189 | m_button_timer = new QTimer ( ); | ||
190 | connect ( m_button_timer, SIGNAL( timeout ( )), this, SLOT( sendHeldAction ( ))); | ||
191 | |||
192 | channel = new QCopChannel( "QPE/System", this ); | ||
193 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | ||
194 | this, SLOT( systemMessage( const QCString&, const QByteArray& ) ) ); | ||
195 | |||
196 | channel = new QCopChannel( "QPE/Launcher", this ); | ||
197 | connect( channel, SIGNAL( received( const QCString&, const QByteArray& ) ), | ||
198 | this, SLOT( launcherMessage( const QCString&, const QByteArray& ) ) ); | ||
199 | |||
200 | m_screensaver = new OpieScreenSaver ( ); | ||
201 | m_screensaver-> setInterval ( -1 ); | ||
202 | QWSServer::setScreenSaver( m_screensaver ); | ||
203 | |||
204 | rereadVolumes(); | ||
205 | connect( qApp, SIGNAL( volumeChanged( bool ) ), this, SLOT( rereadVolumes() ) ); | ||
206 | |||
207 | apmTimeout ( ); | ||
208 | |||
209 | grabKeyboard ( ); | ||
210 | } | ||
211 | |||
212 | |||
213 | DesktopApplication::~DesktopApplication() | ||
214 | { | ||
215 | ungrabKeyboard ( ); | ||
216 | |||
217 | delete m_ps; | ||
218 | delete m_ps_last; | ||
219 | delete pa; | ||
220 | } | ||
221 | |||
222 | void DesktopApplication::apmTimeout() | ||
223 | { | ||
224 | qpedesktop-> checkMemory ( ); // in case no events are being generated | ||
225 | |||
226 | *m_ps_last = *m_ps; | ||
227 | *m_ps = PowerStatusManager::readStatus(); | ||
228 | |||
229 | if ( m_ps-> acStatus ( ) != m_ps_last-> acStatus ( )) | ||
230 | m_screensaver-> powerStatusChanged ( *m_ps ); | ||
231 | |||
232 | if ( m_ps-> acStatus ( ) != PowerStatus::Online ) { | ||
233 | int bat = m_ps-> batteryPercentRemaining ( ); | ||
234 | |||
235 | if ( bat < m_ps_last-> batteryPercentRemaining ( )) { | ||
236 | if ( bat <= m_powerCritical ) | ||
237 | pa->alert( tr( "Battery level is critical!\nKeep power off until power restored!" ), 1 ); | ||
238 | else if ( bat <= m_powerVeryLow ) | ||
239 | pa->alert( tr( "Battery is running very low." ), 2 ); | ||
240 | } | ||
241 | if ( m_ps-> backupBatteryStatus ( ) == PowerStatus::VeryLow ) | ||
242 | pa->alert( tr( "The Back-up battery is very low.\nPlease charge the back-up battery." ), 2 ); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | |||
247 | void DesktopApplication::systemMessage( const QCString & msg, const QByteArray & data ) | ||
248 | { | ||
249 | QDataStream stream ( data, IO_ReadOnly ); | ||
250 | |||
251 | if ( msg == "setScreenSaverInterval(int)" ) { | ||
252 | int time; | ||
253 | stream >> time; | ||
254 | m_screensaver-> setInterval( time ); | ||
255 | } | ||
256 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | ||
257 | int t1, t2, t3; | ||
258 | stream >> t1 >> t2 >> t3; | ||
259 | m_screensaver-> setIntervals( t1, t2, t3 ); | ||
260 | } | ||
261 | else if ( msg == "setBacklight(int)" ) { | ||
262 | int bright; | ||
263 | stream >> bright; | ||
264 | m_screensaver-> setBacklight( bright ); | ||
265 | } | ||
266 | else if ( msg == "setScreenSaverMode(int)" ) { | ||
267 | int mode; | ||
268 | stream >> mode; | ||
269 | m_screensaver-> setMode ( mode ); | ||
270 | } | ||
271 | else if ( msg == "reloadPowerWarnSettings()" ) { | ||
272 | reloadPowerWarnSettings(); | ||
273 | } | ||
274 | else if ( msg == "setDisplayState(int)" ) { | ||
275 | int state; | ||
276 | stream >> state; | ||
277 | m_screensaver-> setDisplayState ( state != 0 ); | ||
278 | } | ||
279 | else if ( msg == "suspend()" ) { | ||
280 | emit power(); | ||
281 | } | ||
282 | else if ( msg == "sendBusinessCard()" ) { | ||
283 | QString card = ::getenv ( "HOME" ); | ||
284 | card += "/Applications/addressbook/businesscard.vcf"; | ||
285 | |||
286 | if ( QFile::exists( card ) ) { | ||
287 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); | ||
288 | QString mimetype = "text/x-vCard"; | ||
289 | e << tr( "business card" ) << card << mimetype; | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | |||
294 | void DesktopApplication::reloadPowerWarnSettings ( ) | ||
295 | { | ||
296 | Config cfg ( "apm" ); | ||
297 | cfg. setGroup ( "Warnings" ); | ||
298 | |||
299 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); | ||
300 | |||
301 | m_apm_timer-> stop ( ); | ||
302 | if ( iv ) | ||
303 | m_apm_timer-> start ( iv ); | ||
304 | |||
305 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); | ||
306 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); | ||
307 | } | ||
308 | |||
309 | |||
310 | enum MemState { Unknown, VeryLow, Low, Normal } memstate = Unknown; | ||
311 | |||
312 | |||
313 | void DesktopApplication::launcherMessage( const QCString & msg, const QByteArray & data ) | ||
314 | { | ||
315 | QDataStream stream ( data, IO_ReadOnly ); | ||
316 | |||
317 | if ( msg == "deviceButton(int,int,int)" ) { | ||
318 | int keycode, press, autoRepeat; | ||
319 | stream >> keycode >> press >> autoRepeat; | ||
320 | |||
321 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( keycode ); | ||
322 | |||
323 | if ( db ) | ||
324 | checkButtonAction ( db, keycode, press, autoRepeat ); | ||
325 | } | ||
326 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { | ||
327 | int k; | ||
328 | QCString c, m; | ||
329 | stream >> k >> c >> m; | ||
330 | |||
331 | keyRegisterList.append ( QCopKeyRegister ( k, c, m )); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | void DesktopApplication::sendHeldAction ( ) | ||
336 | { | ||
337 | if ( m_last_button ) { | ||
338 | m_last_button-> heldAction ( ). send ( ); | ||
339 | m_last_button = 0; | ||
340 | } | ||
341 | } | ||
342 | |||
343 | |||
344 | |||
345 | bool DesktopApplication::checkButtonAction ( const ODeviceButton *db, int /*keycode*/, bool press, bool autoRepeat ) | ||
346 | { | ||
347 | if ( db ) { | ||
348 | if ( !press && !autoRepeat && m_button_timer-> isActive ( )) { | ||
349 | m_button_timer-> stop ( ); | ||
350 | |||
351 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) | ||
352 | { | ||
353 | |||
354 | if ( db-> pressedAction ( ). channel ( )!="ignore") { | ||
355 | |||
356 | db-> pressedAction ( ). send ( ); | ||
357 | } | ||
358 | else | ||
359 | return false; | ||
360 | } | ||
361 | } | ||
362 | else if ( press && !autoRepeat ) { | ||
363 | m_button_timer-> stop ( ); | ||
364 | if (!db-> pressedAction ( ). channel ( ) .isEmpty()) | ||
365 | { | ||
366 | |||
367 | if ( db-> heldAction ( ). channel ( )!="ignore") { | ||
368 | m_last_button = db; | ||
369 | m_button_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); | ||
370 | } | ||
371 | else return false; | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | return true; | ||
376 | } | ||
377 | |||
378 | bool DesktopApplication::eventFilter ( QObject *o, QEvent *e ) | ||
379 | { | ||
380 | |||
381 | if ( e-> type ( ) == QEvent::KeyPress || e-> type ( ) == QEvent::KeyRelease ) { | ||
382 | QKeyEvent *ke = (QKeyEvent *) e; | ||
383 | |||
384 | const ODeviceButton *db = ODevice::inst ( )-> buttonForKeycode ( ke-> key ( )); | ||
385 | |||
386 | if ( db ) { | ||
387 | if (checkButtonAction ( db, ke-> key ( ), e-> type ( ) == QEvent::KeyPress, ke-> isAutoRepeat ( ))) | ||
388 | return true; //checkButtonAction retrune false if events should be routed through | ||
389 | } | ||
390 | } | ||
391 | return QPEApplication::eventFilter ( o, e ); | ||
392 | } | ||
393 | |||
394 | #ifdef Q_WS_QWS | ||
395 | |||
396 | bool DesktopApplication::qwsEventFilter( QWSEvent *e ) | ||
397 | { | ||
398 | qpedesktop->checkMemory(); | ||
399 | |||
400 | if ( e->type == QWSEvent::Key ) { | ||
401 | QWSKeyEvent * ke = (QWSKeyEvent *) e; | ||
402 | ushort keycode = ke-> simpleData. keycode; | ||
403 | |||
404 | if ( !loggedin && keycode != Key_F34 ) | ||
405 | return true; | ||
406 | |||
407 | bool press = ke-> simpleData. is_press; | ||
408 | bool autoRepeat = ke-> simpleData. is_auto_repeat; | ||
409 | |||
410 | if ( !keyboardGrabbed ( )) { | ||
411 | // app that registers key/message to be sent back to the app, when it doesn't have focus, | ||
412 | // when user presses key, unless keyboard has been requested from app. | ||
413 | // will not send multiple repeats if user holds key | ||
414 | // i.e. one shot | ||
415 | |||
416 | if ( keycode != 0 && press && !autoRepeat ) { | ||
417 | for ( KeyRegisterList::Iterator it = keyRegisterList.begin(); it != keyRegisterList.end(); ++it ) { | ||
418 | if (( *it ). getKeyCode ( ) == keycode ) { | ||
419 | QCopEnvelope (( *it ). getChannel ( ), ( *it ). getMessage ( )); | ||
420 | return true; | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | |||
426 | if ( keycode == HardKey_Suspend ) { | ||
427 | if ( press ) | ||
428 | emit power ( ); | ||
429 | return true; | ||
430 | } | ||
431 | else if ( keycode == HardKey_Backlight ) { | ||
432 | if ( press ) | ||
433 | emit backlight ( ); | ||
434 | return true; | ||
435 | } | ||
436 | else if ( keycode == Key_F32 ) { | ||
437 | if ( press ) | ||
438 | QCopEnvelope e( "QPE/Desktop", "startSync()" ); | ||
439 | return true; | ||
440 | } | ||
441 | else if ( keycode == Key_F31 && !ke-> simpleData. modifiers ) { // Symbol Key -> show Unicode IM | ||
442 | if ( press ) | ||
443 | emit symbol ( ); | ||
444 | return true; | ||
445 | } | ||
446 | else if ( keycode == Key_NumLock ) { | ||
447 | if ( press ) | ||
448 | emit numLockStateToggle ( ); | ||
449 | } | ||
450 | else if ( keycode == Key_CapsLock ) { | ||
451 | if ( press ) | ||
452 | emit capsLockStateToggle(); | ||
453 | } | ||
454 | if (( press && !autoRepeat ) || ( !press && autoRepeat )) { | ||
455 | if ( m_keyclick_sound ) | ||
456 | ODevice::inst ( )-> keySound ( ); | ||
457 | } | ||
458 | } | ||
459 | else if ( e-> type == QWSEvent::Mouse ) { | ||
460 | QWSMouseEvent * me = ( QWSMouseEvent * ) e; | ||
461 | static bool up = true; | ||
462 | |||
463 | if ( me-> simpleData. state & LeftButton ) { | ||
464 | if ( up ) { | ||
465 | up = false; | ||
466 | if ( m_screentap_sound ) | ||
467 | ODevice::inst ( ) -> touchSound ( ); | ||
468 | } | ||
469 | } | ||
470 | else { | ||
471 | up = true; | ||
472 | } | ||
473 | } | ||
474 | |||
475 | return QPEApplication::qwsEventFilter ( e ); | ||
476 | } | ||
477 | #endif | ||
478 | |||
479 | |||
480 | |||
481 | #if defined(QPE_HAVE_MEMALERTER) | ||
482 | QPE_MEMALERTER_IMPL | ||
483 | #endif | ||
484 | |||
485 | //=========================================================================== | ||
486 | |||
487 | Desktop::Desktop() : | ||
488 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | ||
489 | qcopBridge( 0 ), | ||
490 | transferServer( 0 ), | ||
491 | packageSlave( 0 ) | ||
492 | { | ||
493 | qpedesktop = this; | ||
494 | |||
495 | // bg = new Info( this ); | ||
496 | tb = new TaskBar; | ||
497 | |||
498 | launcher = new Launcher( 0, 0, WStyle_Customize | QWidget::WGroupLeader ); | ||
499 | |||
500 | connect( launcher, SIGNAL( busy() ), tb, SLOT( startWait() ) ); | ||
501 | connect( launcher, SIGNAL( notBusy( const QString& ) ), tb, SLOT( stopWait( const QString& ) ) ); | ||
502 | |||
503 | int displayw = qApp->desktop() ->width(); | ||
504 | int displayh = qApp->desktop() ->height(); | ||
505 | |||
506 | |||
507 | QSize sz = tb->sizeHint(); | ||
508 | |||
509 | setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | ||
510 | layout(); | ||
511 | |||
512 | tb->show(); | ||
513 | launcher->showMaximized(); | ||
514 | launcher->show(); | ||
515 | launcher->raise(); | ||
516 | #if defined(QPE_HAVE_MEMALERTER) | ||
517 | |||
518 | initMemalerter(); | ||
519 | #endif | ||
520 | // start services | ||
521 | startTransferServer(); | ||
522 | ( void ) new IrServer( this ); | ||
523 | |||
524 | packageSlave = new PackageSlave( this ); | ||
525 | |||
526 | qApp->installEventFilter( this ); | ||
527 | qApp->desktop()->installEventFilter( this ); | ||
528 | |||
529 | qApp-> setMainWidget ( launcher ); | ||
530 | } | ||
531 | |||
532 | void Desktop::show() | ||
533 | { | ||
534 | login( TRUE ); | ||
535 | QWidget::show(); | ||
536 | } | ||
537 | |||
538 | Desktop::~Desktop() | ||
539 | { | ||
540 | delete launcher; | ||
541 | delete tb; | ||
542 | delete qcopBridge; | ||
543 | delete transferServer; | ||
544 | } | ||
545 | |||
546 | bool Desktop::recoverMemory() | ||
547 | { | ||
548 | return tb->recoverMemory(); | ||
549 | } | ||
550 | |||
551 | void Desktop::checkMemory() | ||
552 | { | ||
553 | #if defined(QPE_HAVE_MEMALERTER) | ||
554 | static bool ignoreNormal = FALSE; | ||
555 | static bool existingMessage = FALSE; | ||
556 | |||
557 | if ( existingMessage ) | ||
558 | return ; // don't show a second message while still on first | ||
559 | |||
560 | existingMessage = TRUE; | ||
561 | switch ( memstate ) { | ||
562 | case Unknown: | ||
563 | break; | ||
564 | case Low: | ||
565 | memstate = Unknown; | ||
566 | if ( recoverMemory() ) | ||
567 | ignoreNormal = TRUE; | ||
568 | else | ||
569 | QMessageBox::warning( 0 , "Memory Status", | ||
570 | "The memory smacks of shortage. \n" | ||
571 | "Please save data. " ); | ||
572 | break; | ||
573 | case Normal: | ||
574 | memstate = Unknown; | ||
575 | if ( ignoreNormal ) | ||
576 | ignoreNormal = FALSE; | ||
577 | // else | ||
578 | // QMessageBox::information ( 0 , "Memory Status", | ||
579 | // "There is enough memory again." ); | ||
580 | break; | ||
581 | case VeryLow: | ||
582 | memstate = Unknown; | ||
583 | QMessageBox::critical( 0 , "Memory Status", | ||
584 | "The memory is very low. \n" | ||
585 | "Please end this application \n" | ||
586 | "immediately." ); | ||
587 | recoverMemory(); | ||
588 | } | ||
589 | existingMessage = FALSE; | ||
590 | #endif | ||
591 | } | ||
592 | |||
593 | static bool isVisibleWindow( int wid ) | ||
594 | { | ||
595 | #ifdef QWS | ||
596 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | ||
597 | QWSWindow* w; | ||
598 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | ||
599 | if ( w->winId() == wid ) | ||
600 | return !w->isFullyObscured(); | ||
601 | } | ||
602 | #endif | ||
603 | return FALSE; | ||
604 | } | ||
605 | |||
606 | static bool hasVisibleWindow( const QString& clientname ) | ||
607 | { | ||
608 | #ifdef QWS | ||
609 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | ||
610 | QWSWindow* w; | ||
611 | for ( QListIterator<QWSWindow> it( list ); ( w = it.current() ); ++it ) { | ||
612 | if ( w->client() ->identity() == clientname && !w->isFullyObscured() ) | ||
613 | return TRUE; | ||
614 | } | ||
615 | #endif | ||
616 | return FALSE; | ||
617 | } | ||
618 | |||
619 | |||
620 | void Desktop::executeOrModify( const QString& appLnkFile ) | ||
621 | { | ||
622 | AppLnk lnk( MimeType::appsFolderName() + "/" + appLnkFile ); | ||
623 | if ( lnk.isValid() ) { | ||
624 | QCString app = lnk.exec().utf8(); | ||
625 | Global::terminateBuiltin( "calibrate" ); | ||
626 | if ( QCopChannel::isRegistered( "QPE/Application/" + app ) ) { | ||
627 | // MRUList::addTask( &lnk ); | ||
628 | if ( hasVisibleWindow( app ) ) | ||
629 | QCopChannel::send( "QPE/Application/" + app, "nextView()" ); | ||
630 | else | ||
631 | QCopChannel::send( "QPE/Application/" + app, "raise()" ); | ||
632 | } | ||
633 | else { | ||
634 | lnk.execute(); | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | |||
639 | // autoStarts apps on resume and start | ||
640 | void Desktop::execAutoStart() | ||
641 | { | ||
642 | QString appName; | ||
643 | int delay; | ||
644 | QDateTime now = QDateTime::currentDateTime(); | ||
645 | Config cfg( "autostart" ); | ||
646 | cfg.setGroup( "AutoStart" ); | ||
647 | appName = cfg.readEntry( "Apps", "" ); | ||
648 | delay = ( cfg.readEntry( "Delay", "0" ) ).toInt(); | ||
649 | // If the time between suspend and resume was longer then the | ||
650 | // value saved as delay, start the app | ||
651 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | ||
652 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | ||
653 | e << QString( appName ); | ||
654 | } | ||
655 | } | ||
656 | |||
657 | #if defined(QPE_HAVE_TOGGLELIGHT) | ||
658 | #include <qpe/config.h> | ||
659 | |||
660 | #include <sys/ioctl.h> | ||
661 | #include <sys/types.h> | ||
662 | #include <fcntl.h> | ||
663 | #include <unistd.h> | ||
664 | #include <errno.h> | ||
665 | #include <linux/ioctl.h> | ||
666 | #include <time.h> | ||
667 | #endif | ||
668 | |||
669 | |||
670 | void Desktop::togglePower() | ||
671 | { | ||
672 | static bool excllock = false; | ||
673 | |||
674 | if ( excllock ) | ||
675 | return ; | ||
676 | |||
677 | excllock = true; | ||
678 | |||
679 | bool wasloggedin = loggedin; | ||
680 | loggedin = 0; | ||
681 | suspendTime = QDateTime::currentDateTime(); | ||
682 | |||
683 | #ifdef QWS | ||
684 | |||
685 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { | ||
686 | // Should use a big black window instead. | ||
687 | // But this would not show up fast enough | ||
688 | QGfx *g = qt_screen-> screenGfx ( ); | ||
689 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | ||
690 | delete g; | ||
691 | } | ||
692 | #endif | ||
693 | |||
694 | ODevice::inst ( )-> suspend ( ); | ||
695 | |||
696 | DesktopApplication::switchLCD ( true ); // force LCD on without slow qcop call | ||
697 | QWSServer::screenSaverActivate ( false ); | ||
698 | |||
699 | { | ||
700 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | ||
701 | } | ||
702 | |||
703 | if ( wasloggedin ) | ||
704 | login ( true ); | ||
705 | |||
706 | execAutoStart(); | ||
707 | //qcopBridge->closeOpenConnections(); | ||
708 | |||
709 | excllock = false; | ||
710 | } | ||
711 | |||
712 | void Desktop::toggleLight() | ||
713 | { | ||
714 | QCopEnvelope e( "QPE/System", "setBacklight(int)" ); | ||
715 | e << -2; // toggle | ||
716 | } | ||
717 | |||
718 | void Desktop::toggleSymbolInput() | ||
719 | { | ||
720 | tb->toggleSymbolInput(); | ||
721 | } | ||
722 | |||
723 | void Desktop::toggleNumLockState() | ||
724 | { | ||
725 | tb->toggleNumLockState(); | ||
726 | } | ||
727 | |||
728 | void Desktop::toggleCapsLockState() | ||
729 | { | ||
730 | tb->toggleCapsLockState(); | ||
731 | } | ||
732 | |||
733 | void Desktop::styleChange( QStyle &s ) | ||
734 | { | ||
735 | QWidget::styleChange( s ); | ||
736 | layout(); | ||
737 | } | ||
738 | |||
739 | void DesktopApplication::shutdown() | ||
740 | { | ||
741 | if ( type() != GuiServer ) | ||
742 | return ; | ||
743 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | ||
744 | connect( sd, SIGNAL( shutdown( ShutdownImpl::Type ) ), | ||
745 | this, SLOT( shutdown( ShutdownImpl::Type ) ) ); | ||
746 | sd->showMaximized(); | ||
747 | } | ||
748 | |||
749 | void DesktopApplication::shutdown( ShutdownImpl::Type t ) | ||
750 | { | ||
751 | char *opt = 0; | ||
752 | |||
753 | switch ( t ) { | ||
754 | case ShutdownImpl::ShutdownSystem: | ||
755 | opt = "-h"; | ||
756 | // fall through | ||
757 | case ShutdownImpl::RebootSystem: | ||
758 | if ( opt == 0 ) | ||
759 | opt = "-r"; | ||
760 | |||
761 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) | ||
762 | perror("shutdown"); | ||
763 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); | ||
764 | |||
765 | break; | ||
766 | case ShutdownImpl::RestartDesktop: | ||
767 | restart(); | ||
768 | break; | ||
769 | case ShutdownImpl::TerminateDesktop: | ||
770 | prepareForTermination( FALSE ); | ||
771 | |||
772 | // This is a workaround for a Qt bug | ||
773 | // clipboard applet has to stop its poll timer, or Qt/E | ||
774 | // will hang on quit() right before it emits aboutToQuit() | ||
775 | emit aboutToQuit ( ); | ||
776 | |||
777 | quit(); | ||
778 | break; | ||
779 | } | ||
780 | } | ||
781 | |||
782 | void DesktopApplication::restart() | ||
783 | { | ||
784 | prepareForTermination( TRUE ); | ||
785 | |||
786 | #ifdef Q_WS_QWS | ||
787 | |||
788 | for ( int fd = 3; fd < 100; fd++ ) | ||
789 | close( fd ); | ||
790 | #if defined(QT_DEMO_SINGLE_FLOPPY) | ||
791 | |||
792 | execl( "/sbin/init", "qpe", 0 ); | ||
793 | #elif defined(QT_QWS_CASSIOPEIA) | ||
794 | |||
795 | execl( "/bin/sh", "sh", 0 ); | ||
796 | #else | ||
797 | |||
798 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); | ||
799 | #endif | ||
800 | |||
801 | exit( 1 ); | ||
802 | #endif | ||
803 | } | ||
804 | |||
805 | void Desktop::layout() | ||
806 | { | ||
807 | int displayw = qApp->desktop() ->width(); | ||
808 | int displayh = qApp->desktop() ->height(); | ||
809 | |||
810 | QSize sz = tb->sizeHint(); | ||
811 | |||
812 | tb->setGeometry( 0, displayh - sz.height(), displayw, sz.height() ); | ||
813 | tb->calcMaxWindowRect(); | ||
814 | } | ||
815 | |||
816 | void Desktop::startTransferServer() | ||
817 | { | ||
818 | // start qcop bridge server | ||
819 | qcopBridge = new QCopBridge( 4243 ); | ||
820 | if ( !qcopBridge->ok() ) { | ||
821 | delete qcopBridge; | ||
822 | qcopBridge = 0; | ||
823 | } | ||
824 | // start transfer server | ||
825 | transferServer = new TransferServer( 4242 ); | ||
826 | if ( !transferServer->ok() ) { | ||
827 | delete transferServer; | ||
828 | transferServer = 0; | ||
829 | } | ||
830 | if ( !transferServer || !qcopBridge ) | ||
831 | startTimer( 2000 ); | ||
832 | } | ||
833 | |||
834 | void Desktop::timerEvent( QTimerEvent *e ) | ||
835 | { | ||
836 | killTimer( e->timerId() ); | ||
837 | startTransferServer(); | ||
838 | } | ||
839 | |||
840 | bool Desktop::eventFilter( QObject *o, QEvent *ev ) | ||
841 | { | ||
842 | if ( o != qApp->desktop() || ev->type() != QEvent::Resize ) | ||
843 | return QWidget::eventFilter( o, ev ); | ||
844 | |||
845 | layout(); | ||
846 | |||
847 | return QWidget::eventFilter( o, ev ); | ||
848 | } | ||
849 | |||
850 | void Desktop::terminateServers() | ||
851 | { | ||
852 | delete transferServer; | ||
853 | delete qcopBridge; | ||
854 | transferServer = 0; | ||
855 | qcopBridge = 0; | ||
856 | } | ||
857 | |||
858 | void DesktopApplication::rereadVolumes() | ||
859 | { | ||
860 | Config cfg( "qpe" ); | ||
861 | cfg. setGroup ( "Volume" ); | ||
862 | |||
863 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); | ||
864 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); | ||
865 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); | ||
866 | } | ||
867 | |||
868 | void DesktopApplication::soundAlarm() | ||
869 | { | ||
870 | if ( me ( )-> m_alarm_sound ) | ||
871 | ODevice::inst ( )-> alarmSound ( ); | ||
872 | } | ||
873 | |||
874 | DesktopApplication *DesktopApplication::me ( ) | ||
875 | { | ||
876 | return (DesktopApplication *) qApp; | ||
877 | } | ||
878 | |||