-rw-r--r-- | core/launcher/serverapp.cpp | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp index f1bce40..a2302d8 100644 --- a/core/launcher/serverapp.cpp +++ b/core/launcher/serverapp.cpp | |||
@@ -49,44 +49,50 @@ using namespace Opie::Core; | |||
49 | #ifdef Q_OS_WIN32 | 49 | #ifdef Q_OS_WIN32 |
50 | #include <io.h> | 50 | #include <io.h> |
51 | #include <process.h> | 51 | #include <process.h> |
52 | #else | 52 | #else |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #endif | 54 | #endif |
55 | #include <stdlib.h> | 55 | #include <stdlib.h> |
56 | 56 | ||
57 | static ServerApplication *serverApp = 0; | 57 | static ServerApplication *serverApp = 0; |
58 | static int loggedin=0; | 58 | static int loggedin=0; |
59 | 59 | ||
60 | QCopKeyRegister::QCopKeyRegister() | 60 | QCopKeyRegister::QCopKeyRegister() |
61 | : m_keyCode( 0 ) { | 61 | : m_keyCode( 0 ) |
62 | { | ||
62 | } | 63 | } |
63 | 64 | ||
64 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) | 65 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) |
65 | :m_keyCode( k ), m_channel( c ), m_message( m ) { | 66 | :m_keyCode( k ), m_channel( c ), m_message( m ) |
67 | { | ||
66 | } | 68 | } |
67 | 69 | ||
68 | int QCopKeyRegister::keyCode()const { | 70 | int QCopKeyRegister::keyCode() const |
71 | { | ||
69 | return m_keyCode; | 72 | return m_keyCode; |
70 | } | 73 | } |
71 | 74 | ||
72 | QCString QCopKeyRegister::channel()const { | 75 | QCString QCopKeyRegister::channel() const |
76 | { | ||
73 | return m_channel; | 77 | return m_channel; |
74 | } | 78 | } |
75 | 79 | ||
76 | QCString QCopKeyRegister::message()const { | 80 | QCString QCopKeyRegister::message() const |
81 | { | ||
77 | return m_message; | 82 | return m_message; |
78 | } | 83 | } |
79 | 84 | ||
80 | bool QCopKeyRegister::send() { | 85 | bool QCopKeyRegister::send() |
86 | { | ||
81 | if (m_channel.isNull() ) | 87 | if (m_channel.isNull() ) |
82 | return false; | 88 | return false; |
83 | 89 | ||
84 | QCopEnvelope( m_channel, m_message ); | 90 | QCopEnvelope( m_channel, m_message ); |
85 | 91 | ||
86 | return true; | 92 | return true; |
87 | } | 93 | } |
88 | 94 | ||
89 | //--------------------------------------------------------------------------- | 95 | //--------------------------------------------------------------------------- |
90 | 96 | ||
91 | /* | 97 | /* |
92 | Priority is number of alerts that are needed to pop up | 98 | Priority is number of alerts that are needed to pop up |
@@ -148,65 +154,66 @@ void KeyFilter::timerEvent(QTimerEvent* e) | |||
148 | { | 154 | { |
149 | if ( e->timerId() == held_tid ) { | 155 | if ( e->timerId() == held_tid ) { |
150 | killTimer(held_tid); | 156 | killTimer(held_tid); |
151 | // button held | 157 | // button held |
152 | if ( heldButton ) { | 158 | if ( heldButton ) { |
153 | emit activate(heldButton, TRUE); | 159 | emit activate(heldButton, TRUE); |
154 | heldButton = 0; | 160 | heldButton = 0; |
155 | } | 161 | } |
156 | held_tid = 0; | 162 | held_tid = 0; |
157 | } | 163 | } |
158 | } | 164 | } |
159 | 165 | ||
160 | void KeyFilter::registerKey( const QCopKeyRegister& key ) { | 166 | void KeyFilter::registerKey( const QCopKeyRegister& key ) |
167 | { | ||
161 | m_keys.insert( key.keyCode(), key ); | 168 | m_keys.insert( key.keyCode(), key ); |
162 | } | 169 | } |
163 | 170 | ||
164 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) { | 171 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) |
172 | { | ||
165 | m_keys.remove( key.keyCode() ); | 173 | m_keys.remove( key.keyCode() ); |
166 | } | 174 | } |
167 | 175 | ||
168 | bool KeyFilter::keyRegistered( int key ) { | 176 | bool KeyFilter::keyRegistered( int key ) |
177 | { | ||
169 | /* | 178 | /* |
170 | * Check if we've a key registered | 179 | * Check if we've a key registered |
171 | */ | 180 | */ |
172 | if ( !m_keys[key].send()) | 181 | if ( !m_keys[key].send()) |
173 | return false; | 182 | return false; |
174 | else | 183 | else |
175 | return true; | 184 | return true; |
176 | |||
177 | } | 185 | } |
178 | 186 | ||
179 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) | 187 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) |
180 | { | 188 | { |
181 | if ( !loggedin | 189 | if ( !loggedin |
182 | // Permitted keys | 190 | // Permitted keys |
183 | && keycode != Key_F34 // power | 191 | && keycode != Key_F34 // power |
184 | && keycode != Key_F30 // select | 192 | && keycode != Key_F30 // select |
185 | && keycode != Key_Enter | 193 | && keycode != Key_Enter |
186 | && keycode != Key_Return | 194 | && keycode != Key_Return |
187 | && keycode != Key_Space | 195 | && keycode != Key_Space |
188 | && keycode != Key_Left | 196 | && keycode != Key_Left |
189 | && keycode != Key_Right | 197 | && keycode != Key_Right |
190 | && keycode != Key_Up | 198 | && keycode != Key_Up |
191 | && keycode != Key_Down ) | 199 | && keycode != Key_Down ) |
192 | return TRUE; | 200 | return TRUE; |
193 | 201 | ||
194 | /* check if it was registered */ | 202 | /* check if it was registered */ |
195 | if (!db ) { | 203 | if (!db ) { |
196 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) | 204 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) |
197 | return true; | 205 | return true; |
198 | }else { | 206 | }else { |
199 | 207 | ||
200 | |||
201 | // First check to see if DeviceButtonManager knows something about this button: | 208 | // First check to see if DeviceButtonManager knows something about this button: |
202 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); | 209 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); |
203 | if (button && !autoRepeat) { | 210 | if (button && !autoRepeat) { |
204 | if ( held_tid ) { | 211 | if ( held_tid ) { |
205 | killTimer(held_tid); | 212 | killTimer(held_tid); |
206 | held_tid = 0; | 213 | held_tid = 0; |
207 | } | 214 | } |
208 | if ( button->heldAction().isNull() ) { | 215 | if ( button->heldAction().isNull() ) { |
209 | if ( press ) | 216 | if ( press ) |
210 | emit activate(button, FALSE); | 217 | emit activate(button, FALSE); |
211 | } else if ( press ) { | 218 | } else if ( press ) { |
212 | heldButton = button; | 219 | heldButton = button; |
@@ -257,25 +264,26 @@ enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; | |||
257 | #if defined(QPE_HAVE_MEMALERTER) | 264 | #if defined(QPE_HAVE_MEMALERTER) |
258 | QPE_MEMALERTER_IMPL | 265 | QPE_MEMALERTER_IMPL |
259 | #endif | 266 | #endif |
260 | 267 | ||
261 | 268 | ||
262 | 269 | ||
263 | //--------------------------------------------------------------------------- | 270 | //--------------------------------------------------------------------------- |
264 | 271 | ||
265 | bool ServerApplication::doRestart = FALSE; | 272 | bool ServerApplication::doRestart = FALSE; |
266 | bool ServerApplication::allowRestart = TRUE; | 273 | bool ServerApplication::allowRestart = TRUE; |
267 | bool ServerApplication::ms_is_starting = TRUE; | 274 | bool ServerApplication::ms_is_starting = TRUE; |
268 | 275 | ||
269 | void ServerApplication::switchLCD( bool on ) { | 276 | void ServerApplication::switchLCD( bool on ) |
277 | { | ||
270 | if ( !qApp ) | 278 | if ( !qApp ) |
271 | return; | 279 | return; |
272 | 280 | ||
273 | ServerApplication *dapp = ServerApplication::me() ; | 281 | ServerApplication *dapp = ServerApplication::me() ; |
274 | 282 | ||
275 | if ( !dapp-> m_screensaver ) | 283 | if ( !dapp-> m_screensaver ) |
276 | return; | 284 | return; |
277 | 285 | ||
278 | if ( on ) { | 286 | if ( on ) { |
279 | dapp-> m_screensaver-> setDisplayState ( true ); | 287 | dapp-> m_screensaver-> setDisplayState ( true ); |
280 | dapp-> m_screensaver-> setBacklight ( -3 ); | 288 | dapp-> m_screensaver-> setBacklight ( -3 ); |
281 | }else | 289 | }else |
@@ -350,31 +358,31 @@ ServerApplication::ServerApplication( int& argc, char **argv, Type t ) | |||
350 | grabKeyboard(); | 358 | grabKeyboard(); |
351 | 359 | ||
352 | /* make sure the event filter is installed */ | 360 | /* make sure the event filter is installed */ |
353 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); | 361 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); |
354 | Q_CONST_UNUSED( but ) | 362 | Q_CONST_UNUSED( but ) |
355 | } | 363 | } |
356 | 364 | ||
357 | 365 | ||
358 | ServerApplication::~ServerApplication() | 366 | ServerApplication::~ServerApplication() |
359 | { | 367 | { |
360 | ungrabKeyboard(); | 368 | ungrabKeyboard(); |
361 | 369 | ||
362 | |||
363 | delete pa; | 370 | delete pa; |
364 | delete m_ps; | 371 | delete m_ps; |
365 | delete m_ps_last; | 372 | delete m_ps_last; |
366 | } | 373 | } |
367 | 374 | ||
368 | void ServerApplication::apmTimeout() { | 375 | void ServerApplication::apmTimeout() |
376 | { | ||
369 | serverApp-> checkMemory( ); // in case no events are generated | 377 | serverApp-> checkMemory( ); // in case no events are generated |
370 | *m_ps_last = *m_ps; | 378 | *m_ps_last = *m_ps; |
371 | *m_ps = PowerStatusManager::readStatus(); | 379 | *m_ps = PowerStatusManager::readStatus(); |
372 | 380 | ||
373 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) | 381 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) |
374 | m_screensaver-> powerStatusChanged( *m_ps ); | 382 | m_screensaver-> powerStatusChanged( *m_ps ); |
375 | 383 | ||
376 | if ( m_ps->acStatus() == PowerStatus::Online ) { | 384 | if ( m_ps->acStatus() == PowerStatus::Online ) { |
377 | return; | 385 | return; |
378 | } | 386 | } |
379 | 387 | ||
380 | int bat = m_ps-> batteryPercentRemaining(); | 388 | int bat = m_ps-> batteryPercentRemaining(); |
@@ -399,25 +407,26 @@ void ServerApplication::apmTimeout() { | |||
399 | tr("WARNING"), | 407 | tr("WARNING"), |
400 | tr("<p>The Back-up battery is very low" | 408 | tr("<p>The Back-up battery is very low" |
401 | "<p>Please charge the back-up battery"), | 409 | "<p>Please charge the back-up battery"), |
402 | QMessageBox::Warning, | 410 | QMessageBox::Warning, |
403 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 411 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
404 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 412 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
405 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 413 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
406 | battlow.exec(); | 414 | battlow.exec(); |
407 | } | 415 | } |
408 | } | 416 | } |
409 | 417 | ||
410 | void ServerApplication::systemMessage( const QCString& msg, | 418 | void ServerApplication::systemMessage( const QCString& msg, |
411 | const QByteArray& data ) { | 419 | const QByteArray& data ) |
420 | { | ||
412 | QDataStream stream ( data, IO_ReadOnly ); | 421 | QDataStream stream ( data, IO_ReadOnly ); |
413 | 422 | ||
414 | if ( msg == "setScreenSaverInterval(int)" ) { | 423 | if ( msg == "setScreenSaverInterval(int)" ) { |
415 | int time; | 424 | int time; |
416 | stream >> time; | 425 | stream >> time; |
417 | m_screensaver-> setInterval( time ); | 426 | m_screensaver-> setInterval( time ); |
418 | } | 427 | } |
419 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 428 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
420 | int t1, t2, t3; | 429 | int t1, t2, t3; |
421 | stream >> t1 >> t2 >> t3; | 430 | stream >> t1 >> t2 >> t3; |
422 | m_screensaver-> setIntervals( t1, t2, t3 ); | 431 | m_screensaver-> setIntervals( t1, t2, t3 ); |
423 | } | 432 | } |
@@ -544,25 +553,24 @@ void ServerApplication::togglePower() | |||
544 | static bool excllock = false; | 553 | static bool excllock = false; |
545 | 554 | ||
546 | if ( excllock ) | 555 | if ( excllock ) |
547 | return ; | 556 | return ; |
548 | 557 | ||
549 | excllock = true; | 558 | excllock = true; |
550 | 559 | ||
551 | bool wasloggedin = loggedin; | 560 | bool wasloggedin = loggedin; |
552 | loggedin = 0; | 561 | loggedin = 0; |
553 | m_suspendTime = QDateTime::currentDateTime(); | 562 | m_suspendTime = QDateTime::currentDateTime(); |
554 | 563 | ||
555 | #ifdef QWS | 564 | #ifdef QWS |
556 | |||
557 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { | 565 | if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { |
558 | // Should use a big black window instead. | 566 | // Should use a big black window instead. |
559 | // But this would not show up fast enough | 567 | // But this would not show up fast enough |
560 | QGfx *g = qt_screen-> screenGfx ( ); | 568 | QGfx *g = qt_screen-> screenGfx ( ); |
561 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 569 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
562 | delete g; | 570 | delete g; |
563 | } | 571 | } |
564 | #endif | 572 | #endif |
565 | 573 | ||
566 | ODevice::inst ( )-> suspend ( ); | 574 | ODevice::inst ( )-> suspend ( ); |
567 | 575 | ||
568 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call | 576 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call |
@@ -618,48 +626,50 @@ bool ServerApplication::qwsEventFilter( QWSEvent *e ) | |||
618 | if ( e->type == QWSEvent::Mouse ) { | 626 | if ( e->type == QWSEvent::Mouse ) { |
619 | QWSMouseEvent *me = (QWSMouseEvent *)e; | 627 | QWSMouseEvent *me = (QWSMouseEvent *)e; |
620 | static bool up = TRUE; | 628 | static bool up = TRUE; |
621 | if ( me->simpleData.state&LeftButton ) { | 629 | if ( me->simpleData.state&LeftButton ) { |
622 | if ( up ) { | 630 | if ( up ) { |
623 | up = FALSE; | 631 | up = FALSE; |
624 | screenClick(TRUE); | 632 | screenClick(TRUE); |
625 | } | 633 | } |
626 | } else if ( !up ) { | 634 | } else if ( !up ) { |
627 | up = TRUE; | 635 | up = TRUE; |
628 | screenClick(FALSE); | 636 | screenClick(FALSE); |
629 | } | 637 | } |
630 | }else if ( e->type == QWSEvent::Key ) { | 638 | } else |
639 | if ( e->type == QWSEvent::Key ) { | ||
631 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); | 640 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); |
632 | if ( kf->checkButtonAction( false, | 641 | if ( kf->checkButtonAction( false, |
633 | ke-> simpleData.keycode, | 642 | ke-> simpleData.keycode, |
634 | ke-> simpleData.is_press, | 643 | ke-> simpleData.is_press, |
635 | ke-> simpleData.is_auto_repeat ) ) | 644 | ke-> simpleData.is_auto_repeat ) ) |
636 | return true; | 645 | return true; |
637 | } | 646 | } |
638 | 647 | ||
639 | return QPEApplication::qwsEventFilter( e ); | 648 | return QPEApplication::qwsEventFilter( e ); |
640 | } | 649 | } |
641 | #endif | 650 | #endif |
642 | 651 | ||
643 | 652 | ||
644 | /* ### FIXME libqtopia Plugin Safe Mode */ | 653 | /* ### FIXME libqtopia Plugin Safe Mode */ |
645 | 654 | ||
646 | void ServerApplication::showSafeMode() | 655 | void ServerApplication::showSafeMode() |
647 | { | 656 | { |
648 | #if 0 | 657 | #if 0 |
649 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " | 658 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " |
650 | "and the system is now in Safe Mode. " | 659 | "and the system is now in Safe Mode. " |
651 | "Plugins are not loaded in Safe Mode. " | 660 | "Plugins are not loaded in Safe Mode. " |
652 | "You can use the Plugin Manager to " | 661 | "You can use the Plugin Manager to " |
653 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) { | 662 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) |
663 | { | ||
654 | Global::execute( "pluginmanager" ); | 664 | Global::execute( "pluginmanager" ); |
655 | } | 665 | } |
656 | #endif | 666 | #endif |
657 | } | 667 | } |
658 | 668 | ||
659 | void ServerApplication::clearSafeMode() | 669 | void ServerApplication::clearSafeMode() |
660 | { | 670 | { |
661 | #if 0 | 671 | #if 0 |
662 | // If we've been running OK for a while then we won't bother going into | 672 | // If we've been running OK for a while then we won't bother going into |
663 | // safe mode immediately on the next crash. | 673 | // safe mode immediately on the next crash. |
664 | Config cfg( "PluginLoader" ); | 674 | Config cfg( "PluginLoader" ); |
665 | cfg.setGroup( "Global" ); | 675 | cfg.setGroup( "Global" ); |