summaryrefslogtreecommitdiff
authorzecke <zecke>2003-08-28 14:38:14 (UTC)
committer zecke <zecke>2003-08-28 14:38:14 (UTC)
commitcee2ebb839cdb7d586210e6f99c5e2c4d535c722 (patch) (unidiff)
tree012f80f0b7ee353f0e1b29f5d4bc6d3534dbeb42
parent245dcac2f79d7409f80da37f9c6c47fff70dc949 (diff)
downloadopie-cee2ebb839cdb7d586210e6f99c5e2c4d535c722.zip
opie-cee2ebb839cdb7d586210e6f99c5e2c4d535c722.tar.gz
opie-cee2ebb839cdb7d586210e6f99c5e2c4d535c722.tar.bz2
-kill casiopai support
-Opie Rotation -Opie init -proper killing to clean up
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/main.cpp306
1 files changed, 234 insertions, 72 deletions
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 69a7fea..075985d 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,7 +1,7 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of 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
@@ -18,127 +18,264 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "desktop.h" 21#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
22#define QTOPIA_INTERNAL_FILEOPERATIONS
23#endif
24#include "server.h"
25#include "serverapp.h"
22#include "taskbar.h" 26#include "taskbar.h"
23#include "stabmon.h" 27#include "stabmon.h"
28#include "launcher.h"
29#include "firstuse.h"
30#include "launcherglobal.h"
24 31
25#include <qpe/qpeapplication.h> 32#include <qtopia/qpeapplication.h>
26#include <qpe/network.h> 33#include <qtopia/network.h>
27#include <qpe/config.h> 34#include <qtopia/config.h>
28#if defined( QT_QWS_SL5XXX ) || defined( QT_QWS_IPAQ ) || defined (QT_QWS_RAMSES) 35#include <qtopia/custom.h>
29#include <qpe/custom.h> 36#include <qtopia/global.h>
30#endif
31 37
32#include <opie/odevice.h>
33
34#include <qmessagebox.h>
35#include <qfile.h> 38#include <qfile.h>
36#include <qimage.h> 39#include <qdir.h>
40#ifdef QWS
37#include <qwindowsystem_qws.h> 41#include <qwindowsystem_qws.h>
38#include <qwsmouse_qws.h> 42#include <qtopia/qcopenvelope_qws.h>
39#include <qpe/qcopenvelope_qws.h> 43#endif
40#include <qpe/alarmserver.h> 44#include <qtopia/alarmserver.h>
41 45
42#include <stdlib.h> 46#include <stdlib.h>
43#include <stdio.h> 47#include <stdio.h>
44#include <signal.h> 48#include <signal.h>
49#ifndef Q_OS_WIN32
45#include <unistd.h> 50#include <unistd.h>
51#else
52#include <process.h>
53#endif
54
55#include "calibrate.h"
46 56
47#include "../calibrate/calibrate.h" 57
58#ifdef QT_QWS_LOGIN
59#include "../login/qdmdialogimpl.h"
60#endif
61
62#ifdef Q_WS_QWS
63#include <qkeyboard_qws.h>
64#endif
65
66#include <qmessagebox.h>
67#include <opie/odevice.h>
48 68
49using namespace Opie; 69using namespace Opie;
50 70
71
72static void cleanup()
73{
74 QDir dir( Opie::Global::tempDir(), "qcop-msg-*" );
75
76 QStringList stale = dir.entryList();
77 QStringList::Iterator it;
78 for ( it = stale.begin(); it != stale.end(); ++it ) {
79 dir.remove( *it );
80 }
81}
82
83static void refreshTimeZoneConfig()
84{
85 /* ### FIXME timezone handling */
86#if 0
87 // We need to help WorldTime in setting up its configuration for
88 // the current translation
89 // BEGIN no tr
90 const char *defaultTz[] = {
91 "America/New_York",
92 "America/Los_Angeles",
93 "Europe/Oslo",
94 "Asia/Tokyo",
95 "Asia/Hong_Kong",
96 "Australia/Brisbane",
97 0
98 };
99 // END no tr
100
101 TimeZone curZone;
102 QString zoneID;
103 int zoneIndex;
104 Config cfg = Config( "WorldTime" );
105 cfg.setGroup( "TimeZones" );
106 if (!cfg.hasKey( "Zone0" )){
107 // We have no existing timezones use the defaults which are untranslated strings
108 QString currTz = TimeZone::current().id();
109 QStringList zoneDefaults;
110 zoneDefaults.append( currTz );
111 for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) {
112 if ( defaultTz[i] != currTz )
113 zoneDefaults.append( defaultTz[i] );
114 }
115 zoneIndex = 0;
116 for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){
117 cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it);
118 zoneIndex++;
119 }
120 }
121 // We have an existing list of timezones refresh the
122 // translations of TimeZone name
123 zoneIndex = 0;
124 while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){
125 zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex ));
126 curZone = TimeZone( zoneID );
127 if ( !curZone.isValid() ){
128 qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() );
129 break;
130 }
131 cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() );
132 zoneIndex++;
133 }
134#endif
135}
136
51void initEnvironment() 137void initEnvironment()
52{ 138{
53 int rot; 139#ifdef Q_OS_WIN32
140 // Config file requires HOME dir which uses QDir which needs the winver
141 qt_init_winver();
142#endif
54 Config config("locale"); 143 Config config("locale");
55
56 config.setGroup( "Location" ); 144 config.setGroup( "Location" );
57 QString tz = config.readEntry( "Timezone", getenv("TZ") ); 145 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace();
58 146
59 // if not timezone set, pick New York 147 // if not timezone set, pick New York
60 if (tz.isNull()) 148 if (tz.isNull() || tz.isEmpty())
61 tz = "America/New_York"; 149 tz = "America/New_York";
62 150
63 setenv( "TZ", tz, 1 ); 151 setenv( "TZ", tz, 1 );
64 config.writeEntry( "Timezone", tz); 152 config.writeEntry( "Timezone", tz);
65 153
66 config.setGroup( "Language" ); 154 config.setGroup( "Language" );
67 QString lang = config.readEntry( "Language", getenv("LANG") ); 155 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace();
68 if ( !lang.isNull() ) 156 if( lang.isNull() || lang.isEmpty())
69 setenv( "LANG", lang, 1 ); 157 lang = "en_US";
158
159 setenv( "LANG", lang, 1 );
160 config.writeEntry("Language", lang);
161 config.write();
70 162
71#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_SL5XXX) 163#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_SL5XXX)
72 setenv( "QWS_SIZE", "240x320", 0 ); 164 setenv( "QWS_SIZE", "240x320", 0 );
73#endif 165#endif
74 166
75 QString env(getenv("QWS_DISPLAY"));
76 if (env.contains("Transformed")) {
77 // transformed driver default rotation is controlled by the hardware.
78 Config config("qpe");
79 config.setGroup( "Rotation" );
80 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
81 rot = ODevice::inst ( )-> rotation ( ) * 90;
82 167
83 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 168
84 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ 169 QString env(getenv("QWS_DISPLAY"));
85 } 170 if (env.contains("Transformed")) {
171 int rot;
172 // transformed driver default rotation is controlled by the hardware.
173 Config config("qpe");
174 config.setGroup( "Rotation" );
175 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
176 rot = ODevice::inst ( )-> rotation ( ) * 90;
177
178 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
179 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */
180 }
86} 181}
87 182
183static void initKeyboard()
184{
185 Config config("qpe");
186
187 config.setGroup( "Keyboard" );
188
189 int ard = config.readNumEntry( "RepeatDelay" );
190 int arp = config.readNumEntry( "RepeatPeriod" );
191 if ( ard > 0 && arp > 0 )
192 qwsSetKeyboardAutoRepeat( ard, arp );
193
194 QString layout = config.readEntry( "Layout", "us101" );
195 Server::setKeyboardLayout( layout );
196}
197
198static bool firstUse()
199{
200 bool needFirstUse = FALSE;
201 if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
202 if ( !QFile::exists( "/etc/pointercal" ) )
203 needFirstUse = TRUE;
204 }
205
206 {
207 Config config( "qpe" );
208 config.setGroup( "Startup" );
209 needFirstUse |= config.readBoolEntry( "FirstUse", TRUE );
210 }
211
212 if ( !needFirstUse )
213 return FALSE;
214
215 FirstUse *fu = new FirstUse();
216 fu->exec();
217 bool rs = fu->restartNeeded();
218 delete fu;
219 return rs;
220}
88 221
89int initApplication( int argc, char ** argv ) 222int initApplication( int argc, char ** argv )
90{ 223{
224 cleanup();
225
226
91 initEnvironment(); 227 initEnvironment();
92 228
93 //Don't flicker at startup: 229 //Don't flicker at startup:
230#ifdef QWS
94 QWSServer::setDesktopBackground( QImage() ); 231 QWSServer::setDesktopBackground( QImage() );
232#endif
233 ServerApplication a( argc, argv, QApplication::GuiServer );
234
235 refreshTimeZoneConfig();
95 236
96 DesktopApplication a( argc, argv, QApplication::GuiServer ); 237 initKeyboard();
238
239 // Don't use first use under Windows
240 if ( firstUse() ) {
241 a.restart();
242 return 0;
243 }
97 244
98 ODevice::inst ( )-> setSoftSuspend ( true ); 245 ODevice::inst ( )-> setSoftSuspend ( true );
99 246
100 { // init backlight 247 {
101 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 248 QCopEnvelope e("QPE/System", "setBacklight(int)" );
102 e << -3; // Forced on 249 e << -3; // Forced on
103 } 250 }
104 251
105 AlarmServer::initialize(); 252 AlarmServer::initialize();
106 253
107 Desktop *d = new Desktop();
108 254
109 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
110 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
111 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
112 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
113 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
114 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
115 255
116 (void)new SysFileMonitor(d); 256 Server *s = new Server();
117 Network::createServer(d);
118 257
119 if ( QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 258 (void)new SysFileMonitor(s);
120 if ( !QFile::exists( "/etc/pointercal" ) ) { 259#ifdef QWS
121 // Make sure calibration widget starts on top. 260 Network::createServer(s);
122 Calibrate *cal = new Calibrate; 261#endif
123 cal->exec();
124 delete cal;
125 }
126 }
127 262
128 d->show(); 263 s->show();
129 264
130 if ( QDate::currentDate ( ). year ( ) < 2000 ) { 265 /* THE ARM rtc has problem holdings the time on reset */
131 if ( QMessageBox::information ( 0, DesktopApplication::tr( "Information" ), DesktopApplication::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 ) { 266 if ( QDate::currentDate ( ). year ( ) < 2000 ) {
132 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); 267 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 ) {
133 e << QString ( ); 268 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" );
134 } 269 e << QString ( );
135 } 270 }
271 }
136 272
137 int rv = a.exec(); 273 int rv = a.exec();
138 274
139 delete d; 275 qDebug("exiting...");
276 delete s;
140 277
141 ODevice::inst ( )-> setSoftSuspend ( false ); 278 ODevice::inst()->setSoftSuspend( false );
142 279
143 return rv; 280 return rv;
144} 281}
@@ -166,20 +303,30 @@ void handle_sigterm ( int /* sig */ )
166 qApp-> quit ( ); 303 qApp-> quit ( );
167} 304}
168 305
306#ifndef Q_OS_WIN32
169int main( int argc, char ** argv ) 307int main( int argc, char ** argv )
170{ 308{
309
171 ::signal ( SIGCHLD, SIG_IGN ); 310 ::signal ( SIGCHLD, SIG_IGN );
172 311
173 ::signal ( SIGTERM, handle_sigterm ); 312 ::signal ( SIGTERM, handle_sigterm );
174 ::signal ( SIGINT, handle_sigterm ); 313 ::signal ( SIGINT, handle_sigterm );
175 314
176 ::setsid ( ); 315 ::setsid ( );
177 ::setpgid ( 0, 0 ); 316 ::setpgid ( 0, 0 );
178 317
179 ::atexit ( remove_pidfile ); 318 ::atexit ( remove_pidfile );
180 create_pidfile ( ); 319 create_pidfile ( );
181 320
182 int retVal = initApplication ( argc, argv ); 321 int retVal = initApplication( argc, argv );
322
323 // Have we been asked to restart?
324 if ( ServerApplication::doRestart ) {
325 for ( int fd = 3; fd < 100; fd++ )
326 close( fd );
327
328 execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 );
329 }
183 330
184 // Kill them. Kill them all. 331 // Kill them. Kill them all.
185 ::kill ( 0, SIGTERM ); 332 ::kill ( 0, SIGTERM );
@@ -188,4 +335,19 @@ int main( int argc, char ** argv )
188 335
189 return retVal; 336 return retVal;
190} 337}
338#else
339
340int main( int argc, char ** argv )
341{
342 int retVal = initApplication( argc, argv );
343
344 if ( DesktopApplication::doRestart ) {
345 qDebug("Trying to restart");
346 execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 );
347 }
348
349 return retVal;
350}
351
352#endif
191 353