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