summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/main.cpp142
1 files changed, 65 insertions, 77 deletions
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index aa0dfdf..734d072 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,26 +1,19 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3** Copyright (C) 2003-2005 The Opie Team <opie-devel@handhelds.org>
4** This file is part of the Qtopia Environment.
5** 4**
6** This file may be distributed and/or modified under the terms of the 5** 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 6** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 8** packaging of this file.
10** 9**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** 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. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/ 12**********************************************************************/
20 13
21#ifndef QTOPIA_INTERNAL_FILEOPERATIONS 14#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
22#define QTOPIA_INTERNAL_FILEOPERATIONS 15#define QTOPIA_INTERNAL_FILEOPERATIONS
23#endif 16#endif
24#ifdef QT_QWS_LOGIN 17#ifdef QT_QWS_LOGIN
25#include "../login/qdmdialogimpl.h" 18#include "../login/qdmdialogimpl.h"
26#endif 19#endif
@@ -48,77 +41,69 @@ using namespace Opie::Core;
48#ifdef Q_WS_QWS 41#ifdef Q_WS_QWS
49#include <qkeyboard_qws.h> 42#include <qkeyboard_qws.h>
50#endif 43#endif
51 44
52/* STD */ 45/* STD */
53#include <stdlib.h> 46#include <stdlib.h>
54#include <stdio.h> 47#include <stdio.h>
55#include <signal.h> 48#include <signal.h>
56#ifndef Q_OS_WIN32
57#include <unistd.h> 49#include <unistd.h>
58#else 50#include <errno.h>
59#include <process.h> 51#include <string.h>
60#endif 52
53void create_pidfile();
54void remove_pidfile();
61 55
62static void cleanup() 56static void cleanup()
63{ 57{
64 QDir dir( "/tmp", "qcop-msg-*" ); 58 QDir dir( "/tmp", "qcop-msg-*" );
65 59
66 QStringList stale = dir.entryList(); 60 QStringList stale = dir.entryList();
67 QStringList::Iterator it; 61 QStringList::Iterator it;
68 for ( it = stale.begin(); it != stale.end(); ++it ) { 62 for ( it = stale.begin(); it != stale.end(); ++it ) {
69 dir.remove( *it ); 63 dir.remove( *it );
70 } 64 }
71} 65}
72 66
73static void refreshTimeZoneConfig()
74{
75 /* ### FIXME timezone handling for qtopia */
76}
77
78void initEnvironment() 67void initEnvironment()
79{ 68{
80#ifdef Q_OS_WIN32
81 // Config file requires HOME dir which uses QDir which needs the winver
82 qt_init_winver();
83#endif
84 Config config("locale"); 69 Config config("locale");
85 config.setGroup( "Location" ); 70 config.setGroup( "Location" );
86 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); 71 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace();
87 72
88 // if not timezone set, pick New York 73 // timezone
89 if (tz.isNull() || tz.isEmpty()) 74 if (tz.isNull() || tz.isEmpty()) tz = "America/New_York";
90 tz = "America/New_York";
91
92 setenv( "TZ", tz, 1 ); 75 setenv( "TZ", tz, 1 );
93 config.writeEntry( "Timezone", tz); 76 config.writeEntry( "Timezone", tz);
94 77
78 // language
95 config.setGroup( "Language" ); 79 config.setGroup( "Language" );
96 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); 80 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace();
97 if( lang.isNull() || lang.isEmpty()) 81 if( lang.isNull() || lang.isEmpty()) lang = "en_US";
98 lang = "en_US";
99
100 setenv( "LANG", lang, 1 ); 82 setenv( "LANG", lang, 1 );
101 config.writeEntry("Language", lang); 83 config.writeEntry("Language", lang);
102 config.write(); 84 config.write();
103 85
86 // rotation
87 int t = ODevice::inst()->rotation();
88 odebug << "ODevice reports transformation to be " << t << oendl;
89
90 QString env( getenv("QWS_DISPLAY") );
91 if ( env.isEmpty() )
92 {
93 int rot = ODevice::inst()->rotation() * 90;
94 QString qws_display = QString("Transformed:Rot%1:0").arg(rot);
95 odebug << "setting QWS_DISPLAY to '" << qws_display << "'" << oendl;
96 setenv("QWS_DISPLAY", (const char*) qws_display, 1);
97 }
98 else
99 odebug << "QWS_DISPLAY already set as '" << env << "' - overriding ODevice transformation" << oendl;
104 100
105 QString env(getenv("QWS_DISPLAY")); 101 QPEApplication::defaultRotation(); /* to ensure deforient matches reality */
106 if (env.contains("Transformed")) {
107 int rot;
108 // transformed driver default rotation is controlled by the hardware.
109 Config config("qpe");
110 config.setGroup( "Rotation" );
111 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
112 rot = ODevice::inst ( )-> rotation ( ) * 90;
113
114 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
115 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */
116 }
117} 102}
118 103
119static void initKeyboard() 104static void initKeyboard()
120{ 105{
121 Config config("qpe"); 106 Config config("qpe");
122 107
123 config.setGroup( "Keyboard" ); 108 config.setGroup( "Keyboard" );
124 109
@@ -154,95 +139,99 @@ static bool firstUse()
154 bool rs = fu->restartNeeded(); 139 bool rs = fu->restartNeeded();
155 delete fu; 140 delete fu;
156 return rs; 141 return rs;
157} 142}
158 143
159int initApplication( int argc, char ** argv ) 144int initApplication( int argc, char ** argv )
160{ 145{
161 cleanup(); 146 cleanup();
162
163
164 initEnvironment(); 147 initEnvironment();
165 148
166 //Don't flicker at startup:
167#ifdef QWS 149#ifdef QWS
168 QWSServer::setDesktopBackground( QImage() ); 150 QWSServer::setDesktopBackground( QImage() );
169#endif 151#endif
170 ServerApplication a( argc, argv, QApplication::GuiServer ); 152 ServerApplication a( argc, argv, QApplication::GuiServer );
171
172 refreshTimeZoneConfig();
173
174 initKeyboard(); 153 initKeyboard();
175 154
176 // Don't use first use under Windows 155 if ( firstUse() )
177 if ( firstUse() ) { 156 {
178 a.restart(); 157 a.restart();
179 return 0; 158 return 0;
180 } 159 }
181 160
182 ODevice::inst ( )-> setSoftSuspend ( true ); 161#ifndef Q_OS_MACX
183 162 ODevice::inst()->setSoftSuspend( true );
163#endif
184 { 164 {
185 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 165 QCopEnvelope e("QPE/System", "setBacklight(int)" );
186 e << -3; // Forced on 166 e << -3; // Forced on
187 } 167 }
188 168
189 AlarmServer::initialize(); 169 AlarmServer::initialize();
190
191
192
193 Server *s = new Server(); 170 Server *s = new Server();
194 171 new SysFileMonitor(s);
195 (void)new SysFileMonitor(s);
196#ifdef QWS 172#ifdef QWS
197 Network::createServer(s); 173 Network::createServer(s);
198#endif 174#endif
199
200 s->show(); 175 s->show();
201 176
202 /* THE ARM rtc has problem holdings the time on reset */ 177#if 0
203 if ( QDate::currentDate ( ). year ( ) < 2000 ) { 178 if ( QDate::currentDate().year() < 2005 )
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 ) { 179 {
205 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); 180 if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ),
206 e << QString ( ); 181 ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" )
207 } 182 .arg( TimeString::dateString( QDate::currentDate())), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes )
183 {
184 QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" );
185 e << QString ( );
186 }
208 } 187 }
188#endif
209 189
210 int rv = a.exec(); 190 create_pidfile();
211 191 odebug << "--> mainloop in" << oendl;
212 odebug << "exiting..." << oendl; 192 int rv = a.exec();
193 odebug << "<-- mainloop out" << oendl;
194 remove_pidfile();
195 odebug << "removing server object..." << oendl;
213 delete s; 196 delete s;
214 197
215#ifndef Q_OS_MACX 198#ifndef Q_OS_MACX
216 ODevice::inst()->setSoftSuspend( false ); 199 ODevice::inst()->setSoftSuspend( false );
217#endif 200#endif
218 201
202 odebug << "returning from qpe/initapplication..." << oendl;
219 return rv; 203 return rv;
220} 204}
221 205
222static const char *pidfile_path = "/var/run/opie.pid"; 206static const char *pidfile_path = "/var/run/opie.pid";
223 207
224void create_pidfile ( ) 208void create_pidfile()
225{ 209{
226 FILE *f; 210 FILE *f;
227 211
228 if (( f = ::fopen ( pidfile_path, "w" ))) { 212 if (( f = ::fopen( pidfile_path, "w" ))) {
229 ::fprintf ( f, "%d", getpid ( )); 213 ::fprintf( f, "%d", getpid ( ));
230 ::fclose ( f ); 214 ::fclose( f );
215 }
216 else
217 {
218 odebug << "couldn't create pidfile: " << strerror( errno ) << oendl;
231 } 219 }
232} 220}
233 221
234void remove_pidfile ( ) 222void remove_pidfile()
235{ 223{
236 ::unlink ( pidfile_path ); 224 ::unlink( pidfile_path );
237} 225}
238 226
239void handle_sigterm ( int /* sig */ ) 227void handle_sigterm( int sig )
240{ 228{
229 qDebug( "D'oh! QPE Server process got SIGNAL %d. Trying to exit gracefully...", sig );
241 ::signal( SIGCHLD, SIG_IGN ); 230 ::signal( SIGCHLD, SIG_IGN );
242 ::signal( SIGSEGV, SIG_IGN ); 231 ::signal( SIGSEGV, SIG_IGN );
243 ::signal( SIGBUS, SIG_IGN ); 232 ::signal( SIGBUS, SIG_IGN );
244 ::signal( SIGILL, SIG_IGN ); 233 ::signal( SIGILL, SIG_IGN );
245 ::signal( SIGTERM, SIG_IGN ); 234 ::signal( SIGTERM, SIG_IGN );
246 ::signal ( SIGINT, SIG_IGN ); 235 ::signal ( SIGINT, SIG_IGN );
247 if ( qApp ) qApp->quit(); 236 if ( qApp ) qApp->quit();
248} 237}
@@ -254,17 +243,16 @@ int main( int argc, char ** argv )
254 ::signal( SIGBUS, handle_sigterm ); 243 ::signal( SIGBUS, handle_sigterm );
255 ::signal( SIGILL, handle_sigterm ); 244 ::signal( SIGILL, handle_sigterm );
256 ::signal( SIGTERM, handle_sigterm ); 245 ::signal( SIGTERM, handle_sigterm );
257 ::signal ( SIGINT, handle_sigterm ); 246 ::signal ( SIGINT, handle_sigterm );
258 ::setsid(); 247 ::setsid();
259 ::setpgid( 0, 0 ); 248 ::setpgid( 0, 0 );
260 249
261 ::atexit( remove_pidfile ); 250 ::atexit( remove_pidfile );
262 create_pidfile();
263 251
264 int retVal = initApplication( argc, argv ); 252 int retVal = initApplication( argc, argv );
265 253
266 // Have we been asked to restart? 254 // Have we been asked to restart?
267 if ( ServerApplication::doRestart ) 255 if ( ServerApplication::doRestart )
268 { 256 {
269 for ( int fd = 3; fd < 100; fd++ ) close( fd ); 257 for ( int fd = 3; fd < 100; fd++ ) close( fd );
270 execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); 258 execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 );