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