Diffstat (limited to 'core/launcher/applauncher.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/launcher/applauncher.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp index 7d3c032..08a3cb4 100644 --- a/core/launcher/applauncher.cpp +++ b/core/launcher/applauncher.cpp | |||
@@ -1,190 +1,190 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 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 | #ifndef QTOPIA_INTERNAL_PRELOADACCESS | 21 | #ifndef QTOPIA_INTERNAL_PRELOADACCESS |
22 | #define QTOPIA_INTERNAL_PRELOADACCESS | 22 | #define QTOPIA_INTERNAL_PRELOADACCESS |
23 | #endif | 23 | #endif |
24 | #ifndef QTOPIA_INTERNAL_FILEOPERATIONS | 24 | #ifndef QTOPIA_INTERNAL_FILEOPERATIONS |
25 | #define QTOPIA_INTERNAL_FILEOPERATIONS | 25 | #define QTOPIA_INTERNAL_FILEOPERATIONS |
26 | #endif | 26 | #endif |
27 | #ifndef QTOPIA_PROGRAM_MONITOR | 27 | #ifndef QTOPIA_PROGRAM_MONITOR |
28 | #define QTOPIA_PROGRAM_MONITOR | 28 | #define QTOPIA_PROGRAM_MONITOR |
29 | #endif | 29 | #endif |
30 | #include <opie2/oglobal.h> | 30 | #include <opie2/oglobal.h> |
31 | 31 | ||
32 | #ifndef Q_OS_WIN32 | 32 | #ifndef Q_OS_WIN32 |
33 | #include <sys/stat.h> | 33 | #include <sys/stat.h> |
34 | #include <sys/wait.h> | 34 | #include <sys/wait.h> |
35 | #include <sys/file.h> | 35 | #include <sys/file.h> |
36 | #include <unistd.h> | 36 | #include <unistd.h> |
37 | #include <sys/time.h> | 37 | #include <sys/time.h> |
38 | #include <sys/resource.h> | 38 | #include <sys/resource.h> |
39 | #include <errno.h> | 39 | #include <errno.h> |
40 | #else | 40 | #else |
41 | #include <process.h> | 41 | #include <process.h> |
42 | #include <windows.h> | 42 | #include <windows.h> |
43 | #include <winbase.h> | 43 | #include <winbase.h> |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #include <signal.h> | 46 | #include <signal.h> |
47 | #include <sys/types.h> | 47 | #include <sys/types.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | 49 | ||
50 | #include <qtimer.h> | 50 | #include <qtimer.h> |
51 | #include <qwindowsystem_qws.h> | 51 | #include <qwindowsystem_qws.h> |
52 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
53 | #include <qfileinfo.h> | 53 | #include <qfileinfo.h> |
54 | 54 | ||
55 | #include <qtopia/qcopenvelope_qws.h> | 55 | #include <qtopia/qcopenvelope_qws.h> |
56 | #include <qtopia/qpeapplication.h> | 56 | #include <qtopia/qpeapplication.h> |
57 | 57 | ||
58 | #include "applauncher.h" | 58 | #include "applauncher.h" |
59 | #include "documentlist.h" | 59 | #include "documentlist.h" |
60 | 60 | ||
61 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; | 61 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; |
62 | 62 | ||
63 | //--------------------------------------------------------------------------- | 63 | //--------------------------------------------------------------------------- |
64 | 64 | ||
65 | static AppLauncher* appLauncherPtr; | 65 | static AppLauncher* appLauncherPtr; |
66 | 66 | ||
67 | const int appStopEventID = 1290; | 67 | const int appStopEventID = 1290; |
68 | 68 | ||
69 | class AppStoppedEvent : public QCustomEvent | 69 | class AppStoppedEvent : public QCustomEvent |
70 | { | 70 | { |
71 | public: | 71 | public: |
72 | AppStoppedEvent(int pid, int status) | 72 | AppStoppedEvent(int pid, int status) |
73 | : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } | 73 | : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } |
74 | 74 | ||
75 | int pid() { return mPid; } | 75 | int pid() { return mPid; } |
76 | int status() { return mStatus; } | 76 | int status() { return mStatus; } |
77 | 77 | ||
78 | private: | 78 | private: |
79 | int mPid, mStatus; | 79 | int mPid, mStatus; |
80 | }; | 80 | }; |
81 | 81 | ||
82 | AppLauncher::AppLauncher(QObject *parent, const char *name) | 82 | AppLauncher::AppLauncher(QObject *parent, const char *name) |
83 | : QObject(parent, name), qlPid(0), qlReady(FALSE), | 83 | : QObject(parent, name), qlPid(0), qlReady(FALSE), |
84 | appKillerBox(0) | 84 | appKillerBox(0) |
85 | { | 85 | { |
86 | connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); | 86 | connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); |
87 | connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); | 87 | connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); |
88 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); | 88 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); |
89 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 89 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
90 | this, SLOT(received(const QCString&, const QByteArray&)) ); | 90 | this, SLOT(received(const QCString&,const QByteArray&)) ); |
91 | 91 | ||
92 | channel = new QCopChannel( "QPE/Server", this ); | 92 | channel = new QCopChannel( "QPE/Server", this ); |
93 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 93 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
94 | this, SLOT(received(const QCString&, const QByteArray&)) ); | 94 | this, SLOT(received(const QCString&,const QByteArray&)) ); |
95 | 95 | ||
96 | #ifndef Q_OS_WIN32 | 96 | #ifndef Q_OS_WIN32 |
97 | signal(SIGCHLD, signalHandler); | 97 | signal(SIGCHLD, signalHandler); |
98 | #else | 98 | #else |
99 | runningAppsProc.setAutoDelete( TRUE ); | 99 | runningAppsProc.setAutoDelete( TRUE ); |
100 | #endif | 100 | #endif |
101 | QString tmp = qApp->argv()[0]; | 101 | QString tmp = qApp->argv()[0]; |
102 | int pos = tmp.findRev('/'); | 102 | int pos = tmp.findRev('/'); |
103 | if ( pos > -1 ) | 103 | if ( pos > -1 ) |
104 | tmp = tmp.mid(++pos); | 104 | tmp = tmp.mid(++pos); |
105 | runningApps[::getpid()] = tmp; | 105 | runningApps[::getpid()] = tmp; |
106 | 106 | ||
107 | appLauncherPtr = this; | 107 | appLauncherPtr = this; |
108 | 108 | ||
109 | QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); | 109 | QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); |
110 | } | 110 | } |
111 | 111 | ||
112 | AppLauncher::~AppLauncher() | 112 | AppLauncher::~AppLauncher() |
113 | { | 113 | { |
114 | appLauncherPtr = 0; | 114 | appLauncherPtr = 0; |
115 | #ifndef Q_OS_WIN32 | 115 | #ifndef Q_OS_WIN32 |
116 | signal(SIGCHLD, SIG_DFL); | 116 | signal(SIGCHLD, SIG_DFL); |
117 | #endif | 117 | #endif |
118 | if ( qlPid ) { | 118 | if ( qlPid ) { |
119 | int status; | 119 | int status; |
120 | ::kill( qlPid, SIGTERM ); | 120 | ::kill( qlPid, SIGTERM ); |
121 | waitpid( qlPid, &status, 0 ); | 121 | waitpid( qlPid, &status, 0 ); |
122 | } | 122 | } |
123 | } | 123 | } |
124 | 124 | ||
125 | /* We use the QCopChannel of the app as an indicator of when it has been launched | 125 | /* We use the QCopChannel of the app as an indicator of when it has been launched |
126 | so that we can disable the busy indicators */ | 126 | so that we can disable the busy indicators */ |
127 | void AppLauncher::newQcopChannel(const QString& channelName) | 127 | void AppLauncher::newQcopChannel(const QString& channelName) |
128 | { | 128 | { |
129 | // qDebug("channel %s added", channelName.data() ); | 129 | // qDebug("channel %s added", channelName.data() ); |
130 | QString prefix("QPE/Application/"); | 130 | QString prefix("QPE/Application/"); |
131 | if (channelName.startsWith(prefix)) { | 131 | if (channelName.startsWith(prefix)) { |
132 | { | 132 | { |
133 | QCopEnvelope e("QPE/System", "newChannel(QString)"); | 133 | QCopEnvelope e("QPE/System", "newChannel(QString)"); |
134 | e << channelName; | 134 | e << channelName; |
135 | } | 135 | } |
136 | QString appName = channelName.mid(prefix.length()); | 136 | QString appName = channelName.mid(prefix.length()); |
137 | if ( appName != "quicklauncher" ) { | 137 | if ( appName != "quicklauncher" ) { |
138 | emit connected( appName ); | 138 | emit connected( appName ); |
139 | QCopEnvelope e("QPE/System", "notBusy(QString)"); | 139 | QCopEnvelope e("QPE/System", "notBusy(QString)"); |
140 | e << appName; | 140 | e << appName; |
141 | } | 141 | } |
142 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { | 142 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { |
143 | qDebug("Registered %s", channelName.latin1()); | 143 | qDebug("Registered %s", channelName.latin1()); |
144 | int pid = channelName.mid(18).toInt(); | 144 | int pid = channelName.mid(18).toInt(); |
145 | if (pid == qlPid) | 145 | if (pid == qlPid) |
146 | qlReady = TRUE; | 146 | qlReady = TRUE; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | void AppLauncher::removedQcopChannel(const QString& channelName) | 150 | void AppLauncher::removedQcopChannel(const QString& channelName) |
151 | { | 151 | { |
152 | if (channelName.startsWith("QPE/Application/")) { | 152 | if (channelName.startsWith("QPE/Application/")) { |
153 | QCopEnvelope e("QPE/System", "removedChannel(QString)"); | 153 | QCopEnvelope e("QPE/System", "removedChannel(QString)"); |
154 | e << channelName; | 154 | e << channelName; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | 157 | ||
158 | void AppLauncher::received(const QCString& msg, const QByteArray& data) | 158 | void AppLauncher::received(const QCString& msg, const QByteArray& data) |
159 | { | 159 | { |
160 | QDataStream stream( data, IO_ReadOnly ); | 160 | QDataStream stream( data, IO_ReadOnly ); |
161 | if ( msg == "execute(QString)" ) { | 161 | if ( msg == "execute(QString)" ) { |
162 | QString t; | 162 | QString t; |
163 | stream >> t; | 163 | stream >> t; |
164 | if ( !executeBuiltin( t, QString::null ) ) | 164 | if ( !executeBuiltin( t, QString::null ) ) |
165 | execute(t, QString::null); | 165 | execute(t, QString::null); |
166 | } else if ( msg == "execute(QString,QString)" ) { | 166 | } else if ( msg == "execute(QString,QString)" ) { |
167 | QString t,d; | 167 | QString t,d; |
168 | stream >> t >> d; | 168 | stream >> t >> d; |
169 | if ( !executeBuiltin( t, d ) ) | 169 | if ( !executeBuiltin( t, d ) ) |
170 | execute( t, d ); | 170 | execute( t, d ); |
171 | } else if ( msg == "processQCop(QString)" ) { // from QPE/Server | 171 | } else if ( msg == "processQCop(QString)" ) { // from QPE/Server |
172 | QString t; | 172 | QString t; |
173 | stream >> t; | 173 | stream >> t; |
174 | if ( !executeBuiltin( t, QString::null ) ) | 174 | if ( !executeBuiltin( t, QString::null ) ) |
175 | execute( t, QString::null, TRUE); | 175 | execute( t, QString::null, TRUE); |
176 | } else if ( msg == "raise(QString)" ) { | 176 | } else if ( msg == "raise(QString)" ) { |
177 | QString appName; | 177 | QString appName; |
178 | stream >> appName; | 178 | stream >> appName; |
179 | 179 | ||
180 | if ( !executeBuiltin( appName, QString::null ) ) { | 180 | if ( !executeBuiltin( appName, QString::null ) ) { |
181 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { | 181 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { |
182 | //qDebug( "Raising: %s", appName.latin1() ); | 182 | //qDebug( "Raising: %s", appName.latin1() ); |
183 | QCString channel = "QPE/Application/"; | 183 | QCString channel = "QPE/Application/"; |
184 | channel += appName.latin1(); | 184 | channel += appName.latin1(); |
185 | 185 | ||
186 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile | 186 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile |
187 | QFile f("/tmp/qcop-msg-" + appName); | 187 | QFile f("/tmp/qcop-msg-" + appName); |
188 | if ( f.open(IO_WriteOnly | IO_Append) ) { | 188 | if ( f.open(IO_WriteOnly | IO_Append) ) { |
189 | #ifndef Q_OS_WIN32 | 189 | #ifndef Q_OS_WIN32 |
190 | flock(f.handle(), LOCK_EX); | 190 | flock(f.handle(), LOCK_EX); |