author | mickeyl <mickeyl> | 2005-01-23 20:30:10 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-01-23 20:30:10 (UTC) |
commit | ab0242ff1bbc40ec8bc38c3cb748a44797ffe3db (patch) (unidiff) | |
tree | f9d2e15eb124bf3d39a90c25811c9609d9fd1db0 | |
parent | 8f2fbef1de1b3803a21d51752fee1014c951cc12 (diff) | |
download | opie-ab0242ff1bbc40ec8bc38c3cb748a44797ffe3db.zip opie-ab0242ff1bbc40ec8bc38c3cb748a44797ffe3db.tar.gz opie-ab0242ff1bbc40ec8bc38c3cb748a44797ffe3db.tar.bz2 |
New QWS_DISPLAY handling for gathering the default launcher rotation on startup:
1.) If QWS_DISPLAY is not set, then use ODevice::rotation()
2.) If QWS_DISPLAY is set, then just use whatever it is set to
-rw-r--r-- | core/launcher/main.cpp | 142 |
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,274 +1,262 @@ | |||
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 |
27 | #include "calibrate.h" | 20 | #include "calibrate.h" |
28 | #include "server.h" | 21 | #include "server.h" |
29 | #include "serverapp.h" | 22 | #include "serverapp.h" |
30 | #include "stabmon.h" | 23 | #include "stabmon.h" |
31 | #include "firstuse.h" | 24 | #include "firstuse.h" |
32 | 25 | ||
33 | /* OPIE */ | 26 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 27 | #include <opie2/odebug.h> |
35 | #include <opie2/odevice.h> | 28 | #include <opie2/odevice.h> |
36 | #include <opie2/oglobal.h> | 29 | #include <opie2/oglobal.h> |
37 | #include <qtopia/network.h> | 30 | #include <qtopia/network.h> |
38 | #include <qtopia/alarmserver.h> | 31 | #include <qtopia/alarmserver.h> |
39 | using namespace Opie::Core; | 32 | using namespace Opie::Core; |
40 | 33 | ||
41 | /* QT */ | 34 | /* QT */ |
42 | #include <qdir.h> | 35 | #include <qdir.h> |
43 | #include <qmessagebox.h> | 36 | #include <qmessagebox.h> |
44 | #ifdef QWS | 37 | #ifdef QWS |
45 | #include <qwindowsystem_qws.h> | 38 | #include <qwindowsystem_qws.h> |
46 | #include <qtopia/qcopenvelope_qws.h> | 39 | #include <qtopia/qcopenvelope_qws.h> |
47 | #endif | 40 | #endif |
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 | |
53 | void create_pidfile(); | ||
54 | void remove_pidfile(); | ||
61 | 55 | ||
62 | static void cleanup() | 56 | static 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 | ||
73 | static void refreshTimeZoneConfig() | ||
74 | { | ||
75 | /* ### FIXME timezone handling for qtopia */ | ||
76 | } | ||
77 | |||
78 | void initEnvironment() | 67 | void 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 | ||
119 | static void initKeyboard() | 104 | static void initKeyboard() |
120 | { | 105 | { |
121 | Config config("qpe"); | 106 | Config config("qpe"); |
122 | 107 | ||
123 | config.setGroup( "Keyboard" ); | 108 | config.setGroup( "Keyboard" ); |
124 | 109 | ||
125 | int ard = config.readNumEntry( "RepeatDelay" ); | 110 | int ard = config.readNumEntry( "RepeatDelay" ); |
126 | int arp = config.readNumEntry( "RepeatPeriod" ); | 111 | int arp = config.readNumEntry( "RepeatPeriod" ); |
127 | if ( ard > 0 && arp > 0 ) | 112 | if ( ard > 0 && arp > 0 ) |
128 | qwsSetKeyboardAutoRepeat( ard, arp ); | 113 | qwsSetKeyboardAutoRepeat( ard, arp ); |
129 | 114 | ||
130 | QString layout = config.readEntry( "Layout", "us101" ); | 115 | QString layout = config.readEntry( "Layout", "us101" ); |
131 | Server::setKeyboardLayout( layout ); | 116 | Server::setKeyboardLayout( layout ); |
132 | } | 117 | } |
133 | 118 | ||
134 | static bool firstUse() | 119 | static bool firstUse() |
135 | { | 120 | { |
136 | bool needFirstUse = FALSE; | 121 | bool needFirstUse = FALSE; |
137 | if ( QWSServer::mouseHandler() && | 122 | if ( QWSServer::mouseHandler() && |
138 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 123 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { |
139 | if ( !QFile::exists( "/etc/pointercal" ) ) | 124 | if ( !QFile::exists( "/etc/pointercal" ) ) |
140 | needFirstUse = TRUE; | 125 | needFirstUse = TRUE; |
141 | } | 126 | } |
142 | 127 | ||
143 | { | 128 | { |
144 | Config config( "qpe" ); | 129 | Config config( "qpe" ); |
145 | config.setGroup( "Startup" ); | 130 | config.setGroup( "Startup" ); |
146 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); | 131 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); |
147 | } | 132 | } |
148 | 133 | ||
149 | if ( !needFirstUse ) | 134 | if ( !needFirstUse ) |
150 | return FALSE; | 135 | return FALSE; |
151 | 136 | ||
152 | FirstUse *fu = new FirstUse(); | 137 | FirstUse *fu = new FirstUse(); |
153 | fu->exec(); | 138 | fu->exec(); |
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 | ||
159 | int initApplication( int argc, char ** argv ) | 144 | int 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 | ||
222 | static const char *pidfile_path = "/var/run/opie.pid"; | 206 | static const char *pidfile_path = "/var/run/opie.pid"; |
223 | 207 | ||
224 | void create_pidfile ( ) | 208 | void 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 | ||
234 | void remove_pidfile ( ) | 222 | void remove_pidfile() |
235 | { | 223 | { |
236 | ::unlink ( pidfile_path ); | 224 | ::unlink( pidfile_path ); |
237 | } | 225 | } |
238 | 226 | ||
239 | void handle_sigterm ( int /* sig */ ) | 227 | void 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 | } |
249 | 238 | ||
250 | int main( int argc, char ** argv ) | 239 | int main( int argc, char ** argv ) |
251 | { | 240 | { |
252 | ::signal( SIGCHLD, SIG_IGN ); | 241 | ::signal( SIGCHLD, SIG_IGN ); |
253 | ::signal( SIGSEGV, handle_sigterm ); | 242 | ::signal( SIGSEGV, handle_sigterm ); |
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 ); |
271 | } | 259 | } |
272 | 260 | ||
273 | return retVal; | 261 | return retVal; |
274 | } | 262 | } |