summaryrefslogtreecommitdiff
path: root/core/launcher/main.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/launcher/main.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'core/launcher/main.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/main.cpp276
1 files changed, 276 insertions, 0 deletions
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
new file mode 100644
index 0000000..024f9cc
--- a/dev/null
+++ b/core/launcher/main.cpp
@@ -0,0 +1,276 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
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**********************************************************************/
20
21#include "desktop.h"
22#include "taskbar.h"
23#include "stabmon.h"
24
25#include <qpe/qpeapplication.h>
26#include <qpe/network.h>
27#include <qpe/config.h>
28#ifdef QT_QWS_CUSTOM
29#include <qpe/custom.h>
30#endif
31
32#include <qfile.h>
33#include <qwindowsystem_qws.h>
34#include <qpe/qcopenvelope_qws.h>
35#include <qpe/alarmserver.h>
36
37#include <stdlib.h>
38#include <stdio.h>
39#include <signal.h>
40#include <unistd.h>
41
42#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
43#include "../calibrate/calibrate.h"
44#endif
45
46#ifdef QT_QWS_LOGIN
47#include "../login/qdmdialogimpl.h"
48#endif
49
50#ifdef QT_QWS_CASSIOPEIA
51static void ignoreMessage( QtMsgType, const char * )
52{
53}
54#include <sys/mount.h>
55#include <sys/types.h>
56#include <sys/stat.h>
57#include <sys/time.h>
58#include <fcntl.h>
59#include <qdatetime.h>
60
61void initCassiopeia()
62{
63 // MIPSEL-specific init - make sure /proc exists for shm
64/*
65 if ( mount("/dev/ram0", "/", "ext2", MS_REMOUNT | MS_MGC_VAL, 0 ) ) {
66 perror("Remounting - / read/write");
67 }
68*/
69 if ( mount("none", "/tmp", "ramfs", 0, 0 ) ) {
70 perror("mounting ramfs /tmp");
71 } else {
72 fprintf( stderr, "mounted /tmp\n" );
73 }
74 if ( mount("none", "/home", "ramfs", 0, 0 ) ) {
75 perror("mounting ramfs /home");
76 } else {
77 fprintf( stderr, "mounted /home\n" );
78 }
79 if ( mount("none","/proc","proc",0,0) ) {
80 perror("Mounting - /proc");
81 } else {
82 fprintf( stderr, "mounted /proc\n" );
83 }
84 if ( mount("none","/mnt","shm",0,0) ) {
85 perror("Mounting - shm");
86 }
87 setenv( "QTDIR", "/", 1 );
88 setenv( "QPEDIR", "/", 1 );
89 setenv( "HOME", "/home", 1 );
90 mkdir( "/home/Documents", 0755 );
91
92 // set a reasonable starting date
93 QDateTime dt( QDate( 2001, 3, 15 ) );
94 QDateTime now = QDateTime::currentDateTime();
95 int change = now.secsTo( dt );
96
97 time_t t = ::time(0);
98 t += change;
99 stime(&t);
100
101 qInstallMsgHandler(ignoreMessage);
102}
103#endif
104
105#ifdef QPE_OWNAPM
106#include <sys/ioctl.h>
107#include <sys/types.h>
108#include <fcntl.h>
109#include <unistd.h>
110#include <errno.h>
111#include <linux/ioctl.h>
112#include <qpe/global.h>
113
114static void disableAPM()
115{
116
117 int fd, cur_val, ret;
118 char *device = "/dev/apm_bios";
119
120 fd = open (device, O_WRONLY);
121
122 if (fd == -1) {
123 perror(device);
124 return;
125 }
126
127 cur_val = ioctl(fd, APM_IOCGEVTSRC, 0);
128 if (cur_val == -1) {
129 perror("ioctl");
130 exit(errno);
131 }
132
133 ret = ioctl(fd, APM_IOCSEVTSRC, cur_val & ~APM_EVT_POWER_BUTTON);
134 if (ret == -1) {
135 perror("ioctl");
136 return;
137 }
138 close(fd);
139}
140
141static void initAPM()
142{
143 // So that we have to do it ourself, but better.
144 disableAPM();
145}
146#endif
147
148#ifdef QT_DEMO_SINGLE_FLOPPY
149#include <sys/mount.h>
150
151void initFloppy()
152{
153 mount("none","/proc","proc",0,0);
154 setenv( "QTDIR", "/", 0 );
155 setenv( "HOME", "/root", 0 );
156 setenv( "QWS_SIZE", "240x320", 0 );
157}
158#endif
159
160
161void initEnvironment()
162{
163 Config config("locale");
164 config.setGroup( "Location" );
165 QString tz = config.readEntry( "Timezone", getenv("TZ") );
166
167 // if not timezone set, pick New York
168 if (tz.isNull())
169 tz = "America/New_York";
170
171 setenv( "TZ", tz, 1 );
172 config.writeEntry( "Timezone", tz);
173
174 config.setGroup( "Language" );
175 QString lang = config.readEntry( "Language", getenv("LANG") );
176 if ( !lang.isNull() )
177 setenv( "LANG", lang, 1 );
178}
179
180static void initBacklight()
181{
182 QCopEnvelope e("QPE/System", "setBacklight(int)" );
183 e << -3; // Forced on
184}
185
186
187
188int initApplication( int argc, char ** argv )
189{
190#ifdef QT_QWS_CASSIOPEIA
191 initCassiopeia();
192#endif
193
194#ifdef QPE_OWNAPM
195 initAPM();
196#endif
197
198#ifdef QT_DEMO_SINGLE_FLOPPY
199 initFloppy();
200#endif
201
202 initEnvironment();
203
204#if !defined(QT_QWS_CASSIOPEIA) && !defined(QT_QWS_IPAQ) && !defined(QT_QWS_EBX)
205 setenv( "QWS_SIZE", "240x320", 0 );
206#endif
207
208 //Don't flicker at startup:
209 QWSServer::setDesktopBackground( QImage() );
210 DesktopApplication a( argc, argv, QApplication::GuiServer );
211
212 initBacklight();
213
214 AlarmServer::initialize();
215
216#if defined(QT_QWS_LOGIN)
217 for( int i=0; i<a.argc(); i++ )
218 if( strcmp( a.argv()[i], "-login" ) == 0 ) {
219 QDMDialogImpl::login( );
220 return 0;
221 }
222#endif
223
224 Desktop *d = new Desktop();
225
226 QObject::connect( &a, SIGNAL(datebook()), d, SLOT(raiseDatebook()) );
227 QObject::connect( &a, SIGNAL(contacts()), d, SLOT(raiseContacts()) );
228 QObject::connect( &a, SIGNAL(launch()), d, SLOT(raiseLauncher()) );
229 QObject::connect( &a, SIGNAL(email()), d, SLOT(raiseEmail()) );
230 QObject::connect( &a, SIGNAL(power()), d, SLOT(togglePower()) );
231 QObject::connect( &a, SIGNAL(backlight()), d, SLOT(toggleLight()) );
232 QObject::connect( &a, SIGNAL(symbol()), d, SLOT(toggleSymbolInput()) );
233 QObject::connect( &a, SIGNAL(numLockStateToggle()), d, SLOT(toggleNumLockState()) );
234 QObject::connect( &a, SIGNAL(capsLockStateToggle()), d, SLOT(toggleCapsLockState()) );
235 QObject::connect( &a, SIGNAL(prepareForRestart()), d, SLOT(terminateServers()) );
236
237 (void)new SysFileMonitor(d);
238 Network::createServer(d);
239
240#if defined(QT_QWS_CASSIOPEIA) || defined(QT_QWS_IPAQ) || defined(QT_QWS_EBX)
241 if ( !QFile::exists( "/etc/pointercal" ) ) {
242 // Make sure calibration widget starts on top.
243 Calibrate *cal = new Calibrate;
244 cal->exec();
245 delete cal;
246 }
247#endif
248
249 d->show();
250
251 int rv = a.exec();
252
253 delete d;
254
255 return rv;
256}
257
258int main( int argc, char ** argv )
259{
260#ifndef SINGLE_APP
261 signal( SIGCHLD, SIG_IGN );
262#endif
263
264 int retVal = initApplication( argc, argv );
265
266#ifndef SINGLE_APP
267 // Kill them. Kill them all.
268 setpgid( getpid(), getppid() );
269 killpg( getpid(), SIGTERM );
270 sleep( 1 );
271 killpg( getpid(), SIGKILL );
272#endif
273
274 return retVal;
275}
276