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