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