summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/serverapp.cpp22
-rw-r--r--core/launcher/serverapp.h2
2 files changed, 18 insertions, 6 deletions
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp
index 75d4ac1..6fe0479 100644
--- a/core/launcher/serverapp.cpp
+++ b/core/launcher/serverapp.cpp
@@ -1,851 +1,863 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2003 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 "serverapp.h" 21#include "serverapp.h"
22#include "screensaver.h" 22#include "screensaver.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <opie2/odebug.h> 25#include <opie2/odebug.h>
26#include <opie2/odevice.h> 26#include <opie2/odevice.h>
27#include <opie2/multiauthpassword.h> 27#include <opie2/multiauthpassword.h>
28 28
29#include <qtopia/config.h> 29#include <qtopia/config.h>
30#include <qtopia/power.h> 30#include <qtopia/power.h>
31 31
32#ifdef Q_WS_QWS 32#ifdef Q_WS_QWS
33#include <qtopia/qcopenvelope_qws.h> 33#include <qtopia/qcopenvelope_qws.h>
34#endif 34#endif
35#include <qtopia/global.h> 35#include <qtopia/global.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37 37
38/* QT */ 38/* QT */
39#ifdef Q_WS_QWS 39#ifdef Q_WS_QWS
40#include <qgfx_qws.h> 40#include <qgfx_qws.h>
41#endif 41#endif
42#include <qmessagebox.h> 42#include <qmessagebox.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qpainter.h> 44#include <qpainter.h>
45#include <qfile.h> 45#include <qfile.h>
46#include <qpixmapcache.h> 46#include <qpixmapcache.h>
47 47
48/* STD */ 48/* STD */
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
57static ServerApplication *serverApp = 0; 57static ServerApplication *serverApp = 0;
58static int loggedin=0; 58static int loggedin=0;
59 59
60QCopKeyRegister::QCopKeyRegister() 60QCopKeyRegister::QCopKeyRegister()
61 : m_keyCode( 0 ) 61 : m_keyCode( 0 )
62{ 62{
63 63
64} 64}
65 65
66QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) 66QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m )
67 :m_keyCode( k ), m_channel( c ), m_message( m ) 67 :m_keyCode( k ), m_channel( c ), m_message( m )
68{ 68{
69 69
70} 70}
71 71
72int QCopKeyRegister::keyCode() const 72int QCopKeyRegister::keyCode() const
73{ 73{
74 return m_keyCode; 74 return m_keyCode;
75} 75}
76 76
77QCString QCopKeyRegister::channel() const 77QCString QCopKeyRegister::channel() const
78{ 78{
79 return m_channel; 79 return m_channel;
80} 80}
81 81
82QCString QCopKeyRegister::message() const 82QCString QCopKeyRegister::message() const
83{ 83{
84 return m_message; 84 return m_message;
85} 85}
86 86
87bool QCopKeyRegister::send() 87bool QCopKeyRegister::send()
88{ 88{
89 if (m_channel.isNull() ) 89 if (m_channel.isNull() )
90 return false; 90 return false;
91 91
92 QCopEnvelope e( m_channel, m_message ); 92 QCopEnvelope e( m_channel, m_message );
93 93
94 return true; 94 return true;
95} 95}
96 96
97//--------------------------------------------------------------------------- 97//---------------------------------------------------------------------------
98 98
99/* 99/*
100 Priority is number of alerts that are needed to pop up 100 Priority is number of alerts that are needed to pop up
101 alert. 101 alert.
102 */ 102 */
103class DesktopPowerAlerter : public QMessageBox 103class DesktopPowerAlerter : public QMessageBox
104{ 104{
105 Q_OBJECT 105 Q_OBJECT
106public: 106public:
107 DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) 107 DesktopPowerAlerter( QWidget *parent, const char *name = 0 )
108 : QMessageBox( tr("Battery Status"), tr("Low Battery"), 108 : QMessageBox( tr("Battery Status"), tr("Low Battery"),
109 QMessageBox::Critical, 109 QMessageBox::Critical,
110 QMessageBox::Ok | QMessageBox::Default, 110 QMessageBox::Ok | QMessageBox::Default,
111 QMessageBox::NoButton, QMessageBox::NoButton, 111 QMessageBox::NoButton, QMessageBox::NoButton,
112 parent, name, FALSE ) 112 parent, name, FALSE )
113 { 113 {
114 currentPriority = INT_MAX; 114 currentPriority = INT_MAX;
115 alertCount = 0; 115 alertCount = 0;
116 } 116 }
117 117
118 void alert( const QString &text, int priority ); 118 void alert( const QString &text, int priority );
119 void hideEvent( QHideEvent * ); 119 void hideEvent( QHideEvent * );
120private: 120private:
121 int currentPriority; 121 int currentPriority;
122 int alertCount; 122 int alertCount;
123}; 123};
124 124
125void DesktopPowerAlerter::alert( const QString &text, int priority ) 125void DesktopPowerAlerter::alert( const QString &text, int priority )
126{ 126{
127 alertCount++; 127 alertCount++;
128 if ( alertCount < priority ) 128 if ( alertCount < priority )
129 return; 129 return;
130 if ( priority > currentPriority ) 130 if ( priority > currentPriority )
131 return; 131 return;
132 currentPriority = priority; 132 currentPriority = priority;
133 setText( text ); 133 setText( text );
134 show(); 134 show();
135} 135}
136 136
137 137
138void DesktopPowerAlerter::hideEvent( QHideEvent *e ) 138void DesktopPowerAlerter::hideEvent( QHideEvent *e )
139{ 139{
140 QMessageBox::hideEvent( e ); 140 QMessageBox::hideEvent( e );
141 alertCount = 0; 141 alertCount = 0;
142 currentPriority = INT_MAX; 142 currentPriority = INT_MAX;
143} 143}
144 144
145//--------------------------------------------------------------------------- 145//---------------------------------------------------------------------------
146 146
147KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0) 147KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0),firedHeldButton(0)
148{ 148{
149 /* We don't do this cause it would interfere with ODevice */ 149 /* We don't do this cause it would interfere with ODevice */
150#if 0 150#if 0
151 qwsServer->setKeyboardFilter(this); 151 qwsServer->setKeyboardFilter(this);
152#endif 152#endif
153} 153}
154 154
155void KeyFilter::timerEvent(QTimerEvent* e) 155void KeyFilter::timerEvent(QTimerEvent* e)
156{ 156{
157 if ( e->timerId() == held_tid ) { 157 if ( e->timerId() == held_tid ) {
158 killTimer(held_tid); 158 killTimer(held_tid);
159 // button held 159 // button held
160 if ( heldButton ) { 160 if ( heldButton ) {
161 emit activate(heldButton, TRUE); 161 emit activate(heldButton, TRUE);
162 firedHeldButton = heldButton;
162 heldButton = 0; 163 heldButton = 0;
163 } 164 }
164 held_tid = 0; 165 held_tid = 0;
165 } 166 }
166} 167}
167 168
168void KeyFilter::registerKey( const QCopKeyRegister& key ) 169void KeyFilter::registerKey( const QCopKeyRegister& key )
169{ 170{
170 171
171 m_keys.insert( key.keyCode(), key ); 172 m_keys.insert( key.keyCode(), key );
172} 173}
173 174
174void KeyFilter::unregisterKey( const QCopKeyRegister& key ) 175void KeyFilter::unregisterKey( const QCopKeyRegister& key )
175{ 176{
176 m_keys.remove( key.keyCode() ); 177 m_keys.remove( key.keyCode() );
177} 178}
178 179
179bool KeyFilter::keyRegistered( int key ) 180bool KeyFilter::keyRegistered( int key )
180{ 181{
181 /* 182 /*
182 * Check if we've a key registered 183 * Check if we've a key registered
183 */ 184 */
184 if ( !m_keys[key].send()) 185 if ( !m_keys[key].send())
185 return false; 186 return false;
186 else 187 else
187 return true; 188 return true;
188} 189}
189 190
190bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) 191bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat)
191{ 192{
192 if ( !loggedin 193 if ( !loggedin
193 // Permitted keys 194 // Permitted keys
194 && keycode != Key_F34 // power 195 && keycode != Key_F34 // power
195 && keycode != Key_F30 // select 196 && keycode != Key_F30 // select
196 && keycode != Key_Enter 197 && keycode != Key_Enter
197 && keycode != Key_Return 198 && keycode != Key_Return
198 && keycode != Key_Space 199 && keycode != Key_Space
199 && keycode != Key_Left 200 && keycode != Key_Left
200 && keycode != Key_Right 201 && keycode != Key_Right
201 && keycode != Key_Up 202 && keycode != Key_Up
202 && keycode != Key_Down ) 203 && keycode != Key_Down )
203 return TRUE; 204 return TRUE;
204 205
206// odebug << " KeyFilter::checkButtonAction("<<db<<","<<keycode<<","<<press<<","<<autoRepeat<<")"<<oendl;
205 /* check if it was registered */ 207 /* check if it was registered */
206 if (!db ) { 208 if (!db ) {
207 if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) 209 if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) )
208 return true; 210 return true;
209 } else { 211 } else {
210
211 // First check to see if DeviceButtonManager knows something about this button: 212 // First check to see if DeviceButtonManager knows something about this button:
212 const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); 213 const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode);
213 if (button && !autoRepeat) { 214 if (button && !autoRepeat) {
214 if ( held_tid ) { 215 if (firedHeldButton) {
216 if (held_tid) {
217 killTimer(held_tid);
218 held_tid = 0;
219 }
220 if (!press && button == firedHeldButton) {
221 firedHeldButton = 0;
222 return TRUE;
223 }
224 } else if ( held_tid && heldButton != button) {
215 killTimer(held_tid); 225 killTimer(held_tid);
216 held_tid = 0; 226 held_tid = 0;
217 } 227 }
218 if ( button->heldAction().isNull() ) { 228 if ( button->heldAction().isNull() ) {
219 if ( press ) 229 if ( press )
220 emit activate(button, FALSE); 230 emit activate(button, FALSE);
221 } else if ( press ) { 231 } else if ( press ) {
222 heldButton = button; 232 if (heldButton != button) {
223 held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); 233 heldButton = button;
234 held_tid = startTimer( ODevice::inst ()->buttonHoldTime () );
235 }
224 } else if ( heldButton ) { 236 } else if ( heldButton ) {
225 heldButton = 0; 237 heldButton = 0;
226 emit activate(button, FALSE); 238 emit activate(button, FALSE);
227 } 239 }
228 QWSServer::screenSaverActivate(FALSE); 240 QWSServer::screenSaverActivate(FALSE);
229 return TRUE; 241 return TRUE;
230 } 242 }
231 return false; 243 return false;
232 } 244 }
233 if ( keycode == HardKey_Suspend ) { 245 if ( keycode == HardKey_Suspend ) {
234 if ( press ) emit power(); 246 if ( press ) emit power();
235 return TRUE; 247 return TRUE;
236 } 248 }
237 if ( keycode == HardKey_Backlight ) { 249 if ( keycode == HardKey_Backlight ) {
238 if ( press ) emit backlight(); 250 if ( press ) emit backlight();
239 return TRUE; 251 return TRUE;
240 } 252 }
241 if ( keycode == Key_F32 ) { 253 if ( keycode == Key_F32 ) {
242#ifndef QT_NO_COP 254#ifndef QT_NO_COP
243 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); 255 if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" );
244#endif 256#endif
245 return TRUE; 257 return TRUE;
246 } 258 }
247 if ( keycode == Key_F31 ) { 259 if ( keycode == Key_F31 ) {
248 if ( press ) emit symbol(); 260 if ( press ) emit symbol();
249 QWSServer::screenSaverActivate(FALSE); 261 QWSServer::screenSaverActivate(FALSE);
250 return TRUE; 262 return TRUE;
251 } 263 }
252 264
253 if ( keycode == Key_NumLock ) 265 if ( keycode == Key_NumLock )
254 if ( press ) emit numLockStateToggle(); 266 if ( press ) emit numLockStateToggle();
255 267
256 if ( keycode == Key_CapsLock ) 268 if ( keycode == Key_CapsLock )
257 if ( press ) emit capsLockStateToggle(); 269 if ( press ) emit capsLockStateToggle();
258 270
259 if ( serverApp ) 271 if ( serverApp )
260 serverApp->keyClick(keycode,press,autoRepeat); 272 serverApp->keyClick(keycode,press,autoRepeat);
261 273
262 return FALSE; 274 return FALSE;
263} 275}
264 276
265enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; 277enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown;
266 278
267#if defined(QPE_HAVE_MEMALERTER) 279#if defined(QPE_HAVE_MEMALERTER)
268QPE_MEMALERTER_IMPL 280QPE_MEMALERTER_IMPL
269#endif 281#endif
270 282
271 283
272 284
273//--------------------------------------------------------------------------- 285//---------------------------------------------------------------------------
274 286
275bool ServerApplication::doRestart = FALSE; 287bool ServerApplication::doRestart = FALSE;
276bool ServerApplication::allowRestart = TRUE; 288bool ServerApplication::allowRestart = TRUE;
277bool ServerApplication::ms_is_starting = TRUE; 289bool ServerApplication::ms_is_starting = TRUE;
278 290
279void ServerApplication::switchLCD( bool on ) 291void ServerApplication::switchLCD( bool on )
280{ 292{
281 if ( !qApp ) 293 if ( !qApp )
282 return; 294 return;
283 295
284 ServerApplication *dapp = ServerApplication::me() ; 296 ServerApplication *dapp = ServerApplication::me() ;
285 297
286 if ( !dapp-> m_screensaver ) 298 if ( !dapp-> m_screensaver )
287 return; 299 return;
288 300
289 if ( on ) { 301 if ( on ) {
290 dapp-> m_screensaver-> setDisplayState ( true ); 302 dapp-> m_screensaver-> setDisplayState ( true );
291 dapp-> m_screensaver-> setBacklight ( -3 ); 303 dapp-> m_screensaver-> setBacklight ( -3 );
292 } else 304 } else
293 dapp-> m_screensaver-> setDisplayState ( false ); 305 dapp-> m_screensaver-> setDisplayState ( false );
294 306
295 307
296} 308}
297 309
298ServerApplication::ServerApplication( int& argc, char **argv, Type t ) 310ServerApplication::ServerApplication( int& argc, char **argv, Type t )
299 : Opie::Core::OApplication( argc, argv, t ) 311 : Opie::Core::OApplication( argc, argv, t )
300{ 312{
301 ms_is_starting = true; 313 ms_is_starting = true;
302 314
303 // We know we'll have lots of cached pixmaps due to App/DocLnks 315 // We know we'll have lots of cached pixmaps due to App/DocLnks
304 QPixmapCache::setCacheLimit(512); 316 QPixmapCache::setCacheLimit(512);
305 317
306 m_ps = new PowerStatus; 318 m_ps = new PowerStatus;
307 m_ps_last = new PowerStatus; 319 m_ps_last = new PowerStatus;
308 pa = new DesktopPowerAlerter( 0 ); 320 pa = new DesktopPowerAlerter( 0 );
309 321
310 m_apm_timer = new QTimer( this ); 322 m_apm_timer = new QTimer( this );
311 connect(m_apm_timer, SIGNAL( timeout() ), 323 connect(m_apm_timer, SIGNAL( timeout() ),
312 this, SLOT( apmTimeout() ) ); 324 this, SLOT( apmTimeout() ) );
313 325
314 reloadPowerWarnSettings(); 326 reloadPowerWarnSettings();
315 327
316 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 328 QCopChannel *channel = new QCopChannel( "QPE/System", this );
317 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), 329 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ),
318 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); 330 this, SLOT(systemMessage(const QCString&,const QByteArray&) ) );
319 331
320 channel = new QCopChannel("QPE/Launcher", this ); 332 channel = new QCopChannel("QPE/Launcher", this );
321 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), 333 connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ),
322 this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); 334 this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) );
323 335
324 m_screensaver = new OpieScreenSaver(); 336 m_screensaver = new OpieScreenSaver();
325 m_screensaver->setInterval( -1 ); 337 m_screensaver->setInterval( -1 );
326 QWSServer::setScreenSaver( m_screensaver ); 338 QWSServer::setScreenSaver( m_screensaver );
327 339
328 connect( qApp, SIGNAL( volumeChanged(bool) ), 340 connect( qApp, SIGNAL( volumeChanged(bool) ),
329 this, SLOT( rereadVolumes() ) ); 341 this, SLOT( rereadVolumes() ) );
330 342
331 343
332 /* ### PluginLoader libqtopia SafeMode */ 344 /* ### PluginLoader libqtopia SafeMode */
333#if 0 345#if 0
334 if ( PluginLoader::inSafeMode() ) 346 if ( PluginLoader::inSafeMode() )
335 QTimer::singleShot(500, this, SLOT(showSafeMode()) ); 347 QTimer::singleShot(500, this, SLOT(showSafeMode()) );
336 QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); 348 QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) );
337#endif 349#endif
338 350
339 kf = new KeyFilter(this); 351 kf = new KeyFilter(this);
340 352
341 connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); 353 connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) );
342 connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); 354 connect( kf, SIGNAL(power()), this, SIGNAL(power()) );
343 connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); 355 connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) );
344 connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); 356 connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol()));
345 connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); 357 connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle()));
346 connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); 358 connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle()));
347 connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), 359 connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)),
348 this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); 360 this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)));
349 361
350 362
351 connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); 363 connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) );
352 364
353 connect( this, SIGNAL(power() ), 365 connect( this, SIGNAL(power() ),
354 SLOT(togglePower() ) ); 366 SLOT(togglePower() ) );
355 367
356 rereadVolumes(); 368 rereadVolumes();
357 369
358 serverApp = this; 370 serverApp = this;
359 371
360 apmTimeout(); 372 apmTimeout();
361 grabKeyboard(); 373 grabKeyboard();
362 374
363 /* make sure the event filter is installed */ /* std::limits<short>::max() when you've stdc++ */ 375 /* make sure the event filter is installed */ /* std::limits<short>::max() when you've stdc++ */
364 const ODeviceButton* but = ODevice::inst()->buttonForKeycode( SHRT_MAX ); 376 const ODeviceButton* but = ODevice::inst()->buttonForKeycode( SHRT_MAX );
365 Q_CONST_UNUSED( but ) 377 Q_CONST_UNUSED( but )
366} 378}
367 379
368 380
369ServerApplication::~ServerApplication() 381ServerApplication::~ServerApplication()
370{ 382{
371 ungrabKeyboard(); 383 ungrabKeyboard();
372 384
373 delete pa; 385 delete pa;
374 delete m_ps; 386 delete m_ps;
375 delete m_ps_last; 387 delete m_ps_last;
376} 388}
377 389
378void ServerApplication::apmTimeout() 390void ServerApplication::apmTimeout()
379{ 391{
380 serverApp-> checkMemory( ); // in case no events are generated 392 serverApp-> checkMemory( ); // in case no events are generated
381 *m_ps_last = *m_ps; 393 *m_ps_last = *m_ps;
382 *m_ps = PowerStatusManager::readStatus(); 394 *m_ps = PowerStatusManager::readStatus();
383 395
384 if ( m_ps->acStatus() != m_ps_last-> acStatus() ) 396 if ( m_ps->acStatus() != m_ps_last-> acStatus() )
385 m_screensaver-> powerStatusChanged( *m_ps ); 397 m_screensaver-> powerStatusChanged( *m_ps );
386 398
387 if ( m_ps->acStatus() == PowerStatus::Online ) { 399 if ( m_ps->acStatus() == PowerStatus::Online ) {
388 return; 400 return;
389 } 401 }
390 402
391 int bat = m_ps-> batteryPercentRemaining(); 403 int bat = m_ps-> batteryPercentRemaining();
392 404
393 if ( bat < m_ps_last-> batteryPercentRemaining() ) { 405 if ( bat < m_ps_last-> batteryPercentRemaining() ) {
394 if ( bat <= m_powerCritical ) { 406 if ( bat <= m_powerCritical ) {
395 QMessageBox battlow( 407 QMessageBox battlow(
396 tr("WARNING"), 408 tr("WARNING"),
397 tr("<p>The battery level is critical!" 409 tr("<p>The battery level is critical!"
398 "<p>Keep power off until AC is restored"), 410 "<p>Keep power off until AC is restored"),
399 QMessageBox::Warning, 411 QMessageBox::Warning,
400 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 412 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
401 0, QString::null, TRUE, WStyle_StaysOnTop); 413 0, QString::null, TRUE, WStyle_StaysOnTop);
402 battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); 414 battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
403 battlow.exec(); 415 battlow.exec();
404 } else if ( bat <= m_powerVeryLow ) 416 } else if ( bat <= m_powerVeryLow )
405 pa->alert( tr( "The battery is running very low. "), 2 ); 417 pa->alert( tr( "The battery is running very low. "), 2 );
406 } 418 }
407 419
408 if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { 420 if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) {
409 QMessageBox battlow( 421 QMessageBox battlow(
410 tr("WARNING"), 422 tr("WARNING"),
411 tr("<p>The Back-up battery is very low" 423 tr("<p>The Back-up battery is very low"
412 "<p>Please charge the back-up battery"), 424 "<p>Please charge the back-up battery"),
413 QMessageBox::Warning, 425 QMessageBox::Warning,
414 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 426 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
415 0, QString::null, TRUE, WStyle_StaysOnTop); 427 0, QString::null, TRUE, WStyle_StaysOnTop);
416 battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); 428 battlow.setButtonText(QMessageBox::Cancel, tr("Ok"));
417 battlow.exec(); 429 battlow.exec();
418 } 430 }
419} 431}
420 432
421void ServerApplication::systemMessage( const QCString& msg, 433void ServerApplication::systemMessage( const QCString& msg,
422 const QByteArray& data ) 434 const QByteArray& data )
423{ 435{
424 QDataStream stream ( data, IO_ReadOnly ); 436 QDataStream stream ( data, IO_ReadOnly );
425 437
426 if ( msg == "setScreenSaverInterval(int)" ) { 438 if ( msg == "setScreenSaverInterval(int)" ) {
427 int time; 439 int time;
428 stream >> time; 440 stream >> time;
429 m_screensaver-> setInterval( time ); 441 m_screensaver-> setInterval( time );
430 } 442 }
431 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { 443 else if ( msg == "setScreenSaverIntervals(int,int,int)" ) {
432 int t1, t2, t3; 444 int t1, t2, t3;
433 stream >> t1 >> t2 >> t3; 445 stream >> t1 >> t2 >> t3;
434 m_screensaver-> setIntervals( t1, t2, t3 ); 446 m_screensaver-> setIntervals( t1, t2, t3 );
435 } 447 }
436 else if ( msg == "setBacklight(int)" ) { 448 else if ( msg == "setBacklight(int)" ) {
437 int bright; 449 int bright;
438 stream >> bright; 450 stream >> bright;
439 m_screensaver-> setBacklight( bright ); 451 m_screensaver-> setBacklight( bright );
440 } 452 }
441 else if ( msg == "setScreenSaverMode(int)" ) { 453 else if ( msg == "setScreenSaverMode(int)" ) {
442 int mode; 454 int mode;
443 stream >> mode; 455 stream >> mode;
444 m_screensaver-> setMode ( mode ); 456 m_screensaver-> setMode ( mode );
445 } 457 }
446 else if ( msg == "reloadPowerWarnSettings()" ) { 458 else if ( msg == "reloadPowerWarnSettings()" ) {
447 reloadPowerWarnSettings(); 459 reloadPowerWarnSettings();
448 } 460 }
449 else if ( msg == "setDisplayState(int)" ) { 461 else if ( msg == "setDisplayState(int)" ) {
450 int state; 462 int state;
451 stream >> state; 463 stream >> state;
452 m_screensaver-> setDisplayState ( state != 0 ); 464 m_screensaver-> setDisplayState ( state != 0 );
453 } 465 }
454 else if ( msg == "suspend()" ) { 466 else if ( msg == "suspend()" ) {
455 emit power(); 467 emit power();
456 } 468 }
457 else if ( msg == "sendBusinessCard()" ) { 469 else if ( msg == "sendBusinessCard()" ) {
458 QString card = ::getenv ( "HOME" ); 470 QString card = ::getenv ( "HOME" );
459 card += "/Applications/addressbook/businesscard.vcf"; 471 card += "/Applications/addressbook/businesscard.vcf";
460 472
461 if ( QFile::exists( card ) ) { 473 if ( QFile::exists( card ) ) {
462 QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); 474 QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" );
463 QString mimetype = "text/x-vCard"; 475 QString mimetype = "text/x-vCard";
464 e << tr( "business card" ) << card << mimetype; 476 e << tr( "business card" ) << card << mimetype;
465 } 477 }
466 } 478 }
467} 479}
468 480
469void ServerApplication::reloadPowerWarnSettings ( ) 481void ServerApplication::reloadPowerWarnSettings ( )
470{ 482{
471 Config cfg ( "apm" ); 483 Config cfg ( "apm" );
472 cfg. setGroup ( "Warnings" ); 484 cfg. setGroup ( "Warnings" );
473 485
474 int iv = cfg. readNumEntry ( "checkinterval", 10000 ); 486 int iv = cfg. readNumEntry ( "checkinterval", 10000 );
475 487
476 m_apm_timer-> stop ( ); 488 m_apm_timer-> stop ( );
477 if ( iv ) 489 if ( iv )
478 m_apm_timer-> start ( iv ); 490 m_apm_timer-> start ( iv );
479 491
480 m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); 492 m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 );
481 m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); 493 m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 );
482} 494}
483 495
484void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) 496void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data )
485{ 497{
486 QDataStream stream ( data, IO_ReadOnly ); 498 QDataStream stream ( data, IO_ReadOnly );
487 499
488 if ( msg == "deviceButton(int,int,int)" ) { 500 if ( msg == "deviceButton(int,int,int)" ) {
489 int keycode, press, autoRepeat; 501 int keycode, press, autoRepeat;
490 stream >> keycode >> press >> autoRepeat; 502 stream >> keycode >> press >> autoRepeat;
491 503
492 kf->checkButtonAction ( true, keycode, press, autoRepeat ); 504 kf->checkButtonAction ( true, keycode, press, autoRepeat );
493 } 505 }
494 else if ( msg == "keyRegister(int,QCString,QCString)" ) { 506 else if ( msg == "keyRegister(int,QCString,QCString)" ) {
495 int k; 507 int k;
496 QCString c, m; 508 QCString c, m;
497 stream >> k >> c >> m; 509 stream >> k >> c >> m;
498 510
499 kf -> registerKey( QCopKeyRegister(k, c, m) ); 511 kf -> registerKey( QCopKeyRegister(k, c, m) );
500 } 512 }
501} 513}
502 514
503 515
504bool ServerApplication::screenLocked() 516bool ServerApplication::screenLocked()
505{ 517{
506 return loggedin == 0; 518 return loggedin == 0;
507} 519}
508 520
509void ServerApplication::login(bool at_poweron) 521void ServerApplication::login(bool at_poweron)
510{ 522{
511 if ( !loggedin ) { 523 if ( !loggedin ) {
512 Global::terminateBuiltin("calibrate"); // No tr 524 Global::terminateBuiltin("calibrate"); // No tr
513 int lockMode = at_poweron ? Opie::Security::IfPowerOn : Opie::Security::IfResume; 525 int lockMode = at_poweron ? Opie::Security::IfPowerOn : Opie::Security::IfResume;
514 Opie::Security::MultiauthPassword::authenticate(lockMode); 526 Opie::Security::MultiauthPassword::authenticate(lockMode);
515 loggedin=1; 527 loggedin=1;
516#ifndef QT_NO_COP 528#ifndef QT_NO_COP
517 QCopEnvelope e( "QPE/Desktop", "unlocked()" ); 529 QCopEnvelope e( "QPE/Desktop", "unlocked()" );
518#endif 530#endif
519 } 531 }
520} 532}
521 533
522#if defined(QPE_HAVE_TOGGLELIGHT) 534#if defined(QPE_HAVE_TOGGLELIGHT)
523#include <qtopia/config.h> 535#include <qtopia/config.h>
524 536
525#include <sys/ioctl.h> 537#include <sys/ioctl.h>
526#include <sys/types.h> 538#include <sys/types.h>
527#include <fcntl.h> 539#include <fcntl.h>
528#include <unistd.h> 540#include <unistd.h>
529#include <errno.h> 541#include <errno.h>
530#include <linux/ioctl.h> 542#include <linux/ioctl.h>
531#include <time.h> 543#include <time.h>
532#endif 544#endif
533 545
534namespace { 546namespace {
535 void execAutoStart(const QDateTime& suspendTime ) { 547 void execAutoStart(const QDateTime& suspendTime ) {
536 QString appName; 548 QString appName;
537 int delay; 549 int delay;
538 QDateTime now = QDateTime::currentDateTime(); 550 QDateTime now = QDateTime::currentDateTime();
539 551
540 Config cfg( "autostart" ); 552 Config cfg( "autostart" );
541 cfg.setGroup( "AutoStart" ); 553 cfg.setGroup( "AutoStart" );
542 appName = cfg.readEntry( "Apps", "" ); 554 appName = cfg.readEntry( "Apps", "" );
543 delay = cfg.readNumEntry( "Delay", 0 ); 555 delay = cfg.readNumEntry( "Delay", 0 );
544 556
545 // If the time between suspend and resume was longer then the 557 // If the time between suspend and resume was longer then the
546 // value saved as delay, start the app 558 // value saved as delay, start the app
547 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { 559 if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) {
548 QCopEnvelope e( "QPE/System", "execute(QString)" ); 560 QCopEnvelope e( "QPE/System", "execute(QString)" );
549 e << QString( appName ); 561 e << QString( appName );
550 } 562 }
551 } 563 }
552} 564}
553 565
554 566
555void ServerApplication::togglePower() 567void ServerApplication::togglePower()
556{ 568{
557 static bool excllock = false; 569 static bool excllock = false;
558 570
559 if ( excllock ) 571 if ( excllock )
560 return ; 572 return ;
561 573
562 excllock = true; 574 excllock = true;
563 575
564 bool wasloggedin = loggedin; 576 bool wasloggedin = loggedin;
565 loggedin = 0; 577 loggedin = 0;
566 m_suspendTime = QDateTime::currentDateTime(); 578 m_suspendTime = QDateTime::currentDateTime();
567 579
568#ifdef QWS 580#ifdef QWS
569 if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) { 581 if ( Opie::Security::MultiauthPassword::needToAuthenticate ( true ) && qt_screen ) {
570 // Should use a big black window instead. 582 // Should use a big black window instead.
571 // But this would not show up fast enough 583 // But this would not show up fast enough
572 QGfx *g = qt_screen-> screenGfx ( ); 584 QGfx *g = qt_screen-> screenGfx ( );
573 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); 585 g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( ));
574 delete g; 586 delete g;
575 } 587 }
576#endif 588#endif
577 589
578 ODevice::inst ( )-> suspend ( ); 590 ODevice::inst ( )-> suspend ( );
579 591
580 ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call 592 ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call
581 QWSServer::screenSaverActivate ( false ); 593 QWSServer::screenSaverActivate ( false );
582 594
583 { 595 {
584 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep 596 QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep
585 } 597 }
586 598
587 if ( wasloggedin ) 599 if ( wasloggedin )
588 login ( true ); 600 login ( true );
589 601
590 execAutoStart(m_suspendTime); 602 execAutoStart(m_suspendTime);
591 //qcopBridge->closeOpenConnections(); 603 //qcopBridge->closeOpenConnections();
592 604
593 excllock = false; 605 excllock = false;
594} 606}
595 607
596void ServerApplication::toggleLight() 608void ServerApplication::toggleLight()
597{ 609{
598#ifndef QT_NO_COP 610#ifndef QT_NO_COP
599 QCopEnvelope e("QPE/System", "setBacklight(int)"); 611 QCopEnvelope e("QPE/System", "setBacklight(int)");
600 e << -2; // toggle 612 e << -2; // toggle
601#endif 613#endif
602} 614}
603 615
604 616
605/* 617/*
606 * We still listen to key events but handle them in 618 * We still listen to key events but handle them in
607 * a special class 619 * a special class
608 */ 620 */
609 621
610bool ServerApplication::eventFilter( QObject *o, QEvent *e) { 622bool ServerApplication::eventFilter( QObject *o, QEvent *e) {
611 if ( e->type() != QEvent::KeyPress && 623 if ( e->type() != QEvent::KeyPress &&
612 e->type() != QEvent::KeyRelease ) 624 e->type() != QEvent::KeyRelease )
613 return QPEApplication::eventFilter( o, e ); 625 return QPEApplication::eventFilter( o, e );
614 626
615 QKeyEvent *ke = static_cast<QKeyEvent*>( e ); 627 QKeyEvent *ke = static_cast<QKeyEvent*>( e );
616 if ( kf->checkButtonAction( true, ke->key(), 628 if ( kf->checkButtonAction( true, ke->key(),
617 e->type() == QEvent::KeyPress, 629 e->type() == QEvent::KeyPress,
618 ke-> isAutoRepeat() )) 630 ke-> isAutoRepeat() ))
619 return true; 631 return true;
620 632
621 return QPEApplication::eventFilter( o, e ); 633 return QPEApplication::eventFilter( o, e );
622 634
623} 635}
624 636
625#ifdef Q_WS_QWS 637#ifdef Q_WS_QWS
626bool ServerApplication::qwsEventFilter( QWSEvent *e ) 638bool ServerApplication::qwsEventFilter( QWSEvent *e )
627{ 639{
628 checkMemory(); 640 checkMemory();
629 641
630 if ( e->type == QWSEvent::Mouse ) { 642 if ( e->type == QWSEvent::Mouse ) {
631 QWSMouseEvent *me = (QWSMouseEvent *)e; 643 QWSMouseEvent *me = (QWSMouseEvent *)e;
632 static bool up = TRUE; 644 static bool up = TRUE;
633 if ( me->simpleData.state&LeftButton ) { 645 if ( me->simpleData.state&LeftButton ) {
634 if ( up ) { 646 if ( up ) {
635 up = FALSE; 647 up = FALSE;
636 screenClick(TRUE); 648 screenClick(TRUE);
637 } 649 }
638 } else if ( !up ) { 650 } else if ( !up ) {
639 up = TRUE; 651 up = TRUE;
640 screenClick(FALSE); 652 screenClick(FALSE);
641 } 653 }
642 } else 654 } else
643 if ( e->type == QWSEvent::Key ) { 655 if ( e->type == QWSEvent::Key ) {
644 QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); 656 QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e );
645 if ( kf->checkButtonAction( false, 657 if ( kf->checkButtonAction( false,
646 ke-> simpleData.keycode, 658 ke-> simpleData.keycode,
647 ke-> simpleData.is_press, 659 ke-> simpleData.is_press,
648 ke-> simpleData.is_auto_repeat ) ) 660 ke-> simpleData.is_auto_repeat ) )
649 return true; 661 return true;
650 } 662 }
651 663
652 return QPEApplication::qwsEventFilter( e ); 664 return QPEApplication::qwsEventFilter( e );
653} 665}
654#endif 666#endif
655 667
656 668
657/* ### FIXME libqtopia Plugin Safe Mode */ 669/* ### FIXME libqtopia Plugin Safe Mode */
658 670
659void ServerApplication::showSafeMode() 671void ServerApplication::showSafeMode()
660{ 672{
661#if 0 673#if 0
662 if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " 674 if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, "
663 "and the system is now in Safe Mode. " 675 "and the system is now in Safe Mode. "
664 "Plugins are not loaded in Safe Mode. " 676 "Plugins are not loaded in Safe Mode. "
665 "You can use the Plugin Manager to " 677 "You can use the Plugin Manager to "
666 "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) 678 "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 )
667 { 679 {
668 Global::execute( "pluginmanager" ); 680 Global::execute( "pluginmanager" );
669 } 681 }
670#endif 682#endif
671} 683}
672 684
673void ServerApplication::clearSafeMode() 685void ServerApplication::clearSafeMode()
674{ 686{
675#if 0 687#if 0
676 // If we've been running OK for a while then we won't bother going into 688 // If we've been running OK for a while then we won't bother going into
677 // safe mode immediately on the next crash. 689 // safe mode immediately on the next crash.
678 Config cfg( "PluginLoader" ); 690 Config cfg( "PluginLoader" );
679 cfg.setGroup( "Global" ); 691 cfg.setGroup( "Global" );
680 QString mode = cfg.readEntry( "Mode", "Normal" ); 692 QString mode = cfg.readEntry( "Mode", "Normal" );
681 if ( mode == "MaybeSafe" ) { 693 if ( mode == "MaybeSafe" ) {
682 cfg.writeEntry( "Mode", "Normal" ); 694 cfg.writeEntry( "Mode", "Normal" );
683 } 695 }
684#endif 696#endif
685} 697}
686 698
687 699
688void ServerApplication::shutdown() 700void ServerApplication::shutdown()
689{ 701{
690 if ( type() != GuiServer ) 702 if ( type() != GuiServer )
691 return; 703 return;
692 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); 704 ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose );
693 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), 705 connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)),
694 this, SLOT(shutdown(ShutdownImpl::Type)) ); 706 this, SLOT(shutdown(ShutdownImpl::Type)) );
695 QPEApplication::showWidget( sd ); 707 QPEApplication::showWidget( sd );
696} 708}
697 709
698void ServerApplication::shutdown( ShutdownImpl::Type t ) 710void ServerApplication::shutdown( ShutdownImpl::Type t )
699{ 711{
700 char *opt = 0; 712 char *opt = 0;
701 713
702 switch ( t ) { 714 switch ( t ) {
703 case ShutdownImpl::ShutdownSystem: 715 case ShutdownImpl::ShutdownSystem:
704 opt = "-h"; 716 opt = "-h";
705 // fall through 717 // fall through
706 case ShutdownImpl::RebootSystem: 718 case ShutdownImpl::RebootSystem:
707 if ( opt == 0 ) 719 if ( opt == 0 )
708 opt = "-r"; 720 opt = "-r";
709 721
710 if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) 722 if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 )
711 perror("shutdown"); 723 perror("shutdown");
712// ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); 724// ::syslog ( LOG_ERR, "Erroring execing shutdown\n" );
713 725
714 break; 726 break;
715 case ShutdownImpl::RestartDesktop: 727 case ShutdownImpl::RestartDesktop:
716 restart(); 728 restart();
717 break; 729 break;
718 case ShutdownImpl::TerminateDesktop: 730 case ShutdownImpl::TerminateDesktop:
719 prepareForTermination( FALSE ); 731 prepareForTermination( FALSE );
720 732
721 // This is a workaround for a Qt bug 733 // This is a workaround for a Qt bug
722 // clipboard applet has to stop its poll timer, or Qt/E 734 // clipboard applet has to stop its poll timer, or Qt/E
723 // will hang on quit() right before it emits aboutToQuit() 735 // will hang on quit() right before it emits aboutToQuit()
724 emit aboutToQuit ( ); 736 emit aboutToQuit ( );
725 737
726 quit(); 738 quit();
727 break; 739 break;
728 } 740 }
729} 741}
730 742
731void ServerApplication::restart() 743void ServerApplication::restart()
732{ 744{
733 if ( allowRestart ) { 745 if ( allowRestart ) {
734 746
735 /* 747 /*
736 * Applets and restart is a problem. Some applets delete 748 * Applets and restart is a problem. Some applets delete
737 * their widgets even if ownership gets transfered to the 749 * their widgets even if ownership gets transfered to the
738 * parent (Systray ) but deleting the applet may be unsafe 750 * parent (Systray ) but deleting the applet may be unsafe
739 * as well ( double deletion ). Some have topLevel widgets 751 * as well ( double deletion ). Some have topLevel widgets
740 * and when we dlclose and then delete the widget we will 752 * and when we dlclose and then delete the widget we will
741 * crash and an crash during restart is not nice 753 * crash and an crash during restart is not nice
742 */ 754 */
743#ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED 755#ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED
744 /* same as above */ 756 /* same as above */
745 emit aboutToQuit(); 757 emit aboutToQuit();
746 prepareForTermination(TRUE); 758 prepareForTermination(TRUE);
747 doRestart = TRUE; 759 doRestart = TRUE;
748 quit(); 760 quit();
749#else 761#else
750 prepareForTermination( true ); 762 prepareForTermination( true );
751 for ( int fd = 3; fd < 100; fd++ ) 763 for ( int fd = 3; fd < 100; fd++ )
752 close( fd ); 764 close( fd );
753 execl( ( qpeDir() + "/bin/qpe" ).local8Bit(), "qpe", NULL ); 765 execl( ( qpeDir() + "/bin/qpe" ).local8Bit(), "qpe", NULL );
754 exit( 1 ); 766 exit( 1 );
755#endif 767#endif
756 } 768 }
757} 769}
758 770
759void ServerApplication::rereadVolumes() 771void ServerApplication::rereadVolumes()
760{ 772{
761 Config cfg( "qpe" ); 773 Config cfg( "qpe" );
762 cfg. setGroup ( "Volume" ); 774 cfg. setGroup ( "Volume" );
763 775
764 m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); 776 m_screentap_sound = cfg. readBoolEntry ( "TouchSound" );
765 m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); 777 m_keyclick_sound = cfg. readBoolEntry ( "KeySound" );
766 m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); 778 m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" );
767} 779}
768 780
769 781
770void ServerApplication::checkMemory() 782void ServerApplication::checkMemory()
771{ 783{
772#if defined(QPE_HAVE_MEMALERTER) 784#if defined(QPE_HAVE_MEMALERTER)
773 static bool ignoreNormal=TRUE; 785 static bool ignoreNormal=TRUE;
774 static bool existingMessage=FALSE; 786 static bool existingMessage=FALSE;
775 787
776 if(existingMessage) 788 if(existingMessage)
777 return; // don't show a second message while still on first 789 return; // don't show a second message while still on first
778 790
779 existingMessage = TRUE; 791 existingMessage = TRUE;
780 switch ( memstate ) { 792 switch ( memstate ) {
781 case MemUnknown: 793 case MemUnknown:
782 break; 794 break;
783 case MemLow: 795 case MemLow:
784 memstate = MemUnknown; 796 memstate = MemUnknown;
785 if ( !recoverMemory() ) { 797 if ( !recoverMemory() ) {
786 QMessageBox::warning( 0 , tr("Memory Status"), 798 QMessageBox::warning( 0 , tr("Memory Status"),
787 tr("Memory Low\nPlease save data.") ); 799 tr("Memory Low\nPlease save data.") );
788 ignoreNormal = FALSE; 800 ignoreNormal = FALSE;
789 } 801 }
790 break; 802 break;
791 case MemNormal: 803 case MemNormal:
792 memstate = MemUnknown; 804 memstate = MemUnknown;
793 if ( !ignoreNormal ) { 805 if ( !ignoreNormal ) {
794 ignoreNormal = TRUE; 806 ignoreNormal = TRUE;
795 QMessageBox::information ( 0 , tr("Memory Status"), 807 QMessageBox::information ( 0 , tr("Memory Status"),
796 "Memory OK" ); 808 "Memory OK" );
797 } 809 }
798 break; 810 break;
799 case MemVeryLow: 811 case MemVeryLow:
800 memstate = MemUnknown; 812 memstate = MemUnknown;
801 QMessageBox::critical( 0 , tr("Memory Status"), 813 QMessageBox::critical( 0 , tr("Memory Status"),
802 tr("Critical Memory Shortage\n" 814 tr("Critical Memory Shortage\n"
803 "Please end this application\n" 815 "Please end this application\n"
804 "immediately.") ); 816 "immediately.") );
805 recoverMemory(); 817 recoverMemory();
806 } 818 }
807 existingMessage = FALSE; 819 existingMessage = FALSE;
808#endif 820#endif
809} 821}
810 822
811bool ServerApplication::recoverMemory() 823bool ServerApplication::recoverMemory()
812{ 824{
813 return FALSE; 825 return FALSE;
814} 826}
815 827
816void ServerApplication::keyClick(int , bool press, bool ) 828void ServerApplication::keyClick(int , bool press, bool )
817{ 829{
818 if ( press && m_keyclick_sound ) 830 if ( press && m_keyclick_sound )
819 ODevice::inst() -> playKeySound(); 831 ODevice::inst() -> playKeySound();
820 832
821} 833}
822 834
823void ServerApplication::screenClick(bool press) 835void ServerApplication::screenClick(bool press)
824{ 836{
825 if ( press && m_screentap_sound ) 837 if ( press && m_screentap_sound )
826 ODevice::inst() -> playTouchSound(); 838 ODevice::inst() -> playTouchSound();
827} 839}
828 840
829void ServerApplication::soundAlarm() { 841void ServerApplication::soundAlarm() {
830 if ( me ()->m_alarm_sound ) 842 if ( me ()->m_alarm_sound )
831 ODevice::inst()->playAlarmSound(); 843 ODevice::inst()->playAlarmSound();
832} 844}
833 845
834ServerApplication *ServerApplication::me ( ) 846ServerApplication *ServerApplication::me ( )
835{ 847{
836 return static_cast<ServerApplication*>( qApp ); 848 return static_cast<ServerApplication*>( qApp );
837} 849}
838 850
839bool ServerApplication::isStarting() 851bool ServerApplication::isStarting()
840{ 852{
841 return ms_is_starting; 853 return ms_is_starting;
842} 854}
843 855
844int ServerApplication::exec() 856int ServerApplication::exec()
845{ 857{
846 ms_is_starting = true; 858 ms_is_starting = true;
847 odebug << "Serverapp - exec" << oendl; 859 odebug << "Serverapp - exec" << oendl;
848 return QPEApplication::exec(); 860 return QPEApplication::exec();
849} 861}
850 862
851#include "serverapp.moc" 863#include "serverapp.moc"
diff --git a/core/launcher/serverapp.h b/core/launcher/serverapp.h
index 27be28b..98c5633 100644
--- a/core/launcher/serverapp.h
+++ b/core/launcher/serverapp.h
@@ -1,171 +1,171 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2003 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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 SERVERAPP_H 21#ifndef SERVERAPP_H
22#define SERVERAPP_H 22#define SERVERAPP_H
23 23
24#include <opie2/oapplication.h> 24#include <opie2/oapplication.h>
25 25
26#include <qwidget.h> 26#include <qwidget.h>
27#ifdef QWS 27#ifdef QWS
28#include <qwindowsystem_qws.h> 28#include <qwindowsystem_qws.h>
29#endif 29#endif
30 30
31#include "shutdownimpl.h" 31#include "shutdownimpl.h"
32 32
33class PowerStatus; 33class PowerStatus;
34class DesktopPowerAlerter; 34class DesktopPowerAlerter;
35 35
36class OpieScreenSaver; 36class OpieScreenSaver;
37namespace Opie { 37namespace Opie {
38namespace Core { 38namespace Core {
39 class ODeviceButton; 39 class ODeviceButton;
40} 40}
41} 41}
42 42
43struct QCopKeyRegister { 43struct QCopKeyRegister {
44 QCopKeyRegister(); 44 QCopKeyRegister();
45 QCopKeyRegister( int k, const QCString&, const QCString& ); 45 QCopKeyRegister( int k, const QCString&, const QCString& );
46 int keyCode()const; 46 int keyCode()const;
47 QCString channel()const; 47 QCString channel()const;
48 QCString message()const; 48 QCString message()const;
49 inline bool send(); 49 inline bool send();
50 50
51private: 51private:
52 int m_keyCode; 52 int m_keyCode;
53 QCString m_channel, m_message; 53 QCString m_channel, m_message;
54}; 54};
55 55
56typedef QMap<int, QCopKeyRegister> KeyRegisterList; 56typedef QMap<int, QCopKeyRegister> KeyRegisterList;
57 57
58class KeyFilter : public QObject { 58class KeyFilter : public QObject {
59 Q_OBJECT 59 Q_OBJECT
60public: 60public:
61 KeyFilter(QObject* parent); 61 KeyFilter(QObject* parent);
62 void registerKey( const QCopKeyRegister& ); 62 void registerKey( const QCopKeyRegister& );
63 void unregisterKey( const QCopKeyRegister& ); 63 void unregisterKey( const QCopKeyRegister& );
64 bool checkButtonAction( bool, int, int, int ); 64 bool checkButtonAction( bool, int, int, int );
65 65
66 66
67 67
68protected: 68protected:
69 void timerEvent(QTimerEvent*); 69 void timerEvent(QTimerEvent*);
70 70
71signals: 71signals:
72 void launch(); 72 void launch();
73 void power(); 73 void power();
74 void backlight(); 74 void backlight();
75 void symbol(); 75 void symbol();
76 void numLockStateToggle(); 76 void numLockStateToggle();
77 void capsLockStateToggle(); 77 void capsLockStateToggle();
78 void activate(const Opie::Core::ODeviceButton*,bool); 78 void activate(const Opie::Core::ODeviceButton*,bool);
79 79
80 80
81private: 81private:
82 bool keyRegistered( int key ); 82 bool keyRegistered( int key );
83 int held_tid; 83 int held_tid;
84 const Opie::Core::ODeviceButton* heldButton; 84 const Opie::Core::ODeviceButton* heldButton,*firedHeldButton;
85 KeyRegisterList m_keys; 85 KeyRegisterList m_keys;
86}; 86};
87 87
88class ServerApplication : public Opie::Core::OApplication 88class ServerApplication : public Opie::Core::OApplication
89{ 89{
90 Q_OBJECT 90 Q_OBJECT
91public: 91public:
92 ServerApplication( int& argc, char **argv, Type t ); 92 ServerApplication( int& argc, char **argv, Type t );
93 ~ServerApplication(); 93 ~ServerApplication();
94 94
95 static bool doRestart; 95 static bool doRestart;
96 static bool allowRestart; 96 static bool allowRestart;
97 static bool screenLocked(); 97 static bool screenLocked();
98 static void login(bool at_poweron); 98 static void login(bool at_poweron);
99 99
100 static bool isStarting(); 100 static bool isStarting();
101 101
102 static void switchLCD ( bool on ); // only for togglePower in Desktop 102 static void switchLCD ( bool on ); // only for togglePower in Desktop
103 static void soundAlarm(); // only because QCop soundAlarm() is defined in QPE/TaskBar 103 static void soundAlarm(); // only because QCop soundAlarm() is defined in QPE/TaskBar
104 104
105 void restart(); 105 void restart();
106 int exec(); 106 int exec();
107 107
108signals: 108signals:
109 void menu(); 109 void menu();
110 void home(); 110 void home();
111 void launch(); 111 void launch();
112 void power(); 112 void power();
113 void backlight(); 113 void backlight();
114 void symbol(); 114 void symbol();
115 void numLockStateToggle(); 115 void numLockStateToggle();
116 void capsLockStateToggle(); 116 void capsLockStateToggle();
117 void prepareForRestart(); 117 void prepareForRestart();
118 void activate(const Opie::Core::ODeviceButton*,bool); 118 void activate(const Opie::Core::ODeviceButton*,bool);
119 119
120public slots: 120public slots:
121 virtual void systemMessage( const QCString& msg, const QByteArray& ); 121 virtual void systemMessage( const QCString& msg, const QByteArray& );
122 virtual void launcherMessage( const QCString& msg, const QByteArray& ); 122 virtual void launcherMessage( const QCString& msg, const QByteArray& );
123 void rereadVolumes(); 123 void rereadVolumes();
124 124
125protected: 125protected:
126 bool eventFilter( QObject*, QEvent* ); 126 bool eventFilter( QObject*, QEvent* );
127#ifdef Q_WS_QWS 127#ifdef Q_WS_QWS
128 bool qwsEventFilter( QWSEvent * ); 128 bool qwsEventFilter( QWSEvent * );
129#endif 129#endif
130 void shutdown(); 130 void shutdown();
131 void checkMemory(); 131 void checkMemory();
132 bool recoverMemory(); 132 bool recoverMemory();
133 void keyClick(int keycode, bool press, bool repeat); 133 void keyClick(int keycode, bool press, bool repeat);
134 void screenClick(bool press); 134 void screenClick(bool press);
135 135
136protected slots: 136protected slots:
137 void shutdown(ShutdownImpl::Type); 137 void shutdown(ShutdownImpl::Type);
138 void apmTimeout(); 138 void apmTimeout();
139 void showSafeMode(); 139 void showSafeMode();
140 void clearSafeMode(); 140 void clearSafeMode();
141 void togglePower(); 141 void togglePower();
142 void toggleLight(); 142 void toggleLight();
143 143
144private: 144private:
145 static ServerApplication *me (); 145 static ServerApplication *me ();
146 void reloadPowerWarnSettings(); 146 void reloadPowerWarnSettings();
147 KeyFilter *kf; 147 KeyFilter *kf;
148 148
149 149
150private: 150private:
151 DesktopPowerAlerter *pa; 151 DesktopPowerAlerter *pa;
152 PowerStatus *m_ps, *m_ps_last; 152 PowerStatus *m_ps, *m_ps_last;
153 OpieScreenSaver *m_screensaver; 153 OpieScreenSaver *m_screensaver;
154 QTimer *m_apm_timer; 154 QTimer *m_apm_timer;
155 QDateTime m_suspendTime; 155 QDateTime m_suspendTime;
156 int m_powerVeryLow; 156 int m_powerVeryLow;
157 int m_powerCritical; 157 int m_powerCritical;
158 int m_currentPowerLevel; 158 int m_currentPowerLevel;
159 159
160 bool m_keyclick_sound : 1; 160 bool m_keyclick_sound : 1;
161 bool m_screentap_sound : 1; 161 bool m_screentap_sound : 1;
162 bool m_alarm_sound : 1; 162 bool m_alarm_sound : 1;
163 static bool ms_is_starting; 163 static bool ms_is_starting;
164 164
165 165
166 friend class KeyFilter; 166 friend class KeyFilter;
167}; 167};
168 168
169 169
170#endif // SERVERAPP_H 170#endif // SERVERAPP_H
171 171