summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/tools/quicklauncher/main.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/tools/quicklauncher/main.cpp b/core/tools/quicklauncher/main.cpp
index fb2ca44..286aed2 100644
--- a/core/tools/quicklauncher/main.cpp
+++ b/core/tools/quicklauncher/main.cpp
@@ -1,278 +1,287 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2003 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#define QTOPIA_INTERNAL_INITAPP 21#define QTOPIA_INTERNAL_INITAPP
22#include "dropins.h" 22#include "dropins.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <opie2/odebug.h> 25#include <opie2/odebug.h>
26using namespace Opie::Core; 26using namespace Opie::Core;
27 27
28/* QT */ 28/* QT */
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qstrlist.h> 30#include <qstrlist.h>
31#include <qtimer.h> 31#include <qtimer.h>
32#include <qguardedptr.h> 32#include <qguardedptr.h>
33#include <qcopchannel_qws.h> 33#include <qcopchannel_qws.h>
34 34
35#ifdef private 35#ifdef private
36# undef private 36# undef private
37#endif 37#endif
38#define private public 38#define private public
39#include <qtopia/qpeapplication.h> 39#include <qtopia/qpeapplication.h>
40#undef private 40#undef private
41 41
42/* STD */ 42/* STD */
43#include <stdio.h> 43#include <stdio.h>
44#include <stdlib.h> 44#include <stdlib.h>
45#include <sys/types.h> 45#include <sys/types.h>
46#include <sys/stat.h> 46#include <sys/stat.h>
47
48#ifdef _OS_LINUX_
49#include <sys/prctl.h>
50#ifndef PR_SET_NAME
51#define PR_SET_NAME 15
52#endif
53#endif
54
47#include <unistd.h> 55#include <unistd.h>
48 56
49 57
50using QuickPrivate::PluginLoader; 58using QuickPrivate::PluginLoader;
51 59
52static QPEApplication *app = 0; 60static QPEApplication *app = 0;
53static PluginLoader *loader = 0; 61static PluginLoader *loader = 0;
54static ApplicationInterface *appIface = 0; 62static ApplicationInterface *appIface = 0;
55static QGuardedPtr<QWidget> mainWindow; 63static QGuardedPtr<QWidget> mainWindow;
56 64
57#ifdef _OS_LINUX_ 65#ifdef _OS_LINUX_
58static char **argv0 = 0; 66static char **argv0 = 0;
59static int argv_lth; 67static int argv_lth;
60extern char **environ; 68extern char **environ;
61#ifndef SPT_BUFSIZE 69#ifndef SPT_BUFSIZE
62#define SPT_BUFSIZE 2048 70#define SPT_BUFSIZE 2048
63#endif 71#endif
64#include <stdarg.h> 72#include <stdarg.h>
65void setproctitle (const char *fmt,...) { 73void setproctitle (const char *fmt,...) {
66 int i; 74 int i;
67 char buf[SPT_BUFSIZE]; 75 char buf[SPT_BUFSIZE];
68 va_list ap; 76 va_list ap;
69 77
70 if (!argv0) 78 if (!argv0)
71 return; 79 return;
72 80
73 va_start(ap, fmt); 81 va_start(ap, fmt);
74 (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); 82 (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap);
75 va_end(ap); 83 va_end(ap);
76 84
77 i = strlen (buf); 85 i = strlen (buf);
78 if (i > argv_lth - 2) { 86 if (i > argv_lth - 2) {
79 i = argv_lth - 2; 87 i = argv_lth - 2;
80 buf[i] = '\0'; 88 buf[i] = '\0';
81 } 89 }
82 90
83 memset(argv0[0], '\0', argv_lth); /* clear the memory area */ 91 memset(argv0[0], '\0', argv_lth); /* clear the memory area */
84 (void) strcpy (argv0[0], buf); 92 (void) strcpy (argv0[0], buf);
85 93
86 argv0[1] = NULL; 94 argv0[1] = NULL;
87} 95}
88#endif 96#endif
89 97
90 98
91class QuickLauncher : public QObject 99class QuickLauncher : public QObject
92{ 100{
93 Q_OBJECT 101 Q_OBJECT
94public: 102public:
95 QuickLauncher() : QObject() 103 QuickLauncher() : QObject()
96 { 104 {
97 QCString ch("QPE/QuickLauncher-"); 105 QCString ch("QPE/QuickLauncher-");
98 ch += QString::number(getpid()); 106 ch += QString::number(getpid());
99 qlChannel = new QCopChannel( ch, this); 107 qlChannel = new QCopChannel( ch, this);
100 connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), 108 connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)),
101 this, SLOT(message(const QCString&,const QByteArray&)) ); 109 this, SLOT(message(const QCString&,const QByteArray&)) );
102 } 110 }
103 111
104 static void exec( int /*argc*/, char **argv ) 112 static void exec( int /*argc*/, char **argv )
105 { 113 {
106 QString appName = argv[0]; 114 QString appName = argv[0];
107 int sep = appName.findRev( '/' ); 115 int sep = appName.findRev( '/' );
108 if ( sep > 0 ) 116 if ( sep > 0 )
109 appName = appName.mid( sep+1 ); 117 appName = appName.mid( sep+1 );
110 118
111 appIface = 0; 119 appIface = 0;
112 if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) { 120 if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) {
113 mainWindow = appIface->createMainWindow( appName ); 121 mainWindow = appIface->createMainWindow( appName );
114 } 122 }
115 123
116 if ( mainWindow ) { 124 if ( mainWindow ) {
117 if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { 125 if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) {
118 app->showMainDocumentWidget( mainWindow ); 126 app->showMainDocumentWidget( mainWindow );
119 } else { 127 } else {
120 app->showMainWidget( mainWindow ); 128 app->showMainWidget( mainWindow );
121 } 129 }
122 } else { 130 } else {
123 owarn << "Could not create application main window" << oendl; 131 owarn << "Could not create application main window" << oendl;
124 exit(-1); 132 exit(-1);
125 } 133 }
126 } 134 }
127 135
128private slots: 136private slots:
129 void message(const QCString &msg, const QByteArray & data) 137 void message(const QCString &msg, const QByteArray & data)
130 { 138 {
131 QStrList argList; 139 QStrList argList;
132 140
133 if ( msg == "execute(QStrList)" ) { 141 if ( msg == "execute(QStrList)" ) {
134 delete qlChannel; 142 delete qlChannel;
135 QDataStream stream( data, IO_ReadOnly ); 143 QDataStream stream( data, IO_ReadOnly );
136 QStrList argList; 144 QStrList argList;
137 stream >> argList; 145 stream >> argList;
138 odebug << "QuickLauncher execute: " << argList.at(0) << oendl; 146 odebug << "QuickLauncher execute: " << argList.at(0) << oendl;
139 doQuickLaunch( argList ); 147 doQuickLaunch( argList );
140 delete this; 148 delete this;
141 } else if ( msg == "execute(QString)" ) { 149 } else if ( msg == "execute(QString)" ) {
142 delete qlChannel; 150 delete qlChannel;
143 QDataStream stream( data, IO_ReadOnly ); 151 QDataStream stream( data, IO_ReadOnly );
144 QString arg; 152 QString arg;
145 stream >> arg; 153 stream >> arg;
146 odebug << "QuickLauncher execute: " << arg << oendl; 154 odebug << "QuickLauncher execute: " << arg << oendl;
147 QStrList argList; 155 QStrList argList;
148 argList.append( arg.utf8() ); 156 argList.append( arg.utf8() );
149 doQuickLaunch( argList ); 157 doQuickLaunch( argList );
150 delete this; 158 delete this;
151 } 159 }
152 } 160 }
153 161
154private: 162private:
155 void doQuickLaunch( QStrList &argList ) 163 void doQuickLaunch( QStrList &argList )
156 { 164 {
157 static int myargc = argList.count(); 165 static int myargc = argList.count();
158 static char **myargv = new char *[myargc + 1]; 166 static char **myargv = new char *[myargc + 1];
159 167
160 for ( int j = 0; j < myargc; j++ ) { 168 for ( int j = 0; j < myargc; j++ ) {
161 myargv[j] = new char [strlen(argList.at(j))+1]; 169 myargv[j] = new char [strlen(argList.at(j))+1];
162 strcpy( myargv[j], argList.at(j) ); 170 strcpy( myargv[j], argList.at(j) );
163 } 171 }
164 172
165 myargv[myargc] = NULL; 173 myargv[myargc] = NULL;
166#ifdef _OS_LINUX_ 174#ifdef _OS_LINUX_
167 // Change name of process 175 // Change name of process
168 setproctitle(myargv[0]); 176 setproctitle(myargv[0]);
177 prctl( PR_SET_NAME, (unsigned long)myargv[0], 0, 0, 0 );
169#endif 178#endif
170 179
171 connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); 180 connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit()));
172 app->exit_loop(); 181 app->exit_loop();
173 app->initApp( myargc, myargv ); 182 app->initApp( myargc, myargv );
174 exec( myargc, myargv ); 183 exec( myargc, myargv );
175 } 184 }
176 185
177private: 186private:
178 QCopChannel *qlChannel; 187 QCopChannel *qlChannel;
179}; 188};
180 189
181int main( int argc, char** argv ) 190int main( int argc, char** argv )
182{ 191{
183 app = new QPEApplication( argc, argv ); 192 app = new QPEApplication( argc, argv );
184 193
185 loader = new PluginLoader( "application" ); 194 loader = new PluginLoader( "application" );
186 195
187 unsetenv( "LD_BIND_NOW" ); 196 unsetenv( "LD_BIND_NOW" );
188 197
189 QCString arg0 = argv[0]; 198 QCString arg0 = argv[0];
190 int sep = arg0.findRev( '/' ); 199 int sep = arg0.findRev( '/' );
191 200
192 if ( sep > 0 ) 201 if ( sep > 0 )
193 arg0 = arg0.mid( sep+1 ); 202 arg0 = arg0.mid( sep+1 );
194 203
195 if ( arg0 != "quicklauncher" ) { 204 if ( arg0 != "quicklauncher" ) {
196 odebug << "QuickLauncher invoked as: " << arg0.data() << oendl; 205 odebug << "QuickLauncher invoked as: " << arg0.data() << oendl;
197 QuickLauncher::exec( argc, argv ); 206 QuickLauncher::exec( argc, argv );
198 } else { 207 } else {
199#ifdef _OS_LINUX_ 208#ifdef _OS_LINUX_
200 // Setup to change proc title 209 // Setup to change proc title
201 int i; 210 int i;
202 char **envp = environ; 211 char **envp = environ;
203 /* Move the environment so we can reuse the memory. 212 /* Move the environment so we can reuse the memory.
204 * (Code borrowed from sendmail.) */ 213 * (Code borrowed from sendmail.) */
205 for (i = 0; envp[i] != NULL; i++) 214 for (i = 0; envp[i] != NULL; i++)
206 continue; 215 continue;
207 environ = (char **) malloc(sizeof(char *) * (i + 1)); 216 environ = (char **) malloc(sizeof(char *) * (i + 1));
208 if (environ == NULL) 217 if (environ == NULL)
209 return -1; 218 return -1;
210 for (i = 0; envp[i] != NULL; i++) 219 for (i = 0; envp[i] != NULL; i++)
211 if ((environ[i] = strdup(envp[i])) == NULL) 220 if ((environ[i] = strdup(envp[i])) == NULL)
212 return -1; 221 return -1;
213 environ[i] = NULL; 222 environ[i] = NULL;
214 223
215 argv0 = argv; 224 argv0 = argv;
216 if (i > 0) 225 if (i > 0)
217 argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; 226 argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0];
218 else 227 else
219 argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; 228 argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0];
220#endif 229#endif
221 (void)new QuickLauncher(); 230 (void)new QuickLauncher();
222 odebug << "QuickLauncher running" << oendl; 231 odebug << "QuickLauncher running" << oendl;
223 // Pre-load default fonts 232 // Pre-load default fonts
224 QFontMetrics fm( QApplication::font() ); 233 QFontMetrics fm( QApplication::font() );
225 fm.ascent(); // causes font load. 234 fm.ascent(); // causes font load.
226 QFont f( QApplication::font() ); 235 QFont f( QApplication::font() );
227 f.setWeight( QFont::Bold ); 236 f.setWeight( QFont::Bold );
228 QFontMetrics fmb( f ); 237 QFontMetrics fmb( f );
229 fmb.ascent(); // causes font load. 238 fmb.ascent(); // causes font load.
230 239
231 // Each of the following force internal structures/internal 240 // Each of the following force internal structures/internal
232 // initialization to be performed. This may mean allocating 241 // initialization to be performed. This may mean allocating
233 // memory that is not needed by all applications. 242 // memory that is not needed by all applications.
234 Resource::loadIconSet("new"); // do internal init 243 Resource::loadIconSet("new"); // do internal init
235 244
236 /* make sure libopie gets lined in */ 245 /* make sure libopie gets lined in */
237 { 246 {
238 Opie::Ui::OWait item; 247 Opie::Ui::OWait item;
239 } 248 }
240 249
241 // Create a widget to force initialization of title bar images, etc. 250 // Create a widget to force initialization of title bar images, etc.
242 QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); 251 QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit()));
243 QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool); 252 QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool);
244 w->setGeometry( -100, -100, 10, 10 ); 253 w->setGeometry( -100, -100, 10, 10 );
245 w->show(); 254 w->show();
246 QTimer::singleShot( 0, w, SLOT(close()) ); 255 QTimer::singleShot( 0, w, SLOT(close()) );
247 256
248 app->enter_loop(); 257 app->enter_loop();
249 } 258 }
250 259
251 int rv = app->exec(); 260 int rv = app->exec();
252 261
253 if ( mainWindow ) 262 if ( mainWindow )
254 delete (QWidget*)mainWindow; 263 delete (QWidget*)mainWindow;
255 delete app; 264 delete app;
256 265
257 if ( appIface ) 266 if ( appIface )
258 loader->releaseInterface( appIface ); 267 loader->releaseInterface( appIface );
259 delete loader; 268 delete loader;
260 269
261 270
262 // Neither QLibrary nor my Dropin is a QObject and they don't depend 271 // Neither QLibrary nor my Dropin is a QObject and they don't depend
263 // on a qApp so we destroy QWidget::destroyMapper() without 272 // on a qApp so we destroy QWidget::destroyMapper() without
264 // crashing the app 273 // crashing the app
265 // 274 //
266 // The problem is there are some 'static' resources not freed 275 // The problem is there are some 'static' resources not freed
267 // in the apps and on destructing these objects are not available 276 // in the apps and on destructing these objects are not available
268 // anymore. In future fix up the apps but for now 277 // anymore. In future fix up the apps but for now
269 // we just skip deletion and hope things go well -zecke 278 // we just skip deletion and hope things go well -zecke
270 // delete app; 279 // delete app;
271 // hack instead -zecke 280 // hack instead -zecke
272 // delete app->pidChannel; 281 // delete app->pidChannel;
273 // app->pidChannel = 0; 282 // app->pidChannel = 0;
274 283
275 return rv; 284 return rv;
276} 285}
277 286
278#include "main.moc" 287#include "main.moc"