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