-rw-r--r-- | core/launcher/applauncher.cpp | 83 | ||||
-rw-r--r-- | core/launcher/documentlist.cpp | 46 | ||||
-rw-r--r-- | core/launcher/firstuse.cpp | 44 | ||||
-rw-r--r-- | core/launcher/inputmethods.cpp | 34 | ||||
-rw-r--r-- | core/launcher/irserver.cpp | 16 | ||||
-rw-r--r-- | core/launcher/launcher.cpp | 37 | ||||
-rw-r--r-- | core/launcher/launcherview.cpp | 9 | ||||
-rw-r--r-- | core/launcher/main.cpp | 42 | ||||
-rw-r--r-- | core/launcher/packageslave.cpp | 26 | ||||
-rw-r--r-- | core/launcher/qcopbridge.cpp | 23 | ||||
-rw-r--r-- | core/launcher/qprocess.cpp | 14 | ||||
-rw-r--r-- | core/launcher/qprocess_unix.cpp | 93 | ||||
-rw-r--r-- | core/launcher/runningappbar.cpp | 24 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 2 | ||||
-rw-r--r-- | core/launcher/server.cpp | 32 | ||||
-rw-r--r-- | core/launcher/serverapp.cpp | 26 | ||||
-rw-r--r-- | core/launcher/suspendmonitor.cpp | 2 | ||||
-rw-r--r-- | core/launcher/systray.cpp | 18 | ||||
-rw-r--r-- | core/launcher/taskbar.cpp | 7 | ||||
-rw-r--r-- | core/launcher/transferserver.cpp | 107 |
20 files changed, 334 insertions, 351 deletions
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp index 5a5517c..7000346 100644 --- a/core/launcher/applauncher.cpp +++ b/core/launcher/applauncher.cpp | |||
@@ -1,722 +1,719 @@ | |||
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 | |||
31 | #include "applauncher.h" | ||
32 | #include "documentlist.h" | ||
33 | |||
34 | /* OPIE */ | ||
35 | #include <opie2/odebug.h> | ||
30 | #include <opie2/oglobal.h> | 36 | #include <opie2/oglobal.h> |
37 | #include <qtopia/qcopenvelope_qws.h> | ||
38 | #include <qtopia/qpeapplication.h> | ||
39 | using namespace Opie::Core; | ||
31 | 40 | ||
32 | #ifndef Q_OS_WIN32 | 41 | /* QT */ |
42 | #include <qtimer.h> | ||
43 | #include <qwindowsystem_qws.h> | ||
44 | #include <qmessagebox.h> | ||
45 | #include <qfileinfo.h> | ||
46 | |||
47 | /* STD */ | ||
33 | #include <sys/stat.h> | 48 | #include <sys/stat.h> |
34 | #include <sys/wait.h> | 49 | #include <sys/wait.h> |
35 | #include <sys/file.h> | 50 | #include <sys/file.h> |
36 | #include <unistd.h> | 51 | #include <unistd.h> |
37 | #include <sys/time.h> | 52 | #include <sys/time.h> |
38 | #include <sys/resource.h> | 53 | #include <sys/resource.h> |
39 | #include <errno.h> | 54 | #include <errno.h> |
40 | #else | ||
41 | #include <process.h> | ||
42 | #include <windows.h> | ||
43 | #include <winbase.h> | ||
44 | #endif | ||
45 | |||
46 | #include <signal.h> | 55 | #include <signal.h> |
47 | #include <sys/types.h> | 56 | #include <sys/types.h> |
48 | #include <stdlib.h> | 57 | #include <stdlib.h> |
49 | 58 | ||
50 | #include <qtimer.h> | ||
51 | #include <qwindowsystem_qws.h> | ||
52 | #include <qmessagebox.h> | ||
53 | #include <qfileinfo.h> | ||
54 | |||
55 | #include <qtopia/qcopenvelope_qws.h> | ||
56 | #include <qtopia/qpeapplication.h> | ||
57 | |||
58 | #include "applauncher.h" | ||
59 | #include "documentlist.h" | ||
60 | |||
61 | using namespace Opie::Core; | ||
62 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; | 59 | const int AppLauncher::RAISE_TIMEOUT_MS = 5000; |
63 | 60 | ||
64 | //--------------------------------------------------------------------------- | 61 | //--------------------------------------------------------------------------- |
65 | 62 | ||
66 | static AppLauncher* appLauncherPtr; | 63 | static AppLauncher* appLauncherPtr; |
67 | 64 | ||
68 | const int appStopEventID = 1290; | 65 | const int appStopEventID = 1290; |
69 | 66 | ||
70 | class AppStoppedEvent : public QCustomEvent | 67 | class AppStoppedEvent : public QCustomEvent |
71 | { | 68 | { |
72 | public: | 69 | public: |
73 | AppStoppedEvent(int pid, int status) | 70 | AppStoppedEvent(int pid, int status) |
74 | : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } | 71 | : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } |
75 | 72 | ||
76 | int pid() { return mPid; } | 73 | int pid() { return mPid; } |
77 | int status() { return mStatus; } | 74 | int status() { return mStatus; } |
78 | 75 | ||
79 | private: | 76 | private: |
80 | int mPid, mStatus; | 77 | int mPid, mStatus; |
81 | }; | 78 | }; |
82 | 79 | ||
83 | AppLauncher::AppLauncher(QObject *parent, const char *name) | 80 | AppLauncher::AppLauncher(QObject *parent, const char *name) |
84 | : QObject(parent, name), qlPid(0), qlReady(FALSE), | 81 | : QObject(parent, name), qlPid(0), qlReady(FALSE), |
85 | appKillerBox(0) | 82 | appKillerBox(0) |
86 | { | 83 | { |
87 | connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); | 84 | connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); |
88 | connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); | 85 | connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); |
89 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); | 86 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); |
90 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 87 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
91 | this, SLOT(received(const QCString&,const QByteArray&)) ); | 88 | this, SLOT(received(const QCString&,const QByteArray&)) ); |
92 | 89 | ||
93 | channel = new QCopChannel( "QPE/Server", this ); | 90 | channel = new QCopChannel( "QPE/Server", this ); |
94 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 91 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
95 | this, SLOT(received(const QCString&,const QByteArray&)) ); | 92 | this, SLOT(received(const QCString&,const QByteArray&)) ); |
96 | 93 | ||
97 | #ifndef Q_OS_WIN32 | 94 | #ifndef Q_OS_WIN32 |
98 | signal(SIGCHLD, signalHandler); | 95 | signal(SIGCHLD, signalHandler); |
99 | #else | 96 | #else |
100 | runningAppsProc.setAutoDelete( TRUE ); | 97 | runningAppsProc.setAutoDelete( TRUE ); |
101 | #endif | 98 | #endif |
102 | QString tmp = qApp->argv()[0]; | 99 | QString tmp = qApp->argv()[0]; |
103 | int pos = tmp.findRev('/'); | 100 | int pos = tmp.findRev('/'); |
104 | if ( pos > -1 ) | 101 | if ( pos > -1 ) |
105 | tmp = tmp.mid(++pos); | 102 | tmp = tmp.mid(++pos); |
106 | runningApps[::getpid()] = tmp; | 103 | runningApps[::getpid()] = tmp; |
107 | 104 | ||
108 | appLauncherPtr = this; | 105 | appLauncherPtr = this; |
109 | 106 | ||
110 | QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); | 107 | QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); |
111 | } | 108 | } |
112 | 109 | ||
113 | AppLauncher::~AppLauncher() | 110 | AppLauncher::~AppLauncher() |
114 | { | 111 | { |
115 | appLauncherPtr = 0; | 112 | appLauncherPtr = 0; |
116 | #ifndef Q_OS_WIN32 | 113 | #ifndef Q_OS_WIN32 |
117 | signal(SIGCHLD, SIG_DFL); | 114 | signal(SIGCHLD, SIG_DFL); |
118 | #endif | 115 | #endif |
119 | if ( qlPid ) { | 116 | if ( qlPid ) { |
120 | int status; | 117 | int status; |
121 | ::kill( qlPid, SIGTERM ); | 118 | ::kill( qlPid, SIGTERM ); |
122 | waitpid( qlPid, &status, 0 ); | 119 | waitpid( qlPid, &status, 0 ); |
123 | } | 120 | } |
124 | } | 121 | } |
125 | 122 | ||
126 | /* We use the QCopChannel of the app as an indicator of when it has been launched | 123 | /* We use the QCopChannel of the app as an indicator of when it has been launched |
127 | so that we can disable the busy indicators */ | 124 | so that we can disable the busy indicators */ |
128 | void AppLauncher::newQcopChannel(const QString& channelName) | 125 | void AppLauncher::newQcopChannel(const QString& channelName) |
129 | { | 126 | { |
130 | // qDebug("channel %s added", channelName.data() ); | 127 | // odebug << "channel " << channelName.data() << " added" << oendl; |
131 | QString prefix("QPE/Application/"); | 128 | QString prefix("QPE/Application/"); |
132 | if (channelName.startsWith(prefix)) { | 129 | if (channelName.startsWith(prefix)) { |
133 | { | 130 | { |
134 | QCopEnvelope e("QPE/System", "newChannel(QString)"); | 131 | QCopEnvelope e("QPE/System", "newChannel(QString)"); |
135 | e << channelName; | 132 | e << channelName; |
136 | } | 133 | } |
137 | QString appName = channelName.mid(prefix.length()); | 134 | QString appName = channelName.mid(prefix.length()); |
138 | if ( appName != "quicklauncher" ) { | 135 | if ( appName != "quicklauncher" ) { |
139 | emit connected( appName ); | 136 | emit connected( appName ); |
140 | QCopEnvelope e("QPE/System", "notBusy(QString)"); | 137 | QCopEnvelope e("QPE/System", "notBusy(QString)"); |
141 | e << appName; | 138 | e << appName; |
142 | } | 139 | } |
143 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { | 140 | } else if (channelName.startsWith("QPE/QuickLauncher-")) { |
144 | qDebug("Registered %s", channelName.latin1()); | 141 | odebug << "Registered " << channelName << "" << oendl; |
145 | int pid = channelName.mid(18).toInt(); | 142 | int pid = channelName.mid(18).toInt(); |
146 | if (pid == qlPid) | 143 | if (pid == qlPid) |
147 | qlReady = TRUE; | 144 | qlReady = TRUE; |
148 | } | 145 | } |
149 | } | 146 | } |
150 | 147 | ||
151 | void AppLauncher::removedQcopChannel(const QString& channelName) | 148 | void AppLauncher::removedQcopChannel(const QString& channelName) |
152 | { | 149 | { |
153 | if (channelName.startsWith("QPE/Application/")) { | 150 | if (channelName.startsWith("QPE/Application/")) { |
154 | QCopEnvelope e("QPE/System", "removedChannel(QString)"); | 151 | QCopEnvelope e("QPE/System", "removedChannel(QString)"); |
155 | e << channelName; | 152 | e << channelName; |
156 | } | 153 | } |
157 | } | 154 | } |
158 | 155 | ||
159 | void AppLauncher::received(const QCString& msg, const QByteArray& data) | 156 | void AppLauncher::received(const QCString& msg, const QByteArray& data) |
160 | { | 157 | { |
161 | QDataStream stream( data, IO_ReadOnly ); | 158 | QDataStream stream( data, IO_ReadOnly ); |
162 | if ( msg == "execute(QString)" ) { | 159 | if ( msg == "execute(QString)" ) { |
163 | QString t; | 160 | QString t; |
164 | stream >> t; | 161 | stream >> t; |
165 | if ( !executeBuiltin( t, QString::null ) ) | 162 | if ( !executeBuiltin( t, QString::null ) ) |
166 | execute(t, QString::null); | 163 | execute(t, QString::null); |
167 | } else if ( msg == "execute(QString,QString)" ) { | 164 | } else if ( msg == "execute(QString,QString)" ) { |
168 | QString t,d; | 165 | QString t,d; |
169 | stream >> t >> d; | 166 | stream >> t >> d; |
170 | if ( !executeBuiltin( t, d ) ) | 167 | if ( !executeBuiltin( t, d ) ) |
171 | execute( t, d ); | 168 | execute( t, d ); |
172 | } else if ( msg == "processQCop(QString)" ) { // from QPE/Server | 169 | } else if ( msg == "processQCop(QString)" ) { // from QPE/Server |
173 | QString t; | 170 | QString t; |
174 | stream >> t; | 171 | stream >> t; |
175 | if ( !executeBuiltin( t, QString::null ) ) | 172 | if ( !executeBuiltin( t, QString::null ) ) |
176 | execute( t, QString::null, TRUE); | 173 | execute( t, QString::null, TRUE); |
177 | } else if ( msg == "raise(QString)" ) { | 174 | } else if ( msg == "raise(QString)" ) { |
178 | QString appName; | 175 | QString appName; |
179 | stream >> appName; | 176 | stream >> appName; |
180 | 177 | ||
181 | if ( !executeBuiltin( appName, QString::null ) ) { | 178 | if ( !executeBuiltin( appName, QString::null ) ) { |
182 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { | 179 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { |
183 | //qDebug( "Raising: %s", appName.latin1() ); | 180 | //odebug << "Raising: " << appName << "" << oendl; |
184 | QCString channel = "QPE/Application/"; | 181 | QCString channel = "QPE/Application/"; |
185 | channel += appName.latin1(); | 182 | channel += appName.latin1(); |
186 | 183 | ||
187 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile | 184 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile |
188 | QFile f("/tmp/qcop-msg-" + appName); | 185 | QFile f("/tmp/qcop-msg-" + appName); |
189 | if ( f.open(IO_WriteOnly | IO_Append) ) { | 186 | if ( f.open(IO_WriteOnly | IO_Append) ) { |
190 | #ifndef Q_OS_WIN32 | 187 | #ifndef Q_OS_WIN32 |
191 | flock(f.handle(), LOCK_EX); | 188 | flock(f.handle(), LOCK_EX); |
192 | #endif | 189 | #endif |
193 | QDataStream ds(&f); | 190 | QDataStream ds(&f); |
194 | QByteArray b; | 191 | QByteArray b; |
195 | QDataStream bstream(b, IO_WriteOnly); | 192 | QDataStream bstream(b, IO_WriteOnly); |
196 | ds << channel << QCString("raise()") << b; | 193 | ds << channel << QCString("raise()") << b; |
197 | f.flush(); | 194 | f.flush(); |
198 | #ifndef Q_OS_WIN32 | 195 | #ifndef Q_OS_WIN32 |
199 | flock(f.handle(), LOCK_UN); | 196 | flock(f.handle(), LOCK_UN); |
200 | #endif | 197 | #endif |
201 | f.close(); | 198 | f.close(); |
202 | } | 199 | } |
203 | bool alreadyRunning = isRunning( appName ); | 200 | bool alreadyRunning = isRunning( appName ); |
204 | if ( execute(appName, QString::null) ) { | 201 | if ( execute(appName, QString::null) ) { |
205 | int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0); | 202 | int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0); |
206 | waitingHeartbeat.insert( appName, id ); | 203 | waitingHeartbeat.insert( appName, id ); |
207 | } | 204 | } |
208 | } | 205 | } |
209 | } | 206 | } |
210 | } else if ( msg == "sendRunningApps()" ) { | 207 | } else if ( msg == "sendRunningApps()" ) { |
211 | QStringList apps; | 208 | QStringList apps; |
212 | QMap<int,QString>::Iterator it; | 209 | QMap<int,QString>::Iterator it; |
213 | for( it = runningApps.begin(); it != runningApps.end(); ++it ) | 210 | for( it = runningApps.begin(); it != runningApps.end(); ++it ) |
214 | apps.append( *it ); | 211 | apps.append( *it ); |
215 | QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" ); | 212 | QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" ); |
216 | e << apps; | 213 | e << apps; |
217 | } else if ( msg == "appRaised(QString)" ) { | 214 | } else if ( msg == "appRaised(QString)" ) { |
218 | QString appName; | 215 | QString appName; |
219 | stream >> appName; | 216 | stream >> appName; |
220 | qDebug("Got a heartbeat from %s", appName.latin1()); | 217 | odebug << "Got a heartbeat from " << appName << "" << oendl; |
221 | QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); | 218 | QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); |
222 | if ( it != waitingHeartbeat.end() ) { | 219 | if ( it != waitingHeartbeat.end() ) { |
223 | killTimer( *it ); | 220 | killTimer( *it ); |
224 | waitingHeartbeat.remove(it); | 221 | waitingHeartbeat.remove(it); |
225 | } | 222 | } |
226 | // Check to make sure we're not waiting on user input... | 223 | // Check to make sure we're not waiting on user input... |
227 | if ( appKillerBox && appName == appKillerName ) { | 224 | if ( appKillerBox && appName == appKillerName ) { |
228 | // If we are, we kill the dialog box, and the code waiting on the result | 225 | // If we are, we kill the dialog box, and the code waiting on the result |
229 | // will clean us up (basically the user said "no"). | 226 | // will clean us up (basically the user said "no"). |
230 | delete appKillerBox; | 227 | delete appKillerBox; |
231 | appKillerBox = 0; | 228 | appKillerBox = 0; |
232 | appKillerName = QString::null; | 229 | appKillerName = QString::null; |
233 | } | 230 | } |
234 | } | 231 | } |
235 | } | 232 | } |
236 | 233 | ||
237 | void AppLauncher::signalHandler(int) | 234 | void AppLauncher::signalHandler(int) |
238 | { | 235 | { |
239 | #ifndef Q_OS_WIN32 | 236 | #ifndef Q_OS_WIN32 |
240 | int status; | 237 | int status; |
241 | pid_t pid = waitpid(-1, &status, WNOHANG); | 238 | pid_t pid = waitpid(-1, &status, WNOHANG); |
242 | /* if (pid == 0 || &status == 0 ) { | 239 | /* if (pid == 0 || &status == 0 ) { |
243 | qDebug("hmm, could not get return value from signal"); | 240 | odebug << "hmm, could not get return value from signal" << oendl; |
244 | } | 241 | } |
245 | */ | 242 | */ |
246 | QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); | 243 | QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); |
247 | #else | 244 | #else |
248 | qDebug("Unhandled signal see by AppLauncher::signalHandler(int)"); | 245 | odebug << "Unhandled signal see by AppLauncher::signalHandler(int)" << oendl; |
249 | #endif | 246 | #endif |
250 | } | 247 | } |
251 | 248 | ||
252 | bool AppLauncher::event(QEvent *e) | 249 | bool AppLauncher::event(QEvent *e) |
253 | { | 250 | { |
254 | if ( e->type() == appStopEventID ) { | 251 | if ( e->type() == appStopEventID ) { |
255 | AppStoppedEvent *ae = (AppStoppedEvent *) e; | 252 | AppStoppedEvent *ae = (AppStoppedEvent *) e; |
256 | sigStopped(ae->pid(), ae->status() ); | 253 | sigStopped(ae->pid(), ae->status() ); |
257 | return TRUE; | 254 | return TRUE; |
258 | } | 255 | } |
259 | 256 | ||
260 | return QObject::event(e); | 257 | return QObject::event(e); |
261 | } | 258 | } |
262 | 259 | ||
263 | void AppLauncher::timerEvent( QTimerEvent *e ) | 260 | void AppLauncher::timerEvent( QTimerEvent *e ) |
264 | { | 261 | { |
265 | int id = e->timerId(); | 262 | int id = e->timerId(); |
266 | QMap<QString,int>::Iterator it; | 263 | QMap<QString,int>::Iterator it; |
267 | for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) { | 264 | for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) { |
268 | if ( *it == id ) { | 265 | if ( *it == id ) { |
269 | if ( appKillerBox ) // we're already dealing with one | 266 | if ( appKillerBox ) // we're already dealing with one |
270 | return; | 267 | return; |
271 | 268 | ||
272 | appKillerName = it.key(); | 269 | appKillerName = it.key(); |
273 | killTimer( id ); | 270 | killTimer( id ); |
274 | waitingHeartbeat.remove( it ); | 271 | waitingHeartbeat.remove( it ); |
275 | 272 | ||
276 | // qDebug("Checking in on %s", appKillerName.latin1()); | 273 | // odebug << "Checking in on " << appKillerName << "" << oendl; |
277 | 274 | ||
278 | // We store this incase the application responds while we're | 275 | // We store this incase the application responds while we're |
279 | // waiting for user input so we know not to delete ourselves. | 276 | // waiting for user input so we know not to delete ourselves. |
280 | appKillerBox = new QMessageBox(tr("Application Problem"), | 277 | appKillerBox = new QMessageBox(tr("Application Problem"), |
281 | tr("<p>%1 is not responding.</p>").arg(appKillerName) + | 278 | tr("<p>%1 is not responding.</p>").arg(appKillerName) + |
282 | tr("<p>Would you like to force the application to exit?</p>"), | 279 | tr("<p>Would you like to force the application to exit?</p>"), |
283 | QMessageBox::Warning, QMessageBox::Yes, | 280 | QMessageBox::Warning, QMessageBox::Yes, |
284 | QMessageBox::No | QMessageBox::Default, | 281 | QMessageBox::No | QMessageBox::Default, |
285 | QMessageBox::NoButton); | 282 | QMessageBox::NoButton); |
286 | if (appKillerBox->exec() == QMessageBox::Yes) { | 283 | if (appKillerBox->exec() == QMessageBox::Yes) { |
287 | // qDebug("Killing the app!!! Bwuhahahaha!"); | 284 | // odebug << "Killing the app!!! Bwuhahahaha!" << oendl; |
288 | int pid = pidForName(appKillerName); | 285 | int pid = pidForName(appKillerName); |
289 | if ( pid > 0 ) | 286 | if ( pid > 0 ) |
290 | kill( pid ); | 287 | kill( pid ); |
291 | } | 288 | } |
292 | appKillerName = QString::null; | 289 | appKillerName = QString::null; |
293 | delete appKillerBox; | 290 | delete appKillerBox; |
294 | appKillerBox = 0; | 291 | appKillerBox = 0; |
295 | return; | 292 | return; |
296 | } | 293 | } |
297 | } | 294 | } |
298 | 295 | ||
299 | QObject::timerEvent( e ); | 296 | QObject::timerEvent( e ); |
300 | } | 297 | } |
301 | 298 | ||
302 | #ifndef Q_OS_WIN32 | 299 | #ifndef Q_OS_WIN32 |
303 | void AppLauncher::sigStopped(int sigPid, int sigStatus) | 300 | void AppLauncher::sigStopped(int sigPid, int sigStatus) |
304 | { | 301 | { |
305 | int exitStatus = 0; | 302 | int exitStatus = 0; |
306 | 303 | ||
307 | bool crashed = WIFSIGNALED(sigStatus); | 304 | bool crashed = WIFSIGNALED(sigStatus); |
308 | if ( !crashed ) { | 305 | if ( !crashed ) { |
309 | if ( WIFEXITED(sigStatus) ) | 306 | if ( WIFEXITED(sigStatus) ) |
310 | exitStatus = WEXITSTATUS(sigStatus); | 307 | exitStatus = WEXITSTATUS(sigStatus); |
311 | } else { | 308 | } else { |
312 | exitStatus = WTERMSIG(sigStatus); | 309 | exitStatus = WTERMSIG(sigStatus); |
313 | } | 310 | } |
314 | 311 | ||
315 | QMap<int,QString>::Iterator it = runningApps.find( sigPid ); | 312 | QMap<int,QString>::Iterator it = runningApps.find( sigPid ); |
316 | if ( it == runningApps.end() ) { | 313 | if ( it == runningApps.end() ) { |
317 | if ( sigPid == qlPid ) { | 314 | if ( sigPid == qlPid ) { |
318 | qDebug( "quicklauncher stopped" ); | 315 | odebug << "quicklauncher stopped" << oendl; |
319 | qlPid = 0; | 316 | qlPid = 0; |
320 | qlReady = FALSE; | 317 | qlReady = FALSE; |
321 | QFile::remove("/tmp/qcop-msg-quicklauncher" ); | 318 | QFile::remove("/tmp/qcop-msg-quicklauncher" ); |
322 | QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); | 319 | QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); |
323 | } | 320 | } |
324 | /* | 321 | /* |
325 | if ( sigPid == -1 ) | 322 | if ( sigPid == -1 ) |
326 | qDebug("non-qtopia application exited (disregarded)"); | 323 | odebug << "non-qtopia application exited (disregarded)" << oendl; |
327 | else | 324 | else |
328 | qDebug("==== no pid matching %d in list, definite bug", sigPid); | 325 | odebug << "==== no pid matching " << sigPid << " in list, definite bug" << oendl; |
329 | */ | 326 | */ |
330 | return; | 327 | return; |
331 | } | 328 | } |
332 | QString appName = *it; | 329 | QString appName = *it; |
333 | runningApps.remove(it); | 330 | runningApps.remove(it); |
334 | 331 | ||
335 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); | 332 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); |
336 | if ( hbit != waitingHeartbeat.end() ) { | 333 | if ( hbit != waitingHeartbeat.end() ) { |
337 | killTimer( *hbit ); | 334 | killTimer( *hbit ); |
338 | waitingHeartbeat.remove( hbit ); | 335 | waitingHeartbeat.remove( hbit ); |
339 | } | 336 | } |
340 | if ( appName == appKillerName ) { | 337 | if ( appName == appKillerName ) { |
341 | appKillerName = QString::null; | 338 | appKillerName = QString::null; |
342 | delete appKillerBox; | 339 | delete appKillerBox; |
343 | appKillerBox = 0; | 340 | appKillerBox = 0; |
344 | } | 341 | } |
345 | 342 | ||
346 | /* we must disable preload for an app that crashes as the system logic relies on preloaded apps | 343 | /* we must disable preload for an app that crashes as the system logic relies on preloaded apps |
347 | actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload | 344 | actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload |
348 | the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution) | 345 | the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution) |
349 | */ | 346 | */ |
350 | bool preloadDisabled = FALSE; | 347 | bool preloadDisabled = FALSE; |
351 | if ( !DocumentList::appLnkSet ) return; | 348 | if ( !DocumentList::appLnkSet ) return; |
352 | const AppLnk* app = DocumentList::appLnkSet->findExec( appName ); | 349 | const AppLnk* app = DocumentList::appLnkSet->findExec( appName ); |
353 | if ( !app ) return; // QCop messages processed to slow? | 350 | if ( !app ) return; // QCop messages processed to slow? |
354 | if ( crashed && app->isPreloaded() ) { | 351 | if ( crashed && app->isPreloaded() ) { |
355 | Config cfg("Launcher"); | 352 | Config cfg("Launcher"); |
356 | cfg.setGroup("Preload"); | 353 | cfg.setGroup("Preload"); |
357 | QStringList apps = cfg.readListEntry("Apps",','); | 354 | QStringList apps = cfg.readListEntry("Apps",','); |
358 | QString exe = app->exec(); | 355 | QString exe = app->exec(); |
359 | apps.remove(exe); | 356 | apps.remove(exe); |
360 | cfg.writeEntry("Apps",apps,','); | 357 | cfg.writeEntry("Apps",apps,','); |
361 | preloadDisabled = TRUE; | 358 | preloadDisabled = TRUE; |
362 | } | 359 | } |
363 | 360 | ||
364 | // clean up | 361 | // clean up |
365 | if ( exitStatus ) { | 362 | if ( exitStatus ) { |
366 | QCopEnvelope e("QPE/System", "notBusy(QString)"); | 363 | QCopEnvelope e("QPE/System", "notBusy(QString)"); |
367 | e << app->exec(); | 364 | e << app->exec(); |
368 | } | 365 | } |
369 | /* | 366 | /* |
370 | // debug info | 367 | // debug info |
371 | for (it = runningApps.begin(); it != runningApps.end(); ++it) { | 368 | for (it = runningApps.begin(); it != runningApps.end(); ++it) { |
372 | qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() ); | 369 | odebug << "running according to internal list: " << (*it).data() << ", with pid " << it.key() << "" << oendl; |
373 | } | 370 | } |
374 | */ | 371 | */ |
375 | 372 | ||
376 | #ifdef QTOPIA_PROGRAM_MONITOR | 373 | #ifdef QTOPIA_PROGRAM_MONITOR |
377 | if ( crashed ) { | 374 | if ( crashed ) { |
378 | QString sig; | 375 | QString sig; |
379 | switch( exitStatus ) { | 376 | switch( exitStatus ) { |
380 | case SIGABRT: sig = "SIGABRT"; break; | 377 | case SIGABRT: sig = "SIGABRT"; break; |
381 | case SIGALRM: sig = "SIGALRM"; break; | 378 | case SIGALRM: sig = "SIGALRM"; break; |
382 | case SIGBUS: sig = "SIGBUS"; break; | 379 | case SIGBUS: sig = "SIGBUS"; break; |
383 | case SIGFPE: sig = "SIGFPE"; break; | 380 | case SIGFPE: sig = "SIGFPE"; break; |
384 | case SIGHUP: sig = "SIGHUP"; break; | 381 | case SIGHUP: sig = "SIGHUP"; break; |
385 | case SIGILL: sig = "SIGILL"; break; | 382 | case SIGILL: sig = "SIGILL"; break; |
386 | case SIGKILL: sig = "SIGKILL"; break; | 383 | case SIGKILL: sig = "SIGKILL"; break; |
387 | case SIGPIPE: sig = "SIGPIPE"; break; | 384 | case SIGPIPE: sig = "SIGPIPE"; break; |
388 | case SIGQUIT: sig = "SIGQUIT"; break; | 385 | case SIGQUIT: sig = "SIGQUIT"; break; |
389 | case SIGSEGV: sig = "SIGSEGV"; break; | 386 | case SIGSEGV: sig = "SIGSEGV"; break; |
390 | case SIGTERM: sig = "SIGTERM"; break; | 387 | case SIGTERM: sig = "SIGTERM"; break; |
391 | case SIGTRAP: sig = "SIGTRAP"; break; | 388 | case SIGTRAP: sig = "SIGTRAP"; break; |
392 | default: sig = QString("Unkown %1").arg(exitStatus); | 389 | default: sig = QString("Unkown %1").arg(exitStatus); |
393 | } | 390 | } |
394 | if ( preloadDisabled ) | 391 | if ( preloadDisabled ) |
395 | sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>"); | 392 | sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>"); |
396 | 393 | ||
397 | QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig ); | 394 | QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig ); |
398 | QMessageBox::information(0, tr("Application terminated"), str ); | 395 | QMessageBox::information(0, tr("Application terminated"), str ); |
399 | } else { | 396 | } else { |
400 | if ( exitStatus == 255 ) { //could not find app (because global returns -1) | 397 | if ( exitStatus == 255 ) { //could not find app (because global returns -1) |
401 | QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) ); | 398 | QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) ); |
402 | } else { | 399 | } else { |
403 | QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName); | 400 | QFileInfo fi(QString::fromLatin1("/tmp/qcop-msg-") + appName); |
404 | if ( fi.exists() && fi.size() ) { | 401 | if ( fi.exists() && fi.size() ) { |
405 | emit terminated(sigPid, appName); | 402 | emit terminated(sigPid, appName); |
406 | qWarning("Re executing obmitted for %s", appName.latin1() ); | 403 | owarn << "Re executing obmitted for " << appName << "" << oendl; |
407 | // execute( appName, QString::null ); | 404 | // execute( appName, QString::null ); |
408 | return; | 405 | return; |
409 | } | 406 | } |
410 | } | 407 | } |
411 | } | 408 | } |
412 | 409 | ||
413 | #endif | 410 | #endif |
414 | 411 | ||
415 | emit terminated(sigPid, appName); | 412 | emit terminated(sigPid, appName); |
416 | } | 413 | } |
417 | #else | 414 | #else |
418 | void AppLauncher::sigStopped(int sigPid, int sigStatus) | 415 | void AppLauncher::sigStopped(int sigPid, int sigStatus) |
419 | { | 416 | { |
420 | qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)"); | 417 | odebug << "Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)" << oendl; |
421 | } | 418 | } |
422 | #endif // Q_OS_WIN32 | 419 | #endif // Q_OS_WIN32 |
423 | 420 | ||
424 | bool AppLauncher::isRunning(const QString &app) | 421 | bool AppLauncher::isRunning(const QString &app) |
425 | { | 422 | { |
426 | for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) { | 423 | for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) { |
427 | if ( *it == app ) { | 424 | if ( *it == app ) { |
428 | #ifdef Q_OS_UNIX | 425 | #ifdef Q_OS_UNIX |
429 | pid_t t = ::__getpgid( it.key() ); | 426 | pid_t t = ::__getpgid( it.key() ); |
430 | if ( t == -1 ) { | 427 | if ( t == -1 ) { |
431 | qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() ); | 428 | odebug << "appLauncher bug, " << app.data() << " believed running, but pid " << it.key() << " is not existing" << oendl; |
432 | runningApps.remove( it.key() ); | 429 | runningApps.remove( it.key() ); |
433 | return FALSE; | 430 | return FALSE; |
434 | } | 431 | } |
435 | #endif | 432 | #endif |
436 | return TRUE; | 433 | return TRUE; |
437 | } | 434 | } |
438 | } | 435 | } |
439 | 436 | ||
440 | return FALSE; | 437 | return FALSE; |
441 | } | 438 | } |
442 | 439 | ||
443 | bool AppLauncher::executeBuiltin(const QString &c, const QString &document) | 440 | bool AppLauncher::executeBuiltin(const QString &c, const QString &document) |
444 | { | 441 | { |
445 | Global::Command* builtin = OGlobal::builtinCommands(); | 442 | Global::Command* builtin = OGlobal::builtinCommands(); |
446 | QGuardedPtr<QWidget> *running = OGlobal::builtinRunning(); | 443 | QGuardedPtr<QWidget> *running = OGlobal::builtinRunning(); |
447 | 444 | ||
448 | // Attempt to execute the app using a builtin class for the app | 445 | // Attempt to execute the app using a builtin class for the app |
449 | if (builtin) { | 446 | if (builtin) { |
450 | for (int i = 0; builtin[i].file; i++) { | 447 | for (int i = 0; builtin[i].file; i++) { |
451 | if ( builtin[i].file == c ) { | 448 | if ( builtin[i].file == c ) { |
452 | if ( running[i] ) { | 449 | if ( running[i] ) { |
453 | if ( !document.isNull() && builtin[i].documentary ) | 450 | if ( !document.isNull() && builtin[i].documentary ) |
454 | Global::setDocument(running[i], document); | 451 | Global::setDocument(running[i], document); |
455 | running[i]->raise(); | 452 | running[i]->raise(); |
456 | running[i]->show(); | 453 | running[i]->show(); |
457 | running[i]->setActiveWindow(); | 454 | running[i]->setActiveWindow(); |
458 | } else { | 455 | } else { |
459 | running[i] = builtin[i].func( builtin[i].maximized ); | 456 | running[i] = builtin[i].func( builtin[i].maximized ); |
460 | } | 457 | } |
461 | #ifndef QT_NO_COP | 458 | #ifndef QT_NO_COP |
462 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); | 459 | QCopEnvelope e("QPE/System", "notBusy(QString)" ); |
463 | e << c; // that was quick ;-) | 460 | e << c; // that was quick ;-) |
464 | #endif | 461 | #endif |
465 | return TRUE; | 462 | return TRUE; |
466 | } | 463 | } |
467 | } | 464 | } |
468 | } | 465 | } |
469 | 466 | ||
470 | // Convert the command line in to a list of arguments | 467 | // Convert the command line in to a list of arguments |
471 | QStringList list = QStringList::split(QRegExp(" *"),c); | 468 | QStringList list = QStringList::split(QRegExp(" *"),c); |
472 | QString ap=list[0]; | 469 | QString ap=list[0]; |
473 | 470 | ||
474 | if ( ap == "suspend" ) { // No tr | 471 | if ( ap == "suspend" ) { // No tr |
475 | QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 472 | QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
476 | return TRUE; | 473 | return TRUE; |
477 | } | 474 | } |
478 | 475 | ||
479 | return FALSE; | 476 | return FALSE; |
480 | } | 477 | } |
481 | 478 | ||
482 | bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) | 479 | bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) |
483 | { | 480 | { |
484 | qWarning("AppLauncher::execute '%s' '%s'", (const char*) c, (const char*) docParam ); | 481 | owarn << "AppLauncher::execute '" << c << "' '" << docParam << "'" << oendl; |
485 | // Convert the command line in to a list of arguments | 482 | // Convert the command line in to a list of arguments |
486 | QStringList list = QStringList::split(QRegExp(" *"),c); | 483 | QStringList list = QStringList::split(QRegExp(" *"),c); |
487 | QStringList arglist = QStringList::split(QRegExp(" *"),docParam); | 484 | QStringList arglist = QStringList::split(QRegExp(" *"),docParam); |
488 | for ( QStringList::Iterator it = arglist.begin(); it != arglist.end(); ++it ) | 485 | for ( QStringList::Iterator it = arglist.begin(); it != arglist.end(); ++it ) |
489 | list.append( *it ); | 486 | list.append( *it ); |
490 | 487 | ||
491 | QString appName = list[0]; | 488 | QString appName = list[0]; |
492 | if ( isRunning(appName) ) { | 489 | if ( isRunning(appName) ) { |
493 | QCString channel = "QPE/Application/"; | 490 | QCString channel = "QPE/Application/"; |
494 | channel += appName.latin1(); | 491 | channel += appName.latin1(); |
495 | 492 | ||
496 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile | 493 | // Need to lock it to avoid race conditions with QPEApplication::processQCopFile |
497 | QFile f(QString::fromLatin1("/tmp/qcop-msg-") + appName); | 494 | QFile f(QString::fromLatin1("/tmp/qcop-msg-") + appName); |
498 | if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) { | 495 | if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) { |
499 | #ifndef Q_OS_WIN32 | 496 | #ifndef Q_OS_WIN32 |
500 | flock(f.handle(), LOCK_EX); | 497 | flock(f.handle(), LOCK_EX); |
501 | #endif | 498 | #endif |
502 | 499 | ||
503 | QDataStream ds(&f); | 500 | QDataStream ds(&f); |
504 | QByteArray b; | 501 | QByteArray b; |
505 | QDataStream bstream(b, IO_WriteOnly); | 502 | QDataStream bstream(b, IO_WriteOnly); |
506 | if ( !f.size() ) { | 503 | if ( !f.size() ) { |
507 | ds << channel << QCString("raise()") << b; | 504 | ds << channel << QCString("raise()") << b; |
508 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { | 505 | if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { |
509 | int id = startTimer(RAISE_TIMEOUT_MS); | 506 | int id = startTimer(RAISE_TIMEOUT_MS); |
510 | waitingHeartbeat.insert( appName, id ); | 507 | waitingHeartbeat.insert( appName, id ); |
511 | } | 508 | } |
512 | } | 509 | } |
513 | if ( !docParam.isEmpty() ) { | 510 | if ( !docParam.isEmpty() ) { |
514 | bstream << docParam; | 511 | bstream << docParam; |
515 | ds << channel << QCString("setDocument(QString)") << b; | 512 | ds << channel << QCString("setDocument(QString)") << b; |
516 | } | 513 | } |
517 | 514 | ||
518 | f.flush(); | 515 | f.flush(); |
519 | #ifndef Q_OS_WIN32 | 516 | #ifndef Q_OS_WIN32 |
520 | flock(f.handle(), LOCK_UN); | 517 | flock(f.handle(), LOCK_UN); |
521 | #endif | 518 | #endif |
522 | f.close(); | 519 | f.close(); |
523 | } | 520 | } |
524 | if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings | 521 | if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings |
525 | QCopChannel::send(channel,"QPEProcessQCop()"); | 522 | QCopChannel::send(channel,"QPEProcessQCop()"); |
526 | 523 | ||
527 | return TRUE; | 524 | return TRUE; |
528 | } | 525 | } |
529 | 526 | ||
530 | #ifdef QT_NO_QWS_MULTIPROCESS | 527 | #ifdef QT_NO_QWS_MULTIPROCESS |
531 | QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c), | 528 | QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c), |
532 | tr("OK"), 0, 0, 0, 1 ); | 529 | tr("OK"), 0, 0, 0, 1 ); |
533 | #else | 530 | #else |
534 | 531 | ||
535 | QStrList slist; | 532 | QStrList slist; |
536 | unsigned j; | 533 | unsigned j; |
537 | for ( j = 0; j < list.count(); j++ ) | 534 | for ( j = 0; j < list.count(); j++ ) |
538 | slist.append( list[j].utf8() ); | 535 | slist.append( list[j].utf8() ); |
539 | 536 | ||
540 | const char **args = new const char *[slist.count() + 1]; | 537 | const char **args = new const char *[slist.count() + 1]; |
541 | for ( j = 0; j < slist.count(); j++ ) | 538 | for ( j = 0; j < slist.count(); j++ ) |
542 | args[j] = slist.at(j); | 539 | args[j] = slist.at(j); |
543 | args[j] = NULL; | 540 | args[j] = NULL; |
544 | 541 | ||
545 | #ifndef Q_OS_WIN32 | 542 | #ifndef Q_OS_WIN32 |
546 | #ifdef Q_OS_MACX | 543 | #ifdef Q_OS_MACX |
547 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { | 544 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { |
548 | #else | 545 | #else |
549 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { | 546 | if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { |
550 | #endif /* Q_OS_MACX */ | 547 | #endif /* Q_OS_MACX */ |
551 | qDebug( "Quick launching: %s", args[0] ); | 548 | odebug << "Quick launching: " << args[0] << "" << oendl; |
552 | if ( getuid() == 0 ) | 549 | if ( getuid() == 0 ) |
553 | setpriority( PRIO_PROCESS, qlPid, 0 ); | 550 | setpriority( PRIO_PROCESS, qlPid, 0 ); |
554 | QCString qlch("QPE/QuickLauncher-"); | 551 | QCString qlch("QPE/QuickLauncher-"); |
555 | qlch += QString::number(qlPid); | 552 | qlch += QString::number(qlPid); |
556 | QCopEnvelope env( qlch, "execute(QStrList)" ); | 553 | QCopEnvelope env( qlch, "execute(QStrList)" ); |
557 | env << slist; | 554 | env << slist; |
558 | runningApps[qlPid] = QString(args[0]); | 555 | runningApps[qlPid] = QString(args[0]); |
559 | emit launched(qlPid, QString(args[0])); | 556 | emit launched(qlPid, QString(args[0])); |
560 | QCopEnvelope e("QPE/System", "busy()"); | 557 | QCopEnvelope e("QPE/System", "busy()"); |
561 | qlPid = 0; | 558 | qlPid = 0; |
562 | qlReady = FALSE; | 559 | qlReady = FALSE; |
563 | QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) ); | 560 | QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) ); |
564 | } else { | 561 | } else { |
565 | int pid = ::vfork(); | 562 | int pid = ::vfork(); |
566 | if ( !pid ) { | 563 | if ( !pid ) { |
567 | for ( int fd = 3; fd < 100; fd++ ) | 564 | for ( int fd = 3; fd < 100; fd++ ) |
568 | ::close( fd ); | 565 | ::close( fd ); |
569 | ::setpgid( ::getpid(), ::getppid() ); | 566 | ::setpgid( ::getpid(), ::getppid() ); |
570 | // Try bindir first, so that foo/bar works too | 567 | // Try bindir first, so that foo/bar works too |
571 | ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args ); | 568 | ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args ); |
572 | ::execvp( args[0], (char * const *)args ); | 569 | ::execvp( args[0], (char * const *)args ); |
573 | _exit( -1 ); | 570 | _exit( -1 ); |
574 | } | 571 | } |
575 | 572 | ||
576 | runningApps[pid] = QString(args[0]); | 573 | runningApps[pid] = QString(args[0]); |
577 | emit launched(pid, QString(args[0])); | 574 | emit launched(pid, QString(args[0])); |
578 | QCopEnvelope e("QPE/System", "busy()"); | 575 | QCopEnvelope e("QPE/System", "busy()"); |
579 | } | 576 | } |
580 | #else | 577 | #else |
581 | QProcess *proc = new QProcess(this); | 578 | QProcess *proc = new QProcess(this); |
582 | if (proc){ | 579 | if (proc){ |
583 | for (int i=0; i < slist.count(); i++) | 580 | for (int i=0; i < slist.count(); i++) |
584 | proc->addArgument(args[i]); | 581 | proc->addArgument(args[i]); |
585 | connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); | 582 | connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); |
586 | if (!proc->start()){ | 583 | if (!proc->start()){ |
587 | qDebug("Unable to start application %s", args[0]); | 584 | odebug << "Unable to start application " << args[0] << "" << oendl; |
588 | }else{ | 585 | }else{ |
589 | PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); | 586 | PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); |
590 | if (procInfo){ | 587 | if (procInfo){ |
591 | DWORD pid = procInfo->dwProcessId; | 588 | DWORD pid = procInfo->dwProcessId; |
592 | runningApps[pid] = QString(args[0]); | 589 | runningApps[pid] = QString(args[0]); |
593 | runningAppsProc.append(proc); | 590 | runningAppsProc.append(proc); |
594 | emit launched(pid, QString(args[0])); | 591 | emit launched(pid, QString(args[0])); |
595 | QCopEnvelope e("QPE/System", "busy()"); | 592 | QCopEnvelope e("QPE/System", "busy()"); |
596 | }else{ | 593 | }else{ |
597 | qDebug("Unable to read process inforation #1 for %s", args[0]); | 594 | odebug << "Unable to read process inforation #1 for " << args[0] << "" << oendl; |
598 | } | 595 | } |
599 | } | 596 | } |
600 | }else{ | 597 | }else{ |
601 | qDebug("Unable to create process for application %s", args[0]); | 598 | odebug << "Unable to create process for application " << args[0] << "" << oendl; |
602 | return FALSE; | 599 | return FALSE; |
603 | } | 600 | } |
604 | #endif | 601 | #endif |
605 | #endif //QT_NO_QWS_MULTIPROCESS | 602 | #endif //QT_NO_QWS_MULTIPROCESS |
606 | 603 | ||
607 | delete [] args; | 604 | delete [] args; |
608 | return TRUE; | 605 | return TRUE; |
609 | } | 606 | } |
610 | 607 | ||
611 | void AppLauncher::kill( int pid ) | 608 | void AppLauncher::kill( int pid ) |
612 | { | 609 | { |
613 | #ifndef Q_OS_WIN32 | 610 | #ifndef Q_OS_WIN32 |
614 | ::kill( pid, SIGTERM ); | 611 | ::kill( pid, SIGTERM ); |
615 | #else | 612 | #else |
616 | for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) { | 613 | for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) { |
617 | if ( proc->processIdentifier() == pid ) { | 614 | if ( proc->processIdentifier() == pid ) { |
618 | proc->kill(); | 615 | proc->kill(); |
619 | break; | 616 | break; |
620 | } | 617 | } |
621 | } | 618 | } |
622 | #endif | 619 | #endif |
623 | } | 620 | } |
624 | 621 | ||
625 | int AppLauncher::pidForName( const QString &appName ) | 622 | int AppLauncher::pidForName( const QString &appName ) |
626 | { | 623 | { |
627 | int pid = -1; | 624 | int pid = -1; |
628 | 625 | ||
629 | QMap<int, QString>::Iterator it; | 626 | QMap<int, QString>::Iterator it; |
630 | for (it = runningApps.begin(); it!= runningApps.end(); ++it) { | 627 | for (it = runningApps.begin(); it!= runningApps.end(); ++it) { |
631 | if (*it == appName) { | 628 | if (*it == appName) { |
632 | pid = it.key(); | 629 | pid = it.key(); |
633 | break; | 630 | break; |
634 | } | 631 | } |
635 | } | 632 | } |
636 | 633 | ||
637 | return pid; | 634 | return pid; |
638 | } | 635 | } |
639 | 636 | ||
640 | void AppLauncher::createQuickLauncher() | 637 | void AppLauncher::createQuickLauncher() |
641 | { | 638 | { |
642 | static bool disabled = FALSE; | 639 | static bool disabled = FALSE; |
643 | if (disabled) | 640 | if (disabled) |
644 | return; | 641 | return; |
645 | 642 | ||
646 | qlReady = FALSE; | 643 | qlReady = FALSE; |
647 | qlPid = ::vfork(); | 644 | qlPid = ::vfork(); |
648 | if ( !qlPid ) { | 645 | if ( !qlPid ) { |
649 | char **args = new char *[2]; | 646 | char **args = new char *[2]; |
650 | args[0] = "quicklauncher"; | 647 | args[0] = "quicklauncher"; |
651 | args[1] = 0; | 648 | args[1] = 0; |
652 | for ( int fd = 3; fd < 100; fd++ ) | 649 | for ( int fd = 3; fd < 100; fd++ ) |
653 | ::close( fd ); | 650 | ::close( fd ); |
654 | ::setpgid( ::getpid(), ::getppid() ); | 651 | ::setpgid( ::getpid(), ::getppid() ); |
655 | // Try bindir first, so that foo/bar works too | 652 | // Try bindir first, so that foo/bar works too |
656 | /* | 653 | /* |
657 | * LD_BIND_NOW will change the behaviour of ld.so and dlopen | 654 | * LD_BIND_NOW will change the behaviour of ld.so and dlopen |
658 | * RTLD_LAZY will be made RTLD_NOW which leads to problem | 655 | * RTLD_LAZY will be made RTLD_NOW which leads to problem |
659 | * with miscompiled libraries... if LD_BIND_NOW is set.. there | 656 | * with miscompiled libraries... if LD_BIND_NOW is set.. there |
660 | * is no way back.. We will wait for numbers from TT to see | 657 | * is no way back.. We will wait for numbers from TT to see |
661 | * if using LD_BIND_NOW is worth it - zecke | 658 | * if using LD_BIND_NOW is worth it - zecke |
662 | */ | 659 | */ |
663 | //setenv( "LD_BIND_NOW", "1", 1 ); | 660 | //setenv( "LD_BIND_NOW", "1", 1 ); |
664 | ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args ); | 661 | ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args ); |
665 | ::execvp( "quicklauncher", args ); | 662 | ::execvp( "quicklauncher", args ); |
666 | delete []args; | 663 | delete []args; |
667 | disabled = TRUE; | 664 | disabled = TRUE; |
668 | _exit( -1 ); | 665 | _exit( -1 ); |
669 | } else if ( qlPid == -1 ) { | 666 | } else if ( qlPid == -1 ) { |
670 | qlPid = 0; | 667 | qlPid = 0; |
671 | } else { | 668 | } else { |
672 | if ( getuid() == 0 ) | 669 | if ( getuid() == 0 ) |
673 | setpriority( PRIO_PROCESS, qlPid, 19 ); | 670 | setpriority( PRIO_PROCESS, qlPid, 19 ); |
674 | } | 671 | } |
675 | } | 672 | } |
676 | 673 | ||
677 | // Used only by Win32 | 674 | // Used only by Win32 |
678 | void AppLauncher::processExited() | 675 | void AppLauncher::processExited() |
679 | { | 676 | { |
680 | #ifdef Q_OS_WIN32 | 677 | #ifdef Q_OS_WIN32 |
681 | qDebug("AppLauncher::processExited()"); | 678 | odebug << "AppLauncher::processExited()" << oendl; |
682 | bool found = FALSE; | 679 | bool found = FALSE; |
683 | QProcess *proc = (QProcess *) sender(); | 680 | QProcess *proc = (QProcess *) sender(); |
684 | if (!proc){ | 681 | if (!proc){ |
685 | qDebug("Interanl error NULL proc"); | 682 | odebug << "Interanl error NULL proc" << oendl; |
686 | return; | 683 | return; |
687 | } | 684 | } |
688 | 685 | ||
689 | QString appName = proc->arguments()[0]; | 686 | QString appName = proc->arguments()[0]; |
690 | qDebug("Removing application %s", appName.latin1()); | 687 | odebug << "Removing application " << appName << "" << oendl; |
691 | runningAppsProc.remove(proc); | 688 | runningAppsProc.remove(proc); |
692 | 689 | ||
693 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); | 690 | QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); |
694 | if ( hbit != waitingHeartbeat.end() ) { | 691 | if ( hbit != waitingHeartbeat.end() ) { |
695 | killTimer( *hbit ); | 692 | killTimer( *hbit ); |
696 | waitingHeartbeat.remove( hbit ); | 693 | waitingHeartbeat.remove( hbit ); |
697 | } | 694 | } |
698 | if ( appName == appKillerName ) { | 695 | if ( appName == appKillerName ) { |
699 | appKillerName = QString::null; | 696 | appKillerName = QString::null; |
700 | delete appKillerBox; | 697 | delete appKillerBox; |
701 | appKillerBox = 0; | 698 | appKillerBox = 0; |
702 | } | 699 | } |
703 | 700 | ||
704 | // Search for the app to find its PID | 701 | // Search for the app to find its PID |
705 | QMap<int, QString>::Iterator it; | 702 | QMap<int, QString>::Iterator it; |
706 | for (it = runningApps.begin(); it!= runningApps.end(); ++it){ | 703 | for (it = runningApps.begin(); it!= runningApps.end(); ++it){ |
707 | if (it.data() == appName){ | 704 | if (it.data() == appName){ |
708 | found = TRUE; | 705 | found = TRUE; |
709 | break; | 706 | break; |
710 | } | 707 | } |
711 | } | 708 | } |
712 | 709 | ||
713 | if (found){ | 710 | if (found){ |
714 | emit terminated(it.key(), it.data()); | 711 | emit terminated(it.key(), it.data()); |
715 | runningApps.remove(it.key()); | 712 | runningApps.remove(it.key()); |
716 | }else{ | 713 | }else{ |
717 | qDebug("Internal error application %s not listed as running", appName.latin1()); | 714 | odebug << "Internal error application " << appName << " not listed as running" << oendl; |
718 | } | 715 | } |
719 | 716 | ||
720 | #endif | 717 | #endif |
721 | } | 718 | } |
722 | 719 | ||
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index 3e0a96c..92b8c25 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp | |||
@@ -1,698 +1,700 @@ | |||
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 | #include "documentlist.h" | 20 | #include "documentlist.h" |
21 | #include "serverinterface.h" | 21 | #include "serverinterface.h" |
22 | #include "mediadlg.h" | 22 | #include "mediadlg.h" |
23 | 23 | ||
24 | /* OPIE */ | ||
24 | #include <opie2/oglobal.h> | 25 | #include <opie2/oglobal.h> |
25 | 26 | #include <opie2/odebug.h> | |
26 | #include <qtopia/config.h> | 27 | #include <qtopia/config.h> |
27 | #include <qtopia/mimetype.h> | 28 | #include <qtopia/mimetype.h> |
28 | #include <qtopia/resource.h> | 29 | #include <qtopia/resource.h> |
29 | #include <qtopia/private/categories.h> | 30 | #include <qtopia/private/categories.h> |
30 | #include <qtopia/qpeapplication.h> | 31 | #include <qtopia/qpeapplication.h> |
31 | #include <qtopia/applnk.h> | 32 | #include <qtopia/applnk.h> |
32 | #include <qtopia/storage.h> | 33 | #include <qtopia/storage.h> |
33 | #ifdef Q_WS_QWS | 34 | #ifdef Q_WS_QWS |
34 | #include <qtopia/qcopenvelope_qws.h> | 35 | #include <qtopia/qcopenvelope_qws.h> |
35 | #endif | 36 | #endif |
37 | using namespace Opie::Core; | ||
36 | 38 | ||
39 | /* QT */ | ||
37 | #include <qtimer.h> | 40 | #include <qtimer.h> |
38 | #include <qfileinfo.h> | 41 | #include <qfileinfo.h> |
39 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
40 | #include <qfile.h> | 43 | #include <qfile.h> |
41 | #include <qdir.h> | 44 | #include <qdir.h> |
42 | #include <qpainter.h> | 45 | #include <qpainter.h> |
43 | #include <qimage.h> | 46 | #include <qimage.h> |
44 | #include <qcopchannel_qws.h> | 47 | #include <qcopchannel_qws.h> |
45 | #include <qlistview.h> | 48 | #include <qlistview.h> |
46 | #include <qlist.h> | 49 | #include <qlist.h> |
47 | #include <qpixmap.h> | 50 | #include <qpixmap.h> |
48 | 51 | ||
49 | 52 | ||
50 | using namespace Opie::Core; | ||
51 | AppLnkSet *DocumentList::appLnkSet = 0; | 53 | AppLnkSet *DocumentList::appLnkSet = 0; |
52 | 54 | ||
53 | static const int MAX_SEARCH_DEPTH = 10; | 55 | static const int MAX_SEARCH_DEPTH = 10; |
54 | 56 | ||
55 | 57 | ||
56 | class DocumentListPrivate : public QObject { | 58 | class DocumentListPrivate : public QObject { |
57 | Q_OBJECT | 59 | Q_OBJECT |
58 | public: | 60 | public: |
59 | DocumentListPrivate( ServerInterface *gui ); | 61 | DocumentListPrivate( ServerInterface *gui ); |
60 | ~DocumentListPrivate(); | 62 | ~DocumentListPrivate(); |
61 | 63 | ||
62 | void initialize(); | 64 | void initialize(); |
63 | 65 | ||
64 | const QString nextFile(); | 66 | const QString nextFile(); |
65 | const DocLnk *iterate(); | 67 | const DocLnk *iterate(); |
66 | bool store( DocLnk* dl ); | 68 | bool store( DocLnk* dl ); |
67 | void estimatedPercentScanned(); | 69 | void estimatedPercentScanned(); |
68 | void appendDocpath(FileSystem*); | 70 | void appendDocpath(FileSystem*); |
69 | 71 | ||
70 | 72 | ||
71 | DocLnkSet dls; | 73 | DocLnkSet dls; |
72 | QDict<void> reference; | 74 | QDict<void> reference; |
73 | QDictIterator<void> *dit; | 75 | QDictIterator<void> *dit; |
74 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; | 76 | enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; |
75 | 77 | ||
76 | QStringList docPaths; | 78 | QStringList docPaths; |
77 | unsigned int docPathsSearched; | 79 | unsigned int docPathsSearched; |
78 | 80 | ||
79 | int searchDepth; | 81 | int searchDepth; |
80 | QDir *listDirs[MAX_SEARCH_DEPTH]; | 82 | QDir *listDirs[MAX_SEARCH_DEPTH]; |
81 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; | 83 | const QFileInfoList *lists[MAX_SEARCH_DEPTH]; |
82 | unsigned int listPositions[MAX_SEARCH_DEPTH]; | 84 | unsigned int listPositions[MAX_SEARCH_DEPTH]; |
83 | 85 | ||
84 | StorageInfo *storage; | 86 | StorageInfo *storage; |
85 | 87 | ||
86 | int tid; | 88 | int tid; |
87 | 89 | ||
88 | ServerInterface *serverGui; | 90 | ServerInterface *serverGui; |
89 | 91 | ||
90 | bool needToSendAllDocLinks; | 92 | bool needToSendAllDocLinks; |
91 | bool sendAppLnks; | 93 | bool sendAppLnks; |
92 | bool sendDocLnks; | 94 | bool sendDocLnks; |
93 | bool scanDocs; | 95 | bool scanDocs; |
94 | }; | 96 | }; |
95 | 97 | ||
96 | 98 | ||
97 | /* | 99 | /* |
98 | * scandocs will be read from Config | 100 | * scandocs will be read from Config |
99 | */ | 101 | */ |
100 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, | 102 | DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/, |
101 | QObject *parent, const char *name ) | 103 | QObject *parent, const char *name ) |
102 | : QObject( parent, name ) | 104 | : QObject( parent, name ) |
103 | { | 105 | { |
104 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 106 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
105 | d = new DocumentListPrivate( serverGui ); | 107 | d = new DocumentListPrivate( serverGui ); |
106 | d->needToSendAllDocLinks = false; | 108 | d->needToSendAllDocLinks = false; |
107 | 109 | ||
108 | Config cfg( "Launcher" ); | 110 | Config cfg( "Launcher" ); |
109 | cfg.setGroup( "DocTab" ); | 111 | cfg.setGroup( "DocTab" ); |
110 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); | 112 | d->scanDocs = cfg.readBoolEntry( "Enable", true ); |
111 | qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); | 113 | odebug << "DocumentList::DocumentList() : scanDocs = " << d->scanDocs << "" << oendl; |
112 | 114 | ||
113 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); | 115 | QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); |
114 | } | 116 | } |
115 | 117 | ||
116 | void DocumentList::startInitialScan() | 118 | void DocumentList::startInitialScan() |
117 | { | 119 | { |
118 | reloadAppLnks(); | 120 | reloadAppLnks(); |
119 | reloadDocLnks(); | 121 | reloadDocLnks(); |
120 | } | 122 | } |
121 | 123 | ||
122 | DocumentList::~DocumentList() | 124 | DocumentList::~DocumentList() |
123 | { | 125 | { |
124 | delete appLnkSet; | 126 | delete appLnkSet; |
125 | delete d; | 127 | delete d; |
126 | } | 128 | } |
127 | 129 | ||
128 | 130 | ||
129 | void DocumentList::add( const DocLnk& doc ) | 131 | void DocumentList::add( const DocLnk& doc ) |
130 | { | 132 | { |
131 | if ( d->serverGui && QFile::exists( doc.file() ) ) | 133 | if ( d->serverGui && QFile::exists( doc.file() ) ) |
132 | d->serverGui->documentAdded( doc ); | 134 | d->serverGui->documentAdded( doc ); |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
136 | void DocumentList::start() | 138 | void DocumentList::start() |
137 | { | 139 | { |
138 | resume(); | 140 | resume(); |
139 | } | 141 | } |
140 | 142 | ||
141 | 143 | ||
142 | void DocumentList::pause() | 144 | void DocumentList::pause() |
143 | { | 145 | { |
144 | //qDebug("pause %i", d->tid); | 146 | //odebug << "pause " << d->tid << "" << oendl; |
145 | killTimer( d->tid ); | 147 | killTimer( d->tid ); |
146 | d->tid = 0; | 148 | d->tid = 0; |
147 | } | 149 | } |
148 | 150 | ||
149 | 151 | ||
150 | void DocumentList::resume() | 152 | void DocumentList::resume() |
151 | { | 153 | { |
152 | if ( d->tid == 0 ) { | 154 | if ( d->tid == 0 ) { |
153 | d->tid = startTimer( 20 ); | 155 | d->tid = startTimer( 20 ); |
154 | //qDebug("resumed %i", d->tid); | 156 | //odebug << "resumed " << d->tid << "" << oendl; |
155 | } | 157 | } |
156 | } | 158 | } |
157 | 159 | ||
158 | /* | 160 | /* |
159 | void DocumentList::resend() | 161 | void DocumentList::resend() |
160 | { | 162 | { |
161 | // Re-emits all the added items to the list (firstly letting everyone know to | 163 | // Re-emits all the added items to the list (firstly letting everyone know to |
162 | // clear what they have as it is being sent again) | 164 | // clear what they have as it is being sent again) |
163 | pause(); | 165 | pause(); |
164 | emit allRemoved(); | 166 | emit allRemoved(); |
165 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); | 167 | QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); |
166 | } | 168 | } |
167 | 169 | ||
168 | 170 | ||
169 | void DocumentList::resendWorker() | 171 | void DocumentList::resendWorker() |
170 | { | 172 | { |
171 | const QList<DocLnk> &list = d->dls.children(); | 173 | const QList<DocLnk> &list = d->dls.children(); |
172 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) | 174 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) |
173 | add( *(*it) ); | 175 | add( *(*it) ); |
174 | resume(); | 176 | resume(); |
175 | } | 177 | } |
176 | */ | 178 | */ |
177 | 179 | ||
178 | void DocumentList::rescan() | 180 | void DocumentList::rescan() |
179 | { | 181 | { |
180 | //qDebug("rescan"); | 182 | //odebug << "rescan" << oendl; |
181 | pause(); | 183 | pause(); |
182 | d->initialize(); | 184 | d->initialize(); |
183 | resume(); | 185 | resume(); |
184 | } | 186 | } |
185 | 187 | ||
186 | 188 | ||
187 | void DocumentList::timerEvent( QTimerEvent *te ) | 189 | void DocumentList::timerEvent( QTimerEvent *te ) |
188 | { | 190 | { |
189 | if ( te->timerId() == d->tid ) { | 191 | if ( te->timerId() == d->tid ) { |
190 | // Do 3 at a time | 192 | // Do 3 at a time |
191 | for (int i = 0; i < 3; i++ ) { | 193 | for (int i = 0; i < 3; i++ ) { |
192 | const DocLnk *lnk = d->iterate(); | 194 | const DocLnk *lnk = d->iterate(); |
193 | if ( lnk ) { | 195 | if ( lnk ) { |
194 | add( *lnk ); | 196 | add( *lnk ); |
195 | } else { | 197 | } else { |
196 | // stop when done | 198 | // stop when done |
197 | pause(); | 199 | pause(); |
198 | if ( d->serverGui ) | 200 | if ( d->serverGui ) |
199 | d->serverGui->documentScanningProgress( 100 ); | 201 | d->serverGui->documentScanningProgress( 100 ); |
200 | if ( d->needToSendAllDocLinks ) | 202 | if ( d->needToSendAllDocLinks ) |
201 | sendAllDocLinks(); | 203 | sendAllDocLinks(); |
202 | break; | 204 | break; |
203 | } | 205 | } |
204 | } | 206 | } |
205 | } | 207 | } |
206 | } | 208 | } |
207 | 209 | ||
208 | 210 | ||
209 | void DocumentList::reloadAppLnks() | 211 | void DocumentList::reloadAppLnks() |
210 | { | 212 | { |
211 | if ( d->sendAppLnks && d->serverGui ) { | 213 | if ( d->sendAppLnks && d->serverGui ) { |
212 | d->serverGui->applicationScanningProgress( 0 ); | 214 | d->serverGui->applicationScanningProgress( 0 ); |
213 | d->serverGui->allApplicationsRemoved(); | 215 | d->serverGui->allApplicationsRemoved(); |
214 | } | 216 | } |
215 | 217 | ||
216 | delete appLnkSet; | 218 | delete appLnkSet; |
217 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); | 219 | appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); |
218 | 220 | ||
219 | if ( d->sendAppLnks && d->serverGui ) { | 221 | if ( d->sendAppLnks && d->serverGui ) { |
220 | static QStringList prevTypeList; | 222 | static QStringList prevTypeList; |
221 | QStringList types = appLnkSet->types(); | 223 | QStringList types = appLnkSet->types(); |
222 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { | 224 | for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { |
223 | if ( !(*ittypes).isEmpty() ) { | 225 | if ( !(*ittypes).isEmpty() ) { |
224 | if ( !prevTypeList.contains(*ittypes) ) { | 226 | if ( !prevTypeList.contains(*ittypes) ) { |
225 | QString name = appLnkSet->typeName(*ittypes); | 227 | QString name = appLnkSet->typeName(*ittypes); |
226 | QPixmap pm = appLnkSet->typePixmap(*ittypes); | 228 | QPixmap pm = appLnkSet->typePixmap(*ittypes); |
227 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); | 229 | QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); |
228 | 230 | ||
229 | if (pm.isNull()) { | 231 | if (pm.isNull()) { |
230 | QImage img( Resource::loadImage( "UnknownDocument" ) ); | 232 | QImage img( Resource::loadImage( "UnknownDocument" ) ); |
231 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 233 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
232 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); | 234 | bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); |
233 | } | 235 | } |
234 | 236 | ||
235 | //qDebug("adding type %s", (*ittypes).latin1()); | 237 | //odebug << "adding type " << (*ittypes) << "" << oendl; |
236 | 238 | ||
237 | // ### our current launcher expects docs tab to be last | 239 | // ### our current launcher expects docs tab to be last |
238 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); | 240 | d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); |
239 | } | 241 | } |
240 | prevTypeList.remove(*ittypes); | 242 | prevTypeList.remove(*ittypes); |
241 | } | 243 | } |
242 | } | 244 | } |
243 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { | 245 | for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { |
244 | //qDebug("removing type %s", (*ittypes).latin1()); | 246 | //odebug << "removing type " << (*ittypes) << "" << oendl; |
245 | d->serverGui->typeRemoved(*ittypes); | 247 | d->serverGui->typeRemoved(*ittypes); |
246 | } | 248 | } |
247 | prevTypeList = types; | 249 | prevTypeList = types; |
248 | } | 250 | } |
249 | 251 | ||
250 | QListIterator<AppLnk> itapp( appLnkSet->children() ); | 252 | QListIterator<AppLnk> itapp( appLnkSet->children() ); |
251 | AppLnk* l; | 253 | AppLnk* l; |
252 | while ( (l=itapp.current()) ) { | 254 | while ( (l=itapp.current()) ) { |
253 | ++itapp; | 255 | ++itapp; |
254 | if ( d->sendAppLnks && d->serverGui ) | 256 | if ( d->sendAppLnks && d->serverGui ) |
255 | d->serverGui->applicationAdded( l->type(), *l ); | 257 | d->serverGui->applicationAdded( l->type(), *l ); |
256 | } | 258 | } |
257 | 259 | ||
258 | if ( d->sendAppLnks && d->serverGui ) | 260 | if ( d->sendAppLnks && d->serverGui ) |
259 | d->serverGui->applicationScanningProgress( 100 ); | 261 | d->serverGui->applicationScanningProgress( 100 ); |
260 | } | 262 | } |
261 | 263 | ||
262 | void DocumentList::reloadDocLnks() | 264 | void DocumentList::reloadDocLnks() |
263 | { | 265 | { |
264 | if ( !d->scanDocs ) | 266 | if ( !d->scanDocs ) |
265 | return; | 267 | return; |
266 | 268 | ||
267 | if ( d->sendDocLnks && d->serverGui ) { | 269 | if ( d->sendDocLnks && d->serverGui ) { |
268 | d->serverGui->documentScanningProgress( 0 ); | 270 | d->serverGui->documentScanningProgress( 0 ); |
269 | d->serverGui->allDocumentsRemoved(); | 271 | d->serverGui->allDocumentsRemoved(); |
270 | } | 272 | } |
271 | 273 | ||
272 | rescan(); | 274 | rescan(); |
273 | } | 275 | } |
274 | 276 | ||
275 | void DocumentList::linkChanged( QString arg ) | 277 | void DocumentList::linkChanged( QString arg ) |
276 | { | 278 | { |
277 | //qDebug( "linkchanged( %s )", arg.latin1() ); | 279 | //odebug << "linkchanged( " << arg << " )" << oendl; |
278 | 280 | ||
279 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { | 281 | if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) { |
280 | reloadAppLnks(); | 282 | reloadAppLnks(); |
281 | } else { | 283 | } else { |
282 | 284 | ||
283 | const QList<DocLnk> &list = d->dls.children(); | 285 | const QList<DocLnk> &list = d->dls.children(); |
284 | QListIterator<DocLnk> it( list ); | 286 | QListIterator<DocLnk> it( list ); |
285 | while ( it.current() ) { | 287 | while ( it.current() ) { |
286 | DocLnk *doc = it.current(); | 288 | DocLnk *doc = it.current(); |
287 | ++it; | 289 | ++it; |
288 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) | 290 | if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) |
289 | || ( doc->fileKnown() && doc->file() == arg ) ) { | 291 | || ( doc->fileKnown() && doc->file() == arg ) ) { |
290 | //qDebug( "found old link" ); | 292 | //odebug << "found old link" << oendl; |
291 | DocLnk* dl = new DocLnk( arg ); | 293 | DocLnk* dl = new DocLnk( arg ); |
292 | // add new one if it exists and matches the mimetype | 294 | // add new one if it exists and matches the mimetype |
293 | if ( d->store( dl ) ) { | 295 | if ( d->store( dl ) ) { |
294 | // Existing link has been changed, send old link ref and a ref | 296 | // Existing link has been changed, send old link ref and a ref |
295 | // to the new link | 297 | // to the new link |
296 | //qDebug( "change case" ); | 298 | //odebug << "change case" << oendl; |
297 | if ( d->serverGui ) | 299 | if ( d->serverGui ) |
298 | d->serverGui->documentChanged( *doc, *dl ); | 300 | d->serverGui->documentChanged( *doc, *dl ); |
299 | 301 | ||
300 | } else { | 302 | } else { |
301 | // Link has been removed or doesn't match the mimetypes any more | 303 | // Link has been removed or doesn't match the mimetypes any more |
302 | // so we aren't interested in it, so take it away from the list | 304 | // so we aren't interested in it, so take it away from the list |
303 | //qDebug( "removal case" ); | 305 | //odebug << "removal case" << oendl; |
304 | if ( d->serverGui ) | 306 | if ( d->serverGui ) |
305 | d->serverGui->documentRemoved( *doc ); | 307 | d->serverGui->documentRemoved( *doc ); |
306 | 308 | ||
307 | } | 309 | } |
308 | d->dls.remove( doc ); // remove old link from docLnkSet | 310 | d->dls.remove( doc ); // remove old link from docLnkSet |
309 | delete doc; | 311 | delete doc; |
310 | return; | 312 | return; |
311 | } | 313 | } |
312 | } | 314 | } |
313 | // Didn't find existing link, must be new | 315 | // Didn't find existing link, must be new |
314 | DocLnk* dl = new DocLnk( arg ); | 316 | DocLnk* dl = new DocLnk( arg ); |
315 | if ( d->store( dl ) ) { | 317 | if ( d->store( dl ) ) { |
316 | // Add if it's a link we are interested in | 318 | // Add if it's a link we are interested in |
317 | //qDebug( "add case" ); | 319 | //odebug << "add case" << oendl; |
318 | add( *dl ); | 320 | add( *dl ); |
319 | } | 321 | } |
320 | 322 | ||
321 | } | 323 | } |
322 | } | 324 | } |
323 | 325 | ||
324 | void DocumentList::restoreDone() | 326 | void DocumentList::restoreDone() |
325 | { | 327 | { |
326 | reloadAppLnks(); | 328 | reloadAppLnks(); |
327 | reloadDocLnks(); | 329 | reloadDocLnks(); |
328 | } | 330 | } |
329 | 331 | ||
330 | void DocumentList::storageChanged() | 332 | void DocumentList::storageChanged() |
331 | { | 333 | { |
332 | // ### can implement better | 334 | // ### can implement better |
333 | reloadAppLnks(); | 335 | reloadAppLnks(); |
334 | reloadDocLnks(); | 336 | reloadDocLnks(); |
335 | // ### Optimization opportunity | 337 | // ### Optimization opportunity |
336 | // Could be a bit more intelligent and somehow work out which | 338 | // Could be a bit more intelligent and somehow work out which |
337 | // mtab entry has changed and then only scan that and add and remove | 339 | // mtab entry has changed and then only scan that and add and remove |
338 | // links appropriately. | 340 | // links appropriately. |
339 | // rescan(); | 341 | // rescan(); |
340 | } | 342 | } |
341 | 343 | ||
342 | void DocumentList::sendAllDocLinks() | 344 | void DocumentList::sendAllDocLinks() |
343 | { | 345 | { |
344 | if ( d->tid != 0 ) { | 346 | if ( d->tid != 0 ) { |
345 | // We are in the middle of scanning, set a flag so | 347 | // We are in the middle of scanning, set a flag so |
346 | // we do this when we finish our scanning | 348 | // we do this when we finish our scanning |
347 | d->needToSendAllDocLinks = true; | 349 | d->needToSendAllDocLinks = true; |
348 | return; | 350 | return; |
349 | } | 351 | } |
350 | 352 | ||
351 | QString contents; | 353 | QString contents; |
352 | Categories cats; | 354 | Categories cats; |
353 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { | 355 | for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { |
354 | DocLnk *doc = it.current(); | 356 | DocLnk *doc = it.current(); |
355 | QFileInfo fi( doc->file() ); | 357 | QFileInfo fi( doc->file() ); |
356 | if ( !fi.exists() ) | 358 | if ( !fi.exists() ) |
357 | continue; | 359 | continue; |
358 | 360 | ||
359 | bool fake = !doc->linkFileKnown(); | 361 | bool fake = !doc->linkFileKnown(); |
360 | if ( !fake ) { | 362 | if ( !fake ) { |
361 | QFile f( doc->linkFile() ); | 363 | QFile f( doc->linkFile() ); |
362 | if ( f.open( IO_ReadOnly ) ) { | 364 | if ( f.open( IO_ReadOnly ) ) { |
363 | QTextStream ts( &f ); | 365 | QTextStream ts( &f ); |
364 | ts.setEncoding( QTextStream::UnicodeUTF8 ); | 366 | ts.setEncoding( QTextStream::UnicodeUTF8 ); |
365 | contents += ts.read(); | 367 | contents += ts.read(); |
366 | f.close(); | 368 | f.close(); |
367 | } else | 369 | } else |
368 | fake = TRUE; | 370 | fake = TRUE; |
369 | } | 371 | } |
370 | if (fake) { | 372 | if (fake) { |
371 | contents += "[Desktop Entry]\n"; // No tr | 373 | contents += "[Desktop Entry]\n"; // No tr |
372 | contents += "Categories = " + // No tr | 374 | contents += "Categories = " + // No tr |
373 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr | 375 | cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr |
374 | contents += "Name = "+doc->name()+"\n"; // No tr | 376 | contents += "Name = "+doc->name()+"\n"; // No tr |
375 | contents += "Type = "+doc->type()+"\n"; // No tr | 377 | contents += "Type = "+doc->type()+"\n"; // No tr |
376 | } | 378 | } |
377 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) | 379 | contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) |
378 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr | 380 | contents += QString("Size = %1\n").arg( fi.size() ); // No tr |
379 | } | 381 | } |
380 | 382 | ||
381 | //qDebug( "sending length %d", contents.length() ); | 383 | //odebug << "sending length " << contents.length() << "" << oendl; |
382 | #ifndef QT_NO_COP | 384 | #ifndef QT_NO_COP |
383 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); | 385 | QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); |
384 | e << contents; | 386 | e << contents; |
385 | #endif | 387 | #endif |
386 | //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); | 388 | //odebug << "================ \n\n" << contents << "\n\n===============" << oendl; |
387 | 389 | ||
388 | d->needToSendAllDocLinks = false; | 390 | d->needToSendAllDocLinks = false; |
389 | } | 391 | } |
390 | 392 | ||
391 | 393 | ||
392 | 394 | ||
393 | 395 | ||
394 | 396 | ||
395 | 397 | ||
396 | 398 | ||
397 | 399 | ||
398 | 400 | ||
399 | 401 | ||
400 | 402 | ||
401 | 403 | ||
402 | 404 | ||
403 | 405 | ||
404 | 406 | ||
405 | 407 | ||
406 | 408 | ||
407 | 409 | ||
408 | 410 | ||
409 | 411 | ||
410 | 412 | ||
411 | 413 | ||
412 | 414 | ||
413 | 415 | ||
414 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) | 416 | DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) |
415 | { | 417 | { |
416 | storage = new StorageInfo( this ); | 418 | storage = new StorageInfo( this ); |
417 | serverGui = gui; | 419 | serverGui = gui; |
418 | if ( serverGui ) { | 420 | if ( serverGui ) { |
419 | sendAppLnks = serverGui->requiresApplications(); | 421 | sendAppLnks = serverGui->requiresApplications(); |
420 | sendDocLnks = serverGui->requiresDocuments(); | 422 | sendDocLnks = serverGui->requiresDocuments(); |
421 | } else { | 423 | } else { |
422 | sendAppLnks = false; | 424 | sendAppLnks = false; |
423 | sendDocLnks = false; | 425 | sendDocLnks = false; |
424 | } | 426 | } |
425 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { | 427 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { |
426 | listDirs[i] = 0; | 428 | listDirs[i] = 0; |
427 | lists[i] = 0; | 429 | lists[i] = 0; |
428 | listPositions[i] = 0; | 430 | listPositions[i] = 0; |
429 | } | 431 | } |
430 | initialize(); | 432 | initialize(); |
431 | tid = 0; | 433 | tid = 0; |
432 | } | 434 | } |
433 | 435 | ||
434 | void DocumentListPrivate::appendDocpath(FileSystem*fs) | 436 | void DocumentListPrivate::appendDocpath(FileSystem*fs) |
435 | { | 437 | { |
436 | QDir defPath(fs->path()+"/Documents"); | 438 | QDir defPath(fs->path()+"/Documents"); |
437 | QFileInfo f(fs->path()+"/.opiestorage.cf"); | 439 | QFileInfo f(fs->path()+"/.opiestorage.cf"); |
438 | if (!f.exists()) { | 440 | if (!f.exists()) { |
439 | Mediadlg dlg(fs); | 441 | Mediadlg dlg(fs); |
440 | if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) { | 442 | if (QDialog::Accepted != QPEApplication::execDialog( &dlg )) { |
441 | return; | 443 | return; |
442 | } | 444 | } |
443 | } | 445 | } |
444 | Config conf(f.filePath(), Config::File ); | 446 | Config conf(f.filePath(), Config::File ); |
445 | conf.setGroup("main"); | 447 | conf.setGroup("main"); |
446 | if (!conf.readBoolEntry("check",false)) { | 448 | if (!conf.readBoolEntry("check",false)) { |
447 | return; | 449 | return; |
448 | } | 450 | } |
449 | conf.setGroup("subdirs"); | 451 | conf.setGroup("subdirs"); |
450 | bool read_all = conf.readBoolEntry("wholemedia",true); | 452 | bool read_all = conf.readBoolEntry("wholemedia",true); |
451 | if (read_all) { | 453 | if (read_all) { |
452 | docPaths+=fs->path(); | 454 | docPaths+=fs->path(); |
453 | return; | 455 | return; |
454 | } | 456 | } |
455 | QStringList subDirs = conf.readListEntry("subdirs",':'); | 457 | QStringList subDirs = conf.readListEntry("subdirs",':'); |
456 | if (subDirs.isEmpty()) { | 458 | if (subDirs.isEmpty()) { |
457 | if (defPath.exists()) { | 459 | if (defPath.exists()) { |
458 | docPaths+=defPath.path(); | 460 | docPaths+=defPath.path(); |
459 | } | 461 | } |
460 | return; | 462 | return; |
461 | } | 463 | } |
462 | for (unsigned c = 0; c < subDirs.count();++c) { | 464 | for (unsigned c = 0; c < subDirs.count();++c) { |
463 | QDir docDir(QString(fs->path()+"/"+subDirs[c])); | 465 | QDir docDir(QString(fs->path()+"/"+subDirs[c])); |
464 | if (docDir.exists()) { | 466 | if (docDir.exists()) { |
465 | docPaths+=docDir.path(); | 467 | docPaths+=docDir.path(); |
466 | } | 468 | } |
467 | } | 469 | } |
468 | } | 470 | } |
469 | 471 | ||
470 | void DocumentListPrivate::initialize() | 472 | void DocumentListPrivate::initialize() |
471 | { | 473 | { |
472 | // Reset | 474 | // Reset |
473 | dls.clear(); | 475 | dls.clear(); |
474 | docPaths.clear(); | 476 | docPaths.clear(); |
475 | reference.clear(); | 477 | reference.clear(); |
476 | 478 | ||
477 | QDir docDir( QPEApplication::documentDir() ); | 479 | QDir docDir( QPEApplication::documentDir() ); |
478 | if ( docDir.exists() ) | 480 | if ( docDir.exists() ) |
479 | docPaths += QPEApplication::documentDir(); | 481 | docPaths += QPEApplication::documentDir(); |
480 | int i = 1; | 482 | int i = 1; |
481 | const QList<FileSystem> &fs = storage->fileSystems(); | 483 | const QList<FileSystem> &fs = storage->fileSystems(); |
482 | QListIterator<FileSystem> it( fs ); | 484 | QListIterator<FileSystem> it( fs ); |
483 | for ( ; it.current(); ++it ) { | 485 | for ( ; it.current(); ++it ) { |
484 | if ( (*it)->isRemovable() ) { | 486 | if ( (*it)->isRemovable() ) { |
485 | appendDocpath((*it)); | 487 | appendDocpath((*it)); |
486 | ++i; | 488 | ++i; |
487 | } | 489 | } |
488 | } | 490 | } |
489 | 491 | ||
490 | for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { | 492 | for ( int i = 0; i < MAX_SEARCH_DEPTH; ++i ) { |
491 | if ( listDirs[i] ) { | 493 | if ( listDirs[i] ) { |
492 | delete listDirs[i]; | 494 | delete listDirs[i]; |
493 | listDirs[i] = 0; | 495 | listDirs[i] = 0; |
494 | } | 496 | } |
495 | lists[i] = 0; | 497 | lists[i] = 0; |
496 | listPositions[i] = 0; | 498 | listPositions[i] = 0; |
497 | } | 499 | } |
498 | 500 | ||
499 | docPathsSearched = 0; | 501 | docPathsSearched = 0; |
500 | searchDepth = -1; | 502 | searchDepth = -1; |
501 | state = Find; | 503 | state = Find; |
502 | dit = 0; | 504 | dit = 0; |
503 | } | 505 | } |
504 | 506 | ||
505 | 507 | ||
506 | DocumentListPrivate::~DocumentListPrivate() | 508 | DocumentListPrivate::~DocumentListPrivate() |
507 | { | 509 | { |
508 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) | 510 | for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) |
509 | if ( listDirs[i] ) | 511 | if ( listDirs[i] ) |
510 | delete listDirs[i]; | 512 | delete listDirs[i]; |
511 | delete dit; | 513 | delete dit; |
512 | } | 514 | } |
513 | 515 | ||
514 | 516 | ||
515 | void DocumentListPrivate::estimatedPercentScanned() | 517 | void DocumentListPrivate::estimatedPercentScanned() |
516 | { | 518 | { |
517 | double overallProgress = 0.0; | 519 | double overallProgress = 0.0; |
518 | double levelWeight = 75.0; | 520 | double levelWeight = 75.0; |
519 | 521 | ||
520 | int topCount = docPaths.count(); | 522 | int topCount = docPaths.count(); |
521 | if ( topCount > 1 ) { | 523 | if ( topCount > 1 ) { |
522 | levelWeight = levelWeight / topCount; | 524 | levelWeight = levelWeight / topCount; |
523 | overallProgress += (docPathsSearched - 1) * levelWeight; | 525 | overallProgress += (docPathsSearched - 1) * levelWeight; |
524 | } | 526 | } |
525 | 527 | ||
526 | for ( int d = 0; d <= searchDepth; d++ ) { | 528 | for ( int d = 0; d <= searchDepth; d++ ) { |
527 | if ( listDirs[d] ) { | 529 | if ( listDirs[d] ) { |
528 | int items = lists[d]->count(); | 530 | int items = lists[d]->count(); |
529 | if ( items > 1 ) { | 531 | if ( items > 1 ) { |
530 | levelWeight = levelWeight / items; | 532 | levelWeight = levelWeight / items; |
531 | // Take in to account "." and ".." | 533 | // Take in to account "." and ".." |
532 | overallProgress += (listPositions[d] - 3) * levelWeight; | 534 | overallProgress += (listPositions[d] - 3) * levelWeight; |
533 | } | 535 | } |
534 | } else { | 536 | } else { |
535 | break; | 537 | break; |
536 | } | 538 | } |
537 | } | 539 | } |
538 | 540 | ||
539 | // qDebug( "overallProgress: %f", overallProgress ); | 541 | // odebug << "overallProgress: " << overallProgress << "" << oendl; |
540 | 542 | ||
541 | if ( serverGui ) | 543 | if ( serverGui ) |
542 | serverGui->documentScanningProgress( (int)overallProgress ); | 544 | serverGui->documentScanningProgress( (int)overallProgress ); |
543 | } | 545 | } |
544 | 546 | ||
545 | 547 | ||
546 | const QString DocumentListPrivate::nextFile() | 548 | const QString DocumentListPrivate::nextFile() |
547 | { | 549 | { |
548 | while ( TRUE ) { | 550 | while ( TRUE ) { |
549 | while ( searchDepth < 0 ) { | 551 | while ( searchDepth < 0 ) { |
550 | // go to next base path | 552 | // go to next base path |
551 | if ( docPathsSearched >= docPaths.count() ) { | 553 | if ( docPathsSearched >= docPaths.count() ) { |
552 | // end of base paths | 554 | // end of base paths |
553 | return QString::null; | 555 | return QString::null; |
554 | } else { | 556 | } else { |
555 | QDir dir( docPaths[docPathsSearched] ); | 557 | QDir dir( docPaths[docPathsSearched] ); |
556 | // qDebug("now using base path: %s", docPaths[docPathsSearched].latin1() ); | 558 | // odebug << "now using base path: " << docPaths[docPathsSearched] << "" << oendl; |
557 | docPathsSearched++; | 559 | docPathsSearched++; |
558 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 560 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
559 | listDirs[0] = new QDir( dir ); | 561 | listDirs[0] = new QDir( dir ); |
560 | lists[0] = listDirs[0]->entryInfoList(); | 562 | lists[0] = listDirs[0]->entryInfoList(); |
561 | listPositions[0] = 0; | 563 | listPositions[0] = 0; |
562 | searchDepth = 0; | 564 | searchDepth = 0; |
563 | } | 565 | } |
564 | } | 566 | } |
565 | } | 567 | } |
566 | 568 | ||
567 | const QFileInfoList *fil = lists[searchDepth]; | 569 | const QFileInfoList *fil = lists[searchDepth]; |
568 | if (!fil) { | 570 | if (!fil) { |
569 | return QString::null; | 571 | return QString::null; |
570 | } | 572 | } |
571 | QFileInfoList *fl = (QFileInfoList *)fil; | 573 | QFileInfoList *fl = (QFileInfoList *)fil; |
572 | unsigned int pos = listPositions[searchDepth]; | 574 | unsigned int pos = listPositions[searchDepth]; |
573 | 575 | ||
574 | if ( pos >= fl->count() ) { | 576 | if ( pos >= fl->count() ) { |
575 | // go up a depth | 577 | // go up a depth |
576 | delete listDirs[searchDepth]; | 578 | delete listDirs[searchDepth]; |
577 | listDirs[searchDepth] = 0; | 579 | listDirs[searchDepth] = 0; |
578 | lists[searchDepth] = 0; | 580 | lists[searchDepth] = 0; |
579 | listPositions[searchDepth] = 0; | 581 | listPositions[searchDepth] = 0; |
580 | searchDepth--; | 582 | searchDepth--; |
581 | } else { | 583 | } else { |
582 | const QFileInfo *fi = fl->at(pos); | 584 | const QFileInfo *fi = fl->at(pos); |
583 | listPositions[searchDepth]++; | 585 | listPositions[searchDepth]++; |
584 | QString bn = fi->fileName(); | 586 | QString bn = fi->fileName(); |
585 | if ( bn[0] != '.' ) { | 587 | if ( bn[0] != '.' ) { |
586 | if ( fi->isDir() ) { | 588 | if ( fi->isDir() ) { |
587 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { | 589 | if ( bn != "CVS" && bn != "Qtopia" && bn != "QtPalmtop" ) { |
588 | // go down a depth | 590 | // go down a depth |
589 | QDir dir( fi->filePath() ); | 591 | QDir dir( fi->filePath() ); |
590 | // qDebug("now going in to path: %s", bn.latin1() ); | 592 | // odebug << "now going in to path: " << bn << "" << oendl; |
591 | if ( !dir.exists( ".Qtopia-ignore" ) ) { | 593 | if ( !dir.exists( ".Qtopia-ignore" ) ) { |
592 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { | 594 | if ( searchDepth < MAX_SEARCH_DEPTH - 1) { |
593 | searchDepth++; | 595 | searchDepth++; |
594 | listDirs[searchDepth] = new QDir( dir ); | 596 | listDirs[searchDepth] = new QDir( dir ); |
595 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); | 597 | lists[searchDepth] = listDirs[searchDepth]->entryInfoList(); |
596 | listPositions[searchDepth] = 0; | 598 | listPositions[searchDepth] = 0; |
597 | } | 599 | } |
598 | } | 600 | } |
599 | } | 601 | } |
600 | } else { | 602 | } else { |
601 | estimatedPercentScanned(); | 603 | estimatedPercentScanned(); |
602 | return fl->at(pos)->filePath(); | 604 | return fl->at(pos)->filePath(); |
603 | } | 605 | } |
604 | } | 606 | } |
605 | } | 607 | } |
606 | } | 608 | } |
607 | 609 | ||
608 | return QString::null; | 610 | return QString::null; |
609 | } | 611 | } |
610 | 612 | ||
611 | 613 | ||
612 | bool DocumentListPrivate::store( DocLnk* dl ) | 614 | bool DocumentListPrivate::store( DocLnk* dl ) |
613 | { | 615 | { |
614 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { | 616 | // if ( dl->fileKnown() && !dl->file().isEmpty() ) { |
615 | if ( dl && dl->fileKnown() ) { | 617 | if ( dl && dl->fileKnown() ) { |
616 | dls.add( dl ); // store | 618 | dls.add( dl ); // store |
617 | return TRUE; | 619 | return TRUE; |
618 | } | 620 | } |
619 | 621 | ||
620 | // don't store - delete | 622 | // don't store - delete |
621 | delete dl; | 623 | delete dl; |
622 | return FALSE; | 624 | return FALSE; |
623 | } | 625 | } |
624 | 626 | ||
625 | 627 | ||
626 | #define MAGIC_NUMBER((void*)2) | 628 | #define MAGIC_NUMBER((void*)2) |
627 | 629 | ||
628 | const DocLnk *DocumentListPrivate::iterate() | 630 | const DocLnk *DocumentListPrivate::iterate() |
629 | { | 631 | { |
630 | if ( state == Find ) { | 632 | if ( state == Find ) { |
631 | //qDebug("state Find"); | 633 | //odebug << "state Find" << oendl; |
632 | QString file = nextFile(); | 634 | QString file = nextFile(); |
633 | while ( !file.isNull() ) { | 635 | while ( !file.isNull() ) { |
634 | if ( file.right(8) == ".desktop" ) { // No tr | 636 | if ( file.right(8) == ".desktop" ) { // No tr |
635 | DocLnk* dl = new DocLnk( file ); | 637 | DocLnk* dl = new DocLnk( file ); |
636 | if ( store(dl) ) | 638 | if ( store(dl) ) |
637 | return dl; | 639 | return dl; |
638 | } else { | 640 | } else { |
639 | reference.insert( file, MAGIC_NUMBER ); | 641 | reference.insert( file, MAGIC_NUMBER ); |
640 | } | 642 | } |
641 | file = nextFile(); | 643 | file = nextFile(); |
642 | } | 644 | } |
643 | state = RemoveKnownFiles; | 645 | state = RemoveKnownFiles; |
644 | 646 | ||
645 | if ( serverGui ) | 647 | if ( serverGui ) |
646 | serverGui->documentScanningProgress( 75 ); | 648 | serverGui->documentScanningProgress( 75 ); |
647 | } | 649 | } |
648 | 650 | ||
649 | static int iterationI; | 651 | static int iterationI; |
650 | static int iterationCount; | 652 | static int iterationCount; |
651 | 653 | ||
652 | if ( state == RemoveKnownFiles ) { | 654 | if ( state == RemoveKnownFiles ) { |
653 | //qDebug("state RemoveKnownFiles"); | 655 | //odebug << "state RemoveKnownFiles" << oendl; |
654 | const QList<DocLnk> &list = dls.children(); | 656 | const QList<DocLnk> &list = dls.children(); |
655 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { | 657 | for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) { |
656 | reference.remove( (*it)->file() ); | 658 | reference.remove( (*it)->file() ); |
657 | // ### does this need to be deleted? | 659 | // ### does this need to be deleted? |
658 | } | 660 | } |
659 | dit = new QDictIterator<void>(reference); | 661 | dit = new QDictIterator<void>(reference); |
660 | state = MakeUnknownFiles; | 662 | state = MakeUnknownFiles; |
661 | 663 | ||
662 | iterationI = 0; | 664 | iterationI = 0; |
663 | iterationCount = dit->count(); | 665 | iterationCount = dit->count(); |
664 | } | 666 | } |
665 | 667 | ||
666 | if ( state == MakeUnknownFiles ) { | 668 | if ( state == MakeUnknownFiles ) { |
667 | //qDebug("state MakeUnknownFiles"); | 669 | //odebug << "state MakeUnknownFiles" << oendl; |
668 | for (void* c; (c=dit->current()); ++(*dit) ) { | 670 | for (void* c; (c=dit->current()); ++(*dit) ) { |
669 | if ( c == MAGIC_NUMBER ) { | 671 | if ( c == MAGIC_NUMBER ) { |
670 | DocLnk* dl = new DocLnk; | 672 | DocLnk* dl = new DocLnk; |
671 | QFileInfo fi( dit->currentKey() ); | 673 | QFileInfo fi( dit->currentKey() ); |
672 | dl->setFile( fi.filePath() ); | 674 | dl->setFile( fi.filePath() ); |
673 | dl->setName( fi.baseName() ); | 675 | dl->setName( fi.baseName() ); |
674 | if ( store(dl) ) { | 676 | if ( store(dl) ) { |
675 | ++*dit; | 677 | ++*dit; |
676 | iterationI++; | 678 | iterationI++; |
677 | if ( serverGui ) | 679 | if ( serverGui ) |
678 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); | 680 | serverGui->documentScanningProgress( 75 + (25*iterationI)/iterationCount ); |
679 | return dl; | 681 | return dl; |
680 | } | 682 | } |
681 | } | 683 | } |
682 | iterationI++; | 684 | iterationI++; |
683 | } | 685 | } |
684 | 686 | ||
685 | delete dit; | 687 | delete dit; |
686 | dit = 0; | 688 | dit = 0; |
687 | state = Done; | 689 | state = Done; |
688 | } | 690 | } |
689 | 691 | ||
690 | //qDebug("state Done"); | 692 | //odebug << "state Done" << oendl; |
691 | return NULL; | 693 | return NULL; |
692 | } | 694 | } |
693 | 695 | ||
694 | 696 | ||
695 | #include "documentlist.moc" | 697 | #include "documentlist.moc" |
696 | 698 | ||
697 | 699 | ||
698 | 700 | ||
diff --git a/core/launcher/firstuse.cpp b/core/launcher/firstuse.cpp index 4316648..e9e2d83 100644 --- a/core/launcher/firstuse.cpp +++ b/core/launcher/firstuse.cpp | |||
@@ -1,513 +1,515 @@ | |||
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 | // I need access to some things you don't normally get access to. | 21 | // I need access to some things you don't normally get access to. |
22 | 22 | ||
23 | #ifndef _MSC_VER | 23 | #ifndef _MSC_VER |
24 | //### revise to allow removal of translators under MSVC | 24 | //### revise to allow removal of translators under MSVC |
25 | #define private public | 25 | #define private public |
26 | #define protected public | 26 | #define protected public |
27 | #endif | 27 | #endif |
28 | #include "firstuse.h" | 28 | #include "firstuse.h" |
29 | #include "inputmethods.h" | 29 | #include "inputmethods.h" |
30 | #include "applauncher.h" | 30 | #include "applauncher.h" |
31 | #include "serverapp.h" | 31 | #include "serverapp.h" |
32 | //#include <qtopia/custom.h> | ||
33 | |||
34 | #include "calibrate.h" | 32 | #include "calibrate.h" |
35 | #include "documentlist.h" | 33 | #include "documentlist.h" |
36 | 34 | ||
35 | /* OPIE */ | ||
36 | #include <opie2/odebug.h> | ||
37 | #include <qtopia/resource.h> | 37 | #include <qtopia/resource.h> |
38 | #include <qtopia/qcopenvelope_qws.h> | 38 | #include <qtopia/qcopenvelope_qws.h> |
39 | #include <qtopia/config.h> | 39 | #include <qtopia/config.h> |
40 | #include <qtopia/fontmanager.h> | 40 | #include <qtopia/fontmanager.h> |
41 | using namespace Opie::Core; | ||
41 | 42 | ||
43 | /* QT */ | ||
42 | #include <qfile.h> | 44 | #include <qfile.h> |
43 | #include <qpainter.h> | 45 | #include <qpainter.h> |
44 | #include <qsimplerichtext.h> | 46 | #include <qsimplerichtext.h> |
45 | #include <qpushbutton.h> | 47 | #include <qpushbutton.h> |
46 | #include <qlabel.h> | 48 | #include <qlabel.h> |
47 | #include <qtimer.h> | 49 | #include <qtimer.h> |
48 | 50 | ||
49 | #if defined( Q_WS_QWS ) | 51 | #if defined( Q_WS_QWS ) |
50 | #include <qwsdisplay_qws.h> | 52 | #include <qwsdisplay_qws.h> |
51 | #include <qgfx_qws.h> | 53 | #include <qgfx_qws.h> |
52 | #endif | 54 | #endif |
53 | 55 | ||
54 | 56 | /* STD */ | |
55 | #include <stdlib.h> | 57 | #include <stdlib.h> |
56 | #include <sys/types.h> | 58 | #include <sys/types.h> |
57 | #if defined(Q_OS_LINUX) || defined(_OS_LINUX_) | 59 | #if defined(Q_OS_LINUX) || defined(_OS_LINUX_) |
58 | #include <unistd.h> | 60 | #include <unistd.h> |
59 | #endif | 61 | #endif |
60 | 62 | ||
61 | 63 | ||
62 | struct { | 64 | struct { |
63 | bool enabled; | 65 | bool enabled; |
64 | const char *app; | 66 | const char *app; |
65 | const char *start; | 67 | const char *start; |
66 | const char *stop; | 68 | const char *stop; |
67 | const char *desc; | 69 | const char *desc; |
68 | } | 70 | } |
69 | settingsTable [] = | 71 | settingsTable [] = |
70 | { | 72 | { |
71 | { FALSE, "language", "raise()", "accept()", // No tr | 73 | { FALSE, "language", "raise()", "accept()", // No tr |
72 | QT_TR_NOOP("Language") }, | 74 | QT_TR_NOOP("Language") }, |
73 | { FALSE, "doctab", "raise()", "accept()", // No tr | 75 | { FALSE, "doctab", "raise()", "accept()", // No tr |
74 | QT_TR_NOOP("DocTab") }, | 76 | QT_TR_NOOP("DocTab") }, |
75 | #ifndef Q_OS_WIN32 | 77 | #ifndef Q_OS_WIN32 |
76 | { FALSE, "systemtime", "raise()", "accept()", // No tr | 78 | { FALSE, "systemtime", "raise()", "accept()", // No tr |
77 | QT_TR_NOOP("Time and Date") }, | 79 | QT_TR_NOOP("Time and Date") }, |
78 | #endif | 80 | #endif |
79 | { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr | 81 | { FALSE, "addressbook", "editPersonalAndClose()", "accept()", // No tr |
80 | QT_TR_NOOP("Personal Information") }, | 82 | QT_TR_NOOP("Personal Information") }, |
81 | { FALSE, 0, 0, 0, 0 } | 83 | { FALSE, 0, 0, 0, 0 } |
82 | }; | 84 | }; |
83 | 85 | ||
84 | 86 | ||
85 | FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) : | 87 | FirstUse::FirstUse(QWidget* parent, const char * name, WFlags wf) : |
86 | QDialog( parent, name, TRUE, wf), | 88 | QDialog( parent, name, TRUE, wf), |
87 | transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1), | 89 | transApp(0), transLib(0), needCalibrate(FALSE), currApp(-1), |
88 | waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE) | 90 | waitForExit(-1), waitingForLaunch(FALSE), needRestart(FALSE) |
89 | { | 91 | { |
90 | ServerApplication::allowRestart = FALSE; | 92 | ServerApplication::allowRestart = FALSE; |
91 | // we force our height beyound the maximum (which we set anyway) | 93 | // we force our height beyound the maximum (which we set anyway) |
92 | QRect desk = qApp->desktop()->geometry(); | 94 | QRect desk = qApp->desktop()->geometry(); |
93 | setGeometry( 0, 0, desk.width(), desk.height() ); | 95 | setGeometry( 0, 0, desk.width(), desk.height() ); |
94 | 96 | ||
95 | connect(qwsServer, SIGNAL(newChannel(const QString&)), | 97 | connect(qwsServer, SIGNAL(newChannel(const QString&)), |
96 | this, SLOT(newQcopChannel(const QString&))); | 98 | this, SLOT(newQcopChannel(const QString&))); |
97 | 99 | ||
98 | // Create a DocumentList so appLauncher has appLnkSet to search | 100 | // Create a DocumentList so appLauncher has appLnkSet to search |
99 | docList = new DocumentList( 0, FALSE ); | 101 | docList = new DocumentList( 0, FALSE ); |
100 | appLauncher = new AppLauncher( this ); | 102 | appLauncher = new AppLauncher( this ); |
101 | connect( appLauncher, SIGNAL(terminated(int,const QString&)), | 103 | connect( appLauncher, SIGNAL(terminated(int,const QString&)), |
102 | this, SLOT(terminated(int,const QString&)) ); | 104 | this, SLOT(terminated(int,const QString&)) ); |
103 | 105 | ||
104 | // more hackery | 106 | // more hackery |
105 | // I will be run as either the main server or as part of the main server | 107 | // I will be run as either the main server or as part of the main server |
106 | QWSServer::setScreenSaverIntervals(0); | 108 | QWSServer::setScreenSaverIntervals(0); |
107 | loadPixmaps(); | 109 | loadPixmaps(); |
108 | 110 | ||
109 | //check if there is a language program | 111 | //check if there is a language program |
110 | #ifndef Q_OS_WIN32 | 112 | #ifndef Q_OS_WIN32 |
111 | QString exeSuffix; | 113 | QString exeSuffix; |
112 | #else | 114 | #else |
113 | QString exeSuffix(".exe"); | 115 | QString exeSuffix(".exe"); |
114 | #endif | 116 | #endif |
115 | 117 | ||
116 | for ( int i = 0; settingsTable[i].app; i++ ) { | 118 | for ( int i = 0; settingsTable[i].app; i++ ) { |
117 | QString file = QPEApplication::qpeDir() + "bin/"; | 119 | QString file = QPEApplication::qpeDir() + "bin/"; |
118 | file += settingsTable[i].app; | 120 | file += settingsTable[i].app; |
119 | file += exeSuffix; | 121 | file += exeSuffix; |
120 | if ( QFile::exists(file) ) | 122 | if ( QFile::exists(file) ) |
121 | settingsTable[i].enabled = TRUE; | 123 | settingsTable[i].enabled = TRUE; |
122 | } | 124 | } |
123 | 125 | ||
124 | setFocusPolicy(NoFocus); | 126 | setFocusPolicy(NoFocus); |
125 | 127 | ||
126 | taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader); | 128 | taskBar = new QWidget(0, 0, WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop | WGroupLeader); |
127 | 129 | ||
128 | inputMethods = new InputMethods(taskBar); | 130 | inputMethods = new InputMethods(taskBar); |
129 | connect(inputMethods, SIGNAL(inputToggled(bool)), | 131 | connect(inputMethods, SIGNAL(inputToggled(bool)), |
130 | this, SLOT(calcMaxWindowRect())); | 132 | this, SLOT(calcMaxWindowRect())); |
131 | 133 | ||
132 | back = new QPushButton(tr("<< Back"), taskBar); | 134 | back = new QPushButton(tr("<< Back"), taskBar); |
133 | back->setFocusPolicy(NoFocus); | 135 | back->setFocusPolicy(NoFocus); |
134 | connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) ); | 136 | connect(back, SIGNAL(clicked()), this, SLOT(previousDialog()) ); |
135 | 137 | ||
136 | next = new QPushButton(tr("Next >>"), taskBar); | 138 | next = new QPushButton(tr("Next >>"), taskBar); |
137 | next->setFocusPolicy(NoFocus); | 139 | next->setFocusPolicy(NoFocus); |
138 | connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) ); | 140 | connect(next, SIGNAL(clicked()), this, SLOT(nextDialog()) ); |
139 | 141 | ||
140 | // need to set the geom to lower corner | 142 | // need to set the geom to lower corner |
141 | QSize sz = inputMethods->sizeHint(); | 143 | QSize sz = inputMethods->sizeHint(); |
142 | int buttonWidth = (width() - sz.width()) / 2; | 144 | int buttonWidth = (width() - sz.width()) / 2; |
143 | int x = 0; | 145 | int x = 0; |
144 | 146 | ||
145 | controlHeight = back->sizeHint().height(); | 147 | controlHeight = back->sizeHint().height(); |
146 | 148 | ||
147 | inputMethods->setGeometry(0,0, sz.width(), controlHeight ); | 149 | inputMethods->setGeometry(0,0, sz.width(), controlHeight ); |
148 | x += sz.width(); | 150 | x += sz.width(); |
149 | 151 | ||
150 | back->setGeometry(x, 0, buttonWidth, controlHeight); | 152 | back->setGeometry(x, 0, buttonWidth, controlHeight); |
151 | x += buttonWidth; | 153 | x += buttonWidth; |
152 | next->setGeometry(x, 0, buttonWidth, controlHeight); | 154 | next->setGeometry(x, 0, buttonWidth, controlHeight); |
153 | 155 | ||
154 | taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight); | 156 | taskBar->setGeometry( 0, height() - controlHeight, desk.width(), controlHeight); |
155 | taskBar->hide(); | 157 | taskBar->hide(); |
156 | 158 | ||
157 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 159 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
158 | qDebug("Setting up QCop to QPE/System"); | 160 | odebug << "Setting up QCop to QPE/System" << oendl; |
159 | QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); | 161 | QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); |
160 | connect(sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 162 | connect(sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
161 | this, SLOT(message(const QCString&,const QByteArray&)) ); | 163 | this, SLOT(message(const QCString&,const QByteArray&)) ); |
162 | #endif | 164 | #endif |
163 | calcMaxWindowRect(); | 165 | calcMaxWindowRect(); |
164 | 166 | ||
165 | m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false; | 167 | m_calHandler = ( QWSServer::mouseHandler() && QWSServer::mouseHandler()->inherits("QCalibratedMouseHandler") ) ? true : false; |
166 | 168 | ||
167 | if ( m_calHandler) { | 169 | if ( m_calHandler) { |
168 | if ( !QFile::exists("/etc/pointercal") ) { | 170 | if ( !QFile::exists("/etc/pointercal") ) { |
169 | needCalibrate = TRUE; | 171 | needCalibrate = TRUE; |
170 | grabMouse(); | 172 | grabMouse(); |
171 | } | 173 | } |
172 | } | 174 | } |
173 | 175 | ||
174 | Config config("locale"); | 176 | Config config("locale"); |
175 | config.setGroup( "Language"); | 177 | config.setGroup( "Language"); |
176 | lang = config.readEntry( "Language", "en"); | 178 | lang = config.readEntry( "Language", "en"); |
177 | 179 | ||
178 | defaultFont = font(); | 180 | defaultFont = font(); |
179 | 181 | ||
180 | //###language/font hack; should look it up somewhere | 182 | //###language/font hack; should look it up somewhere |
181 | #ifdef Q_WS_QWS | 183 | #ifdef Q_WS_QWS |
182 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { | 184 | if ( lang == "ja" || lang == "zh_CN" || lang == "zh_TW" || lang == "ko" ) { |
183 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 185 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
184 | qApp->setFont( fn, TRUE ); | 186 | qApp->setFont( fn, TRUE ); |
185 | } | 187 | } |
186 | #endif | 188 | #endif |
187 | } | 189 | } |
188 | 190 | ||
189 | FirstUse::~FirstUse() | 191 | FirstUse::~FirstUse() |
190 | { | 192 | { |
191 | delete appLauncher; | 193 | delete appLauncher; |
192 | delete docList; | 194 | delete docList; |
193 | delete taskBar; | 195 | delete taskBar; |
194 | ServerApplication::allowRestart = TRUE; | 196 | ServerApplication::allowRestart = TRUE; |
195 | } | 197 | } |
196 | 198 | ||
197 | void FirstUse::calcMaxWindowRect() | 199 | void FirstUse::calcMaxWindowRect() |
198 | { | 200 | { |
199 | #ifdef Q_WS_QWS | 201 | #ifdef Q_WS_QWS |
200 | QRect wr; | 202 | QRect wr; |
201 | int displayWidth = qApp->desktop()->width(); | 203 | int displayWidth = qApp->desktop()->width(); |
202 | QRect ir = inputMethods->inputRect(); | 204 | QRect ir = inputMethods->inputRect(); |
203 | if ( ir.isValid() ) { | 205 | if ( ir.isValid() ) { |
204 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); | 206 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); |
205 | } else { | 207 | } else { |
206 | wr.setCoords( 0, 0, displayWidth-1, | 208 | wr.setCoords( 0, 0, displayWidth-1, |
207 | qApp->desktop()->height() - controlHeight-1); | 209 | qApp->desktop()->height() - controlHeight-1); |
208 | } | 210 | } |
209 | 211 | ||
210 | #if QT_VERSION < 0x030000 | 212 | #if QT_VERSION < 0x030000 |
211 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, | 213 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr, |
212 | QSize(qt_screen->width(),qt_screen->height())) | 214 | QSize(qt_screen->width(),qt_screen->height())) |
213 | ); | 215 | ); |
214 | #else | 216 | #else |
215 | QWSServer::setMaxWindowRect( wr ); | 217 | QWSServer::setMaxWindowRect( wr ); |
216 | #endif | 218 | #endif |
217 | #endif | 219 | #endif |
218 | } | 220 | } |
219 | 221 | ||
220 | /* cancel current dialog, and bring up next */ | 222 | /* cancel current dialog, and bring up next */ |
221 | void FirstUse::nextDialog() | 223 | void FirstUse::nextDialog() |
222 | { | 224 | { |
223 | int prevApp = currApp; | 225 | int prevApp = currApp; |
224 | do { | 226 | do { |
225 | currApp++; | 227 | currApp++; |
226 | qDebug( "currApp = %d", currApp ); | 228 | odebug << "currApp = " << currApp << "" << oendl; |
227 | if ( settingsTable[currApp].app == 0 ) { | 229 | if ( settingsTable[currApp].app == 0 ) { |
228 | if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { | 230 | if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { |
229 | // The last application is still running. | 231 | // The last application is still running. |
230 | // Tell it to stop, and when its done we'll come back | 232 | // Tell it to stop, and when its done we'll come back |
231 | // to nextDialog and exit. | 233 | // to nextDialog and exit. |
232 | qDebug( "Waiting for %s to exit", settingsTable[prevApp].app ); | 234 | odebug << "Waiting for " << settingsTable[prevApp].app << " to exit" << oendl; |
233 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, | 235 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, |
234 | settingsTable[prevApp].stop ); | 236 | settingsTable[prevApp].stop ); |
235 | currApp = prevApp; | 237 | currApp = prevApp; |
236 | } else { | 238 | } else { |
237 | qDebug( "Done!" ); | 239 | odebug << "Done!" << oendl; |
238 | Config config( "qpe" ); | 240 | Config config( "qpe" ); |
239 | config.setGroup( "Startup" ); | 241 | config.setGroup( "Startup" ); |
240 | config.writeEntry( "FirstUse", FALSE ); | 242 | config.writeEntry( "FirstUse", FALSE ); |
241 | QPixmap pix = Resource::loadPixmap("bigwait"); | 243 | QPixmap pix = Resource::loadPixmap("bigwait"); |
242 | QLabel *lblWait = new QLabel(0, "wait hack!", // No tr | 244 | QLabel *lblWait = new QLabel(0, "wait hack!", // No tr |
243 | QWidget::WStyle_Customize | QWidget::WDestructiveClose | | 245 | QWidget::WStyle_Customize | QWidget::WDestructiveClose | |
244 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | | 246 | QWidget::WStyle_NoBorder | QWidget::WStyle_Tool | |
245 | QWidget::WStyle_StaysOnTop); | 247 | QWidget::WStyle_StaysOnTop); |
246 | lblWait->setPixmap( pix ); | 248 | lblWait->setPixmap( pix ); |
247 | lblWait->setAlignment( QWidget::AlignCenter ); | 249 | lblWait->setAlignment( QWidget::AlignCenter ); |
248 | lblWait->setGeometry( qApp->desktop()->geometry() ); | 250 | lblWait->setGeometry( qApp->desktop()->geometry() ); |
249 | lblWait->show(); | 251 | lblWait->show(); |
250 | qApp->processEvents(); | 252 | qApp->processEvents(); |
251 | QTimer::singleShot( 1000, lblWait, SLOT(close()) ); | 253 | QTimer::singleShot( 1000, lblWait, SLOT(close()) ); |
252 | repaint(); | 254 | repaint(); |
253 | close(); | 255 | close(); |
254 | ServerApplication::allowRestart = TRUE; | 256 | ServerApplication::allowRestart = TRUE; |
255 | } | 257 | } |
256 | return; | 258 | return; |
257 | } | 259 | } |
258 | } while ( !settingsTable[currApp].enabled ); | 260 | } while ( !settingsTable[currApp].enabled ); |
259 | 261 | ||
260 | if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { | 262 | if ( prevApp >= 0 && appLauncher->isRunning(settingsTable[prevApp].app) ) { |
261 | qDebug( "Shutdown: %s", settingsTable[prevApp].app ); | 263 | odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl; |
262 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, | 264 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, |
263 | settingsTable[prevApp].stop ); | 265 | settingsTable[prevApp].stop ); |
264 | waitForExit = prevApp; | 266 | waitForExit = prevApp; |
265 | } else { | 267 | } else { |
266 | qDebug( "Startup: %s", settingsTable[currApp].app ); | 268 | odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; |
267 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, | 269 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, |
268 | settingsTable[currApp].start ); | 270 | settingsTable[currApp].start ); |
269 | waitingForLaunch = TRUE; | 271 | waitingForLaunch = TRUE; |
270 | } | 272 | } |
271 | 273 | ||
272 | updateButtons(); | 274 | updateButtons(); |
273 | } | 275 | } |
274 | 276 | ||
275 | /* accept current dialog and bring up previous */ | 277 | /* accept current dialog and bring up previous */ |
276 | void FirstUse::previousDialog() | 278 | void FirstUse::previousDialog() |
277 | { | 279 | { |
278 | int prevApp = currApp; | 280 | int prevApp = currApp; |
279 | do { | 281 | do { |
280 | currApp--; | 282 | currApp--; |
281 | if ( currApp < 0 ) { | 283 | if ( currApp < 0 ) { |
282 | currApp = prevApp; | 284 | currApp = prevApp; |
283 | return; | 285 | return; |
284 | } | 286 | } |
285 | } while ( !settingsTable[currApp].enabled ); | 287 | } while ( !settingsTable[currApp].enabled ); |
286 | 288 | ||
287 | if ( prevApp >= 0 ) { | 289 | if ( prevApp >= 0 ) { |
288 | qDebug( "Shutdown: %s", settingsTable[prevApp].app ); | 290 | odebug << "Shutdown: " << settingsTable[prevApp].app << "" << oendl; |
289 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, | 291 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[prevApp].app, |
290 | settingsTable[prevApp].stop ); | 292 | settingsTable[prevApp].stop ); |
291 | /* | 293 | /* |
292 | if (settingsTable[prevApp].app == QString("systemtime")) | 294 | if (settingsTable[prevApp].app == QString("systemtime")) |
293 | QCopEnvelope e("QPE/Application/citytime", "close()"); | 295 | QCopEnvelope e("QPE/Application/citytime", "close()"); |
294 | */ | 296 | */ |
295 | waitForExit = prevApp; | 297 | waitForExit = prevApp; |
296 | } else { | 298 | } else { |
297 | qDebug( "Startup: %s", settingsTable[currApp].app ); | 299 | odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; |
298 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, | 300 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, |
299 | settingsTable[currApp].start ); | 301 | settingsTable[currApp].start ); |
300 | waitingForLaunch = TRUE; | 302 | waitingForLaunch = TRUE; |
301 | } | 303 | } |
302 | 304 | ||
303 | updateButtons(); | 305 | updateButtons(); |
304 | } | 306 | } |
305 | 307 | ||
306 | void FirstUse::message(const QCString &msg, const QByteArray &data) | 308 | void FirstUse::message(const QCString &msg, const QByteArray &data) |
307 | { | 309 | { |
308 | QDataStream stream( data, IO_ReadOnly ); | 310 | QDataStream stream( data, IO_ReadOnly ); |
309 | if ( msg == "timeChange(QString)" ) { | 311 | if ( msg == "timeChange(QString)" ) { |
310 | QString t; | 312 | QString t; |
311 | stream >> t; | 313 | stream >> t; |
312 | if ( t.isNull() ) | 314 | if ( t.isNull() ) |
313 | unsetenv("TZ"); | 315 | unsetenv("TZ"); |
314 | else | 316 | else |
315 | setenv( "TZ", t.latin1(), 1 ); | 317 | setenv( "TZ", t.latin1(), 1 ); |
316 | } | 318 | } |
317 | } | 319 | } |
318 | 320 | ||
319 | void FirstUse::terminated( int, const QString &app ) | 321 | void FirstUse::terminated( int, const QString &app ) |
320 | { | 322 | { |
321 | qDebug( "--- terminated: %s", app.latin1() ); | 323 | odebug << "--- terminated: " << app << "" << oendl; |
322 | if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) { | 324 | if ( waitForExit != -1 && settingsTable[waitForExit].app == app ) { |
323 | qDebug( "Startup: %s", settingsTable[currApp].app ); | 325 | odebug << "Startup: " << settingsTable[currApp].app << "" << oendl; |
324 | if ( settingsTable[waitForExit].app == "language" ) { // No tr | 326 | if ( settingsTable[waitForExit].app == "language" ) { // No tr |
325 | Config config("locale"); | 327 | Config config("locale"); |
326 | config.setGroup( "Language"); | 328 | config.setGroup( "Language"); |
327 | QString l = config.readEntry( "Language", "en"); | 329 | QString l = config.readEntry( "Language", "en"); |
328 | if ( l != lang ) { | 330 | if ( l != lang ) { |
329 | reloadLanguages(); | 331 | reloadLanguages(); |
330 | needRestart = TRUE; | 332 | needRestart = TRUE; |
331 | lang = l; | 333 | lang = l; |
332 | } | 334 | } |
333 | } | 335 | } |
334 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, | 336 | QCopEnvelope e(QCString("QPE/Application/") + settingsTable[currApp].app, |
335 | settingsTable[currApp].start ); | 337 | settingsTable[currApp].start ); |
336 | waitingForLaunch = TRUE; | 338 | waitingForLaunch = TRUE; |
337 | updateButtons(); | 339 | updateButtons(); |
338 | repaint(); | 340 | repaint(); |
339 | waitForExit = -1; | 341 | waitForExit = -1; |
340 | } else if ( settingsTable[currApp].app == app ) { | 342 | } else if ( settingsTable[currApp].app == app ) { |
341 | nextDialog(); | 343 | nextDialog(); |
342 | } else { | 344 | } else { |
343 | back->setEnabled(TRUE); | 345 | back->setEnabled(TRUE); |
344 | next->setEnabled(TRUE); | 346 | next->setEnabled(TRUE); |
345 | } | 347 | } |
346 | } | 348 | } |
347 | 349 | ||
348 | void FirstUse::newQcopChannel(const QString& channelName) | 350 | void FirstUse::newQcopChannel(const QString& channelName) |
349 | { | 351 | { |
350 | qDebug("channel %s added", channelName.data() ); | 352 | odebug << "channel " << channelName.data() << " added" << oendl; |
351 | QString prefix("QPE/Application/"); | 353 | QString prefix("QPE/Application/"); |
352 | if (channelName.startsWith(prefix)) { | 354 | if (channelName.startsWith(prefix)) { |
353 | QString appName = channelName.mid(prefix.length()); | 355 | QString appName = channelName.mid(prefix.length()); |
354 | if ( currApp >= 0 && appName == settingsTable[currApp].app ) { | 356 | if ( currApp >= 0 && appName == settingsTable[currApp].app ) { |
355 | qDebug( "Application: %s started", settingsTable[currApp].app ); | 357 | odebug << "Application: " << settingsTable[currApp].app << " started" << oendl; |
356 | waitingForLaunch = FALSE; | 358 | waitingForLaunch = FALSE; |
357 | updateButtons(); | 359 | updateButtons(); |
358 | repaint(); | 360 | repaint(); |
359 | } else if (appName != "quicklauncher") { | 361 | } else if (appName != "quicklauncher") { |
360 | back->setEnabled(FALSE); | 362 | back->setEnabled(FALSE); |
361 | next->setEnabled(FALSE); | 363 | next->setEnabled(FALSE); |
362 | } | 364 | } |
363 | } | 365 | } |
364 | } | 366 | } |
365 | 367 | ||
366 | void FirstUse::reloadLanguages() | 368 | void FirstUse::reloadLanguages() |
367 | { | 369 | { |
368 | // read language from config file. Waiting on QCop takes too long. | 370 | // read language from config file. Waiting on QCop takes too long. |
369 | Config config("locale"); | 371 | Config config("locale"); |
370 | config.setGroup( "Language"); | 372 | config.setGroup( "Language"); |
371 | QString l = config.readEntry( "Language", "en"); | 373 | QString l = config.readEntry( "Language", "en"); |
372 | QString cl = getenv("LANG"); | 374 | QString cl = getenv("LANG"); |
373 | qWarning("language message - " + l); | 375 | owarn << "language message - " + l << oendl; |
374 | // setting anyway... | 376 | // setting anyway... |
375 | if (l.isNull() ) | 377 | if (l.isNull() ) |
376 | unsetenv( "LANG" ); | 378 | unsetenv( "LANG" ); |
377 | else { | 379 | else { |
378 | qWarning("and its not null"); | 380 | owarn << "and its not null" << oendl; |
379 | setenv( "LANG", l.latin1(), 1 ); | 381 | setenv( "LANG", l.latin1(), 1 ); |
380 | } | 382 | } |
381 | #ifndef QT_NO_TRANSLATION | 383 | #ifndef QT_NO_TRANSLATION |
382 | // clear old translators | 384 | // clear old translators |
383 | #ifndef _MSC_VER | 385 | #ifndef _MSC_VER |
384 | //### revise to allow removal of translators under MSVC | 386 | //### revise to allow removal of translators under MSVC |
385 | if(qApp->translators) { | 387 | if(qApp->translators) { |
386 | qApp->translators->setAutoDelete(TRUE); | 388 | qApp->translators->setAutoDelete(TRUE); |
387 | delete (qApp->translators); | 389 | delete (qApp->translators); |
388 | qApp->translators = 0; | 390 | qApp->translators = 0; |
389 | } | 391 | } |
390 | #endif | 392 | #endif |
391 | 393 | ||
392 | // load translation tables | 394 | // load translation tables |
393 | transApp = new QTranslator(qApp); | 395 | transApp = new QTranslator(qApp); |
394 | QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm"; | 396 | QString tfn = QPEApplication::qpeDir() + "i18n/"+l+"/qpe.qm"; |
395 | qWarning("loading " + tfn); | 397 | owarn << "loading " + tfn << oendl; |
396 | if ( transApp->load(tfn) ) { | 398 | if ( transApp->load(tfn) ) { |
397 | qWarning("installing translator"); | 399 | owarn << "installing translator" << oendl; |
398 | qApp->installTranslator( transApp ); | 400 | qApp->installTranslator( transApp ); |
399 | } else { | 401 | } else { |
400 | delete transApp; | 402 | delete transApp; |
401 | transApp = 0; | 403 | transApp = 0; |
402 | } | 404 | } |
403 | 405 | ||
404 | transLib = new QTranslator(qApp); | 406 | transLib = new QTranslator(qApp); |
405 | tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm"; | 407 | tfn = QPEApplication::qpeDir() + "i18n/"+l+"/libqpe.qm"; |
406 | qWarning("loading " + tfn); | 408 | owarn << "loading " + tfn << oendl; |
407 | if ( transLib->load(tfn) ) { | 409 | if ( transLib->load(tfn) ) { |
408 | qWarning("installing translator library"); | 410 | owarn << "installing translator library" << oendl; |
409 | qApp->installTranslator( transLib ); | 411 | qApp->installTranslator( transLib ); |
410 | } else { | 412 | } else { |
411 | delete transLib; | 413 | delete transLib; |
412 | transLib = 0; | 414 | transLib = 0; |
413 | } | 415 | } |
414 | loadPixmaps(); | 416 | loadPixmaps(); |
415 | //###language/font hack; should look it up somewhere | 417 | //###language/font hack; should look it up somewhere |
416 | #ifdef Q_WS_QWS | 418 | #ifdef Q_WS_QWS |
417 | if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) { | 419 | if ( l == "ja" || l == "zh_CN" || l == "zh_TW" || l == "ko" ) { |
418 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); | 420 | QFont fn = FontManager::unicodeFont( FontManager::Proportional ); |
419 | qApp->setFont( fn, TRUE ); | 421 | qApp->setFont( fn, TRUE ); |
420 | } else { | 422 | } else { |
421 | qApp->setFont( defaultFont, TRUE ); | 423 | qApp->setFont( defaultFont, TRUE ); |
422 | } | 424 | } |
423 | #endif | 425 | #endif |
424 | #endif | 426 | #endif |
425 | } | 427 | } |
426 | 428 | ||
427 | void FirstUse::paintEvent( QPaintEvent * ) | 429 | void FirstUse::paintEvent( QPaintEvent * ) |
428 | { | 430 | { |
429 | QPainter p( this ); | 431 | QPainter p( this ); |
430 | 432 | ||
431 | p.drawPixmap(0,0, splash); | 433 | p.drawPixmap(0,0, splash); |
432 | 434 | ||
433 | QFont f = p.font(); | 435 | QFont f = p.font(); |
434 | f.setPointSize(15); | 436 | f.setPointSize(15); |
435 | f.setItalic(FALSE); | 437 | f.setItalic(FALSE); |
436 | f.setBold(FALSE); | 438 | f.setBold(FALSE); |
437 | p.setFont(f); | 439 | p.setFont(f); |
438 | 440 | ||
439 | if ( currApp < 0 ) { | 441 | if ( currApp < 0 ) { |
440 | drawText(p, tr( "Tap anywhere on the screen to continue." )); | 442 | drawText(p, tr( "Tap anywhere on the screen to continue." )); |
441 | } else if ( settingsTable[currApp].app ) { | 443 | } else if ( settingsTable[currApp].app ) { |
442 | if ( waitingForLaunch ) | 444 | if ( waitingForLaunch ) |
443 | drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) ); | 445 | drawText(p, tr("Please wait, loading %1 settings.").arg(tr(settingsTable[currApp].desc)) ); |
444 | } else { | 446 | } else { |
445 | drawText(p, tr("Please wait...")); | 447 | drawText(p, tr("Please wait...")); |
446 | } | 448 | } |
447 | } | 449 | } |
448 | 450 | ||
449 | void FirstUse::loadPixmaps() | 451 | void FirstUse::loadPixmaps() |
450 | { | 452 | { |
451 | /* create background, tr so can change image with language. | 453 | /* create background, tr so can change image with language. |
452 | images will likely contain text. */ | 454 | images will likely contain text. */ |
453 | splash.convertFromImage( Resource::loadImage(tr("FirstUseBackground")) | 455 | splash.convertFromImage( Resource::loadImage(tr("FirstUseBackground")) |
454 | .smoothScale( width(), height() ) ); | 456 | .smoothScale( width(), height() ) ); |
455 | 457 | ||
456 | setBackgroundPixmap(splash); | 458 | setBackgroundPixmap(splash); |
457 | } | 459 | } |
458 | 460 | ||
459 | void FirstUse::drawText(QPainter &p, const QString &text) | 461 | void FirstUse::drawText(QPainter &p, const QString &text) |
460 | { | 462 | { |
461 | QString altered = "<CENTER>" + text + "</CENTER>"; | 463 | QString altered = "<CENTER>" + text + "</CENTER>"; |
462 | 464 | ||
463 | QSimpleRichText rt(altered, p.font()); | 465 | QSimpleRichText rt(altered, p.font()); |
464 | rt.setWidth(width() - 20); | 466 | rt.setWidth(width() - 20); |
465 | 467 | ||
466 | int h = (height() * 3) / 10; // start at 30% | 468 | int h = (height() * 3) / 10; // start at 30% |
467 | if (rt.height() < height() / 2) | 469 | if (rt.height() < height() / 2) |
468 | h += ((height() / 2) - rt.height()) / 2; | 470 | h += ((height() / 2) - rt.height()) / 2; |
469 | rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette()); | 471 | rt.draw(&p, 10, h, QRegion(0,0, width()-20, height()), palette()); |
470 | } | 472 | } |
471 | 473 | ||
472 | void FirstUse::updateButtons() | 474 | void FirstUse::updateButtons() |
473 | { | 475 | { |
474 | if ( currApp >= 0 ) { | 476 | if ( currApp >= 0 ) { |
475 | taskBar->show(); | 477 | taskBar->show(); |
476 | } | 478 | } |
477 | 479 | ||
478 | int i = currApp-1; | 480 | int i = currApp-1; |
479 | while ( i >= 0 && !settingsTable[i].enabled ) | 481 | while ( i >= 0 && !settingsTable[i].enabled ) |
480 | i--; | 482 | i--; |
481 | back->setText(tr("<< Back")); | 483 | back->setText(tr("<< Back")); |
482 | back->setEnabled( i >= 0 && !waitingForLaunch ); | 484 | back->setEnabled( i >= 0 && !waitingForLaunch ); |
483 | 485 | ||
484 | i = currApp+1; | 486 | i = currApp+1; |
485 | while ( settingsTable[i].app && !settingsTable[i].enabled ) | 487 | while ( settingsTable[i].app && !settingsTable[i].enabled ) |
486 | i++; | 488 | i++; |
487 | if ( !settingsTable[i].app ) | 489 | if ( !settingsTable[i].app ) |
488 | next->setText(tr("Finish")); | 490 | next->setText(tr("Finish")); |
489 | else | 491 | else |
490 | next->setText(tr("Next >>")); | 492 | next->setText(tr("Next >>")); |
491 | 493 | ||
492 | next->setEnabled( !waitingForLaunch ); | 494 | next->setEnabled( !waitingForLaunch ); |
493 | } | 495 | } |
494 | 496 | ||
495 | void FirstUse::keyPressEvent( QKeyEvent *e ) | 497 | void FirstUse::keyPressEvent( QKeyEvent *e ) |
496 | { | 498 | { |
497 | // Allow cancelling at first dialog, in case display is broken. | 499 | // Allow cancelling at first dialog, in case display is broken. |
498 | if ( e->key() == Key_Escape && currApp < 0 ) | 500 | if ( e->key() == Key_Escape && currApp < 0 ) |
499 | QDialog::keyPressEvent(e); | 501 | QDialog::keyPressEvent(e); |
500 | } | 502 | } |
501 | 503 | ||
502 | void FirstUse::mouseReleaseEvent( QMouseEvent * ) | 504 | void FirstUse::mouseReleaseEvent( QMouseEvent * ) |
503 | { | 505 | { |
504 | if ( currApp < 0 ) { | 506 | if ( currApp < 0 ) { |
505 | if ( m_calHandler && needCalibrate ) { | 507 | if ( m_calHandler && needCalibrate ) { |
506 | releaseMouse(); | 508 | releaseMouse(); |
507 | Calibrate *cal = new Calibrate; | 509 | Calibrate *cal = new Calibrate; |
508 | cal->exec(); | 510 | cal->exec(); |
509 | delete cal; | 511 | delete cal; |
510 | } | 512 | } |
511 | nextDialog(); | 513 | nextDialog(); |
512 | } | 514 | } |
513 | } | 515 | } |
diff --git a/core/launcher/inputmethods.cpp b/core/launcher/inputmethods.cpp index 19e799a..cef16bf 100644 --- a/core/launcher/inputmethods.cpp +++ b/core/launcher/inputmethods.cpp | |||
@@ -1,624 +1,620 @@ | |||
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 | #define QTOPIA_INTERNAL_LANGLIST | 21 | #define QTOPIA_INTERNAL_LANGLIST |
22 | #include "inputmethods.h" | 22 | #include "inputmethods.h" |
23 | 23 | ||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
24 | #include <qtopia/config.h> | 26 | #include <qtopia/config.h> |
25 | #include <qtopia/qpeapplication.h> | 27 | #include <qtopia/qpeapplication.h> |
28 | using namespace Opie::Core; | ||
26 | 29 | ||
30 | /* QT */ | ||
27 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
28 | #include <qtoolbutton.h> | 32 | #include <qtoolbutton.h> |
29 | #include <qwidgetstack.h> | 33 | #include <qwidgetstack.h> |
30 | #include <qlayout.h> | 34 | #include <qlayout.h> |
31 | #include <qdir.h> | 35 | #include <qdir.h> |
32 | #include <stdlib.h> | ||
33 | #include <qtl.h> | 36 | #include <qtl.h> |
34 | |||
35 | #ifdef Q_WS_QWS | 37 | #ifdef Q_WS_QWS |
36 | #include <qwindowsystem_qws.h> | 38 | #include <qwindowsystem_qws.h> |
37 | #include <qwsevent_qws.h> | 39 | #include <qwsevent_qws.h> |
38 | #include <qcopchannel_qws.h> | 40 | #include <qcopchannel_qws.h> |
39 | #endif | 41 | #endif |
40 | 42 | ||
41 | /* ### SingleFloppy if someone is interested? */ | 43 | /* STD */ |
42 | #if 0 | 44 | #include <stdlib.h> |
43 | #ifdef QT_NO_COMPONENT | ||
44 | #include "../plugins/inputmethods/handwriting/handwritingimpl.h" | ||
45 | #include "../plugins/inputmethods/keyboard/keyboardimpl.h" | ||
46 | #include "../3rdparty/plugins/inputmethods/pickboard/pickboardimpl.h" | ||
47 | #endif | ||
48 | #endif | ||
49 | 45 | ||
50 | /* XPM */ | 46 | /* XPM */ |
51 | static const char * tri_xpm[]={ | 47 | static const char * tri_xpm[]={ |
52 | "9 9 2 1", | 48 | "9 9 2 1", |
53 | "a c #000000", | 49 | "a c #000000", |
54 | ". c None", | 50 | ". c None", |
55 | ".........", | 51 | ".........", |
56 | ".........", | 52 | ".........", |
57 | ".........", | 53 | ".........", |
58 | "....a....", | 54 | "....a....", |
59 | "...aaa...", | 55 | "...aaa...", |
60 | "..aaaaa..", | 56 | "..aaaaa..", |
61 | ".aaaaaaa.", | 57 | ".aaaaaaa.", |
62 | ".........", | 58 | ".........", |
63 | "........."}; | 59 | "........."}; |
64 | 60 | ||
65 | int InputMethod::operator <(const InputMethod& o) const | 61 | int InputMethod::operator <(const InputMethod& o) const |
66 | { | 62 | { |
67 | return name() < o.name(); | 63 | return name() < o.name(); |
68 | } | 64 | } |
69 | int InputMethod::operator >(const InputMethod& o) const | 65 | int InputMethod::operator >(const InputMethod& o) const |
70 | { | 66 | { |
71 | return name() > o.name(); | 67 | return name() > o.name(); |
72 | } | 68 | } |
73 | int InputMethod::operator <=(const InputMethod& o) const | 69 | int InputMethod::operator <=(const InputMethod& o) const |
74 | { | 70 | { |
75 | return name() <= o.name(); | 71 | return name() <= o.name(); |
76 | } | 72 | } |
77 | 73 | ||
78 | 74 | ||
79 | /* | 75 | /* |
80 | Slightly hacky: We use WStyle_Tool as a flag to say "this widget | 76 | Slightly hacky: We use WStyle_Tool as a flag to say "this widget |
81 | belongs to the IM system, so clicking it should not cause a reset". | 77 | belongs to the IM system, so clicking it should not cause a reset". |
82 | */ | 78 | */ |
83 | class IMToolButton : public QToolButton | 79 | class IMToolButton : public QToolButton |
84 | { | 80 | { |
85 | public: | 81 | public: |
86 | IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) | 82 | IMToolButton::IMToolButton( QWidget *parent ) : QToolButton( parent ) |
87 | { setWFlags( WStyle_Tool ); } | 83 | { setWFlags( WStyle_Tool ); } |
88 | }; | 84 | }; |
89 | 85 | ||
90 | 86 | ||
91 | InputMethods::InputMethods( QWidget *parent ) : | 87 | InputMethods::InputMethods( QWidget *parent ) : |
92 | QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), | 88 | QWidget( parent, "InputMethods", WStyle_Tool | WStyle_Customize ), |
93 | mkeyboard(0), imethod(0) | 89 | mkeyboard(0), imethod(0) |
94 | { | 90 | { |
95 | Config cfg( "Launcher" ); | 91 | Config cfg( "Launcher" ); |
96 | cfg.setGroup( "InputMethods" ); | 92 | cfg.setGroup( "InputMethods" ); |
97 | inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; | 93 | inputWidgetStyle = QWidget::WStyle_Customize | QWidget::WStyle_StaysOnTop | QWidget::WGroupLeader | QWidget::WStyle_Tool; |
98 | inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; | 94 | inputWidgetStyle |= cfg.readBoolEntry( "Float", false ) ? QWidget::WStyle_DialogBorder : 0; |
99 | inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); | 95 | inputWidgetWidth = cfg.readNumEntry( "Width", 100 ); |
100 | 96 | ||
101 | setBackgroundMode( PaletteBackground ); | 97 | setBackgroundMode( PaletteBackground ); |
102 | QHBoxLayout *hbox = new QHBoxLayout( this ); | 98 | QHBoxLayout *hbox = new QHBoxLayout( this ); |
103 | 99 | ||
104 | kbdButton = new IMToolButton( this); | 100 | kbdButton = new IMToolButton( this); |
105 | kbdButton->setFocusPolicy(NoFocus); | 101 | kbdButton->setFocusPolicy(NoFocus); |
106 | kbdButton->setToggleButton( TRUE ); | 102 | kbdButton->setToggleButton( TRUE ); |
107 | if (parent->sizeHint().height() > 0) | 103 | if (parent->sizeHint().height() > 0) |
108 | kbdButton->setFixedHeight( parent->sizeHint().height() ); | 104 | kbdButton->setFixedHeight( parent->sizeHint().height() ); |
109 | kbdButton->setFixedWidth( 32 ); | 105 | kbdButton->setFixedWidth( 32 ); |
110 | kbdButton->setAutoRaise( TRUE ); | 106 | kbdButton->setAutoRaise( TRUE ); |
111 | kbdButton->setUsesBigPixmap( TRUE ); | 107 | kbdButton->setUsesBigPixmap( TRUE ); |
112 | hbox->addWidget( kbdButton ); | 108 | hbox->addWidget( kbdButton ); |
113 | connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); | 109 | connect( kbdButton, SIGNAL(toggled(bool)), this, SLOT(showKbd(bool)) ); |
114 | 110 | ||
115 | kbdChoice = new IMToolButton( this ); | 111 | kbdChoice = new IMToolButton( this ); |
116 | kbdChoice->setFocusPolicy(NoFocus); | 112 | kbdChoice->setFocusPolicy(NoFocus); |
117 | kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); | 113 | kbdChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); |
118 | if (parent->sizeHint().height() > 0) | 114 | if (parent->sizeHint().height() > 0) |
119 | kbdChoice->setFixedHeight( parent->sizeHint().height() ); | 115 | kbdChoice->setFixedHeight( parent->sizeHint().height() ); |
120 | kbdChoice->setFixedWidth( 13 ); | 116 | kbdChoice->setFixedWidth( 13 ); |
121 | kbdChoice->setAutoRaise( TRUE ); | 117 | kbdChoice->setAutoRaise( TRUE ); |
122 | hbox->addWidget( kbdChoice ); | 118 | hbox->addWidget( kbdChoice ); |
123 | connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); | 119 | connect( kbdChoice, SIGNAL(clicked()), this, SLOT(chooseKbd()) ); |
124 | 120 | ||
125 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), | 121 | connect( (QPEApplication*)qApp, SIGNAL(clientMoused()), |
126 | this, SLOT(resetStates()) ); | 122 | this, SLOT(resetStates()) ); |
127 | 123 | ||
128 | 124 | ||
129 | imButton = new QWidgetStack( this ); // later a widget stack | 125 | imButton = new QWidgetStack( this ); // later a widget stack |
130 | imButton->setFocusPolicy(NoFocus); | 126 | imButton->setFocusPolicy(NoFocus); |
131 | if (parent->sizeHint().height() > 0) | 127 | if (parent->sizeHint().height() > 0) |
132 | imButton->setFixedHeight( parent->sizeHint().height() ); | 128 | imButton->setFixedHeight( parent->sizeHint().height() ); |
133 | hbox->addWidget(imButton); | 129 | hbox->addWidget(imButton); |
134 | 130 | ||
135 | imChoice = new QToolButton( this ); | 131 | imChoice = new QToolButton( this ); |
136 | imChoice->setFocusPolicy(NoFocus); | 132 | imChoice->setFocusPolicy(NoFocus); |
137 | imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); | 133 | imChoice->setPixmap( QPixmap( (const char **)tri_xpm ) ); |
138 | if (parent->sizeHint().height() > 0) | 134 | if (parent->sizeHint().height() > 0) |
139 | imChoice->setFixedHeight( parent->sizeHint().height() ); | 135 | imChoice->setFixedHeight( parent->sizeHint().height() ); |
140 | imChoice->setFixedWidth( 13 ); | 136 | imChoice->setFixedWidth( 13 ); |
141 | imChoice->setAutoRaise( TRUE ); | 137 | imChoice->setAutoRaise( TRUE ); |
142 | hbox->addWidget( imChoice ); | 138 | hbox->addWidget( imChoice ); |
143 | connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); | 139 | connect( imChoice, SIGNAL(clicked()), this, SLOT(chooseIm()) ); |
144 | 140 | ||
145 | loadInputMethods(); | 141 | loadInputMethods(); |
146 | 142 | ||
147 | QCopChannel *channel = new QCopChannel( "QPE/IME", this ); | 143 | QCopChannel *channel = new QCopChannel( "QPE/IME", this ); |
148 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 144 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
149 | this, SLOT(qcopReceive(const QCString&,const QByteArray&)) ); | 145 | this, SLOT(qcopReceive(const QCString&,const QByteArray&)) ); |
150 | } | 146 | } |
151 | 147 | ||
152 | InputMethods::~InputMethods() | 148 | InputMethods::~InputMethods() |
153 | { | 149 | { |
154 | Config cfg("qpe"); | 150 | Config cfg("qpe"); |
155 | cfg.setGroup("InputMethod"); | 151 | cfg.setGroup("InputMethod"); |
156 | if (imethod) | 152 | if (imethod) |
157 | cfg.writeEntry("im", imethod->name() ); | 153 | cfg.writeEntry("im", imethod->name() ); |
158 | if (mkeyboard) | 154 | if (mkeyboard) |
159 | cfg.writeEntry("current", mkeyboard->name() ); | 155 | cfg.writeEntry("current", mkeyboard->name() ); |
160 | 156 | ||
161 | unloadInputMethods(); | 157 | unloadInputMethods(); |
162 | } | 158 | } |
163 | 159 | ||
164 | void InputMethods::hideInputMethod() | 160 | void InputMethods::hideInputMethod() |
165 | { | 161 | { |
166 | kbdButton->setOn( FALSE ); | 162 | kbdButton->setOn( FALSE ); |
167 | } | 163 | } |
168 | 164 | ||
169 | void InputMethods::showInputMethod() | 165 | void InputMethods::showInputMethod() |
170 | { | 166 | { |
171 | kbdButton->setOn( TRUE ); | 167 | kbdButton->setOn( TRUE ); |
172 | } | 168 | } |
173 | 169 | ||
174 | void InputMethods::showInputMethod(const QString& name) | 170 | void InputMethods::showInputMethod(const QString& name) |
175 | { | 171 | { |
176 | int i = 0; | 172 | int i = 0; |
177 | QValueList<InputMethod>::Iterator it; | 173 | QValueList<InputMethod>::Iterator it; |
178 | InputMethod *im = 0; | 174 | InputMethod *im = 0; |
179 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { | 175 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { |
180 | QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); | 176 | QString lname = (*it).libName.mid((*it).libName.findRev('/') + 1); |
181 | if ( (*it).name() == name || lname == name ) { | 177 | if ( (*it).name() == name || lname == name ) { |
182 | im = &(*it); | 178 | im = &(*it); |
183 | break; | 179 | break; |
184 | } | 180 | } |
185 | } | 181 | } |
186 | if ( im ) | 182 | if ( im ) |
187 | chooseKeyboard(im); | 183 | chooseKeyboard(im); |
188 | } | 184 | } |
189 | 185 | ||
190 | void InputMethods::resetStates() | 186 | void InputMethods::resetStates() |
191 | { | 187 | { |
192 | if ( mkeyboard && !mkeyboard->newIM ) | 188 | if ( mkeyboard && !mkeyboard->newIM ) |
193 | mkeyboard->interface->resetState(); | 189 | mkeyboard->interface->resetState(); |
194 | } | 190 | } |
195 | 191 | ||
196 | QRect InputMethods::inputRect() const | 192 | QRect InputMethods::inputRect() const |
197 | { | 193 | { |
198 | if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) | 194 | if ( !mkeyboard || !mkeyboard->widget || !mkeyboard->widget->isVisible() ) |
199 | return QRect(); | 195 | return QRect(); |
200 | else | 196 | else |
201 | return mkeyboard->widget->geometry(); | 197 | return mkeyboard->widget->geometry(); |
202 | } | 198 | } |
203 | 199 | ||
204 | void InputMethods::unloadInputMethods() | 200 | void InputMethods::unloadInputMethods() |
205 | { | 201 | { |
206 | unloadMethod( inputMethodList ); | 202 | unloadMethod( inputMethodList ); |
207 | unloadMethod( inputModifierList ); | 203 | unloadMethod( inputModifierList ); |
208 | inputMethodList.clear(); | 204 | inputMethodList.clear(); |
209 | inputModifierList.clear(); | 205 | inputModifierList.clear(); |
210 | 206 | ||
211 | } | 207 | } |
212 | 208 | ||
213 | void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { | 209 | void InputMethods::unloadMethod( QValueList<InputMethod>& list ) { |
214 | QValueList<InputMethod>::Iterator it; | 210 | QValueList<InputMethod>::Iterator it; |
215 | 211 | ||
216 | for (it = list.begin(); it != list.end(); ++it ) | 212 | for (it = list.begin(); it != list.end(); ++it ) |
217 | (*it).releaseInterface(); | 213 | (*it).releaseInterface(); |
218 | 214 | ||
219 | } | 215 | } |
220 | 216 | ||
221 | 217 | ||
222 | QStringList InputMethods::plugins()const { | 218 | QStringList InputMethods::plugins()const { |
223 | QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; | 219 | QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; |
224 | #ifdef Q_OS_MACX | 220 | #ifdef Q_OS_MACX |
225 | QDir dir( path, "lib*.dylib" ); | 221 | QDir dir( path, "lib*.dylib" ); |
226 | #else | 222 | #else |
227 | QDir dir( path, "lib*.so" ); | 223 | QDir dir( path, "lib*.so" ); |
228 | #endif /* Q_OS_MACX */ | 224 | #endif /* Q_OS_MACX */ |
229 | return dir.entryList(); | 225 | return dir.entryList(); |
230 | } | 226 | } |
231 | 227 | ||
232 | void InputMethods::installTranslator( const QString& type ) { | 228 | void InputMethods::installTranslator( const QString& type ) { |
233 | QStringList langs = Global::languageList(); | 229 | QStringList langs = Global::languageList(); |
234 | QStringList::ConstIterator lit; | 230 | QStringList::ConstIterator lit; |
235 | for ( lit= langs.begin(); lit!=langs.end(); ++lit) { | 231 | for ( lit= langs.begin(); lit!=langs.end(); ++lit) { |
236 | QString lang = *lit; | 232 | QString lang = *lit; |
237 | QTranslator * trans = new QTranslator(qApp); | 233 | QTranslator * trans = new QTranslator(qApp); |
238 | 234 | ||
239 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; | 235 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; |
240 | 236 | ||
241 | if ( trans->load( tfn )) | 237 | if ( trans->load( tfn )) |
242 | qApp->installTranslator( trans ); | 238 | qApp->installTranslator( trans ); |
243 | else | 239 | else |
244 | delete trans; | 240 | delete trans; |
245 | } | 241 | } |
246 | } | 242 | } |
247 | 243 | ||
248 | void InputMethods::setPreferedHandlers() { | 244 | void InputMethods::setPreferedHandlers() { |
249 | Config cfg("qpe"); | 245 | Config cfg("qpe"); |
250 | cfg.setGroup("InputMethod"); | 246 | cfg.setGroup("InputMethod"); |
251 | QString current = cfg.readEntry("current"); | 247 | QString current = cfg.readEntry("current"); |
252 | QString im = cfg.readEntry("im"); | 248 | QString im = cfg.readEntry("im"); |
253 | 249 | ||
254 | QValueList<InputMethod>::Iterator it; | 250 | QValueList<InputMethod>::Iterator it; |
255 | if (!inputModifierList.isEmpty() && !im.isEmpty() ) { | 251 | if (!inputModifierList.isEmpty() && !im.isEmpty() ) { |
256 | for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it ) | 252 | for (it = inputModifierList.begin(); it != inputModifierList.end(); ++it ) |
257 | if ( (*it).name() == im ) { | 253 | if ( (*it).name() == im ) { |
258 | imethod = &(*it); break; | 254 | imethod = &(*it); break; |
259 | } | 255 | } |
260 | 256 | ||
261 | } | 257 | } |
262 | if (!inputMethodList.isEmpty() && !current.isEmpty() ) { | 258 | if (!inputMethodList.isEmpty() && !current.isEmpty() ) { |
263 | for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) | 259 | for (it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) |
264 | if ( (*it).name() == current ) { | 260 | if ( (*it).name() == current ) { |
265 | qWarning("preferred keyboard is %s", current.latin1() ); | 261 | owarn << "preferred keyboard is " << current << "" << oendl; |
266 | mkeyboard = &(*it); | 262 | mkeyboard = &(*it); |
267 | kbdButton->setPixmap( *mkeyboard->icon() ); | 263 | kbdButton->setPixmap( *mkeyboard->icon() ); |
268 | break; | 264 | break; |
269 | } | 265 | } |
270 | } | 266 | } |
271 | 267 | ||
272 | } | 268 | } |
273 | 269 | ||
274 | void InputMethods::loadInputMethods() | 270 | void InputMethods::loadInputMethods() |
275 | { | 271 | { |
276 | #ifndef QT_NO_COMPONENT | 272 | #ifndef QT_NO_COMPONENT |
277 | hideInputMethod(); | 273 | hideInputMethod(); |
278 | mkeyboard = 0; | 274 | mkeyboard = 0; |
279 | 275 | ||
280 | unloadInputMethods(); | 276 | unloadInputMethods(); |
281 | 277 | ||
282 | QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; | 278 | QString path = QPEApplication::qpeDir() + "/plugins/inputmethods"; |
283 | QStringList list = plugins(); | 279 | QStringList list = plugins(); |
284 | QStringList::Iterator it; | 280 | QStringList::Iterator it; |
285 | for ( it = list.begin(); it != list.end(); ++it ) { | 281 | for ( it = list.begin(); it != list.end(); ++it ) { |
286 | InputMethodInterface *iface = 0; | 282 | InputMethodInterface *iface = 0; |
287 | ExtInputMethodInterface *eface = 0; | 283 | ExtInputMethodInterface *eface = 0; |
288 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 284 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
289 | 285 | ||
290 | if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { | 286 | if ( lib->queryInterface( IID_InputMethod, (QUnknownInterface**)&iface ) == QS_OK ) { |
291 | InputMethod input; | 287 | InputMethod input; |
292 | input.newIM = FALSE; | 288 | input.newIM = FALSE; |
293 | input.library = lib; | 289 | input.library = lib; |
294 | input.libName = *it; | 290 | input.libName = *it; |
295 | input.interface = iface; | 291 | input.interface = iface; |
296 | input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); | 292 | input.widget = input.interface->inputMethod( 0, inputWidgetStyle ); |
297 | input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); | 293 | input.interface->onKeyPress( this, SLOT(sendKey(ushort,ushort,ushort,bool,bool)) ); |
298 | inputMethodList.append( input ); | 294 | inputMethodList.append( input ); |
299 | } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) { | 295 | } else if ( lib->queryInterface( IID_ExtInputMethod, (QUnknownInterface**)&eface ) == QS_OK ) { |
300 | InputMethod input; | 296 | InputMethod input; |
301 | input.newIM = TRUE; | 297 | input.newIM = TRUE; |
302 | input.library = lib; | 298 | input.library = lib; |
303 | input.libName = *it; | 299 | input.libName = *it; |
304 | input.extInterface = eface; | 300 | input.extInterface = eface; |
305 | input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle ); | 301 | input.widget = input.extInterface->keyboardWidget( 0, inputWidgetStyle ); |
306 | // may be either a simple, or advanced. | 302 | // may be either a simple, or advanced. |
307 | if (input.widget) { | 303 | if (input.widget) { |
308 | //qDebug("its a keyboard"); | 304 | //odebug << "its a keyboard" << oendl; |
309 | inputMethodList.append( input ); | 305 | inputMethodList.append( input ); |
310 | } else { | 306 | } else { |
311 | //qDebug("its a real im"); | 307 | //odebug << "its a real im" << oendl; |
312 | input.widget = input.extInterface->statusWidget( 0, 0 ); | 308 | input.widget = input.extInterface->statusWidget( 0, 0 ); |
313 | if (input.widget) { | 309 | if (input.widget) { |
314 | //qDebug("blah"); | 310 | //odebug << "blah" << oendl; |
315 | inputModifierList.append( input ); | 311 | inputModifierList.append( input ); |
316 | imButton->addWidget(input.widget, inputModifierList.count()); | 312 | imButton->addWidget(input.widget, inputModifierList.count()); |
317 | } | 313 | } |
318 | } | 314 | } |
319 | }else{ | 315 | }else{ |
320 | delete lib; | 316 | delete lib; |
321 | lib = 0l; | 317 | lib = 0l; |
322 | } | 318 | } |
323 | installTranslator( (*it).left( (*it).find(".") ) ); | 319 | installTranslator( (*it).left( (*it).find(".") ) ); |
324 | } | 320 | } |
325 | qHeapSort( inputMethodList ); | 321 | qHeapSort( inputMethodList ); |
326 | #endif /* killed BUILT in cause they would not compile */ | 322 | #endif /* killed BUILT in cause they would not compile */ |
327 | 323 | ||
328 | QWSServer::setCurrentInputMethod( 0 ); | 324 | QWSServer::setCurrentInputMethod( 0 ); |
329 | 325 | ||
330 | /* set the prefered IM + handler */ | 326 | /* set the prefered IM + handler */ |
331 | setPreferedHandlers(); | 327 | setPreferedHandlers(); |
332 | if ( !inputModifierList.isEmpty() ) { | 328 | if ( !inputModifierList.isEmpty() ) { |
333 | if (!imethod) | 329 | if (!imethod) |
334 | imethod = &inputModifierList[0]; | 330 | imethod = &inputModifierList[0]; |
335 | imButton->raiseWidget(imethod->widget); | 331 | imButton->raiseWidget(imethod->widget); |
336 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); | 332 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); |
337 | } else { | 333 | } else { |
338 | imethod = 0; | 334 | imethod = 0; |
339 | } | 335 | } |
340 | 336 | ||
341 | // we need to update keyboards afterwards, as some of them may not be compatible with | 337 | // we need to update keyboards afterwards, as some of them may not be compatible with |
342 | // the current input method | 338 | // the current input method |
343 | updateKeyboards(imethod); | 339 | updateKeyboards(imethod); |
344 | 340 | ||
345 | if ( !inputModifierList.isEmpty() ) | 341 | if ( !inputModifierList.isEmpty() ) |
346 | imButton->show(); | 342 | imButton->show(); |
347 | else | 343 | else |
348 | imButton->hide(); | 344 | imButton->hide(); |
349 | 345 | ||
350 | if ( inputModifierList.count() > 1 ) | 346 | if ( inputModifierList.count() > 1 ) |
351 | imChoice->show(); | 347 | imChoice->show(); |
352 | else | 348 | else |
353 | imChoice->hide(); | 349 | imChoice->hide(); |
354 | } | 350 | } |
355 | 351 | ||
356 | void InputMethods::chooseKbd() | 352 | void InputMethods::chooseKbd() |
357 | { | 353 | { |
358 | QPopupMenu pop( this ); | 354 | QPopupMenu pop( this ); |
359 | pop.setFocusPolicy( NoFocus ); //don't reset IM | 355 | pop.setFocusPolicy( NoFocus ); //don't reset IM |
360 | 356 | ||
361 | QString imname; | 357 | QString imname; |
362 | if (imethod) | 358 | if (imethod) |
363 | imname = imethod->libName.mid(imethod->libName.findRev('/') + 1); | 359 | imname = imethod->libName.mid(imethod->libName.findRev('/') + 1); |
364 | 360 | ||
365 | int i = 0; | 361 | int i = 0; |
366 | int firstDepKbd = 0; | 362 | int firstDepKbd = 0; |
367 | 363 | ||
368 | QValueList<InputMethod>::Iterator it; | 364 | QValueList<InputMethod>::Iterator it; |
369 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { | 365 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it, i++ ) { |
370 | // add empty new items, all old items. | 366 | // add empty new items, all old items. |
371 | if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) { | 367 | if (!(*it).newIM || (*it).extInterface->compatible().count() == 0 ) { |
372 | pop.insertItem( (*it).name(), i, firstDepKbd); | 368 | pop.insertItem( (*it).name(), i, firstDepKbd); |
373 | if ( mkeyboard == &(*it) ) | 369 | if ( mkeyboard == &(*it) ) |
374 | pop.setItemChecked( i, TRUE ); | 370 | pop.setItemChecked( i, TRUE ); |
375 | 371 | ||
376 | firstDepKbd++; | 372 | firstDepKbd++; |
377 | } else if ( (*it).extInterface->compatible().contains(imname)) { | 373 | } else if ( (*it).extInterface->compatible().contains(imname)) { |
378 | // check if we need to insert a sep. | 374 | // check if we need to insert a sep. |
379 | if (firstDepKbd == i) | 375 | if (firstDepKbd == i) |
380 | pop.insertSeparator(); | 376 | pop.insertSeparator(); |
381 | pop.insertItem( (*it).name(), i, -1); | 377 | pop.insertItem( (*it).name(), i, -1); |
382 | if ( mkeyboard == &(*it) ) | 378 | if ( mkeyboard == &(*it) ) |
383 | pop.setItemChecked( i, TRUE ); | 379 | pop.setItemChecked( i, TRUE ); |
384 | } | 380 | } |
385 | } | 381 | } |
386 | 382 | ||
387 | QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); | 383 | QPoint pt = mapToGlobal(kbdChoice->geometry().topRight()); |
388 | QSize s = pop.sizeHint(); | 384 | QSize s = pop.sizeHint(); |
389 | pt.ry() -= s.height(); | 385 | pt.ry() -= s.height(); |
390 | pt.rx() -= s.width(); | 386 | pt.rx() -= s.width(); |
391 | i = pop.exec( pt ); | 387 | i = pop.exec( pt ); |
392 | if ( i == -1 ) | 388 | if ( i == -1 ) |
393 | return; | 389 | return; |
394 | InputMethod *im = &inputMethodList[i]; | 390 | InputMethod *im = &inputMethodList[i]; |
395 | chooseKeyboard(im); | 391 | chooseKeyboard(im); |
396 | } | 392 | } |
397 | 393 | ||
398 | void InputMethods::chooseIm() | 394 | void InputMethods::chooseIm() |
399 | { | 395 | { |
400 | QPopupMenu pop( this ); | 396 | QPopupMenu pop( this ); |
401 | 397 | ||
402 | int i = 0; | 398 | int i = 0; |
403 | QValueList<InputMethod>::Iterator it; | 399 | QValueList<InputMethod>::Iterator it; |
404 | for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) { | 400 | for ( it = inputModifierList.begin(); it != inputModifierList.end(); ++it, i++ ) { |
405 | pop.insertItem( (*it).name(), i ); | 401 | pop.insertItem( (*it).name(), i ); |
406 | if ( imethod == &(*it) ) | 402 | if ( imethod == &(*it) ) |
407 | pop.setItemChecked( i, TRUE ); | 403 | pop.setItemChecked( i, TRUE ); |
408 | } | 404 | } |
409 | 405 | ||
410 | QPoint pt = mapToGlobal(imChoice->geometry().topRight()); | 406 | QPoint pt = mapToGlobal(imChoice->geometry().topRight()); |
411 | QSize s = pop.sizeHint(); | 407 | QSize s = pop.sizeHint(); |
412 | pt.ry() -= s.height(); | 408 | pt.ry() -= s.height(); |
413 | pt.rx() -= s.width(); | 409 | pt.rx() -= s.width(); |
414 | i = pop.exec( pt ); | 410 | i = pop.exec( pt ); |
415 | if ( i == -1 ) | 411 | if ( i == -1 ) |
416 | return; | 412 | return; |
417 | InputMethod *im = &inputModifierList[i]; | 413 | InputMethod *im = &inputModifierList[i]; |
418 | 414 | ||
419 | chooseMethod(im); | 415 | chooseMethod(im); |
420 | } | 416 | } |
421 | 417 | ||
422 | void InputMethods::chooseKeyboard(InputMethod* im) | 418 | void InputMethods::chooseKeyboard(InputMethod* im) |
423 | { | 419 | { |
424 | if ( im != mkeyboard ) { | 420 | if ( im != mkeyboard ) { |
425 | if ( mkeyboard && mkeyboard->widget->isVisible() ) | 421 | if ( mkeyboard && mkeyboard->widget->isVisible() ) |
426 | mkeyboard->widget->hide(); | 422 | mkeyboard->widget->hide(); |
427 | mkeyboard = im; | 423 | mkeyboard = im; |
428 | kbdButton->setPixmap( *mkeyboard->icon() ); | 424 | kbdButton->setPixmap( *mkeyboard->icon() ); |
429 | } | 425 | } |
430 | if ( !kbdButton->isOn() ) | 426 | if ( !kbdButton->isOn() ) |
431 | kbdButton->setOn( TRUE ); | 427 | kbdButton->setOn( TRUE ); |
432 | else | 428 | else |
433 | showKbd( TRUE ); | 429 | showKbd( TRUE ); |
434 | } | 430 | } |
435 | 431 | ||
436 | static bool keyboardCompatible(InputMethod *keyb, const QString &imname ) | 432 | static bool keyboardCompatible(InputMethod *keyb, const QString &imname ) |
437 | { | 433 | { |
438 | if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() ) | 434 | if ( !keyb || !keyb->newIM || !keyb->extInterface->compatible().count() ) |
439 | return TRUE; | 435 | return TRUE; |
440 | 436 | ||
441 | if ( keyb->extInterface->compatible().contains(imname) ) | 437 | if ( keyb->extInterface->compatible().contains(imname) ) |
442 | return TRUE; | 438 | return TRUE; |
443 | 439 | ||
444 | return FALSE; | 440 | return FALSE; |
445 | } | 441 | } |
446 | 442 | ||
447 | // Updates the display of the soft keyboards available to the current input method | 443 | // Updates the display of the soft keyboards available to the current input method |
448 | void InputMethods::updateKeyboards(InputMethod *im ) | 444 | void InputMethods::updateKeyboards(InputMethod *im ) |
449 | { | 445 | { |
450 | uint count; | 446 | uint count; |
451 | 447 | ||
452 | if ( im ) { | 448 | if ( im ) { |
453 | QString imname = im->libName.mid(im->libName.findRev('/') + 1); | 449 | QString imname = im->libName.mid(im->libName.findRev('/') + 1); |
454 | 450 | ||
455 | if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) { | 451 | if ( mkeyboard && !keyboardCompatible(mkeyboard, imname) ) { |
456 | kbdButton->setOn( FALSE ); | 452 | kbdButton->setOn( FALSE ); |
457 | showKbd( FALSE ); | 453 | showKbd( FALSE ); |
458 | mkeyboard = 0; | 454 | mkeyboard = 0; |
459 | } | 455 | } |
460 | 456 | ||
461 | count = 0; | 457 | count = 0; |
462 | 458 | ||
463 | QValueList<InputMethod>::Iterator it; | 459 | QValueList<InputMethod>::Iterator it; |
464 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) { | 460 | for ( it = inputMethodList.begin(); it != inputMethodList.end(); ++it ) { |
465 | if ( keyboardCompatible( &(*it), imname ) ) { | 461 | if ( keyboardCompatible( &(*it), imname ) ) { |
466 | if ( !mkeyboard ) { | 462 | if ( !mkeyboard ) { |
467 | mkeyboard = &(*it); | 463 | mkeyboard = &(*it); |
468 | kbdButton->setPixmap( *mkeyboard->icon() ); | 464 | kbdButton->setPixmap( *mkeyboard->icon() ); |
469 | } | 465 | } |
470 | 466 | ||
471 | count++; | 467 | count++; |
472 | } | 468 | } |
473 | } | 469 | } |
474 | } else { | 470 | } else { |
475 | count = inputMethodList.count(); | 471 | count = inputMethodList.count(); |
476 | if ( count && !mkeyboard ) { | 472 | if ( count && !mkeyboard ) { |
477 | mkeyboard = &inputMethodList[0]; | 473 | mkeyboard = &inputMethodList[0]; |
478 | kbdButton->setPixmap( *mkeyboard->icon() ); | 474 | kbdButton->setPixmap( *mkeyboard->icon() ); |
479 | } else if (!count){ | 475 | } else if (!count){ |
480 | mkeyboard = 0; //might be redundant | 476 | mkeyboard = 0; //might be redundant |
481 | } | 477 | } |
482 | } | 478 | } |
483 | 479 | ||
484 | if ( count > 1 ) | 480 | if ( count > 1 ) |
485 | kbdChoice->show(); | 481 | kbdChoice->show(); |
486 | else | 482 | else |
487 | kbdChoice->hide(); | 483 | kbdChoice->hide(); |
488 | 484 | ||
489 | if ( count ) | 485 | if ( count ) |
490 | kbdButton->show(); | 486 | kbdButton->show(); |
491 | else | 487 | else |
492 | kbdButton->hide(); | 488 | kbdButton->hide(); |
493 | } | 489 | } |
494 | 490 | ||
495 | void InputMethods::chooseMethod(InputMethod* im) | 491 | void InputMethods::chooseMethod(InputMethod* im) |
496 | { | 492 | { |
497 | if ( im != imethod ) { | 493 | if ( im != imethod ) { |
498 | updateKeyboards( im ); | 494 | updateKeyboards( im ); |
499 | 495 | ||
500 | Config cfg("qpe"); | 496 | Config cfg("qpe"); |
501 | cfg.setGroup("InputMethod"); | 497 | cfg.setGroup("InputMethod"); |
502 | if (im ) | 498 | if (im ) |
503 | cfg.writeEntry("im", im->name() ); | 499 | cfg.writeEntry("im", im->name() ); |
504 | if (mkeyboard) | 500 | if (mkeyboard) |
505 | cfg.writeEntry("current", mkeyboard->name() ); | 501 | cfg.writeEntry("current", mkeyboard->name() ); |
506 | 502 | ||
507 | QWSServer::setCurrentInputMethod( 0 ); | 503 | QWSServer::setCurrentInputMethod( 0 ); |
508 | imethod = im; | 504 | imethod = im; |
509 | if ( imethod && imethod->newIM ) | 505 | if ( imethod && imethod->newIM ) |
510 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); | 506 | QWSServer::setCurrentInputMethod( imethod->extInterface->inputMethod() ); |
511 | else | 507 | else |
512 | QWSServer::setCurrentInputMethod( 0 ); | 508 | QWSServer::setCurrentInputMethod( 0 ); |
513 | 509 | ||
514 | if ( im ) | 510 | if ( im ) |
515 | imButton->raiseWidget(im->widget); | 511 | imButton->raiseWidget(im->widget); |
516 | else | 512 | else |
517 | imButton->hide(); //### good UI? make sure it is shown again! | 513 | imButton->hide(); //### good UI? make sure it is shown again! |
518 | } | 514 | } |
519 | } | 515 | } |
520 | 516 | ||
521 | void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) | 517 | void InputMethods::qcopReceive( const QCString &msg, const QByteArray &data ) |
522 | { | 518 | { |
523 | if ( imethod && imethod->newIM ) | 519 | if ( imethod && imethod->newIM ) |
524 | imethod->extInterface->qcopReceive( msg, data ); | 520 | imethod->extInterface->qcopReceive( msg, data ); |
525 | } | 521 | } |
526 | 522 | ||
527 | 523 | ||
528 | void InputMethods::showKbd( bool on ) | 524 | void InputMethods::showKbd( bool on ) |
529 | { | 525 | { |
530 | if ( !mkeyboard ) | 526 | if ( !mkeyboard ) |
531 | return; | 527 | return; |
532 | 528 | ||
533 | if ( on ) | 529 | if ( on ) |
534 | { | 530 | { |
535 | mkeyboard->resetState(); | 531 | mkeyboard->resetState(); |
536 | 532 | ||
537 | int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); | 533 | int height = QMIN( mkeyboard->widget->sizeHint().height(), 134 ); |
538 | int width = qApp->desktop()->width() * (inputWidgetWidth*0.01); | 534 | int width = qApp->desktop()->width() * (inputWidgetWidth*0.01); |
539 | int left = 0; | 535 | int left = 0; |
540 | int top = mapToGlobal( QPoint() ).y() - height; | 536 | int top = mapToGlobal( QPoint() ).y() - height; |
541 | 537 | ||
542 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) | 538 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) |
543 | { | 539 | { |
544 | qDebug( "InputMethods: reading geometry." ); | 540 | odebug << "InputMethods: reading geometry." << oendl; |
545 | Config cfg( "Launcher" ); | 541 | Config cfg( "Launcher" ); |
546 | cfg.setGroup( "InputMethods" ); | 542 | cfg.setGroup( "InputMethods" ); |
547 | int l = cfg.readNumEntry( "absX", -1 ); | 543 | int l = cfg.readNumEntry( "absX", -1 ); |
548 | int t = cfg.readNumEntry( "absY", -1 ); | 544 | int t = cfg.readNumEntry( "absY", -1 ); |
549 | int w = cfg.readNumEntry( "absWidth", -1 ); | 545 | int w = cfg.readNumEntry( "absWidth", -1 ); |
550 | int h = cfg.readNumEntry( "absHeight", -1 ); | 546 | int h = cfg.readNumEntry( "absHeight", -1 ); |
551 | 547 | ||
552 | if ( l > -1 && t > -1 && w > -1 && h > -1 ) | 548 | if ( l > -1 && t > -1 && w > -1 && h > -1 ) |
553 | { | 549 | { |
554 | qDebug( "InputMethods: config values ( %d, %d, %d, %d ) are ok.", l, t, w, h ); | 550 | odebug << "InputMethods: config values ( " << l << ", " << t << ", " << w << ", " << h << " ) are ok." << oendl; |
555 | left = l; | 551 | left = l; |
556 | top = t; | 552 | top = t; |
557 | width = w; | 553 | width = w; |
558 | height = h; | 554 | height = h; |
559 | } | 555 | } |
560 | else | 556 | else |
561 | { | 557 | { |
562 | qDebug( "InputMethods: config values are new or not ok." ); | 558 | odebug << "InputMethods: config values are new or not ok." << oendl; |
563 | } | 559 | } |
564 | } | 560 | } |
565 | else | 561 | else |
566 | { | 562 | { |
567 | qDebug( "InputMethods: no floating selected." ); | 563 | odebug << "InputMethods: no floating selected." << oendl; |
568 | } | 564 | } |
569 | mkeyboard->widget->resize( width, height ); | 565 | mkeyboard->widget->resize( width, height ); |
570 | mkeyboard->widget->move( left, top ); | 566 | mkeyboard->widget->move( left, top ); |
571 | mkeyboard->widget->show(); | 567 | mkeyboard->widget->show(); |
572 | mkeyboard->widget->installEventFilter( this ); | 568 | mkeyboard->widget->installEventFilter( this ); |
573 | } | 569 | } |
574 | else | 570 | else |
575 | { | 571 | { |
576 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) | 572 | if ( inputWidgetStyle & QWidget::WStyle_DialogBorder ) |
577 | { | 573 | { |
578 | QPoint pos = mkeyboard->widget->pos(); | 574 | QPoint pos = mkeyboard->widget->pos(); |
579 | QSize siz = mkeyboard->widget->size(); | 575 | QSize siz = mkeyboard->widget->size(); |
580 | qDebug( "InputMethods: saving geometry." ); | 576 | odebug << "InputMethods: saving geometry." << oendl; |
581 | Config cfg( "Launcher" ); | 577 | Config cfg( "Launcher" ); |
582 | cfg.setGroup( "InputMethods" ); | 578 | cfg.setGroup( "InputMethods" ); |
583 | cfg.writeEntry( "absX", pos.x() ); | 579 | cfg.writeEntry( "absX", pos.x() ); |
584 | cfg.writeEntry( "absY", pos.y() ); | 580 | cfg.writeEntry( "absY", pos.y() ); |
585 | cfg.writeEntry( "absWidth", siz.width() ); | 581 | cfg.writeEntry( "absWidth", siz.width() ); |
586 | cfg.writeEntry( "absHeight", siz.height() ); | 582 | cfg.writeEntry( "absHeight", siz.height() ); |
587 | cfg.write(); | 583 | cfg.write(); |
588 | mkeyboard->widget->removeEventFilter( this ); | 584 | mkeyboard->widget->removeEventFilter( this ); |
589 | } | 585 | } |
590 | mkeyboard->widget->hide(); | 586 | mkeyboard->widget->hide(); |
591 | } | 587 | } |
592 | 588 | ||
593 | emit inputToggled( on ); | 589 | emit inputToggled( on ); |
594 | } | 590 | } |
595 | 591 | ||
596 | bool InputMethods::shown() const | 592 | bool InputMethods::shown() const |
597 | { | 593 | { |
598 | return mkeyboard && mkeyboard->widget->isVisible(); | 594 | return mkeyboard && mkeyboard->widget->isVisible(); |
599 | } | 595 | } |
600 | 596 | ||
601 | QString InputMethods::currentShown() const | 597 | QString InputMethods::currentShown() const |
602 | { | 598 | { |
603 | return mkeyboard && mkeyboard->widget->isVisible() | 599 | return mkeyboard && mkeyboard->widget->isVisible() |
604 | ? mkeyboard->name() : QString::null; | 600 | ? mkeyboard->name() : QString::null; |
605 | } | 601 | } |
606 | 602 | ||
607 | void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) | 603 | void InputMethods::sendKey( ushort unicode, ushort scancode, ushort mod, bool press, bool repeat ) |
608 | { | 604 | { |
609 | #if defined(Q_WS_QWS) | 605 | #if defined(Q_WS_QWS) |
610 | QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); | 606 | QWSServer::sendKeyEvent( unicode, scancode, mod, press, repeat ); |
611 | #endif | 607 | #endif |
612 | } | 608 | } |
613 | 609 | ||
614 | bool InputMethods::eventFilter( QObject* o, QEvent* e ) | 610 | bool InputMethods::eventFilter( QObject* o, QEvent* e ) |
615 | { | 611 | { |
616 | if ( e->type() == QEvent::Close ) | 612 | if ( e->type() == QEvent::Close ) |
617 | { | 613 | { |
618 | ( (QCloseEvent*) e )->ignore(); | 614 | ( (QCloseEvent*) e )->ignore(); |
619 | showKbd( false ); | 615 | showKbd( false ); |
620 | kbdButton->setOn( false ); | 616 | kbdButton->setOn( false ); |
621 | return true; | 617 | return true; |
622 | } | 618 | } |
623 | return false; | 619 | return false; |
624 | } | 620 | } |
diff --git a/core/launcher/irserver.cpp b/core/launcher/irserver.cpp index a0e9c16..092eb0c 100644 --- a/core/launcher/irserver.cpp +++ b/core/launcher/irserver.cpp | |||
@@ -1,76 +1,76 @@ | |||
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 | |||
22 | #include "irserver.h" | 21 | #include "irserver.h" |
22 | #include "obexinterface.h" | ||
23 | 23 | ||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
24 | #include <qtopia/qlibrary.h> | 26 | #include <qtopia/qlibrary.h> |
25 | #include <qtopia/qpeapplication.h> | 27 | #include <qtopia/qpeapplication.h> |
26 | 28 | ||
27 | 29 | /* QT */ | |
28 | #include "obexinterface.h" | ||
29 | |||
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | 31 | ||
32 | IrServer::IrServer( QObject *parent, const char *name ) | 32 | IrServer::IrServer( QObject *parent, const char *name ) |
33 | : QObject( parent, name ), obexIface(0) | 33 | : QObject( parent, name ), obexIface(0) |
34 | { | 34 | { |
35 | lib = 0; | 35 | lib = 0; |
36 | obexIface = 0; | 36 | obexIface = 0; |
37 | QString path = QPEApplication::qpeDir() + "/plugins/obex/"; | 37 | QString path = QPEApplication::qpeDir() + "/plugins/obex/"; |
38 | #ifdef Q_OS_MACX | 38 | #ifdef Q_OS_MACX |
39 | QDir dir( path, "lib*.dylib" ); | 39 | QDir dir( path, "lib*.dylib" ); |
40 | #else | 40 | #else |
41 | QDir dir( path, "lib*.so" ); | 41 | QDir dir( path, "lib*.so" ); |
42 | #endif /* Q_OS_MACX */ | 42 | #endif /* Q_OS_MACX */ |
43 | QStringList list = dir.entryList(); | 43 | QStringList list = dir.entryList(); |
44 | QStringList::Iterator it; | 44 | QStringList::Iterator it; |
45 | for ( it = list.begin(); it != list.end(); ++it ) { | 45 | for ( it = list.begin(); it != list.end(); ++it ) { |
46 | QLibrary *trylib = new QLibrary( path + *it ); | 46 | QLibrary *trylib = new QLibrary( path + *it ); |
47 | //qDebug("trying lib %s", (path + (*it)).latin1() ); | 47 | //odebug << "trying lib " << (path + (*it)) << "" << oendl; |
48 | if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) { | 48 | if ( trylib->queryInterface( IID_ObexInterface, (QUnknownInterface**)&obexIface ) == QS_OK ) { |
49 | lib = trylib; | 49 | lib = trylib; |
50 | //qDebug("found obex lib" ); | 50 | //odebug << "found obex lib" << oendl; |
51 | QString lang = getenv( "LANG" ); | 51 | QString lang = getenv( "LANG" ); |
52 | QTranslator * trans = new QTranslator(qApp); | 52 | QTranslator * trans = new QTranslator(qApp); |
53 | QString type = (*it).left( (*it).find(".") ); | 53 | QString type = (*it).left( (*it).find(".") ); |
54 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; | 54 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; |
55 | //qDebug("tr fpr obex: %s", tfn.latin1() ); | 55 | //odebug << "tr fpr obex: " << tfn << "" << oendl; |
56 | if ( trans->load( tfn )) | 56 | if ( trans->load( tfn )) |
57 | qApp->installTranslator( trans ); | 57 | qApp->installTranslator( trans ); |
58 | else | 58 | else |
59 | delete trans; | 59 | delete trans; |
60 | 60 | ||
61 | break; | 61 | break; |
62 | } else { | 62 | } else { |
63 | delete lib; | 63 | delete lib; |
64 | } | 64 | } |
65 | } | 65 | } |
66 | if ( !lib ) | 66 | if ( !lib ) |
67 | qDebug("could not load IR plugin" ); | 67 | odebug << "could not load IR plugin" << oendl; |
68 | } | 68 | } |
69 | 69 | ||
70 | IrServer::~IrServer() | 70 | IrServer::~IrServer() |
71 | { | 71 | { |
72 | if ( obexIface ) | 72 | if ( obexIface ) |
73 | obexIface->release(); | 73 | obexIface->release(); |
74 | delete lib; | 74 | delete lib; |
75 | } | 75 | } |
76 | 76 | ||
diff --git a/core/launcher/launcher.cpp b/core/launcher/launcher.cpp index 5d0c778..bf2287d 100644 --- a/core/launcher/launcher.cpp +++ b/core/launcher/launcher.cpp | |||
@@ -1,779 +1,776 @@ | |||
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 | #include "startmenu.h" | ||
22 | #include "taskbar.h" | ||
23 | #include "serverinterface.h" | ||
24 | #include "launcherview.h" | ||
25 | #include "launcher.h" | ||
26 | #include "server.h" | ||
27 | |||
28 | /* OPIE */ | ||
29 | #include <opie2/odebug.h> | ||
21 | #include <qtopia/global.h> | 30 | #include <qtopia/global.h> |
22 | #ifdef Q_WS_QWS | 31 | #ifdef Q_WS_QWS |
23 | #include <qtopia/qcopenvelope_qws.h> | 32 | #include <qtopia/qcopenvelope_qws.h> |
24 | #endif | 33 | #endif |
25 | #include <qtopia/resource.h> | 34 | #include <qtopia/resource.h> |
26 | #include <qtopia/applnk.h> | 35 | #include <qtopia/applnk.h> |
27 | #include <qtopia/config.h> | 36 | #include <qtopia/config.h> |
28 | #include <qtopia/qpeapplication.h> | 37 | #include <qtopia/qpeapplication.h> |
29 | #include <qtopia/mimetype.h> | 38 | #include <qtopia/mimetype.h> |
30 | #include <qtopia/private/categories.h> | 39 | #include <qtopia/private/categories.h> |
31 | //#include <qtopia/custom.h> | 40 | #define QTOPIA_INTERNAL_FSLP |
41 | #include <qtopia/lnkproperties.h> | ||
32 | 42 | ||
43 | /* QT */ | ||
33 | #include <qdir.h> | 44 | #include <qdir.h> |
34 | #ifdef Q_WS_QWS | 45 | #ifdef Q_WS_QWS |
46 | #include <qkeyboard_qws.h> | ||
35 | #include <qwindowsystem_qws.h> | 47 | #include <qwindowsystem_qws.h> |
36 | #endif | 48 | #endif |
37 | #include <qtimer.h> | 49 | #include <qtimer.h> |
38 | #include <qcombobox.h> | 50 | #include <qcombobox.h> |
39 | #include <qvbox.h> | 51 | #include <qvbox.h> |
40 | #include <qlayout.h> | 52 | #include <qlayout.h> |
41 | #include <qstyle.h> | 53 | #include <qstyle.h> |
42 | #include <qpushbutton.h> | 54 | #include <qpushbutton.h> |
43 | #include <qtabbar.h> | 55 | #include <qtabbar.h> |
44 | #include <qwidgetstack.h> | 56 | #include <qwidgetstack.h> |
45 | #include <qregexp.h> | 57 | #include <qregexp.h> |
46 | #include <qmessagebox.h> | 58 | #include <qmessagebox.h> |
47 | #include <qframe.h> | 59 | #include <qframe.h> |
48 | #include <qpainter.h> | 60 | #include <qpainter.h> |
49 | #include <qlabel.h> | 61 | #include <qlabel.h> |
50 | #include <qtextstream.h> | 62 | #include <qtextstream.h> |
51 | #include <qpopupmenu.h> | 63 | #include <qpopupmenu.h> |
52 | 64 | ||
53 | #include "startmenu.h" | 65 | /* STD */ |
54 | #include "taskbar.h" | ||
55 | |||
56 | #include "serverinterface.h" | ||
57 | #include "launcherview.h" | ||
58 | #include "launcher.h" | ||
59 | #include "server.h" | ||
60 | |||
61 | #define QTOPIA_INTERNAL_FSLP | ||
62 | #include <qtopia/lnkproperties.h> | ||
63 | #include <stdlib.h> | 66 | #include <stdlib.h> |
64 | #include <assert.h> | 67 | #include <assert.h> |
65 | |||
66 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 68 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
67 | #include <unistd.h> | 69 | #include <unistd.h> |
68 | #include <stdio.h> | 70 | #include <stdio.h> |
69 | #include <sys/vfs.h> | 71 | #include <sys/vfs.h> |
70 | #include <mntent.h> | 72 | #include <mntent.h> |
71 | #endif | 73 | #endif |
72 | 74 | ||
73 | #ifdef Q_WS_QWS | ||
74 | #include <qkeyboard_qws.h> | ||
75 | #include <qpe/lnkproperties.h> | ||
76 | #endif | ||
77 | |||
78 | 75 | ||
79 | static bool isVisibleWindow( int ); | 76 | static bool isVisibleWindow( int ); |
80 | //=========================================================================== | 77 | //=========================================================================== |
81 | 78 | ||
82 | LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : | 79 | LauncherTabWidget::LauncherTabWidget( Launcher* parent ) : |
83 | QVBox( parent ), docview( 0 ) | 80 | QVBox( parent ), docview( 0 ) |
84 | { | 81 | { |
85 | docLoadingWidgetEnabled = false; | 82 | docLoadingWidgetEnabled = false; |
86 | docLoadingWidget = 0; | 83 | docLoadingWidget = 0; |
87 | docLoadingWidgetProgress = 0; | 84 | docLoadingWidgetProgress = 0; |
88 | launcher = parent; | 85 | launcher = parent; |
89 | categoryBar = new LauncherTabBar( this ); | 86 | categoryBar = new LauncherTabBar( this ); |
90 | QPalette pal = categoryBar->palette(); | 87 | QPalette pal = categoryBar->palette(); |
91 | pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); | 88 | pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); |
92 | pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); | 89 | pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); |
93 | categoryBar->setPalette( pal ); | 90 | categoryBar->setPalette( pal ); |
94 | stack = new QWidgetStack(this); | 91 | stack = new QWidgetStack(this); |
95 | connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); | 92 | connect( categoryBar, SIGNAL(selected(int)), this, SLOT(raiseTabWidget()) ); |
96 | categoryBar->show(); | 93 | categoryBar->show(); |
97 | stack->show(); | 94 | stack->show(); |
98 | 95 | ||
99 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 96 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
100 | QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); | 97 | QCopChannel *channel = new QCopChannel( "QPE/Launcher", this ); |
101 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 98 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
102 | this, SLOT(launcherMessage(const QCString&,const QByteArray&)) ); | 99 | this, SLOT(launcherMessage(const QCString&,const QByteArray&)) ); |
103 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 100 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
104 | this, SLOT(appMessage(const QCString&,const QByteArray&))); | 101 | this, SLOT(appMessage(const QCString&,const QByteArray&))); |
105 | #endif | 102 | #endif |
106 | 103 | ||
107 | createDocLoadingWidget(); | 104 | createDocLoadingWidget(); |
108 | } | 105 | } |
109 | 106 | ||
110 | void LauncherTabWidget::createDocLoadingWidget() | 107 | void LauncherTabWidget::createDocLoadingWidget() |
111 | { | 108 | { |
112 | // Construct the 'doc loading widget' shown when finding documents | 109 | // Construct the 'doc loading widget' shown when finding documents |
113 | 110 | ||
114 | // ### LauncherView class needs changing to be more generic so | 111 | // ### LauncherView class needs changing to be more generic so |
115 | // this widget can change its background similar to the iconviews | 112 | // this widget can change its background similar to the iconviews |
116 | // so the background for this matches | 113 | // so the background for this matches |
117 | docLoadingWidget = new LauncherView( stack ); | 114 | docLoadingWidget = new LauncherView( stack ); |
118 | docLoadingWidget->hideIcons(); | 115 | docLoadingWidget->hideIcons(); |
119 | QVBox *docLoadingVBox = new QVBox( docLoadingWidget ); | 116 | QVBox *docLoadingVBox = new QVBox( docLoadingWidget ); |
120 | 117 | ||
121 | docLoadingVBox->setSpacing( 20 ); | 118 | docLoadingVBox->setSpacing( 20 ); |
122 | docLoadingVBox->setMargin( 10 ); | 119 | docLoadingVBox->setMargin( 10 ); |
123 | 120 | ||
124 | QWidget *space1 = new QWidget( docLoadingVBox ); | 121 | QWidget *space1 = new QWidget( docLoadingVBox ); |
125 | docLoadingVBox->setStretchFactor( space1, 1 ); | 122 | docLoadingVBox->setStretchFactor( space1, 1 ); |
126 | 123 | ||
127 | QLabel *waitPixmap = new QLabel( docLoadingVBox ); | 124 | QLabel *waitPixmap = new QLabel( docLoadingVBox ); |
128 | waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); | 125 | waitPixmap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, waitPixmap->sizePolicy().hasHeightForWidth() ) ); |
129 | waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); | 126 | waitPixmap->setPixmap( Resource::loadPixmap( "bigwait" ) ); |
130 | waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); | 127 | waitPixmap->setAlignment( int( QLabel::AlignCenter ) ); |
131 | 128 | ||
132 | Config cfg( "Launcher" ); | 129 | Config cfg( "Launcher" ); |
133 | cfg.setGroup( "DocTab" ); | 130 | cfg.setGroup( "DocTab" ); |
134 | bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); | 131 | bool docTabEnabled = cfg.readBoolEntry( "Enable", true ); |
135 | 132 | ||
136 | QLabel *textLabel = new QLabel( docLoadingVBox ); | 133 | QLabel *textLabel = new QLabel( docLoadingVBox ); |
137 | textLabel->setAlignment( int( QLabel::AlignCenter ) ); | 134 | textLabel->setAlignment( int( QLabel::AlignCenter ) ); |
138 | docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); | 135 | docLoadingWidgetProgress = new QProgressBar( docLoadingVBox ); |
139 | docLoadingWidgetProgress->setProgress( 0 ); | 136 | docLoadingWidgetProgress->setProgress( 0 ); |
140 | docLoadingWidgetProgress->setCenterIndicator( TRUE ); | 137 | docLoadingWidgetProgress->setCenterIndicator( TRUE ); |
141 | docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker | 138 | docLoadingWidgetProgress->setBackgroundMode( NoBackground ); // No flicker |
142 | setProgressStyle(); | 139 | setProgressStyle(); |
143 | 140 | ||
144 | if ( docTabEnabled ) | 141 | if ( docTabEnabled ) |
145 | { | 142 | { |
146 | textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); | 143 | textLabel->setText( tr( "<b>Finding Documents...</b>" ) ); |
147 | } | 144 | } |
148 | else | 145 | else |
149 | { | 146 | { |
150 | textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>" | 147 | textLabel->setText( tr( "<b>The Documents Tab<p>has been disabled.<p>" |
151 | "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) ); | 148 | "Use Settings->Launcher->DocTab<p>to reenable it.</b></center>" ) ); |
152 | docLoadingWidgetProgress->hide(); | 149 | docLoadingWidgetProgress->hide(); |
153 | docLoadingWidgetEnabled = true; | 150 | docLoadingWidgetEnabled = true; |
154 | } | 151 | } |
155 | 152 | ||
156 | QWidget *space2 = new QWidget( docLoadingVBox ); | 153 | QWidget *space2 = new QWidget( docLoadingVBox ); |
157 | docLoadingVBox->setStretchFactor( space2, 1 ); | 154 | docLoadingVBox->setStretchFactor( space2, 1 ); |
158 | 155 | ||
159 | cfg.setGroup( "Tab Documents" ); // No tr | 156 | cfg.setGroup( "Tab Documents" ); // No tr |
160 | setTabViewAppearance( docLoadingWidget, cfg ); | 157 | setTabViewAppearance( docLoadingWidget, cfg ); |
161 | 158 | ||
162 | stack->addWidget( docLoadingWidget, 0 ); | 159 | stack->addWidget( docLoadingWidget, 0 ); |
163 | } | 160 | } |
164 | 161 | ||
165 | void LauncherTabWidget::initLayout() | 162 | void LauncherTabWidget::initLayout() |
166 | { | 163 | { |
167 | layout()->activate(); | 164 | layout()->activate(); |
168 | docView()->setFocus(); | 165 | docView()->setFocus(); |
169 | categoryBar->showTab("Documents"); | 166 | categoryBar->showTab("Documents"); |
170 | } | 167 | } |
171 | 168 | ||
172 | void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) | 169 | void LauncherTabWidget::appMessage(const QCString& message, const QByteArray&) |
173 | { | 170 | { |
174 | if ( message == "nextView()" ) | 171 | if ( message == "nextView()" ) |
175 | categoryBar->nextTab(); | 172 | categoryBar->nextTab(); |
176 | } | 173 | } |
177 | 174 | ||
178 | void LauncherTabWidget::raiseTabWidget() | 175 | void LauncherTabWidget::raiseTabWidget() |
179 | { | 176 | { |
180 | if ( categoryBar->currentView() == docView() | 177 | if ( categoryBar->currentView() == docView() |
181 | && docLoadingWidgetEnabled ) { | 178 | && docLoadingWidgetEnabled ) { |
182 | stack->raiseWidget( docLoadingWidget ); | 179 | stack->raiseWidget( docLoadingWidget ); |
183 | docLoadingWidget->updateGeometry(); | 180 | docLoadingWidget->updateGeometry(); |
184 | } else { | 181 | } else { |
185 | stack->raiseWidget( categoryBar->currentView() ); | 182 | stack->raiseWidget( categoryBar->currentView() ); |
186 | } | 183 | } |
187 | } | 184 | } |
188 | 185 | ||
189 | void LauncherTabWidget::tabProperties() | 186 | void LauncherTabWidget::tabProperties() |
190 | { | 187 | { |
191 | LauncherView *view = categoryBar->currentView(); | 188 | LauncherView *view = categoryBar->currentView(); |
192 | QPopupMenu *m = new QPopupMenu( this ); | 189 | QPopupMenu *m = new QPopupMenu( this ); |
193 | m->insertItem( tr("Icon View"), LauncherView::Icon ); | 190 | m->insertItem( tr("Icon View"), LauncherView::Icon ); |
194 | m->insertItem( tr("List View"), LauncherView::List ); | 191 | m->insertItem( tr("List View"), LauncherView::List ); |
195 | m->setItemChecked( (int)view->viewMode(), TRUE ); | 192 | m->setItemChecked( (int)view->viewMode(), TRUE ); |
196 | int rv = m->exec( QCursor::pos() ); | 193 | int rv = m->exec( QCursor::pos() ); |
197 | if ( rv >= 0 && rv != view->viewMode() ) { | 194 | if ( rv >= 0 && rv != view->viewMode() ) { |
198 | view->setViewMode( (LauncherView::ViewMode)rv ); | 195 | view->setViewMode( (LauncherView::ViewMode)rv ); |
199 | } | 196 | } |
200 | 197 | ||
201 | delete m; | 198 | delete m; |
202 | } | 199 | } |
203 | 200 | ||
204 | void LauncherTabWidget::deleteView( const QString& id ) | 201 | void LauncherTabWidget::deleteView( const QString& id ) |
205 | { | 202 | { |
206 | LauncherTab *t = categoryBar->launcherTab(id); | 203 | LauncherTab *t = categoryBar->launcherTab(id); |
207 | if ( t ) { | 204 | if ( t ) { |
208 | stack->removeWidget( t->view ); | 205 | stack->removeWidget( t->view ); |
209 | delete t->view; | 206 | delete t->view; |
210 | categoryBar->removeTab( t ); | 207 | categoryBar->removeTab( t ); |
211 | } | 208 | } |
212 | } | 209 | } |
213 | 210 | ||
214 | LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) | 211 | LauncherView* LauncherTabWidget::newView( const QString& id, const QPixmap& pm, const QString& label ) |
215 | { | 212 | { |
216 | LauncherView* view = new LauncherView( stack ); | 213 | LauncherView* view = new LauncherView( stack ); |
217 | connect( view, SIGNAL(clicked(const AppLnk*)), | 214 | connect( view, SIGNAL(clicked(const AppLnk*)), |
218 | this, SIGNAL(clicked(const AppLnk*))); | 215 | this, SIGNAL(clicked(const AppLnk*))); |
219 | connect( view, SIGNAL(rightPressed(AppLnk*)), | 216 | connect( view, SIGNAL(rightPressed(AppLnk*)), |
220 | this, SIGNAL(rightPressed(AppLnk*))); | 217 | this, SIGNAL(rightPressed(AppLnk*))); |
221 | 218 | ||
222 | int n = categoryBar->count(); | 219 | int n = categoryBar->count(); |
223 | stack->addWidget( view, n ); | 220 | stack->addWidget( view, n ); |
224 | 221 | ||
225 | LauncherTab *tab = new LauncherTab( id, view, pm, label ); | 222 | LauncherTab *tab = new LauncherTab( id, view, pm, label ); |
226 | categoryBar->insertTab( tab, n-1 ); | 223 | categoryBar->insertTab( tab, n-1 ); |
227 | 224 | ||
228 | if ( id == "Documents" ) | 225 | if ( id == "Documents" ) |
229 | docview = view; | 226 | docview = view; |
230 | 227 | ||
231 | qDebug("inserting %s at %d", id.latin1(), n-1 ); | 228 | odebug << "inserting " << id << " at " << n-1 << "" << oendl; |
232 | 229 | ||
233 | Config cfg("Launcher"); | 230 | Config cfg("Launcher"); |
234 | setTabAppearance( tab, cfg ); | 231 | setTabAppearance( tab, cfg ); |
235 | 232 | ||
236 | cfg.setGroup( "GUI" ); | 233 | cfg.setGroup( "GUI" ); |
237 | view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) ); | 234 | view->setBusyIndicatorType( cfg.readEntry( "BusyType", QString::null ) ); |
238 | 235 | ||
239 | return view; | 236 | return view; |
240 | } | 237 | } |
241 | 238 | ||
242 | LauncherView *LauncherTabWidget::view( const QString &id ) | 239 | LauncherView *LauncherTabWidget::view( const QString &id ) |
243 | { | 240 | { |
244 | LauncherTab *t = categoryBar->launcherTab(id); | 241 | LauncherTab *t = categoryBar->launcherTab(id); |
245 | if ( !t ) | 242 | if ( !t ) |
246 | return 0; | 243 | return 0; |
247 | return t->view; | 244 | return t->view; |
248 | } | 245 | } |
249 | 246 | ||
250 | LauncherView *LauncherTabWidget::docView() | 247 | LauncherView *LauncherTabWidget::docView() |
251 | { | 248 | { |
252 | return docview; | 249 | return docview; |
253 | } | 250 | } |
254 | 251 | ||
255 | void LauncherTabWidget::setLoadingWidgetEnabled( bool v ) | 252 | void LauncherTabWidget::setLoadingWidgetEnabled( bool v ) |
256 | { | 253 | { |
257 | if ( v != docLoadingWidgetEnabled && docLoadingWidget ) { | 254 | if ( v != docLoadingWidgetEnabled && docLoadingWidget ) { |
258 | docLoadingWidgetEnabled = v; | 255 | docLoadingWidgetEnabled = v; |
259 | raiseTabWidget(); | 256 | raiseTabWidget(); |
260 | } | 257 | } |
261 | } | 258 | } |
262 | 259 | ||
263 | void LauncherTabWidget::setLoadingProgress( int percent ) | 260 | void LauncherTabWidget::setLoadingProgress( int percent ) |
264 | { | 261 | { |
265 | docLoadingWidgetProgress->setProgress( (percent / 4) * 4 ); | 262 | docLoadingWidgetProgress->setProgress( (percent / 4) * 4 ); |
266 | } | 263 | } |
267 | 264 | ||
268 | // ### this function could more to LauncherView | 265 | // ### this function could more to LauncherView |
269 | void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg ) | 266 | void LauncherTabWidget::setTabViewAppearance( LauncherView *v, Config &cfg ) |
270 | { | 267 | { |
271 | // View | 268 | // View |
272 | QString view = cfg.readEntry( "View", "Icon" ); | 269 | QString view = cfg.readEntry( "View", "Icon" ); |
273 | if ( view == "List" ) // No tr | 270 | if ( view == "List" ) // No tr |
274 | v->setViewMode( LauncherView::List ); | 271 | v->setViewMode( LauncherView::List ); |
275 | QString bgType = cfg.readEntry( "BackgroundType", "Image" ); | 272 | QString bgType = cfg.readEntry( "BackgroundType", "Image" ); |
276 | if ( bgType == "Image" ) { // No tr | 273 | if ( bgType == "Image" ) { // No tr |
277 | QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); | 274 | QString pm = cfg.readEntry( "BackgroundImage", "launcher/opie-background" ); |
278 | v->setBackgroundType( LauncherView::Image, pm ); | 275 | v->setBackgroundType( LauncherView::Image, pm ); |
279 | } else if ( bgType == "SolidColor" ) { | 276 | } else if ( bgType == "SolidColor" ) { |
280 | QString c = cfg.readEntry( "BackgroundColor" ); | 277 | QString c = cfg.readEntry( "BackgroundColor" ); |
281 | v->setBackgroundType( LauncherView::SolidColor, c ); | 278 | v->setBackgroundType( LauncherView::SolidColor, c ); |
282 | } else { | 279 | } else { |
283 | v->setBackgroundType( LauncherView::Ruled, QString::null ); | 280 | v->setBackgroundType( LauncherView::Ruled, QString::null ); |
284 | } | 281 | } |
285 | QString textCol = cfg.readEntry( "TextColor" ); | 282 | QString textCol = cfg.readEntry( "TextColor" ); |
286 | if ( textCol.isEmpty() ) | 283 | if ( textCol.isEmpty() ) |
287 | v->setTextColor( QColor() ); | 284 | v->setTextColor( QColor() ); |
288 | else | 285 | else |
289 | v->setTextColor( QColor(textCol) ); | 286 | v->setTextColor( QColor(textCol) ); |
290 | // bool customFont = cfg.readBoolEntry( "CustomFont", FALSE ); | 287 | // bool customFont = cfg.readBoolEntry( "CustomFont", FALSE ); |
291 | 288 | ||
292 | 289 | ||
293 | QStringList font = cfg.readListEntry( "Font", ',' ); | 290 | QStringList font = cfg.readListEntry( "Font", ',' ); |
294 | if ( font.count() == 4 ) | 291 | if ( font.count() == 4 ) |
295 | v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); | 292 | v->setViewFont( QFont(font[0], font[1].toInt(), font[2].toInt(), font[3].toInt()!=0) ); |
296 | 293 | ||
297 | // ### FIXME TabColor TabTextColor | 294 | // ### FIXME TabColor TabTextColor |
298 | 295 | ||
299 | } | 296 | } |
300 | 297 | ||
301 | // ### Could move to LauncherTab | 298 | // ### Could move to LauncherTab |
302 | void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg ) | 299 | void LauncherTabWidget::setTabAppearance( LauncherTab *tab, Config &cfg ) |
303 | { | 300 | { |
304 | cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr | 301 | cfg.setGroup( QString( "Tab %1" ).arg(tab->type) ); // No tr |
305 | 302 | ||
306 | setTabViewAppearance( tab->view, cfg ); | 303 | setTabViewAppearance( tab->view, cfg ); |
307 | 304 | ||
308 | // Tabs | 305 | // Tabs |
309 | QString tabCol = cfg.readEntry( "TabColor" ); | 306 | QString tabCol = cfg.readEntry( "TabColor" ); |
310 | if ( tabCol.isEmpty() ) | 307 | if ( tabCol.isEmpty() ) |
311 | tab->bgColor = QColor(); | 308 | tab->bgColor = QColor(); |
312 | else | 309 | else |
313 | tab->bgColor = QColor(tabCol); | 310 | tab->bgColor = QColor(tabCol); |
314 | QString tabTextCol = cfg.readEntry( "TabTextColor" ); | 311 | QString tabTextCol = cfg.readEntry( "TabTextColor" ); |
315 | if ( tabTextCol.isEmpty() ) | 312 | if ( tabTextCol.isEmpty() ) |
316 | tab->fgColor = QColor(); | 313 | tab->fgColor = QColor(); |
317 | else | 314 | else |
318 | tab->fgColor = QColor(tabTextCol); | 315 | tab->fgColor = QColor(tabTextCol); |
319 | } | 316 | } |
320 | 317 | ||
321 | void LauncherTabWidget::paletteChange( const QPalette &p ) | 318 | void LauncherTabWidget::paletteChange( const QPalette &p ) |
322 | { | 319 | { |
323 | QVBox::paletteChange( p ); | 320 | QVBox::paletteChange( p ); |
324 | QPalette pal = palette(); | 321 | QPalette pal = palette(); |
325 | pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); | 322 | pal.setColor( QColorGroup::Light, pal.color(QPalette::Active,QColorGroup::Shadow) ); |
326 | pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); | 323 | pal.setColor( QColorGroup::Background, pal.active().background().light(110) ); |
327 | categoryBar->setPalette( pal ); | 324 | categoryBar->setPalette( pal ); |
328 | categoryBar->update(); | 325 | categoryBar->update(); |
329 | } | 326 | } |
330 | 327 | ||
331 | void LauncherTabWidget::styleChange( QStyle & ) | 328 | void LauncherTabWidget::styleChange( QStyle & ) |
332 | { | 329 | { |
333 | QTimer::singleShot( 0, this, SLOT(setProgressStyle()) ); | 330 | QTimer::singleShot( 0, this, SLOT(setProgressStyle()) ); |
334 | } | 331 | } |
335 | 332 | ||
336 | void LauncherTabWidget::setProgressStyle() | 333 | void LauncherTabWidget::setProgressStyle() |
337 | { | 334 | { |
338 | if (docLoadingWidgetProgress) { | 335 | if (docLoadingWidgetProgress) { |
339 | docLoadingWidgetProgress->setFrameShape( QProgressBar::Box ); | 336 | docLoadingWidgetProgress->setFrameShape( QProgressBar::Box ); |
340 | docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain ); | 337 | docLoadingWidgetProgress->setFrameShadow( QProgressBar::Plain ); |
341 | docLoadingWidgetProgress->setMargin( 1 ); | 338 | docLoadingWidgetProgress->setMargin( 1 ); |
342 | docLoadingWidgetProgress->setLineWidth( 1 ); | 339 | docLoadingWidgetProgress->setLineWidth( 1 ); |
343 | } | 340 | } |
344 | } | 341 | } |
345 | 342 | ||
346 | void LauncherTabWidget::setBusy(bool on) | 343 | void LauncherTabWidget::setBusy(bool on) |
347 | { | 344 | { |
348 | if ( on ) | 345 | if ( on ) |
349 | currentView()->setBusy(TRUE); | 346 | currentView()->setBusy(TRUE); |
350 | else { | 347 | else { |
351 | for ( int i = 0; i < categoryBar->count(); i++ ) { | 348 | for ( int i = 0; i < categoryBar->count(); i++ ) { |
352 | LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view; | 349 | LauncherView *view = ((LauncherTab *)categoryBar->tab(i))->view; |
353 | view->setBusy( FALSE ); | 350 | view->setBusy( FALSE ); |
354 | } | 351 | } |
355 | } | 352 | } |
356 | } | 353 | } |
357 | 354 | ||
358 | void LauncherTabWidget::setBusyIndicatorType( const QString& str ) { | 355 | void LauncherTabWidget::setBusyIndicatorType( const QString& str ) { |
359 | for (int i = 0; i < categoryBar->count(); i++ ) { | 356 | for (int i = 0; i < categoryBar->count(); i++ ) { |
360 | LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view; | 357 | LauncherView* view = static_cast<LauncherTab*>( categoryBar->tab(i) )->view; |
361 | view->setBusyIndicatorType( str ); | 358 | view->setBusyIndicatorType( str ); |
362 | } | 359 | } |
363 | } | 360 | } |
364 | 361 | ||
365 | LauncherView *LauncherTabWidget::currentView(void) | 362 | LauncherView *LauncherTabWidget::currentView(void) |
366 | { | 363 | { |
367 | return (LauncherView*)stack->visibleWidget(); | 364 | return (LauncherView*)stack->visibleWidget(); |
368 | } | 365 | } |
369 | 366 | ||
370 | 367 | ||
371 | 368 | ||
372 | void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data) | 369 | void LauncherTabWidget::launcherMessage( const QCString &msg, const QByteArray &data) |
373 | { | 370 | { |
374 | QDataStream stream( data, IO_ReadOnly ); | 371 | QDataStream stream( data, IO_ReadOnly ); |
375 | if ( msg == "setTabView(QString,int)" ) { | 372 | if ( msg == "setTabView(QString,int)" ) { |
376 | QString id; | 373 | QString id; |
377 | stream >> id; | 374 | stream >> id; |
378 | int mode; | 375 | int mode; |
379 | stream >> mode; | 376 | stream >> mode; |
380 | if ( view(id) ) | 377 | if ( view(id) ) |
381 | view(id)->setViewMode( (LauncherView::ViewMode)mode ); | 378 | view(id)->setViewMode( (LauncherView::ViewMode)mode ); |
382 | } else if ( msg == "setTabBackground(QString,int,QString)" ) { | 379 | } else if ( msg == "setTabBackground(QString,int,QString)" ) { |
383 | QString id; | 380 | QString id; |
384 | stream >> id; | 381 | stream >> id; |
385 | int mode; | 382 | int mode; |
386 | stream >> mode; | 383 | stream >> mode; |
387 | QString pixmapOrColor; | 384 | QString pixmapOrColor; |
388 | stream >> pixmapOrColor; | 385 | stream >> pixmapOrColor; |
389 | if ( view(id) ) | 386 | if ( view(id) ) |
390 | view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); | 387 | view(id)->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); |
391 | if ( id == "Documents" ) | 388 | if ( id == "Documents" ) |
392 | docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); | 389 | docLoadingWidget->setBackgroundType( (LauncherView::BackgroundType)mode, pixmapOrColor ); |
393 | } else if ( msg == "setTextColor(QString,QString)" ) { | 390 | } else if ( msg == "setTextColor(QString,QString)" ) { |
394 | QString id; | 391 | QString id; |
395 | stream >> id; | 392 | stream >> id; |
396 | QString color; | 393 | QString color; |
397 | stream >> color; | 394 | stream >> color; |
398 | if ( view(id) ) | 395 | if ( view(id) ) |
399 | view(id)->setTextColor( QColor(color) ); | 396 | view(id)->setTextColor( QColor(color) ); |
400 | if ( id == "Documents" ) | 397 | if ( id == "Documents" ) |
401 | docLoadingWidget->setTextColor( QColor(color) ); | 398 | docLoadingWidget->setTextColor( QColor(color) ); |
402 | } else if ( msg == "setFont(QString,QString,int,int,int)" ) { | 399 | } else if ( msg == "setFont(QString,QString,int,int,int)" ) { |
403 | QString id; | 400 | QString id; |
404 | stream >> id; | 401 | stream >> id; |
405 | QString fam; | 402 | QString fam; |
406 | stream >> fam; | 403 | stream >> fam; |
407 | int size; | 404 | int size; |
408 | stream >> size; | 405 | stream >> size; |
409 | int weight; | 406 | int weight; |
410 | stream >> weight; | 407 | stream >> weight; |
411 | int italic; | 408 | int italic; |
412 | stream >> italic; | 409 | stream >> italic; |
413 | if ( view(id) ) { | 410 | if ( view(id) ) { |
414 | if ( !fam.isEmpty() ) { | 411 | if ( !fam.isEmpty() ) { |
415 | view(id)->setViewFont( QFont(fam, size, weight, italic!=0) ); | 412 | view(id)->setViewFont( QFont(fam, size, weight, italic!=0) ); |
416 | qDebug( "setFont: %s, %d, %d, %d", fam.latin1(), size, weight, italic ); | 413 | odebug << "setFont: " << fam << ", " << size << ", " << weight << ", " << italic << "" << oendl; |
417 | } else { | 414 | } else { |
418 | view(id)->clearViewFont(); | 415 | view(id)->clearViewFont(); |
419 | } | 416 | } |
420 | } | 417 | } |
421 | }else if ( msg == "setBusyIndicatorType(QString)" ) { | 418 | }else if ( msg == "setBusyIndicatorType(QString)" ) { |
422 | QString type; | 419 | QString type; |
423 | stream >> type; | 420 | stream >> type; |
424 | setBusyIndicatorType( type ); | 421 | setBusyIndicatorType( type ); |
425 | }else if ( msg == "home()" ) { | 422 | }else if ( msg == "home()" ) { |
426 | if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) { | 423 | if ( isVisibleWindow( static_cast<QWidget*>(parent())->winId() ) ) { |
427 | if (categoryBar) | 424 | if (categoryBar) |
428 | categoryBar->nextTab(); | 425 | categoryBar->nextTab(); |
429 | }else | 426 | }else |
430 | static_cast<QWidget*>(parent())->raise(); | 427 | static_cast<QWidget*>(parent())->raise(); |
431 | } | 428 | } |
432 | } | 429 | } |
433 | 430 | ||
434 | 431 | ||
435 | 432 | ||
436 | //--------------------------------------------------------------------------- | 433 | //--------------------------------------------------------------------------- |
437 | 434 | ||
438 | Launcher::Launcher() | 435 | Launcher::Launcher() |
439 | : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader ) | 436 | : QMainWindow( 0, "PDA User Interface", QWidget::WStyle_Customize | QWidget::WGroupLeader ) |
440 | { | 437 | { |
441 | tabs = 0; | 438 | tabs = 0; |
442 | tb = 0; | 439 | tb = 0; |
443 | Config cfg( "Launcher" ); | 440 | Config cfg( "Launcher" ); |
444 | cfg.setGroup( "DocTab" ); | 441 | cfg.setGroup( "DocTab" ); |
445 | docTabEnabled = cfg.readBoolEntry( "Enable", true ); | 442 | docTabEnabled = cfg.readBoolEntry( "Enable", true ); |
446 | } | 443 | } |
447 | 444 | ||
448 | void Launcher::createGUI() | 445 | void Launcher::createGUI() |
449 | { | 446 | { |
450 | setCaption( tr("Launcher") ); | 447 | setCaption( tr("Launcher") ); |
451 | 448 | ||
452 | // we have a pretty good idea how big we'll be | 449 | // we have a pretty good idea how big we'll be |
453 | setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); | 450 | setGeometry( 0, 0, qApp->desktop()->width(), qApp->desktop()->height() ); |
454 | 451 | ||
455 | tb = new TaskBar; | 452 | tb = new TaskBar; |
456 | tabs = new LauncherTabWidget( this ); | 453 | tabs = new LauncherTabWidget( this ); |
457 | setCentralWidget( tabs ); | 454 | setCentralWidget( tabs ); |
458 | 455 | ||
459 | ServerInterface::dockWidget( tb, ServerInterface::Bottom ); | 456 | ServerInterface::dockWidget( tb, ServerInterface::Bottom ); |
460 | tb->show(); | 457 | tb->show(); |
461 | 458 | ||
462 | qApp->installEventFilter( this ); | 459 | qApp->installEventFilter( this ); |
463 | 460 | ||
464 | 461 | ||
465 | connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); | 462 | connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); |
466 | connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); | 463 | connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); |
467 | connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); | 464 | connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); |
468 | 465 | ||
469 | connect( tb, SIGNAL(tabSelected(const QString&)), | 466 | connect( tb, SIGNAL(tabSelected(const QString&)), |
470 | this, SLOT(showTab(const QString&)) ); | 467 | this, SLOT(showTab(const QString&)) ); |
471 | connect( tabs, SIGNAL(selected(const QString&)), | 468 | connect( tabs, SIGNAL(selected(const QString&)), |
472 | this, SLOT(viewSelected(const QString&)) ); | 469 | this, SLOT(viewSelected(const QString&)) ); |
473 | connect( tabs, SIGNAL(clicked(const AppLnk*)), | 470 | connect( tabs, SIGNAL(clicked(const AppLnk*)), |
474 | this, SLOT(select(const AppLnk*))); | 471 | this, SLOT(select(const AppLnk*))); |
475 | connect( tabs, SIGNAL(rightPressed(AppLnk*)), | 472 | connect( tabs, SIGNAL(rightPressed(AppLnk*)), |
476 | this, SLOT(properties(AppLnk*))); | 473 | this, SLOT(properties(AppLnk*))); |
477 | 474 | ||
478 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 475 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
479 | QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); | 476 | QCopChannel* sysChannel = new QCopChannel( "QPE/System", this ); |
480 | connect( sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 477 | connect( sysChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
481 | this, SLOT(systemMessage(const QCString&,const QByteArray&)) ); | 478 | this, SLOT(systemMessage(const QCString&,const QByteArray&)) ); |
482 | #endif | 479 | #endif |
483 | 480 | ||
484 | // all documents | 481 | // all documents |
485 | QImage img( Resource::loadImage( "DocsIcon" ) ); | 482 | QImage img( Resource::loadImage( "DocsIcon" ) ); |
486 | QPixmap pm; | 483 | QPixmap pm; |
487 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 484 | pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
488 | // It could add this itself if it handles docs | 485 | // It could add this itself if it handles docs |
489 | 486 | ||
490 | tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE ); | 487 | tabs->newView("Documents", pm, tr("Documents") )->setToolsEnabled( TRUE ); |
491 | 488 | ||
492 | QTimer::singleShot( 0, tabs, SLOT( initLayout() ) ); | 489 | QTimer::singleShot( 0, tabs, SLOT( initLayout() ) ); |
493 | qApp->setMainWidget( this ); | 490 | qApp->setMainWidget( this ); |
494 | QTimer::singleShot( 500, this, SLOT( makeVisible() ) ); | 491 | QTimer::singleShot( 500, this, SLOT( makeVisible() ) ); |
495 | } | 492 | } |
496 | 493 | ||
497 | Launcher::~Launcher() | 494 | Launcher::~Launcher() |
498 | { | 495 | { |
499 | if ( tb ) | 496 | if ( tb ) |
500 | destroyGUI(); | 497 | destroyGUI(); |
501 | } | 498 | } |
502 | 499 | ||
503 | bool Launcher::requiresDocuments() const | 500 | bool Launcher::requiresDocuments() const |
504 | { | 501 | { |
505 | Config cfg( "Launcher" ); | 502 | Config cfg( "Launcher" ); |
506 | cfg.setGroup( "DocTab" ); | 503 | cfg.setGroup( "DocTab" ); |
507 | return cfg.readBoolEntry( "Enable", true ); | 504 | return cfg.readBoolEntry( "Enable", true ); |
508 | } | 505 | } |
509 | 506 | ||
510 | void Launcher::makeVisible() | 507 | void Launcher::makeVisible() |
511 | { | 508 | { |
512 | showMaximized(); | 509 | showMaximized(); |
513 | } | 510 | } |
514 | 511 | ||
515 | void Launcher::destroyGUI() | 512 | void Launcher::destroyGUI() |
516 | { | 513 | { |
517 | delete tb; | 514 | delete tb; |
518 | tb = 0; | 515 | tb = 0; |
519 | delete tabs; | 516 | delete tabs; |
520 | tabs =0; | 517 | tabs =0; |
521 | } | 518 | } |
522 | 519 | ||
523 | bool Launcher::eventFilter( QObject*, QEvent *ev ) | 520 | bool Launcher::eventFilter( QObject*, QEvent *ev ) |
524 | { | 521 | { |
525 | #ifdef QT_QWS_CUSTOM | 522 | #ifdef QT_QWS_CUSTOM |
526 | if ( ev->type() == QEvent::KeyPress ) { | 523 | if ( ev->type() == QEvent::KeyPress ) { |
527 | QKeyEvent *ke = (QKeyEvent *)ev; | 524 | QKeyEvent *ke = (QKeyEvent *)ev; |
528 | if ( ke->key() == Qt::Key_F11 ) { // menu key | 525 | if ( ke->key() == Qt::Key_F11 ) { // menu key |
529 | QWidget *active = qApp->activeWindow(); | 526 | QWidget *active = qApp->activeWindow(); |
530 | if ( active && active->isPopup() ) | 527 | if ( active && active->isPopup() ) |
531 | active->close(); | 528 | active->close(); |
532 | else { | 529 | else { |
533 | Global::terminateBuiltin("calibrate"); // No tr | 530 | Global::terminateBuiltin("calibrate"); // No tr |
534 | tb->launchStartMenu(); | 531 | tb->launchStartMenu(); |
535 | } | 532 | } |
536 | return TRUE; | 533 | return TRUE; |
537 | } | 534 | } |
538 | } | 535 | } |
539 | #else | 536 | #else |
540 | Q_UNUSED(ev); | 537 | Q_UNUSED(ev); |
541 | #endif | 538 | #endif |
542 | return FALSE; | 539 | return FALSE; |
543 | } | 540 | } |
544 | 541 | ||
545 | void Launcher::toggleSymbolInput() | 542 | void Launcher::toggleSymbolInput() |
546 | { | 543 | { |
547 | tb->toggleSymbolInput(); | 544 | tb->toggleSymbolInput(); |
548 | } | 545 | } |
549 | 546 | ||
550 | void Launcher::toggleNumLockState() | 547 | void Launcher::toggleNumLockState() |
551 | { | 548 | { |
552 | tb->toggleNumLockState(); | 549 | tb->toggleNumLockState(); |
553 | } | 550 | } |
554 | 551 | ||
555 | void Launcher::toggleCapsLockState() | 552 | void Launcher::toggleCapsLockState() |
556 | { | 553 | { |
557 | tb->toggleCapsLockState(); | 554 | tb->toggleCapsLockState(); |
558 | } | 555 | } |
559 | 556 | ||
560 | static bool isVisibleWindow(int wid) | 557 | static bool isVisibleWindow(int wid) |
561 | { | 558 | { |
562 | #ifdef Q_WS_QWS | 559 | #ifdef Q_WS_QWS |
563 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 560 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
564 | QWSWindow* w; | 561 | QWSWindow* w; |
565 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { | 562 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { |
566 | if ( w->winId() == wid ) | 563 | if ( w->winId() == wid ) |
567 | return !w->isFullyObscured(); | 564 | return !w->isFullyObscured(); |
568 | } | 565 | } |
569 | #endif | 566 | #endif |
570 | return FALSE; | 567 | return FALSE; |
571 | } | 568 | } |
572 | 569 | ||
573 | void Launcher::viewSelected(const QString& s) | 570 | void Launcher::viewSelected(const QString& s) |
574 | { | 571 | { |
575 | setCaption( s + tr(" - Launcher") ); | 572 | setCaption( s + tr(" - Launcher") ); |
576 | } | 573 | } |
577 | 574 | ||
578 | void Launcher::showTab(const QString& id) | 575 | void Launcher::showTab(const QString& id) |
579 | { | 576 | { |
580 | tabs->categoryBar->showTab(id); | 577 | tabs->categoryBar->showTab(id); |
581 | raise(); | 578 | raise(); |
582 | } | 579 | } |
583 | 580 | ||
584 | void Launcher::select( const AppLnk *appLnk ) | 581 | void Launcher::select( const AppLnk *appLnk ) |
585 | { | 582 | { |
586 | if ( appLnk->type() == "Folder" ) { // No tr | 583 | if ( appLnk->type() == "Folder" ) { // No tr |
587 | // Not supported: flat is simpler for the user | 584 | // Not supported: flat is simpler for the user |
588 | } else { | 585 | } else { |
589 | if ( appLnk->exec().isNull() ) { | 586 | if ( appLnk->exec().isNull() ) { |
590 | int i = QMessageBox::information(this,tr("No application"), | 587 | int i = QMessageBox::information(this,tr("No application"), |
591 | tr("<p>No application is defined for this document." | 588 | tr("<p>No application is defined for this document." |
592 | "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1); | 589 | "<p>Type is %1.").arg(appLnk->type()), tr("OK"), tr("View as text"), 0, 0, 1); |
593 | 590 | ||
594 | /* ### Fixme */ | 591 | /* ### Fixme */ |
595 | if ( i == 1 ) | 592 | if ( i == 1 ) |
596 | Global::execute("textedit",appLnk->file()); | 593 | Global::execute("textedit",appLnk->file()); |
597 | 594 | ||
598 | return; | 595 | return; |
599 | } | 596 | } |
600 | tabs->setBusy(TRUE); | 597 | tabs->setBusy(TRUE); |
601 | emit executing( appLnk ); | 598 | emit executing( appLnk ); |
602 | appLnk->execute(); | 599 | appLnk->execute(); |
603 | } | 600 | } |
604 | } | 601 | } |
605 | 602 | ||
606 | void Launcher::properties( AppLnk *appLnk ) | 603 | void Launcher::properties( AppLnk *appLnk ) |
607 | { | 604 | { |
608 | if ( appLnk->type() == "Folder" ) { // No tr | 605 | if ( appLnk->type() == "Folder" ) { // No tr |
609 | // Not supported: flat is simpler for the user | 606 | // Not supported: flat is simpler for the user |
610 | } else { | 607 | } else { |
611 | /* ### libqtopia FIXME also moving docLnks... */ | 608 | /* ### libqtopia FIXME also moving docLnks... */ |
612 | LnkProperties prop(appLnk,0 ); | 609 | LnkProperties prop(appLnk,0 ); |
613 | 610 | ||
614 | QPEApplication::execDialog( &prop ); | 611 | QPEApplication::execDialog( &prop ); |
615 | } | 612 | } |
616 | } | 613 | } |
617 | 614 | ||
618 | void Launcher::storageChanged( const QList<FileSystem> &fs ) | 615 | void Launcher::storageChanged( const QList<FileSystem> &fs ) |
619 | { | 616 | { |
620 | // ### update combo boxes if we had a combo box for the storage type | 617 | // ### update combo boxes if we had a combo box for the storage type |
621 | } | 618 | } |
622 | 619 | ||
623 | void Launcher::systemMessage( const QCString &msg, const QByteArray &data) | 620 | void Launcher::systemMessage( const QCString &msg, const QByteArray &data) |
624 | { | 621 | { |
625 | QDataStream stream( data, IO_ReadOnly ); | 622 | QDataStream stream( data, IO_ReadOnly ); |
626 | if ( msg == "busy()" ) { | 623 | if ( msg == "busy()" ) { |
627 | tb->startWait(); | 624 | tb->startWait(); |
628 | } else if ( msg == "notBusy(QString)" ) { | 625 | } else if ( msg == "notBusy(QString)" ) { |
629 | QString app; | 626 | QString app; |
630 | stream >> app; | 627 | stream >> app; |
631 | tabs->setBusy(FALSE); | 628 | tabs->setBusy(FALSE); |
632 | tb->stopWait(app); | 629 | tb->stopWait(app); |
633 | } else if (msg == "applyStyle()") { | 630 | } else if (msg == "applyStyle()") { |
634 | tabs->currentView()->relayout(); | 631 | tabs->currentView()->relayout(); |
635 | } | 632 | } |
636 | } | 633 | } |
637 | 634 | ||
638 | // These are the update functions from the server | 635 | // These are the update functions from the server |
639 | void Launcher::typeAdded( const QString& type, const QString& name, | 636 | void Launcher::typeAdded( const QString& type, const QString& name, |
640 | const QPixmap& pixmap, const QPixmap& ) | 637 | const QPixmap& pixmap, const QPixmap& ) |
641 | { | 638 | { |
642 | tabs->newView( type, pixmap, name ); | 639 | tabs->newView( type, pixmap, name ); |
643 | ids.append( type ); | 640 | ids.append( type ); |
644 | /* this will be called in applicationScanningProgress with value 100! */ | 641 | /* this will be called in applicationScanningProgress with value 100! */ |
645 | // tb->refreshStartMenu(); | 642 | // tb->refreshStartMenu(); |
646 | 643 | ||
647 | static bool first = TRUE; | 644 | static bool first = TRUE; |
648 | if ( first ) { | 645 | if ( first ) { |
649 | first = FALSE; | 646 | first = FALSE; |
650 | tabs->categoryBar->showTab(type); | 647 | tabs->categoryBar->showTab(type); |
651 | } | 648 | } |
652 | 649 | ||
653 | tabs->view( type )->setUpdatesEnabled( FALSE ); | 650 | tabs->view( type )->setUpdatesEnabled( FALSE ); |
654 | tabs->view( type )->setSortEnabled( FALSE ); | 651 | tabs->view( type )->setSortEnabled( FALSE ); |
655 | } | 652 | } |
656 | 653 | ||
657 | void Launcher::typeRemoved( const QString& type ) | 654 | void Launcher::typeRemoved( const QString& type ) |
658 | { | 655 | { |
659 | tabs->view( type )->removeAllItems(); | 656 | tabs->view( type )->removeAllItems(); |
660 | tabs->deleteView( type ); | 657 | tabs->deleteView( type ); |
661 | ids.remove( type ); | 658 | ids.remove( type ); |
662 | /* this will be called in applicationScanningProgress with value 100! */ | 659 | /* this will be called in applicationScanningProgress with value 100! */ |
663 | // tb->refreshStartMenu(); | 660 | // tb->refreshStartMenu(); |
664 | } | 661 | } |
665 | 662 | ||
666 | void Launcher::applicationAdded( const QString& type, const AppLnk& app ) | 663 | void Launcher::applicationAdded( const QString& type, const AppLnk& app ) |
667 | { | 664 | { |
668 | if ( app.type() == "Separator" ) // No tr | 665 | if ( app.type() == "Separator" ) // No tr |
669 | return; | 666 | return; |
670 | 667 | ||
671 | LauncherView *view = tabs->view( type ); | 668 | LauncherView *view = tabs->view( type ); |
672 | if ( view ) | 669 | if ( view ) |
673 | view->addItem( new AppLnk( app ), FALSE ); | 670 | view->addItem( new AppLnk( app ), FALSE ); |
674 | else | 671 | else |
675 | qWarning("addAppLnk: No view for type %s. Can't add app %s!", | 672 | qWarning("addAppLnk: No view for type %s. Can't add app %s!", |
676 | type.latin1(),app.name().latin1() ); | 673 | type.latin1(),app.name().latin1() ); |
677 | 674 | ||
678 | MimeType::registerApp( app ); | 675 | MimeType::registerApp( app ); |
679 | } | 676 | } |
680 | 677 | ||
681 | void Launcher::applicationRemoved( const QString& type, const AppLnk& app ) | 678 | void Launcher::applicationRemoved( const QString& type, const AppLnk& app ) |
682 | { | 679 | { |
683 | LauncherView *view = tabs->view( type ); | 680 | LauncherView *view = tabs->view( type ); |
684 | if ( view ) | 681 | if ( view ) |
685 | view->removeLink( app.linkFile() ); | 682 | view->removeLink( app.linkFile() ); |
686 | else | 683 | else |
687 | qWarning("removeAppLnk: No view for %s!", type.latin1() ); | 684 | owarn << "removeAppLnk: No view for " << type << "!" << oendl; |
688 | } | 685 | } |
689 | 686 | ||
690 | void Launcher::allApplicationsRemoved() | 687 | void Launcher::allApplicationsRemoved() |
691 | { | 688 | { |
692 | MimeType::clear(); | 689 | MimeType::clear(); |
693 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) | 690 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) |
694 | tabs->view( (*it) )->removeAllItems(); | 691 | tabs->view( (*it) )->removeAllItems(); |
695 | } | 692 | } |
696 | 693 | ||
697 | void Launcher::documentAdded( const DocLnk& doc ) | 694 | void Launcher::documentAdded( const DocLnk& doc ) |
698 | { | 695 | { |
699 | tabs->docView()->addItem( new DocLnk( doc ), FALSE ); | 696 | tabs->docView()->addItem( new DocLnk( doc ), FALSE ); |
700 | } | 697 | } |
701 | 698 | ||
702 | void Launcher::showLoadingDocs() | 699 | void Launcher::showLoadingDocs() |
703 | { | 700 | { |
704 | tabs->docView()->hide(); | 701 | tabs->docView()->hide(); |
705 | } | 702 | } |
706 | 703 | ||
707 | void Launcher::showDocTab() | 704 | void Launcher::showDocTab() |
708 | { | 705 | { |
709 | if ( tabs->categoryBar->currentView() == tabs->docView() ) | 706 | if ( tabs->categoryBar->currentView() == tabs->docView() ) |
710 | tabs->docView()->show(); | 707 | tabs->docView()->show(); |
711 | } | 708 | } |
712 | 709 | ||
713 | void Launcher::documentRemoved( const DocLnk& doc ) | 710 | void Launcher::documentRemoved( const DocLnk& doc ) |
714 | { | 711 | { |
715 | tabs->docView()->removeLink( doc.linkFile() ); | 712 | tabs->docView()->removeLink( doc.linkFile() ); |
716 | } | 713 | } |
717 | 714 | ||
718 | void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc ) | 715 | void Launcher::documentChanged( const DocLnk& oldDoc, const DocLnk& newDoc ) |
719 | { | 716 | { |
720 | documentRemoved( oldDoc ); | 717 | documentRemoved( oldDoc ); |
721 | documentAdded( newDoc ); | 718 | documentAdded( newDoc ); |
722 | } | 719 | } |
723 | 720 | ||
724 | void Launcher::allDocumentsRemoved() | 721 | void Launcher::allDocumentsRemoved() |
725 | { | 722 | { |
726 | tabs->docView()->removeAllItems(); | 723 | tabs->docView()->removeAllItems(); |
727 | } | 724 | } |
728 | 725 | ||
729 | void Launcher::applicationStateChanged( const QString& name, ApplicationState state ) | 726 | void Launcher::applicationStateChanged( const QString& name, ApplicationState state ) |
730 | { | 727 | { |
731 | tb->setApplicationState( name, state ); | 728 | tb->setApplicationState( name, state ); |
732 | } | 729 | } |
733 | 730 | ||
734 | void Launcher::applicationScanningProgress( int percent ) | 731 | void Launcher::applicationScanningProgress( int percent ) |
735 | { | 732 | { |
736 | switch ( percent ) { | 733 | switch ( percent ) { |
737 | case 0: { | 734 | case 0: { |
738 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { | 735 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { |
739 | tabs->view( (*it) )->setUpdatesEnabled( FALSE ); | 736 | tabs->view( (*it) )->setUpdatesEnabled( FALSE ); |
740 | tabs->view( (*it) )->setSortEnabled( FALSE ); | 737 | tabs->view( (*it) )->setSortEnabled( FALSE ); |
741 | } | 738 | } |
742 | break; | 739 | break; |
743 | } | 740 | } |
744 | case 100: { | 741 | case 100: { |
745 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { | 742 | for ( QStringList::ConstIterator it=ids.begin(); it!= ids.end(); ++it) { |
746 | tabs->view( (*it) )->setUpdatesEnabled( TRUE ); | 743 | tabs->view( (*it) )->setUpdatesEnabled( TRUE ); |
747 | tabs->view( (*it) )->setSortEnabled( TRUE ); | 744 | tabs->view( (*it) )->setSortEnabled( TRUE ); |
748 | } | 745 | } |
749 | tb->refreshStartMenu(); | 746 | tb->refreshStartMenu(); |
750 | break; | 747 | break; |
751 | } | 748 | } |
752 | default: | 749 | default: |
753 | break; | 750 | break; |
754 | } | 751 | } |
755 | } | 752 | } |
756 | 753 | ||
757 | void Launcher::documentScanningProgress( int percent ) | 754 | void Launcher::documentScanningProgress( int percent ) |
758 | { | 755 | { |
759 | switch ( percent ) { | 756 | switch ( percent ) { |
760 | case 0: { | 757 | case 0: { |
761 | tabs->setLoadingProgress( 0 ); | 758 | tabs->setLoadingProgress( 0 ); |
762 | tabs->setLoadingWidgetEnabled( TRUE ); | 759 | tabs->setLoadingWidgetEnabled( TRUE ); |
763 | tabs->docView()->setUpdatesEnabled( FALSE ); | 760 | tabs->docView()->setUpdatesEnabled( FALSE ); |
764 | tabs->docView()->setSortEnabled( FALSE ); | 761 | tabs->docView()->setSortEnabled( FALSE ); |
765 | break; | 762 | break; |
766 | } | 763 | } |
767 | case 100: { | 764 | case 100: { |
768 | tabs->docView()->updateTools(); | 765 | tabs->docView()->updateTools(); |
769 | tabs->docView()->setSortEnabled( TRUE ); | 766 | tabs->docView()->setSortEnabled( TRUE ); |
770 | tabs->docView()->setUpdatesEnabled( TRUE ); | 767 | tabs->docView()->setUpdatesEnabled( TRUE ); |
771 | tabs->setLoadingWidgetEnabled( FALSE ); | 768 | tabs->setLoadingWidgetEnabled( FALSE ); |
772 | break; | 769 | break; |
773 | } | 770 | } |
774 | default: | 771 | default: |
775 | tabs->setLoadingProgress( percent ); | 772 | tabs->setLoadingProgress( percent ); |
776 | break; | 773 | break; |
777 | } | 774 | } |
778 | } | 775 | } |
779 | 776 | ||
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp index 6c7d487..71e8753 100644 --- a/core/launcher/launcherview.cpp +++ b/core/launcher/launcherview.cpp | |||
@@ -1,1056 +1,1059 @@ | |||
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 | #include "launcherview.h" | 21 | #include "launcherview.h" |
22 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
23 | #include <qtopia/qpeapplication.h> | 25 | #include <qtopia/qpeapplication.h> |
24 | #include <qtopia/private/categories.h> | 26 | #include <qtopia/private/categories.h> |
25 | #include <qtopia/categoryselect.h> | 27 | #include <qtopia/categoryselect.h> |
26 | #include <qtopia/mimetype.h> | 28 | #include <qtopia/mimetype.h> |
27 | #include <qtopia/resource.h> | 29 | #include <qtopia/resource.h> |
28 | //#include <qtopia/private/palmtoprecord.h> | 30 | using namespace Opie::Core; |
29 | 31 | ||
32 | /* QT */ | ||
30 | #include <qtimer.h> | 33 | #include <qtimer.h> |
31 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
32 | #include <qiconview.h> | 35 | #include <qiconview.h> |
33 | #include <qobjectlist.h> | 36 | #include <qobjectlist.h> |
34 | 37 | ||
35 | 38 | ||
36 | // These define how the busy icon is animated and highlighted | 39 | // These define how the busy icon is animated and highlighted |
37 | #define BRIGHTEN_BUSY_ICON | 40 | #define BRIGHTEN_BUSY_ICON |
38 | //#define ALPHA_FADE_BUSY_ICON | 41 | //#define ALPHA_FADE_BUSY_ICON |
39 | //#define USE_ANIMATED_BUSY_ICON_OVERLAY | 42 | //#define USE_ANIMATED_BUSY_ICON_OVERLAY |
40 | #define BOUNCE_BUSY_ICON | 43 | #define BOUNCE_BUSY_ICON |
41 | 44 | ||
42 | 45 | ||
43 | class BgPixmap | 46 | class BgPixmap |
44 | { | 47 | { |
45 | public: | 48 | public: |
46 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} | 49 | BgPixmap( const QPixmap &p ) : pm(p), ref(1) {} |
47 | QPixmap pm; | 50 | QPixmap pm; |
48 | int ref; | 51 | int ref; |
49 | }; | 52 | }; |
50 | 53 | ||
51 | 54 | ||
52 | static QMap<QString,BgPixmap*> *bgCache = 0; | 55 | static QMap<QString,BgPixmap*> *bgCache = 0; |
53 | 56 | ||
54 | static void cleanup_cache() | 57 | static void cleanup_cache() |
55 | { | 58 | { |
56 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 59 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); |
57 | while ( it != bgCache->end() ) { | 60 | while ( it != bgCache->end() ) { |
58 | QMap<QString,BgPixmap*>::Iterator curr = it; | 61 | QMap<QString,BgPixmap*>::Iterator curr = it; |
59 | ++it; | 62 | ++it; |
60 | delete (*curr); | 63 | delete (*curr); |
61 | bgCache->remove( curr ); | 64 | bgCache->remove( curr ); |
62 | } | 65 | } |
63 | delete bgCache; | 66 | delete bgCache; |
64 | bgCache = 0; | 67 | bgCache = 0; |
65 | } | 68 | } |
66 | 69 | ||
67 | 70 | ||
68 | class LauncherItem : public QIconViewItem | 71 | class LauncherItem : public QIconViewItem |
69 | { | 72 | { |
70 | public: | 73 | public: |
71 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); | 74 | LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE ); |
72 | ~LauncherItem(); | 75 | ~LauncherItem(); |
73 | 76 | ||
74 | AppLnk *appLnk() const { return app; } | 77 | AppLnk *appLnk() const { return app; } |
75 | AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } | 78 | AppLnk *takeAppLnk() { AppLnk* r=app; app=0; return r; } |
76 | 79 | ||
77 | void animateIcon(); | 80 | void animateIcon(); |
78 | void resetIcon(); | 81 | void resetIcon(); |
79 | 82 | ||
80 | virtual int compare ( QIconViewItem * i ) const; | 83 | virtual int compare ( QIconViewItem * i ) const; |
81 | void paintItem( QPainter *p, const QColorGroup &cg ); | 84 | void paintItem( QPainter *p, const QColorGroup &cg ); |
82 | 85 | ||
83 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } | 86 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } |
84 | protected: | 87 | protected: |
85 | bool isBigIcon; | 88 | bool isBigIcon; |
86 | int iteration; | 89 | int iteration; |
87 | AppLnk* app; | 90 | AppLnk* app; |
88 | private: | 91 | private: |
89 | void paintAnimatedIcon( QPainter *p ); | 92 | void paintAnimatedIcon( QPainter *p ); |
90 | BusyIndicatorType busyType; | 93 | BusyIndicatorType busyType; |
91 | }; | 94 | }; |
92 | 95 | ||
93 | 96 | ||
94 | class LauncherIconView : public QIconView { | 97 | class LauncherIconView : public QIconView { |
95 | public: | 98 | public: |
96 | LauncherIconView( QWidget* parent, const char* name=0 ) : | 99 | LauncherIconView( QWidget* parent, const char* name=0 ) : |
97 | QIconView(parent,name), | 100 | QIconView(parent,name), |
98 | tf(""), | 101 | tf(""), |
99 | cf(0), | 102 | cf(0), |
100 | bsy(0), | 103 | bsy(0), |
101 | busyTimer(0), | 104 | busyTimer(0), |
102 | bigIcns(TRUE), | 105 | bigIcns(TRUE), |
103 | bgColor(white) | 106 | bgColor(white) |
104 | { | 107 | { |
105 | sortmeth = Name; | 108 | sortmeth = Name; |
106 | hidden.setAutoDelete(TRUE); | 109 | hidden.setAutoDelete(TRUE); |
107 | ike = FALSE; | 110 | ike = FALSE; |
108 | calculateGrid( Bottom ); | 111 | calculateGrid( Bottom ); |
109 | } | 112 | } |
110 | 113 | ||
111 | ~LauncherIconView() | 114 | ~LauncherIconView() |
112 | { | 115 | { |
113 | #if 0 // debuggery | 116 | #if 0 // debuggery |
114 | QListIterator<AppLnk> it(hidden); | 117 | QListIterator<AppLnk> it(hidden); |
115 | AppLnk* l; | 118 | AppLnk* l; |
116 | while ((l=it.current())) { | 119 | while ((l=it.current())) { |
117 | ++it; | 120 | ++it; |
118 | //qDebug("%p: hidden (should remove)",l); | 121 | //odebug << "" << l << ": hidden (should remove)" << oendl; |
119 | } | 122 | } |
120 | #endif | 123 | #endif |
121 | } | 124 | } |
122 | 125 | ||
123 | QIconViewItem* busyItem() const { return bsy; } | 126 | QIconViewItem* busyItem() const { return bsy; } |
124 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 127 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
125 | QPixmap busyPixmap() const { return busyPix; } | 128 | QPixmap busyPixmap() const { return busyPix; } |
126 | #endif | 129 | #endif |
127 | void setBigIcons( bool bi ) { | 130 | void setBigIcons( bool bi ) { |
128 | bigIcns = bi; | 131 | bigIcns = bi; |
129 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 132 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
130 | busyPix.resize(0,0); | 133 | busyPix.resize(0,0); |
131 | #endif | 134 | #endif |
132 | } | 135 | } |
133 | 136 | ||
134 | void updateCategoriesAndMimeTypes(); | 137 | void updateCategoriesAndMimeTypes(); |
135 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } | 138 | void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; } |
136 | void doAutoScroll() | 139 | void doAutoScroll() |
137 | { | 140 | { |
138 | // We don't want rubberbanding (yet) | 141 | // We don't want rubberbanding (yet) |
139 | } | 142 | } |
140 | 143 | ||
141 | void setBusy(bool on) | 144 | void setBusy(bool on) |
142 | { | 145 | { |
143 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 146 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
144 | if ( busyPix.isNull() ) { | 147 | if ( busyPix.isNull() ) { |
145 | int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); | 148 | int size = ( bigIcns ) ? AppLnk::bigIconSize() : AppLnk::smallIconSize(); |
146 | busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); | 149 | busyPix.convertFromImage( Resource::loadImage( "busy" ).smoothScale( size * 16, size ) ); |
147 | } | 150 | } |
148 | #endif | 151 | #endif |
149 | 152 | ||
150 | if ( on ) { | 153 | if ( on ) { |
151 | busyTimer = startTimer( 100 ); | 154 | busyTimer = startTimer( 100 ); |
152 | } else { | 155 | } else { |
153 | if ( busyTimer ) { | 156 | if ( busyTimer ) { |
154 | killTimer( busyTimer ); | 157 | killTimer( busyTimer ); |
155 | busyTimer = 0; | 158 | busyTimer = 0; |
156 | } | 159 | } |
157 | } | 160 | } |
158 | 161 | ||
159 | LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; | 162 | LauncherItem *c = on ? (LauncherItem*)currentItem() : 0; |
160 | 163 | ||
161 | if ( bsy != c ) { | 164 | if ( bsy != c ) { |
162 | LauncherItem *oldBusy = bsy; | 165 | LauncherItem *oldBusy = bsy; |
163 | bsy = c; | 166 | bsy = c; |
164 | if ( oldBusy ) { | 167 | if ( oldBusy ) { |
165 | oldBusy->resetIcon(); | 168 | oldBusy->resetIcon(); |
166 | } | 169 | } |
167 | if ( bsy ) { | 170 | if ( bsy ) { |
168 | bsy->setBusyIndicatorType( busyType ) ; | 171 | bsy->setBusyIndicatorType( busyType ) ; |
169 | bsy->animateIcon(); | 172 | bsy->animateIcon(); |
170 | } | 173 | } |
171 | } | 174 | } |
172 | } | 175 | } |
173 | 176 | ||
174 | bool inKeyEvent() const { return ike; } | 177 | bool inKeyEvent() const { return ike; } |
175 | void keyPressEvent(QKeyEvent* e) | 178 | void keyPressEvent(QKeyEvent* e) |
176 | { | 179 | { |
177 | ike = TRUE; | 180 | ike = TRUE; |
178 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { | 181 | if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space ) { |
179 | if ( (e->state() & ShiftButton) ) | 182 | if ( (e->state() & ShiftButton) ) |
180 | emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); | 183 | emit mouseButtonPressed(ShiftButton, currentItem(), QPoint() ); |
181 | else | 184 | else |
182 | returnPressed(currentItem()); | 185 | returnPressed(currentItem()); |
183 | } | 186 | } |
184 | 187 | ||
185 | QIconView::keyPressEvent(e); | 188 | QIconView::keyPressEvent(e); |
186 | ike = FALSE; | 189 | ike = FALSE; |
187 | } | 190 | } |
188 | 191 | ||
189 | void addItem(AppLnk* app, bool resort=TRUE); | 192 | void addItem(AppLnk* app, bool resort=TRUE); |
190 | bool removeLink(const QString& linkfile); | 193 | bool removeLink(const QString& linkfile); |
191 | 194 | ||
192 | QStringList mimeTypes() const; | 195 | QStringList mimeTypes() const; |
193 | QStringList categories() const; | 196 | QStringList categories() const; |
194 | 197 | ||
195 | void clear() | 198 | void clear() |
196 | { | 199 | { |
197 | mimes.clear(); | 200 | mimes.clear(); |
198 | cats.clear(); | 201 | cats.clear(); |
199 | QIconView::clear(); | 202 | QIconView::clear(); |
200 | hidden.clear(); | 203 | hidden.clear(); |
201 | } | 204 | } |
202 | 205 | ||
203 | void addCatsAndMimes(AppLnk* app) | 206 | void addCatsAndMimes(AppLnk* app) |
204 | { | 207 | { |
205 | // QStringList c = app->categories(); | 208 | // QStringList c = app->categories(); |
206 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { | 209 | // for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) { |
207 | // cats.replace(*cit,(void*)1); | 210 | // cats.replace(*cit,(void*)1); |
208 | // } | 211 | // } |
209 | QString maj=app->type(); | 212 | QString maj=app->type(); |
210 | int sl=maj.find('/'); | 213 | int sl=maj.find('/'); |
211 | if (sl>=0) { | 214 | if (sl>=0) { |
212 | QString k; | 215 | QString k; |
213 | k = maj.left(12) == "application/" ? maj : maj.left(sl); | 216 | k = maj.left(12) == "application/" ? maj : maj.left(sl); |
214 | mimes.replace(k,(void*)1); | 217 | mimes.replace(k,(void*)1); |
215 | } | 218 | } |
216 | } | 219 | } |
217 | 220 | ||
218 | void setBackgroundOrigin( QWidget::BackgroundOrigin ) { | 221 | void setBackgroundOrigin( QWidget::BackgroundOrigin ) { |
219 | } | 222 | } |
220 | 223 | ||
221 | void setBackgroundPixmap( const QPixmap &pm ) { | 224 | void setBackgroundPixmap( const QPixmap &pm ) { |
222 | bgPixmap = pm; | 225 | bgPixmap = pm; |
223 | } | 226 | } |
224 | 227 | ||
225 | void setBackgroundColor( const QColor &c ) { | 228 | void setBackgroundColor( const QColor &c ) { |
226 | bgColor = c; | 229 | bgColor = c; |
227 | } | 230 | } |
228 | 231 | ||
229 | void drawBackground( QPainter *p, const QRect &r ) | 232 | void drawBackground( QPainter *p, const QRect &r ) |
230 | { | 233 | { |
231 | if ( !bgPixmap.isNull() ) { | 234 | if ( !bgPixmap.isNull() ) { |
232 | p->drawTiledPixmap( r, bgPixmap, | 235 | p->drawTiledPixmap( r, bgPixmap, |
233 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), | 236 | QPoint( (r.x() + contentsX()) % bgPixmap.width(), |
234 | (r.y() + contentsY()) % bgPixmap.height() ) ); | 237 | (r.y() + contentsY()) % bgPixmap.height() ) ); |
235 | } else { | 238 | } else { |
236 | p->fillRect( r, bgColor ); | 239 | p->fillRect( r, bgColor ); |
237 | } | 240 | } |
238 | } | 241 | } |
239 | 242 | ||
240 | void setItemTextPos( ItemTextPos pos ) | 243 | void setItemTextPos( ItemTextPos pos ) |
241 | { | 244 | { |
242 | calculateGrid( pos ); | 245 | calculateGrid( pos ); |
243 | QIconView::setItemTextPos( pos ); | 246 | QIconView::setItemTextPos( pos ); |
244 | } | 247 | } |
245 | 248 | ||
246 | void hideOrShowItems(bool resort); | 249 | void hideOrShowItems(bool resort); |
247 | 250 | ||
248 | void setTypeFilter(const QString& typefilter, bool resort) | 251 | void setTypeFilter(const QString& typefilter, bool resort) |
249 | { | 252 | { |
250 | tf = QRegExp(typefilter,FALSE,TRUE); | 253 | tf = QRegExp(typefilter,FALSE,TRUE); |
251 | hideOrShowItems(resort); | 254 | hideOrShowItems(resort); |
252 | } | 255 | } |
253 | 256 | ||
254 | void setCategoryFilter( int catfilter, bool resort ) | 257 | void setCategoryFilter( int catfilter, bool resort ) |
255 | { | 258 | { |
256 | Categories cat; | 259 | Categories cat; |
257 | cat.load( categoryFileName() ); | 260 | cat.load( categoryFileName() ); |
258 | QString str; | 261 | QString str; |
259 | if ( catfilter == -2 ) | 262 | if ( catfilter == -2 ) |
260 | cf = 0; | 263 | cf = 0; |
261 | else | 264 | else |
262 | cf = catfilter; | 265 | cf = catfilter; |
263 | hideOrShowItems(resort); | 266 | hideOrShowItems(resort); |
264 | } | 267 | } |
265 | 268 | ||
266 | enum SortMethod { Name, Date, Type }; | 269 | enum SortMethod { Name, Date, Type }; |
267 | 270 | ||
268 | void setSortMethod( SortMethod m ) | 271 | void setSortMethod( SortMethod m ) |
269 | { | 272 | { |
270 | if ( sortmeth != m ) { | 273 | if ( sortmeth != m ) { |
271 | sortmeth = m; | 274 | sortmeth = m; |
272 | sort(); | 275 | sort(); |
273 | } | 276 | } |
274 | } | 277 | } |
275 | 278 | ||
276 | int compare(const AppLnk* a, const AppLnk* b) | 279 | int compare(const AppLnk* a, const AppLnk* b) |
277 | { | 280 | { |
278 | switch (sortmeth) { | 281 | switch (sortmeth) { |
279 | case Name: | 282 | case Name: |
280 | return a->name().lower().compare(b->name().lower()); | 283 | return a->name().lower().compare(b->name().lower()); |
281 | case Date: { | 284 | case Date: { |
282 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); | 285 | QFileInfo fa(a->linkFileKnown() ? a->linkFile() : a->file()); |
283 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); | 286 | QFileInfo fb(b->linkFileKnown() ? b->linkFile() : b->file()); |
284 | return fa.lastModified().secsTo(fb.lastModified()); | 287 | return fa.lastModified().secsTo(fb.lastModified()); |
285 | } | 288 | } |
286 | case Type: | 289 | case Type: |
287 | return a->type().compare(b->type()); | 290 | return a->type().compare(b->type()); |
288 | } | 291 | } |
289 | return 0; | 292 | return 0; |
290 | } | 293 | } |
291 | 294 | ||
292 | protected: | 295 | protected: |
293 | 296 | ||
294 | void timerEvent( QTimerEvent *te ) | 297 | void timerEvent( QTimerEvent *te ) |
295 | { | 298 | { |
296 | if ( te->timerId() == busyTimer ) { | 299 | if ( te->timerId() == busyTimer ) { |
297 | if ( bsy ) | 300 | if ( bsy ) |
298 | bsy->animateIcon(); | 301 | bsy->animateIcon(); |
299 | } else { | 302 | } else { |
300 | QIconView::timerEvent( te ); | 303 | QIconView::timerEvent( te ); |
301 | } | 304 | } |
302 | } | 305 | } |
303 | 306 | ||
304 | void styleChange( QStyle &old ) | 307 | void styleChange( QStyle &old ) |
305 | { | 308 | { |
306 | QIconView::styleChange( old ); | 309 | QIconView::styleChange( old ); |
307 | calculateGrid( itemTextPos() ); | 310 | calculateGrid( itemTextPos() ); |
308 | } | 311 | } |
309 | 312 | ||
310 | void calculateGrid( ItemTextPos pos ) | 313 | void calculateGrid( ItemTextPos pos ) |
311 | { | 314 | { |
312 | int dw = QApplication::desktop()->width(); | 315 | int dw = QApplication::desktop()->width(); |
313 | int viewerWidth = dw-style().scrollBarExtent().width(); | 316 | int viewerWidth = dw-style().scrollBarExtent().width(); |
314 | if ( pos == Bottom ) { | 317 | if ( pos == Bottom ) { |
315 | int cols = 3; | 318 | int cols = 3; |
316 | if ( viewerWidth <= 200 ) | 319 | if ( viewerWidth <= 200 ) |
317 | cols = 2; | 320 | cols = 2; |
318 | else if ( viewerWidth >= 400 ) | 321 | else if ( viewerWidth >= 400 ) |
319 | cols = viewerWidth/96; | 322 | cols = viewerWidth/96; |
320 | setSpacing( 4 ); | 323 | setSpacing( 4 ); |
321 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 324 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
322 | setGridY( fontMetrics().height()*2+24 ); | 325 | setGridY( fontMetrics().height()*2+24 ); |
323 | } else { | 326 | } else { |
324 | int cols = 2; | 327 | int cols = 2; |
325 | if ( viewerWidth < 150 ) | 328 | if ( viewerWidth < 150 ) |
326 | cols = 1; | 329 | cols = 1; |
327 | else if ( viewerWidth >= 400 ) | 330 | else if ( viewerWidth >= 400 ) |
328 | cols = viewerWidth/150; | 331 | cols = viewerWidth/150; |
329 | setSpacing( 2 ); | 332 | setSpacing( 2 ); |
330 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); | 333 | setGridX( (viewerWidth-(cols+1)*spacing())/cols ); |
331 | setGridY( fontMetrics().height()+2 ); | 334 | setGridY( fontMetrics().height()+2 ); |
332 | } | 335 | } |
333 | } | 336 | } |
334 | 337 | ||
335 | void focusInEvent( QFocusEvent * ) {} | 338 | void focusInEvent( QFocusEvent * ) {} |
336 | void focusOutEvent( QFocusEvent * ) {} | 339 | void focusOutEvent( QFocusEvent * ) {} |
337 | 340 | ||
338 | private: | 341 | private: |
339 | QList<AppLnk> hidden; | 342 | QList<AppLnk> hidden; |
340 | QDict<void> mimes; | 343 | QDict<void> mimes; |
341 | QDict<void> cats; | 344 | QDict<void> cats; |
342 | SortMethod sortmeth; | 345 | SortMethod sortmeth; |
343 | QRegExp tf; | 346 | QRegExp tf; |
344 | int cf; | 347 | int cf; |
345 | LauncherItem* bsy; | 348 | LauncherItem* bsy; |
346 | int busyTimer; | 349 | int busyTimer; |
347 | bool ike; | 350 | bool ike; |
348 | bool bigIcns; | 351 | bool bigIcns; |
349 | QPixmap bgPixmap; | 352 | QPixmap bgPixmap; |
350 | QColor bgColor; | 353 | QColor bgColor; |
351 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 354 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
352 | QPixmap busyPix; | 355 | QPixmap busyPix; |
353 | #endif | 356 | #endif |
354 | BusyIndicatorType busyType; | 357 | BusyIndicatorType busyType; |
355 | }; | 358 | }; |
356 | 359 | ||
357 | 360 | ||
358 | bool LauncherView::bsy=FALSE; | 361 | bool LauncherView::bsy=FALSE; |
359 | 362 | ||
360 | void LauncherView::setBusy(bool on) | 363 | void LauncherView::setBusy(bool on) |
361 | { | 364 | { |
362 | icons->setBusy(on); | 365 | icons->setBusy(on); |
363 | } | 366 | } |
364 | 367 | ||
365 | void LauncherView::setBusyIndicatorType( const QString& type ) { | 368 | void LauncherView::setBusyIndicatorType( const QString& type ) { |
366 | if ( type. lower ( ) == "animated" ) | 369 | if ( type. lower ( ) == "animated" ) |
367 | icons->setBusyIndicatorType( BIT_Animated ) ; | 370 | icons->setBusyIndicatorType( BIT_Animated ) ; |
368 | else | 371 | else |
369 | icons->setBusyIndicatorType( BIT_Normal ) ; | 372 | icons->setBusyIndicatorType( BIT_Normal ) ; |
370 | } | 373 | } |
371 | 374 | ||
372 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) | 375 | LauncherItem::LauncherItem( QIconView *parent, AppLnk *applnk, bool bigIcon ) |
373 | : QIconViewItem( parent, applnk->name(), | 376 | : QIconViewItem( parent, applnk->name(), |
374 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), | 377 | bigIcon ? applnk->bigPixmap() :applnk->pixmap() ), |
375 | isBigIcon( bigIcon ), | 378 | isBigIcon( bigIcon ), |
376 | iteration(0), | 379 | iteration(0), |
377 | app(applnk) // Takes ownership | 380 | app(applnk) // Takes ownership |
378 | { | 381 | { |
379 | } | 382 | } |
380 | 383 | ||
381 | LauncherItem::~LauncherItem() | 384 | LauncherItem::~LauncherItem() |
382 | { | 385 | { |
383 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 386 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
384 | if ( liv->busyItem() == this ) | 387 | if ( liv->busyItem() == this ) |
385 | liv->setBusy(FALSE); | 388 | liv->setBusy(FALSE); |
386 | delete app; | 389 | delete app; |
387 | } | 390 | } |
388 | 391 | ||
389 | int LauncherItem::compare ( QIconViewItem * i ) const | 392 | int LauncherItem::compare ( QIconViewItem * i ) const |
390 | { | 393 | { |
391 | LauncherIconView* view = (LauncherIconView*)iconView(); | 394 | LauncherIconView* view = (LauncherIconView*)iconView(); |
392 | return view->compare(app,((LauncherItem *)i)->appLnk()); | 395 | return view->compare(app,((LauncherItem *)i)->appLnk()); |
393 | } | 396 | } |
394 | 397 | ||
395 | void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) | 398 | void LauncherItem::paintItem( QPainter *p, const QColorGroup &cg ) |
396 | { | 399 | { |
397 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 400 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
398 | QBrush oldBrush( liv->itemTextBackground() ); | 401 | QBrush oldBrush( liv->itemTextBackground() ); |
399 | QColorGroup mycg( cg ); | 402 | QColorGroup mycg( cg ); |
400 | if ( liv->currentItem() == this ) { | 403 | if ( liv->currentItem() == this ) { |
401 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); | 404 | liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) ); |
402 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); | 405 | mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) ); |
403 | } | 406 | } |
404 | 407 | ||
405 | QIconViewItem::paintItem(p,mycg); | 408 | QIconViewItem::paintItem(p,mycg); |
406 | 409 | ||
407 | // Paint animation overlay | 410 | // Paint animation overlay |
408 | if ( liv->busyItem() == this ) | 411 | if ( liv->busyItem() == this ) |
409 | paintAnimatedIcon(p); | 412 | paintAnimatedIcon(p); |
410 | 413 | ||
411 | if ( liv->currentItem() == this ) | 414 | if ( liv->currentItem() == this ) |
412 | liv->setItemTextBackground( oldBrush ); | 415 | liv->setItemTextBackground( oldBrush ); |
413 | } | 416 | } |
414 | 417 | ||
415 | 418 | ||
416 | 419 | ||
417 | void LauncherItem::paintAnimatedIcon( QPainter *p ) | 420 | void LauncherItem::paintAnimatedIcon( QPainter *p ) |
418 | { | 421 | { |
419 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 422 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
420 | int pic = iteration % 16; | 423 | int pic = iteration % 16; |
421 | int w = pixmap()->width(), h = pixmap()->height(); | 424 | int w = pixmap()->width(), h = pixmap()->height(); |
422 | QPixmap dblBuf( w, h + 4 ); | 425 | QPixmap dblBuf( w, h + 4 ); |
423 | QPainter p2( &dblBuf ); | 426 | QPainter p2( &dblBuf ); |
424 | int x1, y1; | 427 | int x1, y1; |
425 | if ( liv->itemTextPos() == QIconView::Bottom ) { | 428 | if ( liv->itemTextPos() == QIconView::Bottom ) { |
426 | x1 = x() + (width() - w) / 2 - liv->contentsX(); | 429 | x1 = x() + (width() - w) / 2 - liv->contentsX(); |
427 | y1 = y() - liv->contentsY(); | 430 | y1 = y() - liv->contentsY(); |
428 | } else { | 431 | } else { |
429 | x1 = x() - liv->contentsX(); | 432 | x1 = x() - liv->contentsX(); |
430 | y1 = y() + (height() - h) / 2 - liv->contentsY(); | 433 | y1 = y() + (height() - h) / 2 - liv->contentsY(); |
431 | } | 434 | } |
432 | y1 -= 2; | 435 | y1 -= 2; |
433 | p2.translate(-x1,-y1); | 436 | p2.translate(-x1,-y1); |
434 | liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); | 437 | liv->drawBackground( &p2, QRect(x1,y1,w,h+4) ); |
435 | int bounceY = 2; | 438 | int bounceY = 2; |
436 | #ifdef BOUNCE_BUSY_ICON | 439 | #ifdef BOUNCE_BUSY_ICON |
437 | if ( busyType == BIT_Animated ) { | 440 | if ( busyType == BIT_Animated ) { |
438 | bounceY = 4 - ((iteration+2)%8); | 441 | bounceY = 4 - ((iteration+2)%8); |
439 | bounceY = bounceY < 0 ? -bounceY : bounceY; | 442 | bounceY = bounceY < 0 ? -bounceY : bounceY; |
440 | } | 443 | } |
441 | #endif | 444 | #endif |
442 | p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); | 445 | p2.drawPixmap( x1, y1 + bounceY, *pixmap() ); |
443 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY | 446 | #ifdef USE_ANIMATED_BUSY_ICON_OVERLAY |
444 | p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); | 447 | p2.drawPixmap( x1, y1 + bounceY, liv->busyPixmap(), w * pic, 0, w, h ); |
445 | #endif | 448 | #endif |
446 | p->drawPixmap( x1, y1, dblBuf ); | 449 | p->drawPixmap( x1, y1, dblBuf ); |
447 | } | 450 | } |
448 | 451 | ||
449 | void LauncherItem::animateIcon() | 452 | void LauncherItem::animateIcon() |
450 | { | 453 | { |
451 | LauncherIconView* liv = (LauncherIconView*)iconView(); | 454 | LauncherIconView* liv = (LauncherIconView*)iconView(); |
452 | 455 | ||
453 | if ( liv->busyItem() != this || !app ) | 456 | if ( liv->busyItem() != this || !app ) |
454 | return; | 457 | return; |
455 | 458 | ||
456 | // Highlight the icon | 459 | // Highlight the icon |
457 | if ( iteration == 0 ) { | 460 | if ( iteration == 0 ) { |
458 | QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); | 461 | QPixmap src = isBigIcon ? app->bigPixmap() : app->pixmap(); |
459 | QImage img = src.convertToImage(); | 462 | QImage img = src.convertToImage(); |
460 | QRgb *rgb; | 463 | QRgb *rgb; |
461 | int count; | 464 | int count; |
462 | if ( img.depth() == 32 ) { | 465 | if ( img.depth() == 32 ) { |
463 | rgb = (QRgb*)img.bits(); | 466 | rgb = (QRgb*)img.bits(); |
464 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); | 467 | count = img.bytesPerLine()/sizeof(QRgb)*img.height(); |
465 | } else { | 468 | } else { |
466 | rgb = img.colorTable(); | 469 | rgb = img.colorTable(); |
467 | count = img.numColors(); | 470 | count = img.numColors(); |
468 | } | 471 | } |
469 | for ( int r = 0; r < count; r++, rgb++ ) { | 472 | for ( int r = 0; r < count; r++, rgb++ ) { |
470 | #if defined(BRIGHTEN_BUSY_ICON) | 473 | #if defined(BRIGHTEN_BUSY_ICON) |
471 | QColor c(*rgb); | 474 | QColor c(*rgb); |
472 | int h, s, v; | 475 | int h, s, v; |
473 | c.hsv(&h,&s,&v); | 476 | c.hsv(&h,&s,&v); |
474 | c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); | 477 | c.setHsv(h,QMAX(s-24,0),QMIN(v+48,255)); |
475 | *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); | 478 | *rgb = qRgba(c.red(),c.green(),c.blue(),qAlpha(*rgb)); |
476 | #elif defined(ALPHA_FADE_BUSY_ICON) | 479 | #elif defined(ALPHA_FADE_BUSY_ICON) |
477 | *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); | 480 | *rgb = qRgba(qRed(*rgb),qGreen(*rgb),qBlue(*rgb),qAlpha(*rgb)/2); |
478 | #endif | 481 | #endif |
479 | } | 482 | } |
480 | src.convertFromImage( img ); | 483 | src.convertFromImage( img ); |
481 | setPixmap( src ); | 484 | setPixmap( src ); |
482 | } | 485 | } |
483 | 486 | ||
484 | iteration++; | 487 | iteration++; |
485 | 488 | ||
486 | // Paint animation overlay | 489 | // Paint animation overlay |
487 | QPainter p( liv->viewport() ); | 490 | QPainter p( liv->viewport() ); |
488 | paintAnimatedIcon( &p ); | 491 | paintAnimatedIcon( &p ); |
489 | } | 492 | } |
490 | 493 | ||
491 | void LauncherItem::resetIcon() | 494 | void LauncherItem::resetIcon() |
492 | { | 495 | { |
493 | iteration = 0; | 496 | iteration = 0; |
494 | setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); | 497 | setPixmap( isBigIcon ? app->bigPixmap() : app->pixmap() ); |
495 | } | 498 | } |
496 | 499 | ||
497 | //=========================================================================== | 500 | //=========================================================================== |
498 | 501 | ||
499 | QStringList LauncherIconView::mimeTypes() const | 502 | QStringList LauncherIconView::mimeTypes() const |
500 | { | 503 | { |
501 | QStringList r; | 504 | QStringList r; |
502 | QDictIterator<void> it(mimes); | 505 | QDictIterator<void> it(mimes); |
503 | while (it.current()) { | 506 | while (it.current()) { |
504 | r.append(it.currentKey()); | 507 | r.append(it.currentKey()); |
505 | ++it; | 508 | ++it; |
506 | } | 509 | } |
507 | r.sort(); | 510 | r.sort(); |
508 | return r; | 511 | return r; |
509 | } | 512 | } |
510 | 513 | ||
511 | void LauncherIconView::addItem(AppLnk* app, bool resort) | 514 | void LauncherIconView::addItem(AppLnk* app, bool resort) |
512 | { | 515 | { |
513 | addCatsAndMimes(app); | 516 | addCatsAndMimes(app); |
514 | 517 | ||
515 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) | 518 | if ( (tf.isEmpty() || tf.match(app->type()) >= 0) |
516 | && (cf == 0 || app->categories().contains(cf) | 519 | && (cf == 0 || app->categories().contains(cf) |
517 | || cf == -1 && app->categories().count() == 0 ) ) | 520 | || cf == -1 && app->categories().count() == 0 ) ) |
518 | (void) new LauncherItem( this, app, bigIcns ); | 521 | (void) new LauncherItem( this, app, bigIcns ); |
519 | else | 522 | else |
520 | hidden.append(app); | 523 | hidden.append(app); |
521 | if ( resort ) | 524 | if ( resort ) |
522 | sort(); | 525 | sort(); |
523 | } | 526 | } |
524 | 527 | ||
525 | void LauncherIconView::updateCategoriesAndMimeTypes() | 528 | void LauncherIconView::updateCategoriesAndMimeTypes() |
526 | { | 529 | { |
527 | mimes.clear(); | 530 | mimes.clear(); |
528 | cats.clear(); | 531 | cats.clear(); |
529 | LauncherItem* item = (LauncherItem*)firstItem(); | 532 | LauncherItem* item = (LauncherItem*)firstItem(); |
530 | while (item) { | 533 | while (item) { |
531 | addCatsAndMimes(item->appLnk()); | 534 | addCatsAndMimes(item->appLnk()); |
532 | item = (LauncherItem*)item->nextItem(); | 535 | item = (LauncherItem*)item->nextItem(); |
533 | } | 536 | } |
534 | QListIterator<AppLnk> it(hidden); | 537 | QListIterator<AppLnk> it(hidden); |
535 | AppLnk* l; | 538 | AppLnk* l; |
536 | while ((l=it.current())) { | 539 | while ((l=it.current())) { |
537 | addCatsAndMimes(l); | 540 | addCatsAndMimes(l); |
538 | ++it; | 541 | ++it; |
539 | } | 542 | } |
540 | } | 543 | } |
541 | 544 | ||
542 | void LauncherIconView::hideOrShowItems(bool resort) | 545 | void LauncherIconView::hideOrShowItems(bool resort) |
543 | { | 546 | { |
544 | viewport()->setUpdatesEnabled( FALSE ); | 547 | viewport()->setUpdatesEnabled( FALSE ); |
545 | hidden.setAutoDelete(FALSE); | 548 | hidden.setAutoDelete(FALSE); |
546 | QList<AppLnk> links=hidden; | 549 | QList<AppLnk> links=hidden; |
547 | hidden.clear(); | 550 | hidden.clear(); |
548 | hidden.setAutoDelete(TRUE); | 551 | hidden.setAutoDelete(TRUE); |
549 | LauncherItem* item = (LauncherItem*)firstItem(); | 552 | LauncherItem* item = (LauncherItem*)firstItem(); |
550 | while (item) { | 553 | while (item) { |
551 | links.append(item->takeAppLnk()); | 554 | links.append(item->takeAppLnk()); |
552 | item = (LauncherItem*)item->nextItem(); | 555 | item = (LauncherItem*)item->nextItem(); |
553 | } | 556 | } |
554 | clear(); | 557 | clear(); |
555 | QListIterator<AppLnk> it(links); | 558 | QListIterator<AppLnk> it(links); |
556 | AppLnk* l; | 559 | AppLnk* l; |
557 | while ((l=it.current())) { | 560 | while ((l=it.current())) { |
558 | addItem(l,FALSE); | 561 | addItem(l,FALSE); |
559 | ++it; | 562 | ++it; |
560 | } | 563 | } |
561 | if ( resort && !autoArrange() ) | 564 | if ( resort && !autoArrange() ) |
562 | sort(); | 565 | sort(); |
563 | viewport()->setUpdatesEnabled( TRUE ); | 566 | viewport()->setUpdatesEnabled( TRUE ); |
564 | } | 567 | } |
565 | 568 | ||
566 | bool LauncherIconView::removeLink(const QString& linkfile) | 569 | bool LauncherIconView::removeLink(const QString& linkfile) |
567 | { | 570 | { |
568 | LauncherItem* item = (LauncherItem*)firstItem(); | 571 | LauncherItem* item = (LauncherItem*)firstItem(); |
569 | AppLnk* l; | 572 | AppLnk* l; |
570 | bool did = FALSE; | 573 | bool did = FALSE; |
571 | DocLnk dl(linkfile); | 574 | DocLnk dl(linkfile); |
572 | while (item) { | 575 | while (item) { |
573 | l = item->appLnk(); | 576 | l = item->appLnk(); |
574 | LauncherItem *nextItem = (LauncherItem *)item->nextItem(); | 577 | LauncherItem *nextItem = (LauncherItem *)item->nextItem(); |
575 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 578 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
576 | || l->fileKnown() && ( | 579 | || l->fileKnown() && ( |
577 | l->file() == linkfile | 580 | l->file() == linkfile |
578 | || dl.isValid() && dl.file() == l->file() ) ) { | 581 | || dl.isValid() && dl.file() == l->file() ) ) { |
579 | delete item; | 582 | delete item; |
580 | did = TRUE; | 583 | did = TRUE; |
581 | } | 584 | } |
582 | item = nextItem; | 585 | item = nextItem; |
583 | } | 586 | } |
584 | QListIterator<AppLnk> it(hidden); | 587 | QListIterator<AppLnk> it(hidden); |
585 | while ((l=it.current())) { | 588 | while ((l=it.current())) { |
586 | ++it; | 589 | ++it; |
587 | if ( l->linkFileKnown() && l->linkFile() == linkfile | 590 | if ( l->linkFileKnown() && l->linkFile() == linkfile |
588 | || l->file() == linkfile | 591 | || l->file() == linkfile |
589 | || dl.isValid() && dl.file() == l->file() ) { | 592 | || dl.isValid() && dl.file() == l->file() ) { |
590 | hidden.removeRef(l); | 593 | hidden.removeRef(l); |
591 | did = TRUE; | 594 | did = TRUE; |
592 | } | 595 | } |
593 | } | 596 | } |
594 | return did; | 597 | return did; |
595 | } | 598 | } |
596 | 599 | ||
597 | //=========================================================================== | 600 | //=========================================================================== |
598 | 601 | ||
599 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) | 602 | LauncherView::LauncherView( QWidget* parent, const char* name, WFlags fl ) |
600 | : QVBox( parent, name, fl ) | 603 | : QVBox( parent, name, fl ) |
601 | { | 604 | { |
602 | catmb = 0; | 605 | catmb = 0; |
603 | icons = new LauncherIconView( this ); | 606 | icons = new LauncherIconView( this ); |
604 | setFocusProxy(icons); | 607 | setFocusProxy(icons); |
605 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); | 608 | QPEApplication::setStylusOperation( icons->viewport(), QPEApplication::RightOnHold ); |
606 | 609 | ||
607 | icons->setItemsMovable( FALSE ); | 610 | icons->setItemsMovable( FALSE ); |
608 | icons->setAutoArrange( TRUE ); | 611 | icons->setAutoArrange( TRUE ); |
609 | icons->setSorting( TRUE ); | 612 | icons->setSorting( TRUE ); |
610 | icons->setFrameStyle( QFrame::NoFrame ); | 613 | icons->setFrameStyle( QFrame::NoFrame ); |
611 | icons->setMargin( 0 ); | 614 | icons->setMargin( 0 ); |
612 | icons->setSelectionMode( QIconView::NoSelection ); | 615 | icons->setSelectionMode( QIconView::NoSelection ); |
613 | icons->setBackgroundMode( PaletteBase ); | 616 | icons->setBackgroundMode( PaletteBase ); |
614 | icons->setResizeMode( QIconView::Fixed ); | 617 | icons->setResizeMode( QIconView::Fixed ); |
615 | vmode = (ViewMode)-1; | 618 | vmode = (ViewMode)-1; |
616 | setViewMode( Icon ); | 619 | setViewMode( Icon ); |
617 | 620 | ||
618 | connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), | 621 | connect( icons, SIGNAL(mouseButtonClicked(int,QIconViewItem*,const QPoint&)), |
619 | SLOT(itemClicked(int,QIconViewItem*)) ); | 622 | SLOT(itemClicked(int,QIconViewItem*)) ); |
620 | connect( icons, SIGNAL(selectionChanged()), | 623 | connect( icons, SIGNAL(selectionChanged()), |
621 | SLOT(selectionChanged()) ); | 624 | SLOT(selectionChanged()) ); |
622 | connect( icons, SIGNAL(returnPressed(QIconViewItem*)), | 625 | connect( icons, SIGNAL(returnPressed(QIconViewItem*)), |
623 | SLOT(returnPressed(QIconViewItem*)) ); | 626 | SLOT(returnPressed(QIconViewItem*)) ); |
624 | connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), | 627 | connect( icons, SIGNAL(mouseButtonPressed(int,QIconViewItem*,const QPoint&)), |
625 | SLOT(itemPressed(int,QIconViewItem*)) ); | 628 | SLOT(itemPressed(int,QIconViewItem*)) ); |
626 | 629 | ||
627 | tools = 0; | 630 | tools = 0; |
628 | setBackgroundType( Ruled, QString::null ); | 631 | setBackgroundType( Ruled, QString::null ); |
629 | } | 632 | } |
630 | 633 | ||
631 | LauncherView::~LauncherView() | 634 | LauncherView::~LauncherView() |
632 | { | 635 | { |
633 | if ( bgCache && bgCache->contains( bgName ) ) | 636 | if ( bgCache && bgCache->contains( bgName ) ) |
634 | (*bgCache)[bgName]->ref--; | 637 | (*bgCache)[bgName]->ref--; |
635 | } | 638 | } |
636 | 639 | ||
637 | void LauncherView::hideIcons() | 640 | void LauncherView::hideIcons() |
638 | { | 641 | { |
639 | icons->hide(); | 642 | icons->hide(); |
640 | } | 643 | } |
641 | 644 | ||
642 | void LauncherView::setToolsEnabled(bool y) | 645 | void LauncherView::setToolsEnabled(bool y) |
643 | { | 646 | { |
644 | if ( !y != !tools ) { | 647 | if ( !y != !tools ) { |
645 | if ( y ) { | 648 | if ( y ) { |
646 | tools = new QHBox(this); | 649 | tools = new QHBox(this); |
647 | 650 | ||
648 | // Type filter | 651 | // Type filter |
649 | typemb = new QComboBox(tools); | 652 | typemb = new QComboBox(tools); |
650 | QSizePolicy p = typemb->sizePolicy(); | 653 | QSizePolicy p = typemb->sizePolicy(); |
651 | p.setHorData(QSizePolicy::Expanding); | 654 | p.setHorData(QSizePolicy::Expanding); |
652 | typemb->setSizePolicy(p); | 655 | typemb->setSizePolicy(p); |
653 | 656 | ||
654 | // Category filter | 657 | // Category filter |
655 | updateTools(); | 658 | updateTools(); |
656 | tools->show(); | 659 | tools->show(); |
657 | 660 | ||
658 | // Always show vscrollbar | 661 | // Always show vscrollbar |
659 | icons->setVScrollBarMode( QScrollView::AlwaysOn ); | 662 | icons->setVScrollBarMode( QScrollView::AlwaysOn ); |
660 | } else { | 663 | } else { |
661 | delete tools; | 664 | delete tools; |
662 | tools = 0; | 665 | tools = 0; |
663 | } | 666 | } |
664 | } | 667 | } |
665 | } | 668 | } |
666 | 669 | ||
667 | void LauncherView::updateTools() | 670 | void LauncherView::updateTools() |
668 | { | 671 | { |
669 | disconnect( typemb, SIGNAL(activated(int)), | 672 | disconnect( typemb, SIGNAL(activated(int)), |
670 | this, SLOT(showType(int)) ); | 673 | this, SLOT(showType(int)) ); |
671 | if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), | 674 | if ( catmb ) disconnect( catmb, SIGNAL(signalSelected(int)), |
672 | this, SLOT(showCategory(int)) ); | 675 | this, SLOT(showCategory(int)) ); |
673 | 676 | ||
674 | // ### I want to remove this | 677 | // ### I want to remove this |
675 | icons->updateCategoriesAndMimeTypes(); | 678 | icons->updateCategoriesAndMimeTypes(); |
676 | 679 | ||
677 | QString prev; | 680 | QString prev; |
678 | 681 | ||
679 | // Type filter | 682 | // Type filter |
680 | QStringList types; | 683 | QStringList types; |
681 | typelist = icons->mimeTypes(); | 684 | typelist = icons->mimeTypes(); |
682 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { | 685 | for (QStringList::ConstIterator it = typelist.begin(); it!=typelist.end(); ++it) { |
683 | QString t = *it; | 686 | QString t = *it; |
684 | if ( t.left(12) == "application/" ) { | 687 | if ( t.left(12) == "application/" ) { |
685 | MimeType mt(t); | 688 | MimeType mt(t); |
686 | const AppLnk* app = mt.application(); | 689 | const AppLnk* app = mt.application(); |
687 | if ( app ) | 690 | if ( app ) |
688 | t = app->name(); | 691 | t = app->name(); |
689 | else | 692 | else |
690 | t = t.mid(12); | 693 | t = t.mid(12); |
691 | } else { | 694 | } else { |
692 | t[0] = t[0].upper(); | 695 | t[0] = t[0].upper(); |
693 | } | 696 | } |
694 | types += t; | 697 | types += t; |
695 | } | 698 | } |
696 | types << tr("All types"); | 699 | types << tr("All types"); |
697 | prev = typemb->currentText(); | 700 | prev = typemb->currentText(); |
698 | typemb->clear(); | 701 | typemb->clear(); |
699 | typemb->insertStringList(types); | 702 | typemb->insertStringList(types); |
700 | for (int i=0; i<typemb->count(); i++) { | 703 | for (int i=0; i<typemb->count(); i++) { |
701 | if ( typemb->text(i) == prev ) { | 704 | if ( typemb->text(i) == prev ) { |
702 | typemb->setCurrentItem(i); | 705 | typemb->setCurrentItem(i); |
703 | break; | 706 | break; |
704 | } | 707 | } |
705 | } | 708 | } |
706 | if ( prev.isNull() ) | 709 | if ( prev.isNull() ) |
707 | typemb->setCurrentItem(typemb->count()-1); | 710 | typemb->setCurrentItem(typemb->count()-1); |
708 | 711 | ||
709 | int pcat = catmb ? catmb->currentCategory() : -2; | 712 | int pcat = catmb ? catmb->currentCategory() : -2; |
710 | if ( !catmb ) | 713 | if ( !catmb ) |
711 | catmb = new CategorySelect(tools); | 714 | catmb = new CategorySelect(tools); |
712 | Categories cats( 0 ); | 715 | Categories cats( 0 ); |
713 | cats.load( categoryFileName() ); | 716 | cats.load( categoryFileName() ); |
714 | QArray<int> vl( 0 ); | 717 | QArray<int> vl( 0 ); |
715 | catmb->setCategories( vl, "Document View", // No tr | 718 | catmb->setCategories( vl, "Document View", // No tr |
716 | tr("Document View") ); | 719 | tr("Document View") ); |
717 | catmb->setRemoveCategoryEdit( TRUE ); | 720 | catmb->setRemoveCategoryEdit( TRUE ); |
718 | catmb->setAllCategories( TRUE ); | 721 | catmb->setAllCategories( TRUE ); |
719 | catmb->setCurrentCategory(pcat); | 722 | catmb->setCurrentCategory(pcat); |
720 | 723 | ||
721 | // if type has changed we need to redisplay | 724 | // if type has changed we need to redisplay |
722 | if ( typemb->currentText() != prev ) | 725 | if ( typemb->currentText() != prev ) |
723 | showType( typemb->currentItem() ); | 726 | showType( typemb->currentItem() ); |
724 | 727 | ||
725 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); | 728 | connect(typemb, SIGNAL(activated(int)), this, SLOT(showType(int))); |
726 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); | 729 | connect(catmb, SIGNAL(signalSelected(int)), this, SLOT(showCategory(int))); |
727 | } | 730 | } |
728 | 731 | ||
729 | void LauncherView::sortBy(int s) | 732 | void LauncherView::sortBy(int s) |
730 | { | 733 | { |
731 | icons->setSortMethod((LauncherIconView::SortMethod)s); | 734 | icons->setSortMethod((LauncherIconView::SortMethod)s); |
732 | } | 735 | } |
733 | 736 | ||
734 | void LauncherView::showType(int t) | 737 | void LauncherView::showType(int t) |
735 | { | 738 | { |
736 | if ( t >= (int)typelist.count() ) { | 739 | if ( t >= (int)typelist.count() ) { |
737 | icons->setTypeFilter("",TRUE); | 740 | icons->setTypeFilter("",TRUE); |
738 | } else { | 741 | } else { |
739 | QString ty = typelist[t]; | 742 | QString ty = typelist[t]; |
740 | if ( !ty.contains('/') ) | 743 | if ( !ty.contains('/') ) |
741 | ty += "/*"; | 744 | ty += "/*"; |
742 | icons->setTypeFilter(ty,TRUE); | 745 | icons->setTypeFilter(ty,TRUE); |
743 | } | 746 | } |
744 | } | 747 | } |
745 | 748 | ||
746 | void LauncherView::showCategory( int c ) | 749 | void LauncherView::showCategory( int c ) |
747 | { | 750 | { |
748 | icons->setCategoryFilter( c, TRUE ); | 751 | icons->setCategoryFilter( c, TRUE ); |
749 | } | 752 | } |
750 | 753 | ||
751 | void LauncherView::setViewMode( ViewMode m ) | 754 | void LauncherView::setViewMode( ViewMode m ) |
752 | { | 755 | { |
753 | if ( vmode != m ) { | 756 | if ( vmode != m ) { |
754 | bool bigIcons = m == Icon; | 757 | bool bigIcons = m == Icon; |
755 | icons->viewport()->setUpdatesEnabled( FALSE ); | 758 | icons->viewport()->setUpdatesEnabled( FALSE ); |
756 | icons->setBigIcons( bigIcons ); | 759 | icons->setBigIcons( bigIcons ); |
757 | switch ( m ) { | 760 | switch ( m ) { |
758 | case List: | 761 | case List: |
759 | icons->setItemTextPos( QIconView::Right ); | 762 | icons->setItemTextPos( QIconView::Right ); |
760 | break; | 763 | break; |
761 | case Icon: | 764 | case Icon: |
762 | icons->setItemTextPos( QIconView::Bottom ); | 765 | icons->setItemTextPos( QIconView::Bottom ); |
763 | break; | 766 | break; |
764 | } | 767 | } |
765 | icons->hideOrShowItems( FALSE ); | 768 | icons->hideOrShowItems( FALSE ); |
766 | icons->viewport()->setUpdatesEnabled( TRUE ); | 769 | icons->viewport()->setUpdatesEnabled( TRUE ); |
767 | vmode = m; | 770 | vmode = m; |
768 | } | 771 | } |
769 | } | 772 | } |
770 | 773 | ||
771 | // | 774 | // |
772 | // User images may require scaling. | 775 | // User images may require scaling. |
773 | // | 776 | // |
774 | QImage LauncherView::loadBackgroundImage(QString &bgName) | 777 | QImage LauncherView::loadBackgroundImage(QString &bgName) |
775 | { | 778 | { |
776 | QImageIO imgio; | 779 | QImageIO imgio; |
777 | QSize ds = qApp->desktop()->size(); // should be launcher, not desktop | 780 | QSize ds = qApp->desktop()->size(); // should be launcher, not desktop |
778 | bool further_scaling = TRUE; | 781 | bool further_scaling = TRUE; |
779 | 782 | ||
780 | imgio.setFileName( bgName ); | 783 | imgio.setFileName( bgName ); |
781 | imgio.setParameters("GetHeaderInformation"); | 784 | imgio.setParameters("GetHeaderInformation"); |
782 | 785 | ||
783 | if (imgio.read() == FALSE) { | 786 | if (imgio.read() == FALSE) { |
784 | return imgio.image(); | 787 | return imgio.image(); |
785 | } | 788 | } |
786 | 789 | ||
787 | if (imgio.image().width() < ds.width() && | 790 | if (imgio.image().width() < ds.width() && |
788 | imgio.image().height() < ds.height()) { | 791 | imgio.image().height() < ds.height()) { |
789 | further_scaling = FALSE; | 792 | further_scaling = FALSE; |
790 | } | 793 | } |
791 | 794 | ||
792 | if (!imgio.image().bits()) { | 795 | if (!imgio.image().bits()) { |
793 | // | 796 | // |
794 | // Scale and load. Note we don't scale up. | 797 | // Scale and load. Note we don't scale up. |
795 | // | 798 | // |
796 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr | 799 | QString param( "Scale( %1, %2, ScaleMin )" ); // No tr |
797 | imgio.setParameters(further_scaling ? | 800 | imgio.setParameters(further_scaling ? |
798 | param.arg(ds.width()).arg(ds.height()).latin1() : | 801 | param.arg(ds.width()).arg(ds.height()).latin1() : |
799 | ""); | 802 | ""); |
800 | imgio.read(); | 803 | imgio.read(); |
801 | } else { | 804 | } else { |
802 | if (further_scaling) { | 805 | if (further_scaling) { |
803 | intt1 = imgio.image().width() * ds.height(); | 806 | intt1 = imgio.image().width() * ds.height(); |
804 | int t2 = imgio.image().height() * ds.width(); | 807 | int t2 = imgio.image().height() * ds.width(); |
805 | int dsth = ds.height(); | 808 | int dsth = ds.height(); |
806 | int dstw = ds.width(); | 809 | int dstw = ds.width(); |
807 | 810 | ||
808 | if (t1 > t2) { | 811 | if (t1 > t2) { |
809 | dsth = t2 / imgio.image().width(); | 812 | dsth = t2 / imgio.image().width(); |
810 | } else { | 813 | } else { |
811 | dstw = t1 / imgio.image().height(); | 814 | dstw = t1 / imgio.image().height(); |
812 | } | 815 | } |
813 | 816 | ||
814 | // | 817 | // |
815 | // Loader didn't scale for us. Do it manually. | 818 | // Loader didn't scale for us. Do it manually. |
816 | // | 819 | // |
817 | return imgio.image().smoothScale(dstw, dsth); | 820 | return imgio.image().smoothScale(dstw, dsth); |
818 | } | 821 | } |
819 | } | 822 | } |
820 | 823 | ||
821 | return imgio.image(); | 824 | return imgio.image(); |
822 | } | 825 | } |
823 | 826 | ||
824 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) | 827 | void LauncherView::setBackgroundType( BackgroundType t, const QString &val ) |
825 | { | 828 | { |
826 | if ( !bgCache ) { | 829 | if ( !bgCache ) { |
827 | bgCache = new QMap<QString,BgPixmap*>; | 830 | bgCache = new QMap<QString,BgPixmap*>; |
828 | qAddPostRoutine( cleanup_cache ); | 831 | qAddPostRoutine( cleanup_cache ); |
829 | } | 832 | } |
830 | 833 | ||
831 | if ( bgCache->contains( bgName ) ) | 834 | if ( bgCache->contains( bgName ) ) |
832 | (*bgCache)[bgName]->ref--; | 835 | (*bgCache)[bgName]->ref--; |
833 | bgName = ""; | 836 | bgName = ""; |
834 | 837 | ||
835 | QPixmap bg; | 838 | QPixmap bg; |
836 | 839 | ||
837 | switch ( t ) { | 840 | switch ( t ) { |
838 | case Ruled: { | 841 | case Ruled: { |
839 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr | 842 | bgName = QString("Ruled_%1").arg(colorGroup().background().name()); // No tr |
840 | if ( bgCache->contains( bgName ) ) { | 843 | if ( bgCache->contains( bgName ) ) { |
841 | (*bgCache)[bgName]->ref++; | 844 | (*bgCache)[bgName]->ref++; |
842 | bg = (*bgCache)[bgName]->pm; | 845 | bg = (*bgCache)[bgName]->pm; |
843 | } else { | 846 | } else { |
844 | bg.resize( width(), 9 ); | 847 | bg.resize( width(), 9 ); |
845 | QPainter painter( &bg ); | 848 | QPainter painter( &bg ); |
846 | for ( int i = 0; i < 3; i++ ) { | 849 | for ( int i = 0; i < 3; i++ ) { |
847 | painter.setPen( white ); | 850 | painter.setPen( white ); |
848 | painter.drawLine( 0, i*3, width()-1, i*3 ); | 851 | painter.drawLine( 0, i*3, width()-1, i*3 ); |
849 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); | 852 | painter.drawLine( 0, i*3+1, width()-1, i*3+1 ); |
850 | painter.setPen( colorGroup().background().light(105) ); | 853 | painter.setPen( colorGroup().background().light(105) ); |
851 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); | 854 | painter.drawLine( 0, i*3+2, width()-1, i*3+2 ); |
852 | } | 855 | } |
853 | painter.end(); | 856 | painter.end(); |
854 | bgCache->insert( bgName, new BgPixmap(bg) ); | 857 | bgCache->insert( bgName, new BgPixmap(bg) ); |
855 | } | 858 | } |
856 | break; | 859 | break; |
857 | } | 860 | } |
858 | 861 | ||
859 | case Image: | 862 | case Image: |
860 | if (!val.isEmpty()) { | 863 | if (!val.isEmpty()) { |
861 | bgName = val; | 864 | bgName = val; |
862 | if ( bgCache->contains( bgName ) ) { | 865 | if ( bgCache->contains( bgName ) ) { |
863 | (*bgCache)[bgName]->ref++; | 866 | (*bgCache)[bgName]->ref++; |
864 | bg = (*bgCache)[bgName]->pm; | 867 | bg = (*bgCache)[bgName]->pm; |
865 | } else { | 868 | } else { |
866 | QString imgFile = bgName; | 869 | QString imgFile = bgName; |
867 | bool tile = FALSE; | 870 | bool tile = FALSE; |
868 | if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { | 871 | if ( imgFile[0]!='/' || !QFile::exists(imgFile) ) { |
869 | imgFile = Resource::findPixmap( imgFile ); | 872 | imgFile = Resource::findPixmap( imgFile ); |
870 | tile = TRUE; | 873 | tile = TRUE; |
871 | } | 874 | } |
872 | QImage img = loadBackgroundImage(imgFile); | 875 | QImage img = loadBackgroundImage(imgFile); |
873 | 876 | ||
874 | 877 | ||
875 | if ( img.depth() == 1 ) | 878 | if ( img.depth() == 1 ) |
876 | img = img.convertDepth(8); | 879 | img = img.convertDepth(8); |
877 | img.setAlphaBuffer(FALSE); | 880 | img.setAlphaBuffer(FALSE); |
878 | bg.convertFromImage(img); | 881 | bg.convertFromImage(img); |
879 | bgCache->insert( bgName, new BgPixmap(bg) ); | 882 | bgCache->insert( bgName, new BgPixmap(bg) ); |
880 | } | 883 | } |
881 | } | 884 | } |
882 | break; | 885 | break; |
883 | 886 | ||
884 | case SolidColor: | 887 | case SolidColor: |
885 | default: | 888 | default: |
886 | break; | 889 | break; |
887 | } | 890 | } |
888 | 891 | ||
889 | const QObjectList *list = queryList( "QWidget", 0, FALSE ); | 892 | const QObjectList *list = queryList( "QWidget", 0, FALSE ); |
890 | QObject *obj; | 893 | QObject *obj; |
891 | for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { | 894 | for ( QObjectListIt it( *list ); (obj=it.current()); ++it ) { |
892 | if ( obj->isWidgetType() ) { | 895 | if ( obj->isWidgetType() ) { |
893 | QWidget *w = (QWidget*)obj; | 896 | QWidget *w = (QWidget*)obj; |
894 | w->setBackgroundPixmap( bg ); | 897 | w->setBackgroundPixmap( bg ); |
895 | if ( bgName.isEmpty() ) { | 898 | if ( bgName.isEmpty() ) { |
896 | // Solid Color | 899 | // Solid Color |
897 | if ( val.isEmpty() ) | 900 | if ( val.isEmpty() ) |
898 | w->setBackgroundColor( colorGroup().base() ); | 901 | w->setBackgroundColor( colorGroup().base() ); |
899 | else | 902 | else |
900 | w->setBackgroundColor( val ); | 903 | w->setBackgroundColor( val ); |
901 | } else { | 904 | } else { |
902 | // Ruled or Image pixmap | 905 | // Ruled or Image pixmap |
903 | w->setBackgroundOrigin( ParentOrigin ); | 906 | w->setBackgroundOrigin( ParentOrigin ); |
904 | } | 907 | } |
905 | } | 908 | } |
906 | } | 909 | } |
907 | delete list; | 910 | delete list; |
908 | 911 | ||
909 | bgType = t; | 912 | bgType = t; |
910 | icons->viewport()->update(); | 913 | icons->viewport()->update(); |
911 | 914 | ||
912 | QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); | 915 | QTimer::singleShot( 1000, this, SLOT(flushBgCache()) ); |
913 | } | 916 | } |
914 | 917 | ||
915 | void LauncherView::setTextColor( const QColor &tc ) | 918 | void LauncherView::setTextColor( const QColor &tc ) |
916 | { | 919 | { |
917 | textCol = tc; | 920 | textCol = tc; |
918 | QColorGroup cg = icons->colorGroup(); | 921 | QColorGroup cg = icons->colorGroup(); |
919 | cg.setColor( QColorGroup::Text, tc ); | 922 | cg.setColor( QColorGroup::Text, tc ); |
920 | icons->setPalette( QPalette(cg,cg,cg) ); | 923 | icons->setPalette( QPalette(cg,cg,cg) ); |
921 | icons->viewport()->update(); | 924 | icons->viewport()->update(); |
922 | } | 925 | } |
923 | 926 | ||
924 | void LauncherView::setViewFont( const QFont &f ) | 927 | void LauncherView::setViewFont( const QFont &f ) |
925 | { | 928 | { |
926 | icons->setFont( f ); | 929 | icons->setFont( f ); |
927 | icons->hideOrShowItems( FALSE ); | 930 | icons->hideOrShowItems( FALSE ); |
928 | } | 931 | } |
929 | 932 | ||
930 | void LauncherView::clearViewFont() | 933 | void LauncherView::clearViewFont() |
931 | { | 934 | { |
932 | icons->unsetFont(); | 935 | icons->unsetFont(); |
933 | icons->hideOrShowItems( FALSE ); | 936 | icons->hideOrShowItems( FALSE ); |
934 | } | 937 | } |
935 | 938 | ||
936 | void LauncherView::resizeEvent(QResizeEvent *e) | 939 | void LauncherView::resizeEvent(QResizeEvent *e) |
937 | { | 940 | { |
938 | QVBox::resizeEvent( e ); | 941 | QVBox::resizeEvent( e ); |
939 | if ( e->size().width() != e->oldSize().width() ) | 942 | if ( e->size().width() != e->oldSize().width() ) |
940 | sort(); | 943 | sort(); |
941 | } | 944 | } |
942 | 945 | ||
943 | void LauncherView::selectionChanged() | 946 | void LauncherView::selectionChanged() |
944 | { | 947 | { |
945 | QIconViewItem* item = icons->currentItem(); | 948 | QIconViewItem* item = icons->currentItem(); |
946 | if ( item && item->isSelected() ) { | 949 | if ( item && item->isSelected() ) { |
947 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 950 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
948 | if ( icons->inKeyEvent() ) // not for mouse press | 951 | if ( icons->inKeyEvent() ) // not for mouse press |
949 | emit clicked( appLnk ); | 952 | emit clicked( appLnk ); |
950 | item->setSelected(FALSE); | 953 | item->setSelected(FALSE); |
951 | } | 954 | } |
952 | } | 955 | } |
953 | 956 | ||
954 | void LauncherView::returnPressed( QIconViewItem *item ) | 957 | void LauncherView::returnPressed( QIconViewItem *item ) |
955 | { | 958 | { |
956 | if ( item ) { | 959 | if ( item ) { |
957 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 960 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
958 | emit clicked( appLnk ); | 961 | emit clicked( appLnk ); |
959 | } | 962 | } |
960 | } | 963 | } |
961 | 964 | ||
962 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) | 965 | void LauncherView::itemClicked( int btn, QIconViewItem *item ) |
963 | { | 966 | { |
964 | if ( item ) { | 967 | if ( item ) { |
965 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 968 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
966 | if ( btn == LeftButton ) { | 969 | if ( btn == LeftButton ) { |
967 | // Make sure it's the item we execute that gets highlighted | 970 | // Make sure it's the item we execute that gets highlighted |
968 | icons->setCurrentItem( item ); | 971 | icons->setCurrentItem( item ); |
969 | emit clicked( appLnk ); | 972 | emit clicked( appLnk ); |
970 | } | 973 | } |
971 | item->setSelected(FALSE); | 974 | item->setSelected(FALSE); |
972 | } | 975 | } |
973 | } | 976 | } |
974 | 977 | ||
975 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) | 978 | void LauncherView::itemPressed( int btn, QIconViewItem *item ) |
976 | { | 979 | { |
977 | if ( item ) { | 980 | if ( item ) { |
978 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); | 981 | AppLnk *appLnk = ((LauncherItem *)item)->appLnk(); |
979 | if ( btn == RightButton ) | 982 | if ( btn == RightButton ) |
980 | emit rightPressed( appLnk ); | 983 | emit rightPressed( appLnk ); |
981 | else if ( btn == ShiftButton ) | 984 | else if ( btn == ShiftButton ) |
982 | emit rightPressed( appLnk ); | 985 | emit rightPressed( appLnk ); |
983 | item->setSelected(FALSE); | 986 | item->setSelected(FALSE); |
984 | } | 987 | } |
985 | } | 988 | } |
986 | 989 | ||
987 | void LauncherView::removeAllItems() | 990 | void LauncherView::removeAllItems() |
988 | { | 991 | { |
989 | icons->clear(); | 992 | icons->clear(); |
990 | } | 993 | } |
991 | 994 | ||
992 | bool LauncherView::removeLink(const QString& linkfile) | 995 | bool LauncherView::removeLink(const QString& linkfile) |
993 | { | 996 | { |
994 | return icons->removeLink(linkfile); | 997 | return icons->removeLink(linkfile); |
995 | } | 998 | } |
996 | 999 | ||
997 | void LauncherView::setSortEnabled( bool v ) | 1000 | void LauncherView::setSortEnabled( bool v ) |
998 | { | 1001 | { |
999 | icons->setSorting( v ); | 1002 | icons->setSorting( v ); |
1000 | if ( v ) | 1003 | if ( v ) |
1001 | sort(); | 1004 | sort(); |
1002 | } | 1005 | } |
1003 | 1006 | ||
1004 | void LauncherView::setUpdatesEnabled( bool u ) | 1007 | void LauncherView::setUpdatesEnabled( bool u ) |
1005 | { | 1008 | { |
1006 | icons->setUpdatesEnabled( u ); | 1009 | icons->setUpdatesEnabled( u ); |
1007 | } | 1010 | } |
1008 | 1011 | ||
1009 | void LauncherView::sort() | 1012 | void LauncherView::sort() |
1010 | { | 1013 | { |
1011 | icons->sort(); | 1014 | icons->sort(); |
1012 | } | 1015 | } |
1013 | 1016 | ||
1014 | void LauncherView::addItem(AppLnk* app, bool resort) | 1017 | void LauncherView::addItem(AppLnk* app, bool resort) |
1015 | { | 1018 | { |
1016 | icons->addItem(app,resort); | 1019 | icons->addItem(app,resort); |
1017 | } | 1020 | } |
1018 | 1021 | ||
1019 | void LauncherView::paletteChange( const QPalette &p ) | 1022 | void LauncherView::paletteChange( const QPalette &p ) |
1020 | { | 1023 | { |
1021 | icons->unsetPalette(); | 1024 | icons->unsetPalette(); |
1022 | QVBox::paletteChange( p ); | 1025 | QVBox::paletteChange( p ); |
1023 | if ( bgType == Ruled ) | 1026 | if ( bgType == Ruled ) |
1024 | setBackgroundType( Ruled, QString::null ); | 1027 | setBackgroundType( Ruled, QString::null ); |
1025 | QColorGroup cg = icons->colorGroup(); | 1028 | QColorGroup cg = icons->colorGroup(); |
1026 | cg.setColor( QColorGroup::Text, textCol ); | 1029 | cg.setColor( QColorGroup::Text, textCol ); |
1027 | icons->setPalette( QPalette(cg,cg,cg) ); | 1030 | icons->setPalette( QPalette(cg,cg,cg) ); |
1028 | } | 1031 | } |
1029 | 1032 | ||
1030 | void LauncherView::fontChanged(const QFont&) | 1033 | void LauncherView::fontChanged(const QFont&) |
1031 | { | 1034 | { |
1032 | qDebug("LauncherView::fontChanged()"); | 1035 | odebug << "LauncherView::fontChanged()" << oendl; |
1033 | icons->hideOrShowItems( FALSE ); | 1036 | icons->hideOrShowItems( FALSE ); |
1034 | } | 1037 | } |
1035 | 1038 | ||
1036 | void LauncherView::relayout(void) | 1039 | void LauncherView::relayout(void) |
1037 | { | 1040 | { |
1038 | icons->hideOrShowItems(FALSE); | 1041 | icons->hideOrShowItems(FALSE); |
1039 | } | 1042 | } |
1040 | 1043 | ||
1041 | void LauncherView::flushBgCache() | 1044 | void LauncherView::flushBgCache() |
1042 | { | 1045 | { |
1043 | if ( !bgCache ) | 1046 | if ( !bgCache ) |
1044 | return; | 1047 | return; |
1045 | // remove unreferenced backgrounds. | 1048 | // remove unreferenced backgrounds. |
1046 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); | 1049 | QMap<QString,BgPixmap*>::Iterator it = bgCache->begin(); |
1047 | while ( it != bgCache->end() ) { | 1050 | while ( it != bgCache->end() ) { |
1048 | QMap<QString,BgPixmap*>::Iterator curr = it; | 1051 | QMap<QString,BgPixmap*>::Iterator curr = it; |
1049 | ++it; | 1052 | ++it; |
1050 | if ( (*curr)->ref == 0 ) { | 1053 | if ( (*curr)->ref == 0 ) { |
1051 | delete (*curr); | 1054 | delete (*curr); |
1052 | bgCache->remove( curr ); | 1055 | bgCache->remove( curr ); |
1053 | } | 1056 | } |
1054 | } | 1057 | } |
1055 | } | 1058 | } |
1056 | 1059 | ||
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp index 3e7e0d2..a86aca6 100644 --- a/core/launcher/main.cpp +++ b/core/launcher/main.cpp | |||
@@ -1,352 +1,346 @@ | |||
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_FILEOPERATIONS | 21 | #ifndef QTOPIA_INTERNAL_FILEOPERATIONS |
22 | #define QTOPIA_INTERNAL_FILEOPERATIONS | 22 | #define QTOPIA_INTERNAL_FILEOPERATIONS |
23 | #endif | 23 | #endif |
24 | #ifdef QT_QWS_LOGIN | ||
25 | #include "../login/qdmdialogimpl.h" | ||
26 | #endif | ||
27 | #include "calibrate.h" | ||
24 | #include "server.h" | 28 | #include "server.h" |
25 | #include "serverapp.h" | 29 | #include "serverapp.h" |
26 | #include "stabmon.h" | 30 | #include "stabmon.h" |
27 | #include "firstuse.h" | 31 | #include "firstuse.h" |
28 | 32 | ||
33 | /* OPIE */ | ||
34 | #include <opie2/odebug.h> | ||
35 | #include <opie2/odevice.h> | ||
29 | #include <opie2/oglobal.h> | 36 | #include <opie2/oglobal.h> |
30 | |||
31 | #include <qtopia/network.h> | 37 | #include <qtopia/network.h> |
32 | //#include <qtopia/custom.h> | 38 | #include <qtopia/alarmserver.h> |
33 | 39 | using namespace Opie::Core; | |
34 | 40 | ||
41 | /* QT */ | ||
35 | #include <qdir.h> | 42 | #include <qdir.h> |
43 | #include <qmessagebox.h> | ||
36 | #ifdef QWS | 44 | #ifdef QWS |
37 | #include <qwindowsystem_qws.h> | 45 | #include <qwindowsystem_qws.h> |
38 | #include <qtopia/qcopenvelope_qws.h> | 46 | #include <qtopia/qcopenvelope_qws.h> |
39 | #endif | 47 | #endif |
40 | #include <qtopia/alarmserver.h> | 48 | #ifdef Q_WS_QWS |
49 | #include <qkeyboard_qws.h> | ||
50 | #endif | ||
41 | 51 | ||
52 | /* STD */ | ||
42 | #include <stdlib.h> | 53 | #include <stdlib.h> |
43 | #include <stdio.h> | 54 | #include <stdio.h> |
44 | #include <signal.h> | 55 | #include <signal.h> |
45 | #ifndef Q_OS_WIN32 | 56 | #ifndef Q_OS_WIN32 |
46 | #include <unistd.h> | 57 | #include <unistd.h> |
47 | #else | 58 | #else |
48 | #include <process.h> | 59 | #include <process.h> |
49 | #endif | 60 | #endif |
50 | 61 | ||
51 | #include "calibrate.h" | ||
52 | |||
53 | |||
54 | #ifdef QT_QWS_LOGIN | ||
55 | #include "../login/qdmdialogimpl.h" | ||
56 | #endif | ||
57 | |||
58 | #ifdef Q_WS_QWS | ||
59 | #include <qkeyboard_qws.h> | ||
60 | #endif | ||
61 | |||
62 | #include <qmessagebox.h> | ||
63 | #include <opie2/odevice.h> | ||
64 | |||
65 | using namespace Opie::Core; | ||
66 | |||
67 | |||
68 | static void cleanup() | 62 | static void cleanup() |
69 | { | 63 | { |
70 | QDir dir( "/tmp", "qcop-msg-*" ); | 64 | QDir dir( "/tmp", "qcop-msg-*" ); |
71 | 65 | ||
72 | QStringList stale = dir.entryList(); | 66 | QStringList stale = dir.entryList(); |
73 | QStringList::Iterator it; | 67 | QStringList::Iterator it; |
74 | for ( it = stale.begin(); it != stale.end(); ++it ) { | 68 | for ( it = stale.begin(); it != stale.end(); ++it ) { |
75 | dir.remove( *it ); | 69 | dir.remove( *it ); |
76 | } | 70 | } |
77 | } | 71 | } |
78 | 72 | ||
79 | static void refreshTimeZoneConfig() | 73 | static void refreshTimeZoneConfig() |
80 | { | 74 | { |
81 | /* ### FIXME timezone handling */ | 75 | /* ### FIXME timezone handling */ |
82 | #if 0 | 76 | #if 0 |
83 | // We need to help WorldTime in setting up its configuration for | 77 | // We need to help WorldTime in setting up its configuration for |
84 | // the current translation | 78 | // the current translation |
85 | // BEGIN no tr | 79 | // BEGIN no tr |
86 | const char *defaultTz[] = { | 80 | const char *defaultTz[] = { |
87 | "America/New_York", | 81 | "America/New_York", |
88 | "America/Los_Angeles", | 82 | "America/Los_Angeles", |
89 | "Europe/Oslo", | 83 | "Europe/Oslo", |
90 | "Asia/Tokyo", | 84 | "Asia/Tokyo", |
91 | "Asia/Hong_Kong", | 85 | "Asia/Hong_Kong", |
92 | "Australia/Brisbane", | 86 | "Australia/Brisbane", |
93 | 0 | 87 | 0 |
94 | }; | 88 | }; |
95 | // END no tr | 89 | // END no tr |
96 | 90 | ||
97 | TimeZone curZone; | 91 | TimeZone curZone; |
98 | QString zoneID; | 92 | QString zoneID; |
99 | int zoneIndex; | 93 | int zoneIndex; |
100 | Config cfg = Config( "WorldTime" ); | 94 | Config cfg = Config( "WorldTime" ); |
101 | cfg.setGroup( "TimeZones" ); | 95 | cfg.setGroup( "TimeZones" ); |
102 | if (!cfg.hasKey( "Zone0" )){ | 96 | if (!cfg.hasKey( "Zone0" )){ |
103 | // We have no existing timezones use the defaults which are untranslated strings | 97 | // We have no existing timezones use the defaults which are untranslated strings |
104 | QString currTz = TimeZone::current().id(); | 98 | QString currTz = TimeZone::current().id(); |
105 | QStringList zoneDefaults; | 99 | QStringList zoneDefaults; |
106 | zoneDefaults.append( currTz ); | 100 | zoneDefaults.append( currTz ); |
107 | for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { | 101 | for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { |
108 | if ( defaultTz[i] != currTz ) | 102 | if ( defaultTz[i] != currTz ) |
109 | zoneDefaults.append( defaultTz[i] ); | 103 | zoneDefaults.append( defaultTz[i] ); |
110 | } | 104 | } |
111 | zoneIndex = 0; | 105 | zoneIndex = 0; |
112 | for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ | 106 | for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ |
113 | cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it); | 107 | cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it); |
114 | zoneIndex++; | 108 | zoneIndex++; |
115 | } | 109 | } |
116 | } | 110 | } |
117 | // We have an existing list of timezones refresh the | 111 | // We have an existing list of timezones refresh the |
118 | // translations of TimeZone name | 112 | // translations of TimeZone name |
119 | zoneIndex = 0; | 113 | zoneIndex = 0; |
120 | while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){ | 114 | while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){ |
121 | zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex )); | 115 | zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex )); |
122 | curZone = TimeZone( zoneID ); | 116 | curZone = TimeZone( zoneID ); |
123 | if ( !curZone.isValid() ){ | 117 | if ( !curZone.isValid() ){ |
124 | qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() ); | 118 | odebug << "initEnvironment() Invalid TimeZone " << zoneID << "" << oendl; |
125 | break; | 119 | break; |
126 | } | 120 | } |
127 | cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() ); | 121 | cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() ); |
128 | zoneIndex++; | 122 | zoneIndex++; |
129 | } | 123 | } |
130 | #endif | 124 | #endif |
131 | } | 125 | } |
132 | 126 | ||
133 | void initEnvironment() | 127 | void initEnvironment() |
134 | { | 128 | { |
135 | #ifdef Q_OS_WIN32 | 129 | #ifdef Q_OS_WIN32 |
136 | // Config file requires HOME dir which uses QDir which needs the winver | 130 | // Config file requires HOME dir which uses QDir which needs the winver |
137 | qt_init_winver(); | 131 | qt_init_winver(); |
138 | #endif | 132 | #endif |
139 | Config config("locale"); | 133 | Config config("locale"); |
140 | config.setGroup( "Location" ); | 134 | config.setGroup( "Location" ); |
141 | QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); | 135 | QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); |
142 | 136 | ||
143 | // if not timezone set, pick New York | 137 | // if not timezone set, pick New York |
144 | if (tz.isNull() || tz.isEmpty()) | 138 | if (tz.isNull() || tz.isEmpty()) |
145 | tz = "America/New_York"; | 139 | tz = "America/New_York"; |
146 | 140 | ||
147 | setenv( "TZ", tz, 1 ); | 141 | setenv( "TZ", tz, 1 ); |
148 | config.writeEntry( "Timezone", tz); | 142 | config.writeEntry( "Timezone", tz); |
149 | 143 | ||
150 | config.setGroup( "Language" ); | 144 | config.setGroup( "Language" ); |
151 | QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); | 145 | QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); |
152 | if( lang.isNull() || lang.isEmpty()) | 146 | if( lang.isNull() || lang.isEmpty()) |
153 | lang = "en_US"; | 147 | lang = "en_US"; |
154 | 148 | ||
155 | setenv( "LANG", lang, 1 ); | 149 | setenv( "LANG", lang, 1 ); |
156 | config.writeEntry("Language", lang); | 150 | config.writeEntry("Language", lang); |
157 | config.write(); | 151 | config.write(); |
158 | 152 | ||
159 | #if 0 | 153 | #if 0 |
160 | setenv( "QWS_SIZE", "240x320", 0 ); | 154 | setenv( "QWS_SIZE", "240x320", 0 ); |
161 | #endif | 155 | #endif |
162 | 156 | ||
163 | 157 | ||
164 | 158 | ||
165 | QString env(getenv("QWS_DISPLAY")); | 159 | QString env(getenv("QWS_DISPLAY")); |
166 | if (env.contains("Transformed")) { | 160 | if (env.contains("Transformed")) { |
167 | int rot; | 161 | int rot; |
168 | // transformed driver default rotation is controlled by the hardware. | 162 | // transformed driver default rotation is controlled by the hardware. |
169 | Config config("qpe"); | 163 | Config config("qpe"); |
170 | config.setGroup( "Rotation" ); | 164 | config.setGroup( "Rotation" ); |
171 | if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) | 165 | if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) |
172 | rot = ODevice::inst ( )-> rotation ( ) * 90; | 166 | rot = ODevice::inst ( )-> rotation ( ) * 90; |
173 | 167 | ||
174 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); | 168 | setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); |
175 | QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ | 169 | QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ |
176 | } | 170 | } |
177 | } | 171 | } |
178 | 172 | ||
179 | static void initKeyboard() | 173 | static void initKeyboard() |
180 | { | 174 | { |
181 | Config config("qpe"); | 175 | Config config("qpe"); |
182 | 176 | ||
183 | config.setGroup( "Keyboard" ); | 177 | config.setGroup( "Keyboard" ); |
184 | 178 | ||
185 | int ard = config.readNumEntry( "RepeatDelay" ); | 179 | int ard = config.readNumEntry( "RepeatDelay" ); |
186 | int arp = config.readNumEntry( "RepeatPeriod" ); | 180 | int arp = config.readNumEntry( "RepeatPeriod" ); |
187 | if ( ard > 0 && arp > 0 ) | 181 | if ( ard > 0 && arp > 0 ) |
188 | qwsSetKeyboardAutoRepeat( ard, arp ); | 182 | qwsSetKeyboardAutoRepeat( ard, arp ); |
189 | 183 | ||
190 | QString layout = config.readEntry( "Layout", "us101" ); | 184 | QString layout = config.readEntry( "Layout", "us101" ); |
191 | Server::setKeyboardLayout( layout ); | 185 | Server::setKeyboardLayout( layout ); |
192 | } | 186 | } |
193 | 187 | ||
194 | static bool firstUse() | 188 | static bool firstUse() |
195 | { | 189 | { |
196 | bool needFirstUse = FALSE; | 190 | bool needFirstUse = FALSE; |
197 | if ( QWSServer::mouseHandler() && | 191 | if ( QWSServer::mouseHandler() && |
198 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { | 192 | QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { |
199 | if ( !QFile::exists( "/etc/pointercal" ) ) | 193 | if ( !QFile::exists( "/etc/pointercal" ) ) |
200 | needFirstUse = TRUE; | 194 | needFirstUse = TRUE; |
201 | } | 195 | } |
202 | 196 | ||
203 | { | 197 | { |
204 | Config config( "qpe" ); | 198 | Config config( "qpe" ); |
205 | config.setGroup( "Startup" ); | 199 | config.setGroup( "Startup" ); |
206 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); | 200 | needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); |
207 | } | 201 | } |
208 | 202 | ||
209 | if ( !needFirstUse ) | 203 | if ( !needFirstUse ) |
210 | return FALSE; | 204 | return FALSE; |
211 | 205 | ||
212 | FirstUse *fu = new FirstUse(); | 206 | FirstUse *fu = new FirstUse(); |
213 | fu->exec(); | 207 | fu->exec(); |
214 | bool rs = fu->restartNeeded(); | 208 | bool rs = fu->restartNeeded(); |
215 | delete fu; | 209 | delete fu; |
216 | return rs; | 210 | return rs; |
217 | } | 211 | } |
218 | 212 | ||
219 | int initApplication( int argc, char ** argv ) | 213 | int initApplication( int argc, char ** argv ) |
220 | { | 214 | { |
221 | cleanup(); | 215 | cleanup(); |
222 | 216 | ||
223 | 217 | ||
224 | initEnvironment(); | 218 | initEnvironment(); |
225 | 219 | ||
226 | //Don't flicker at startup: | 220 | //Don't flicker at startup: |
227 | #ifdef QWS | 221 | #ifdef QWS |
228 | QWSServer::setDesktopBackground( QImage() ); | 222 | QWSServer::setDesktopBackground( QImage() ); |
229 | #endif | 223 | #endif |
230 | ServerApplication a( argc, argv, QApplication::GuiServer ); | 224 | ServerApplication a( argc, argv, QApplication::GuiServer ); |
231 | 225 | ||
232 | refreshTimeZoneConfig(); | 226 | refreshTimeZoneConfig(); |
233 | 227 | ||
234 | initKeyboard(); | 228 | initKeyboard(); |
235 | 229 | ||
236 | // Don't use first use under Windows | 230 | // Don't use first use under Windows |
237 | if ( firstUse() ) { | 231 | if ( firstUse() ) { |
238 | a.restart(); | 232 | a.restart(); |
239 | return 0; | 233 | return 0; |
240 | } | 234 | } |
241 | 235 | ||
242 | ODevice::inst ( )-> setSoftSuspend ( true ); | 236 | ODevice::inst ( )-> setSoftSuspend ( true ); |
243 | 237 | ||
244 | { | 238 | { |
245 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); | 239 | QCopEnvelope e("QPE/System", "setBacklight(int)" ); |
246 | e << -3; // Forced on | 240 | e << -3; // Forced on |
247 | } | 241 | } |
248 | 242 | ||
249 | AlarmServer::initialize(); | 243 | AlarmServer::initialize(); |
250 | 244 | ||
251 | 245 | ||
252 | 246 | ||
253 | Server *s = new Server(); | 247 | Server *s = new Server(); |
254 | 248 | ||
255 | (void)new SysFileMonitor(s); | 249 | (void)new SysFileMonitor(s); |
256 | #ifdef QWS | 250 | #ifdef QWS |
257 | Network::createServer(s); | 251 | Network::createServer(s); |
258 | #endif | 252 | #endif |
259 | 253 | ||
260 | s->show(); | 254 | s->show(); |
261 | 255 | ||
262 | /* THE ARM rtc has problem holdings the time on reset */ | 256 | /* THE ARM rtc has problem holdings the time on reset */ |
263 | if ( QDate::currentDate ( ). year ( ) < 2000 ) { | 257 | if ( QDate::currentDate ( ). year ( ) < 2000 ) { |
264 | if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 258 | if ( QMessageBox::information ( 0, ServerApplication::tr( "Information" ), ServerApplication::tr( "<p>The system date doesn't seem to be valid.\n(%1)</p><p>Do you want to correct the clock ?</p>" ). arg( TimeString::dateString ( QDate::currentDate ( ))), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
265 | QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); | 259 | QCopEnvelope e ( "QPE/Application/systemtime", "setDocument(QString)" ); |
266 | e << QString ( ); | 260 | e << QString ( ); |
267 | } | 261 | } |
268 | } | 262 | } |
269 | 263 | ||
270 | int rv = a.exec(); | 264 | int rv = a.exec(); |
271 | 265 | ||
272 | qDebug("exiting..."); | 266 | odebug << "exiting..." << oendl; |
273 | delete s; | 267 | delete s; |
274 | 268 | ||
275 | #ifndef Q_OS_MACX | 269 | #ifndef Q_OS_MACX |
276 | ODevice::inst()->setSoftSuspend( false ); | 270 | ODevice::inst()->setSoftSuspend( false ); |
277 | #endif | 271 | #endif |
278 | 272 | ||
279 | return rv; | 273 | return rv; |
280 | } | 274 | } |
281 | 275 | ||
282 | static const char *pidfile_path = "/var/run/opie.pid"; | 276 | static const char *pidfile_path = "/var/run/opie.pid"; |
283 | 277 | ||
284 | void create_pidfile ( ) | 278 | void create_pidfile ( ) |
285 | { | 279 | { |
286 | FILE *f; | 280 | FILE *f; |
287 | 281 | ||
288 | if (( f = ::fopen ( pidfile_path, "w" ))) { | 282 | if (( f = ::fopen ( pidfile_path, "w" ))) { |
289 | ::fprintf ( f, "%d", getpid ( )); | 283 | ::fprintf ( f, "%d", getpid ( )); |
290 | ::fclose ( f ); | 284 | ::fclose ( f ); |
291 | } | 285 | } |
292 | } | 286 | } |
293 | 287 | ||
294 | void remove_pidfile ( ) | 288 | void remove_pidfile ( ) |
295 | { | 289 | { |
296 | ::unlink ( pidfile_path ); | 290 | ::unlink ( pidfile_path ); |
297 | } | 291 | } |
298 | 292 | ||
299 | void handle_sigterm ( int /* sig */ ) | 293 | void handle_sigterm ( int /* sig */ ) |
300 | { | 294 | { |
301 | if ( qApp ) | 295 | if ( qApp ) |
302 | qApp-> quit ( ); | 296 | qApp-> quit ( ); |
303 | } | 297 | } |
304 | 298 | ||
305 | #ifndef Q_OS_WIN32 | 299 | #ifndef Q_OS_WIN32 |
306 | int main( int argc, char ** argv ) | 300 | int main( int argc, char ** argv ) |
307 | { | 301 | { |
308 | 302 | ||
309 | ::signal ( SIGCHLD, SIG_IGN ); | 303 | ::signal ( SIGCHLD, SIG_IGN ); |
310 | 304 | ||
311 | ::signal ( SIGTERM, handle_sigterm ); | 305 | ::signal ( SIGTERM, handle_sigterm ); |
312 | ::signal ( SIGINT, handle_sigterm ); | 306 | ::signal ( SIGINT, handle_sigterm ); |
313 | 307 | ||
314 | ::setsid ( ); | 308 | ::setsid ( ); |
315 | ::setpgid ( 0, 0 ); | 309 | ::setpgid ( 0, 0 ); |
316 | 310 | ||
317 | ::atexit ( remove_pidfile ); | 311 | ::atexit ( remove_pidfile ); |
318 | create_pidfile ( ); | 312 | create_pidfile ( ); |
319 | 313 | ||
320 | int retVal = initApplication( argc, argv ); | 314 | int retVal = initApplication( argc, argv ); |
321 | 315 | ||
322 | // Have we been asked to restart? | 316 | // Have we been asked to restart? |
323 | if ( ServerApplication::doRestart ) { | 317 | if ( ServerApplication::doRestart ) { |
324 | for ( int fd = 3; fd < 100; fd++ ) | 318 | for ( int fd = 3; fd < 100; fd++ ) |
325 | close( fd ); | 319 | close( fd ); |
326 | 320 | ||
327 | execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); | 321 | execl( (QPEApplication::qpeDir()+"bin/qpe").latin1(), "qpe", 0 ); |
328 | } | 322 | } |
329 | 323 | ||
330 | // Kill them. Kill them all. | 324 | // Kill them. Kill them all. |
331 | ::kill ( 0, SIGTERM ); | 325 | ::kill ( 0, SIGTERM ); |
332 | ::sleep ( 1 ); | 326 | ::sleep ( 1 ); |
333 | ::kill ( 0, SIGKILL ); | 327 | ::kill ( 0, SIGKILL ); |
334 | 328 | ||
335 | return retVal; | 329 | return retVal; |
336 | } | 330 | } |
337 | #else | 331 | #else |
338 | 332 | ||
339 | int main( int argc, char ** argv ) | 333 | int main( int argc, char ** argv ) |
340 | { | 334 | { |
341 | int retVal = initApplication( argc, argv ); | 335 | int retVal = initApplication( argc, argv ); |
342 | 336 | ||
343 | if ( DesktopApplication::doRestart ) { | 337 | if ( DesktopApplication::doRestart ) { |
344 | qDebug("Trying to restart"); | 338 | odebug << "Trying to restart" << oendl; |
345 | execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 ); | 339 | execl( (QPEApplication::qpeDir()+"bin\\qpe").latin1(), "qpe", 0 ); |
346 | } | 340 | } |
347 | 341 | ||
348 | return retVal; | 342 | return retVal; |
349 | } | 343 | } |
350 | 344 | ||
351 | #endif | 345 | #endif |
352 | 346 | ||
diff --git a/core/launcher/packageslave.cpp b/core/launcher/packageslave.cpp index 7e61b0e..a11ac86 100644 --- a/core/launcher/packageslave.cpp +++ b/core/launcher/packageslave.cpp | |||
@@ -1,339 +1,339 @@ | |||
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 | #include "packageslave.h" | 21 | #include "packageslave.h" |
22 | #include <qtopia/qprocess.h> | ||
23 | 22 | ||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
25 | #include <qtopia/qprocess.h> | ||
24 | #ifdef Q_WS_QWS | 26 | #ifdef Q_WS_QWS |
25 | #include <qtopia/qcopenvelope_qws.h> | 27 | #include <qtopia/qcopenvelope_qws.h> |
26 | #endif | 28 | #endif |
29 | using namespace Opie::Core; | ||
27 | 30 | ||
31 | /* QT */ | ||
28 | #ifdef Q_WS_QWS | 32 | #ifdef Q_WS_QWS |
29 | #include <qcopchannel_qws.h> | 33 | #include <qcopchannel_qws.h> |
30 | #endif | 34 | #endif |
31 | |||
32 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
33 | 36 | ||
37 | /* STD */ | ||
34 | #include <stdlib.h> | 38 | #include <stdlib.h> |
35 | #include <sys/stat.h> // mkdir() | 39 | #include <sys/stat.h> // mkdir() |
36 | |||
37 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 40 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
38 | #include <unistd.h> | 41 | #include <unistd.h> |
39 | #include <sys/vfs.h> | 42 | #include <sys/vfs.h> |
40 | #include <mntent.h> | 43 | #include <mntent.h> |
41 | #elif defined(Q_OS_WIN32) | ||
42 | #include <windows.h> | ||
43 | #include <winbase.h> | ||
44 | #elif defined(Q_OS_MACX) | 44 | #elif defined(Q_OS_MACX) |
45 | #include <unistd.h> | 45 | #include <unistd.h> |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | 48 | ||
49 | PackageHandler::PackageHandler( QObject *parent, char* name ) | 49 | PackageHandler::PackageHandler( QObject *parent, char* name ) |
50 | : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) | 50 | : QObject( parent, name ), packageChannel( 0 ), currentProcess( 0 ), mNoSpaceLeft( FALSE ) |
51 | { | 51 | { |
52 | // setup qcop channel | 52 | // setup qcop channel |
53 | #ifndef QT_NO_COP | 53 | #ifndef QT_NO_COP |
54 | packageChannel = new QCopChannel( "QPE/Package", this ); | 54 | packageChannel = new QCopChannel( "QPE/Package", this ); |
55 | connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ), | 55 | connect( packageChannel, SIGNAL( received(const QCString&,const QByteArray&) ), |
56 | this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) ); | 56 | this, SLOT( qcopMessage(const QCString&,const QByteArray&) ) ); |
57 | #endif | 57 | #endif |
58 | } | 58 | } |
59 | 59 | ||
60 | void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) | 60 | void PackageHandler::qcopMessage( const QCString &msg, const QByteArray &data ) |
61 | { | 61 | { |
62 | QDataStream stream( data, IO_ReadOnly ); | 62 | QDataStream stream( data, IO_ReadOnly ); |
63 | 63 | ||
64 | if ( msg == "installPackage(QString)" ) { | 64 | if ( msg == "installPackage(QString)" ) { |
65 | QString file; | 65 | QString file; |
66 | stream >> file; | 66 | stream >> file; |
67 | installPackage( file ); | 67 | installPackage( file ); |
68 | } else if ( msg == "removePackage(QString)" ) { | 68 | } else if ( msg == "removePackage(QString)" ) { |
69 | QString file; | 69 | QString file; |
70 | stream >> file; | 70 | stream >> file; |
71 | removePackage( file ); | 71 | removePackage( file ); |
72 | } else if ( msg == "addPackageFiles(QString,QString)" ) { | 72 | } else if ( msg == "addPackageFiles(QString,QString)" ) { |
73 | QString location, listfile; | 73 | QString location, listfile; |
74 | stream >> location >> listfile; | 74 | stream >> location >> listfile; |
75 | addPackageFiles( location, listfile); | 75 | addPackageFiles( location, listfile); |
76 | } else if ( msg == "addPackages(QString)" ) { | 76 | } else if ( msg == "addPackages(QString)" ) { |
77 | QString location; | 77 | QString location; |
78 | stream >> location; | 78 | stream >> location; |
79 | addPackages( location ); | 79 | addPackages( location ); |
80 | } else if ( msg == "cleanupPackageFiles(QString)" ) { | 80 | } else if ( msg == "cleanupPackageFiles(QString)" ) { |
81 | QString listfile; | 81 | QString listfile; |
82 | stream >> listfile; | 82 | stream >> listfile; |
83 | cleanupPackageFiles( listfile ); | 83 | cleanupPackageFiles( listfile ); |
84 | } else if ( msg == "cleanupPackages(QString)" ) { | 84 | } else if ( msg == "cleanupPackages(QString)" ) { |
85 | QString location; | 85 | QString location; |
86 | stream >> location; | 86 | stream >> location; |
87 | cleanupPackages( location ); | 87 | cleanupPackages( location ); |
88 | } else if ( msg == "prepareInstall(QString,QString)" ) { | 88 | } else if ( msg == "prepareInstall(QString,QString)" ) { |
89 | QString size, path; | 89 | QString size, path; |
90 | stream >> size; | 90 | stream >> size; |
91 | stream >> path; | 91 | stream >> path; |
92 | prepareInstall( size, path ); | 92 | prepareInstall( size, path ); |
93 | } | 93 | } |
94 | } | 94 | } |
95 | 95 | ||
96 | void PackageHandler::installPackage( const QString &package ) | 96 | void PackageHandler::installPackage( const QString &package ) |
97 | { | 97 | { |
98 | if ( mNoSpaceLeft ) { | 98 | if ( mNoSpaceLeft ) { |
99 | mNoSpaceLeft = FALSE; | 99 | mNoSpaceLeft = FALSE; |
100 | // Don't emit that for now, I still couldn't test it (Wener) | 100 | // Don't emit that for now, I still couldn't test it (Wener) |
101 | //sendReply( "installFailed(QString)", package ); | 101 | //sendReply( "installFailed(QString)", package ); |
102 | //return; | 102 | //return; |
103 | } | 103 | } |
104 | 104 | ||
105 | currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr | 105 | currentProcess = new QProcess( QStringList() << "ipkg" << "install" << package ); // No tr |
106 | connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); | 106 | connect( currentProcess, SIGNAL( processExited() ), SLOT( iProcessExited() ) ); |
107 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); | 107 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); |
108 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); | 108 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); |
109 | currentPackage = package; | 109 | currentPackage = package; |
110 | 110 | ||
111 | currentProcessError=""; | 111 | currentProcessError=""; |
112 | sendReply( "installStarted(QString)", package ); | 112 | sendReply( "installStarted(QString)", package ); |
113 | currentProcess->start(); | 113 | currentProcess->start(); |
114 | } | 114 | } |
115 | 115 | ||
116 | void PackageHandler::removePackage( const QString &package ) | 116 | void PackageHandler::removePackage( const QString &package ) |
117 | { | 117 | { |
118 | currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr | 118 | currentProcess = new QProcess( QStringList() << "ipkg" << "remove" << package ); // No tr |
119 | connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); | 119 | connect( currentProcess, SIGNAL( processExited() ), SLOT( rmProcessExited() ) ); |
120 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); | 120 | connect( currentProcess, SIGNAL( readyReadStdout() ), SLOT( readyReadStdout() ) ); |
121 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); | 121 | connect( currentProcess, SIGNAL( readyReadStderr() ), SLOT( readyReadStderr() ) ); |
122 | currentPackage = package; | 122 | currentPackage = package; |
123 | 123 | ||
124 | currentProcessError=""; | 124 | currentProcessError=""; |
125 | sendReply( "removeStarted(QString)", package ); | 125 | sendReply( "removeStarted(QString)", package ); |
126 | currentProcess->start(); | 126 | currentProcess->start(); |
127 | } | 127 | } |
128 | 128 | ||
129 | void PackageHandler::sendReply( const QCString& msg, const QString& arg ) | 129 | void PackageHandler::sendReply( const QCString& msg, const QString& arg ) |
130 | { | 130 | { |
131 | #ifndef QT_NO_COP | 131 | #ifndef QT_NO_COP |
132 | QCopEnvelope e( "QPE/Desktop", msg ); | 132 | QCopEnvelope e( "QPE/Desktop", msg ); |
133 | e << arg; | 133 | e << arg; |
134 | #endif | 134 | #endif |
135 | } | 135 | } |
136 | 136 | ||
137 | void PackageHandler::addPackageFiles( const QString &location, | 137 | void PackageHandler::addPackageFiles( const QString &location, |
138 | const QString &listfile ) | 138 | const QString &listfile ) |
139 | { | 139 | { |
140 | QFile f(listfile); | 140 | QFile f(listfile); |
141 | #ifndef Q_OS_WIN32 | 141 | #ifndef Q_OS_WIN32 |
142 | //make a copy so we can remove the symlinks later | 142 | //make a copy so we can remove the symlinks later |
143 | mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); | 143 | mkdir( ("/usr/lib/ipkg/info/"+location).ascii(), 0777 ); |
144 | system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); | 144 | system(("cp " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); |
145 | #else | 145 | #else |
146 | QDir d; | 146 | QDir d; |
147 | //#### revise | 147 | //#### revise |
148 | qDebug("Copy file at %s: %s", __FILE__, __LINE__ ); | 148 | odebug << "Copy file at " << __FILE__ << ": " << __LINE__ << "" << oendl; |
149 | d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); | 149 | d.mkdir(("/usr/lib/ipkg/info/" + location).ascii()); |
150 | system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); | 150 | system(("copy " + f.name() + " /usr/lib/ipkg/info/"+location).ascii()); |
151 | #endif | 151 | #endif |
152 | 152 | ||
153 | 153 | ||
154 | if ( f.open(IO_ReadOnly) ) { | 154 | if ( f.open(IO_ReadOnly) ) { |
155 | QTextStream ts(&f); | 155 | QTextStream ts(&f); |
156 | 156 | ||
157 | QString s; | 157 | QString s; |
158 | while ( !ts.eof() ) { // until end of file... | 158 | while ( !ts.eof() ) { // until end of file... |
159 | s = ts.readLine(); // line of text excluding '\n' | 159 | s = ts.readLine(); // line of text excluding '\n' |
160 | // for s, do link/mkdir. | 160 | // for s, do link/mkdir. |
161 | if ( s.right(1) == "/" ) { | 161 | if ( s.right(1) == "/" ) { |
162 | qDebug("do mkdir for %s", s.ascii()); | 162 | odebug << "do mkdir for " << s.ascii() << "" << oendl; |
163 | #ifndef Q_OS_WIN32 | 163 | #ifndef Q_OS_WIN32 |
164 | mkdir( s.ascii(), 0777 ); | 164 | mkdir( s.ascii(), 0777 ); |
165 | //possible optimization: symlink directories | 165 | //possible optimization: symlink directories |
166 | //that don't exist already. -- Risky. | 166 | //that don't exist already. -- Risky. |
167 | #else | 167 | #else |
168 | d.mkdir( s.ascii()); | 168 | d.mkdir( s.ascii()); |
169 | #endif | 169 | #endif |
170 | 170 | ||
171 | } else { | 171 | } else { |
172 | #ifndef Q_OS_WIN32 | 172 | #ifndef Q_OS_WIN32 |
173 | qDebug("do symlink for %s", s.ascii()); | 173 | odebug << "do symlink for " << s.ascii() << "" << oendl; |
174 | symlink( (location + s).ascii(), s.ascii() ); | 174 | symlink( (location + s).ascii(), s.ascii() ); |
175 | #else | 175 | #else |
176 | qDebug("Copy file instead of a symlink for WIN32"); | 176 | odebug << "Copy file instead of a symlink for WIN32" << oendl; |
177 | if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) | 177 | if (!CopyFile((TCHAR*)qt_winTchar((location + s), TRUE), (TCHAR*)qt_winTchar(s, TRUE), FALSE)) |
178 | qWarning("Unable to create symlinkfor %s", | 178 | qWarning("Unable to create symlinkfor %s", |
179 | (location + s).ascii()); | 179 | (location + s).ascii()); |
180 | #endif | 180 | #endif |
181 | } | 181 | } |
182 | } | 182 | } |
183 | f.close(); | 183 | f.close(); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | void PackageHandler::addPackages( const QString &location ) | 187 | void PackageHandler::addPackages( const QString &location ) |
188 | { | 188 | { |
189 | // get list of *.list in location/usr/lib/ipkg/info/*.list | 189 | // get list of *.list in location/usr/lib/ipkg/info/*.list |
190 | QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr | 190 | QDir dir(location + "/usr/lib/ipkg/info", "*.list", // No tr |
191 | QDir::Name, QDir::Files); | 191 | QDir::Name, QDir::Files); |
192 | if ( !dir.exists() ) | 192 | if ( !dir.exists() ) |
193 | return; | 193 | return; |
194 | 194 | ||
195 | QStringList packages = dir.entryList(); | 195 | QStringList packages = dir.entryList(); |
196 | for ( QStringList::Iterator it = packages.begin(); | 196 | for ( QStringList::Iterator it = packages.begin(); |
197 | it != packages.end(); ++it ) { | 197 | it != packages.end(); ++it ) { |
198 | addPackageFiles( location, *it ); | 198 | addPackageFiles( location, *it ); |
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | 202 | ||
203 | void PackageHandler::cleanupPackageFiles( const QString &listfile ) | 203 | void PackageHandler::cleanupPackageFiles( const QString &listfile ) |
204 | { | 204 | { |
205 | QFile f(listfile); | 205 | QFile f(listfile); |
206 | 206 | ||
207 | if ( f.open(IO_ReadOnly) ) { | 207 | if ( f.open(IO_ReadOnly) ) { |
208 | QTextStream ts(&f); | 208 | QTextStream ts(&f); |
209 | 209 | ||
210 | QString s; | 210 | QString s; |
211 | while ( !ts.eof() ) { // until end of file... | 211 | while ( !ts.eof() ) { // until end of file... |
212 | s = ts.readLine(); // line of text excluding '\n' | 212 | s = ts.readLine(); // line of text excluding '\n' |
213 | // for s, do link/mkdir. | 213 | // for s, do link/mkdir. |
214 | if ( s.right(1) == "/" ) { | 214 | if ( s.right(1) == "/" ) { |
215 | //should rmdir if empty, after all files have been removed | 215 | //should rmdir if empty, after all files have been removed |
216 | } else { | 216 | } else { |
217 | #ifndef Q_OS_WIN32 | 217 | #ifndef Q_OS_WIN32 |
218 | qDebug("remove symlink for %s", s.ascii()); | 218 | odebug << "remove symlink for " << s.ascii() << "" << oendl; |
219 | //check if it is a symlink first (don't remove /etc/passwd...) | 219 | //check if it is a symlink first (don't remove /etc/passwd...) |
220 | char buf[10]; //we don't care about the contents | 220 | char buf[10]; //we don't care about the contents |
221 | if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) | 221 | if ( ::readlink( s.ascii(),buf, 10 >= 0 ) ) |
222 | ::unlink( s.ascii() ); | 222 | ::unlink( s.ascii() ); |
223 | #else | 223 | #else |
224 | // ### revise | 224 | // ### revise |
225 | qWarning("Unable to remove symlink %s:%s", __FILE__, __LINE__); | 225 | owarn << "Unable to remove symlink " << __FILE__ << ":" << __LINE__ << "" << oendl; |
226 | #endif | 226 | #endif |
227 | } | 227 | } |
228 | } | 228 | } |
229 | f.close(); | 229 | f.close(); |
230 | 230 | ||
231 | //remove the list file | 231 | //remove the list file |
232 | ::unlink( listfile.ascii() ); | 232 | ::unlink( listfile.ascii() ); |
233 | 233 | ||
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
237 | void PackageHandler::cleanupPackages( const QString &location ) | 237 | void PackageHandler::cleanupPackages( const QString &location ) |
238 | { | 238 | { |
239 | // get list of *.list in location/usr/lib/ipkg/info/*.list | 239 | // get list of *.list in location/usr/lib/ipkg/info/*.list |
240 | QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr | 240 | QDir dir( "/usr/lib/ipkg/info/"+location, "*.list", // No tr |
241 | QDir::Name, QDir::Files); | 241 | QDir::Name, QDir::Files); |
242 | if ( !dir.exists() ) | 242 | if ( !dir.exists() ) |
243 | return; | 243 | return; |
244 | 244 | ||
245 | QStringList packages = dir.entryList(); | 245 | QStringList packages = dir.entryList(); |
246 | for ( QStringList::Iterator it = packages.begin(); | 246 | for ( QStringList::Iterator it = packages.begin(); |
247 | it != packages.end(); ++it ) { | 247 | it != packages.end(); ++it ) { |
248 | cleanupPackageFiles( *it ); | 248 | cleanupPackageFiles( *it ); |
249 | } | 249 | } |
250 | 250 | ||
251 | //remove the backup directory | 251 | //remove the backup directory |
252 | //### | 252 | //### |
253 | } | 253 | } |
254 | 254 | ||
255 | void PackageHandler::prepareInstall( const QString& size, const QString& path ) | 255 | void PackageHandler::prepareInstall( const QString& size, const QString& path ) |
256 | { | 256 | { |
257 | // Check whether there will be enough space to install the next package. | 257 | // Check whether there will be enough space to install the next package. |
258 | bool ok; | 258 | bool ok; |
259 | unsigned int s = size.toUInt( &ok ); | 259 | unsigned int s = size.toUInt( &ok ); |
260 | 260 | ||
261 | if ( !ok ) | 261 | if ( !ok ) |
262 | return; | 262 | return; |
263 | 263 | ||
264 | // Shamelessly stolen from the sysinfo application (Werner) | 264 | // Shamelessly stolen from the sysinfo application (Werner) |
265 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 265 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
266 | struct statfs fs; | 266 | struct statfs fs; |
267 | if ( statfs( path.latin1(), &fs ) == 0 ) | 267 | if ( statfs( path.latin1(), &fs ) == 0 ) |
268 | if ( s > fs.f_bsize * fs.f_bavail ) { | 268 | if ( s > fs.f_bsize * fs.f_bavail ) { |
269 | //qDebug("############### Not enough space left ###############"); | 269 | //odebug << "############### Not enough space left ###############" << oendl; |
270 | mNoSpaceLeft = TRUE; | 270 | mNoSpaceLeft = TRUE; |
271 | } | 271 | } |
272 | #endif | 272 | #endif |
273 | } | 273 | } |
274 | 274 | ||
275 | void PackageHandler::iProcessExited() | 275 | void PackageHandler::iProcessExited() |
276 | { | 276 | { |
277 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) | 277 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) |
278 | sendReply( "installDone(QString)", currentPackage ); | 278 | sendReply( "installDone(QString)", currentPackage ); |
279 | else { | 279 | else { |
280 | #ifndef QT_NO_COP | 280 | #ifndef QT_NO_COP |
281 | QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); | 281 | QCopEnvelope e( "QPE/Desktop", "installFailed(QString,int,QString)" ); |
282 | e << currentPackage << currentProcess->exitStatus() | 282 | e << currentPackage << currentProcess->exitStatus() |
283 | << currentProcessError; | 283 | << currentProcessError; |
284 | #endif | 284 | #endif |
285 | } | 285 | } |
286 | 286 | ||
287 | delete currentProcess; | 287 | delete currentProcess; |
288 | currentProcess = 0; | 288 | currentProcess = 0; |
289 | 289 | ||
290 | #ifndef QT_NO_COP | 290 | #ifndef QT_NO_COP |
291 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 291 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
292 | QString lf = QString::null; | 292 | QString lf = QString::null; |
293 | e << lf; | 293 | e << lf; |
294 | #endif | 294 | #endif |
295 | unlink( currentPackage ); | 295 | unlink( currentPackage ); |
296 | } | 296 | } |
297 | 297 | ||
298 | void PackageHandler::rmProcessExited() | 298 | void PackageHandler::rmProcessExited() |
299 | { | 299 | { |
300 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) | 300 | if ( currentProcess->normalExit() && currentProcess->exitStatus() == 0 ) |
301 | sendReply( "removeDone(QString)", currentPackage ); | 301 | sendReply( "removeDone(QString)", currentPackage ); |
302 | else | 302 | else |
303 | sendReply( "removeFailed(QString)", currentPackage ); | 303 | sendReply( "removeFailed(QString)", currentPackage ); |
304 | 304 | ||
305 | #ifndef QT_NO_COP | 305 | #ifndef QT_NO_COP |
306 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 306 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
307 | QString lf = QString::null; | 307 | QString lf = QString::null; |
308 | e << lf; | 308 | e << lf; |
309 | #endif | 309 | #endif |
310 | } | 310 | } |
311 | 311 | ||
312 | void PackageHandler::readyReadStdout() | 312 | void PackageHandler::readyReadStdout() |
313 | { | 313 | { |
314 | while ( currentProcess->canReadLineStdout() ) { | 314 | while ( currentProcess->canReadLineStdout() ) { |
315 | QString line = currentProcess->readLineStdout(); | 315 | QString line = currentProcess->readLineStdout(); |
316 | currentProcessError.append("OUT:"+line); | 316 | currentProcessError.append("OUT:"+line); |
317 | if ( line.contains( "Unpacking" ) ) // No tr | 317 | if ( line.contains( "Unpacking" ) ) // No tr |
318 | sendReply( "installStep(QString)", "one" ); // No tr | 318 | sendReply( "installStep(QString)", "one" ); // No tr |
319 | else if ( line.contains( "Configuring" ) ) // No tr | 319 | else if ( line.contains( "Configuring" ) ) // No tr |
320 | sendReply( "installStep(QString)", "two" ); // No tr | 320 | sendReply( "installStep(QString)", "two" ); // No tr |
321 | } | 321 | } |
322 | } | 322 | } |
323 | 323 | ||
324 | void PackageHandler::readyReadStderr() | 324 | void PackageHandler::readyReadStderr() |
325 | { | 325 | { |
326 | while ( currentProcess->canReadLineStderr() ) { | 326 | while ( currentProcess->canReadLineStderr() ) { |
327 | QString line = currentProcess->readLineStderr(); | 327 | QString line = currentProcess->readLineStderr(); |
328 | currentProcessError.append("ERR:"+line); | 328 | currentProcessError.append("ERR:"+line); |
329 | } | 329 | } |
330 | } | 330 | } |
331 | 331 | ||
332 | void PackageHandler::redoPackages() | 332 | void PackageHandler::redoPackages() |
333 | { | 333 | { |
334 | //get list of filesystems | 334 | //get list of filesystems |
335 | 335 | ||
336 | //call cleanupPackages for the ones that have disappeared | 336 | //call cleanupPackages for the ones that have disappeared |
337 | 337 | ||
338 | //call addPackageFiles for the new ones | 338 | //call addPackageFiles for the new ones |
339 | } | 339 | } |
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp index 33df6c4..e339dc7 100644 --- a/core/launcher/qcopbridge.cpp +++ b/core/launcher/qcopbridge.cpp | |||
@@ -1,491 +1,490 @@ | |||
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 | #include "qcopbridge.h" | 21 | #include "qcopbridge.h" |
22 | #include "transferserver.h" | 22 | #include "transferserver.h" |
23 | 23 | ||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
24 | #include <opie2/oglobal.h> | 26 | #include <opie2/oglobal.h> |
25 | |||
26 | #ifdef Q_WS_QWS | 27 | #ifdef Q_WS_QWS |
27 | #include <qtopia/qcopenvelope_qws.h> | 28 | #include <qtopia/qcopenvelope_qws.h> |
28 | #endif | 29 | #endif |
29 | #include <qtopia/qpeapplication.h> | 30 | #include <qtopia/qpeapplication.h> |
30 | |||
31 | #include <qtopia/version.h> | 31 | #include <qtopia/version.h> |
32 | using namespace Opie::Core; | ||
32 | 33 | ||
34 | /* QT */ | ||
33 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
34 | #include <qtimer.h> | 36 | #include <qtimer.h> |
35 | #ifdef Q_WS_QWS | 37 | #ifdef Q_WS_QWS |
36 | #include <qcopchannel_qws.h> | 38 | #include <qcopchannel_qws.h> |
37 | #endif | 39 | #endif |
38 | 40 | ||
41 | /* STD */ | ||
39 | #ifndef _XOPEN_SOURCE | 42 | #ifndef _XOPEN_SOURCE |
40 | #define _XOPEN_SOURCE | 43 | #define _XOPEN_SOURCE |
41 | #endif | 44 | #endif |
42 | #ifndef Q_OS_WIN32 | 45 | #ifndef Q_OS_WIN32 |
43 | #include <pwd.h> | 46 | #include <pwd.h> |
44 | #include <unistd.h> | 47 | #include <unistd.h> |
45 | #include <sys/types.h> | 48 | #include <sys/types.h> |
46 | #endif | 49 | #endif |
47 | 50 | ||
48 | #if defined(_OS_LINUX_) | 51 | #if defined(_OS_LINUX_) |
49 | #include <shadow.h> | 52 | #include <shadow.h> |
50 | #endif | 53 | #endif |
51 | 54 | ||
52 | |||
53 | //#define INSECURE | ||
54 | |||
55 | const int block_size = 51200; | 55 | const int block_size = 51200; |
56 | 56 | ||
57 | using namespace Opie::Core; | ||
58 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, | 57 | QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, |
59 | const char* name ) | 58 | const char* name ) |
60 | : QServerSocket( port, 1, parent, name ), | 59 | : QServerSocket( port, 1, parent, name ), |
61 | desktopChannel( 0 ), | 60 | desktopChannel( 0 ), |
62 | cardChannel( 0 ) | 61 | cardChannel( 0 ) |
63 | { | 62 | { |
64 | if ( !ok() ) | 63 | if ( !ok() ) |
65 | qWarning( "Failed to bind to port %d", port ); | 64 | owarn << "Failed to bind to port " << port << "" << oendl; |
66 | else { | 65 | else { |
67 | #ifndef QT_NO_COP | 66 | #ifndef QT_NO_COP |
68 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); | 67 | desktopChannel = new QCopChannel( "QPE/Desktop", this ); |
69 | connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 68 | connect( desktopChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
70 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); | 69 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); |
71 | cardChannel = new QCopChannel( "QPE/Card", this ); | 70 | cardChannel = new QCopChannel( "QPE/Card", this ); |
72 | connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 71 | connect( cardChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
73 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); | 72 | this, SLOT(desktopMessage(const QCString&,const QByteArray&)) ); |
74 | #endif | 73 | #endif |
75 | } | 74 | } |
76 | sendSync = FALSE; | 75 | sendSync = FALSE; |
77 | openConnections.setAutoDelete( TRUE ); | 76 | openConnections.setAutoDelete( TRUE ); |
78 | authorizeConnections(); | 77 | authorizeConnections(); |
79 | } | 78 | } |
80 | 79 | ||
81 | QCopBridge::~QCopBridge() | 80 | QCopBridge::~QCopBridge() |
82 | { | 81 | { |
83 | #ifndef QT_NO_COP | 82 | #ifndef QT_NO_COP |
84 | delete desktopChannel; | 83 | delete desktopChannel; |
85 | #endif | 84 | #endif |
86 | } | 85 | } |
87 | 86 | ||
88 | void QCopBridge::authorizeConnections() | 87 | void QCopBridge::authorizeConnections() |
89 | { | 88 | { |
90 | Config cfg("Security"); | 89 | Config cfg("Security"); |
91 | cfg.setGroup("SyncMode"); | 90 | cfg.setGroup("SyncMode"); |
92 | m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); | 91 | m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); |
93 | QListIterator<QCopBridgePI> it(openConnections); | 92 | QListIterator<QCopBridgePI> it(openConnections); |
94 | while ( it.current() ) { | 93 | while ( it.current() ) { |
95 | if ( !it.current()->verifyAuthorised() ) { | 94 | if ( !it.current()->verifyAuthorised() ) { |
96 | disconnect ( it.current(), SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) ); | 95 | disconnect ( it.current(), SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) ); |
97 | openConnections.removeRef( it.current() ); | 96 | openConnections.removeRef( it.current() ); |
98 | } else | 97 | } else |
99 | ++it; | 98 | ++it; |
100 | } | 99 | } |
101 | } | 100 | } |
102 | 101 | ||
103 | void QCopBridge::newConnection( int socket ) | 102 | void QCopBridge::newConnection( int socket ) |
104 | { | 103 | { |
105 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); | 104 | QCopBridgePI *pi = new QCopBridgePI( socket, this ); |
106 | openConnections.append( pi ); | 105 | openConnections.append( pi ); |
107 | connect ( pi, SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) ); | 106 | connect ( pi, SIGNAL( connectionClosed(QCopBridgePI*) ), this, SLOT( closed(QCopBridgePI*) ) ); |
108 | 107 | ||
109 | /* ### libqtopia merge FIXME */ | 108 | /* ### libqtopia merge FIXME */ |
110 | #if 0 | 109 | #if 0 |
111 | QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); | 110 | QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); |
112 | #endif | 111 | #endif |
113 | #ifndef QT_NO_COP | 112 | #ifndef QT_NO_COP |
114 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; | 113 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; |
115 | #endif | 114 | #endif |
116 | 115 | ||
117 | if ( sendSync ) { | 116 | if ( sendSync ) { |
118 | pi ->startSync(); | 117 | pi ->startSync(); |
119 | sendSync = FALSE; | 118 | sendSync = FALSE; |
120 | } | 119 | } |
121 | } | 120 | } |
122 | 121 | ||
123 | void QCopBridge::closed( QCopBridgePI *pi ) | 122 | void QCopBridge::closed( QCopBridgePI *pi ) |
124 | { | 123 | { |
125 | emit connectionClosed( pi->peerAddress() ); | 124 | emit connectionClosed( pi->peerAddress() ); |
126 | openConnections.removeRef( pi ); | 125 | openConnections.removeRef( pi ); |
127 | if ( openConnections.count() == 0 ) { | 126 | if ( openConnections.count() == 0 ) { |
128 | /* ### FIXME libqtopia merge */ | 127 | /* ### FIXME libqtopia merge */ |
129 | #if 0 | 128 | #if 0 |
130 | QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); | 129 | QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); |
131 | #endif | 130 | #endif |
132 | #ifndef QT_NO_COP | 131 | #ifndef QT_NO_COP |
133 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 132 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
134 | #endif | 133 | #endif |
135 | } | 134 | } |
136 | } | 135 | } |
137 | 136 | ||
138 | void QCopBridge::closeOpenConnections() | 137 | void QCopBridge::closeOpenConnections() |
139 | { | 138 | { |
140 | QCopBridgePI *pi; | 139 | QCopBridgePI *pi; |
141 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 140 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
142 | pi->close(); | 141 | pi->close(); |
143 | } | 142 | } |
144 | 143 | ||
145 | 144 | ||
146 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) | 145 | void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) |
147 | { | 146 | { |
148 | if ( command == "startSync()" ) { | 147 | if ( command == "startSync()" ) { |
149 | // we need to buffer it a bit | 148 | // we need to buffer it a bit |
150 | sendSync = TRUE; | 149 | sendSync = TRUE; |
151 | startTimer( 20000 ); | 150 | startTimer( 20000 ); |
152 | } | 151 | } |
153 | 152 | ||
154 | if ( m_mode & Qtopia1_7 ) { | 153 | if ( m_mode & Qtopia1_7 ) { |
155 | // send the command to all open connections | 154 | // send the command to all open connections |
156 | QCopBridgePI *pi; | 155 | QCopBridgePI *pi; |
157 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { | 156 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { |
158 | pi->sendDesktopMessage( command, data ); | 157 | pi->sendDesktopMessage( command, data ); |
159 | } | 158 | } |
160 | } | 159 | } |
161 | if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) | 160 | if ( ( m_mode & Sharp ) || (m_mode & IntelliSync) ) |
162 | sendDesktopMessageOld( command, data ); | 161 | sendDesktopMessageOld( command, data ); |
163 | } | 162 | } |
164 | 163 | ||
165 | #ifndef OPIE_NO_OLD_SYNC_CODE | 164 | #ifndef OPIE_NO_OLD_SYNC_CODE |
166 | /* | 165 | /* |
167 | * Old compat mode | 166 | * Old compat mode |
168 | */ | 167 | */ |
169 | void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { | 168 | void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { |
170 | command.stripWhiteSpace(); | 169 | command.stripWhiteSpace(); |
171 | 170 | ||
172 | int paren = command.find( "(" ); | 171 | int paren = command.find( "(" ); |
173 | if ( paren <= 0 ) { | 172 | if ( paren <= 0 ) { |
174 | qDebug("DesktopMessage: bad qcop syntax"); | 173 | odebug << "DesktopMessage: bad qcop syntax" << oendl; |
175 | return; | 174 | return; |
176 | } | 175 | } |
177 | 176 | ||
178 | QString params = command.mid( paren + 1 ); | 177 | QString params = command.mid( paren + 1 ); |
179 | if ( params[params.length()-1] != ')' ) { | 178 | if ( params[params.length()-1] != ')' ) { |
180 | qDebug("DesktopMessage: bad qcop syntax"); | 179 | odebug << "DesktopMessage: bad qcop syntax" << oendl; |
181 | return; | 180 | return; |
182 | } | 181 | } |
183 | 182 | ||
184 | params.truncate( params.length()-1 ); | 183 | params.truncate( params.length()-1 ); |
185 | 184 | ||
186 | QStringList paramList = QStringList::split( ",", params ); | 185 | QStringList paramList = QStringList::split( ",", params ); |
187 | QString data; | 186 | QString data; |
188 | if ( paramList.count() ) { | 187 | if ( paramList.count() ) { |
189 | QDataStream stream( args, IO_ReadOnly ); | 188 | QDataStream stream( args, IO_ReadOnly ); |
190 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | 189 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { |
191 | QString str; | 190 | QString str; |
192 | if ( *it == "QString" ) { | 191 | if ( *it == "QString" ) { |
193 | stream >> str; | 192 | stream >> str; |
194 | } else if ( *it == "QCString" ) { | 193 | } else if ( *it == "QCString" ) { |
195 | QCString cstr; | 194 | QCString cstr; |
196 | stream >> cstr; | 195 | stream >> cstr; |
197 | str = QString::fromLocal8Bit( cstr ); | 196 | str = QString::fromLocal8Bit( cstr ); |
198 | } else if ( *it == "int" ) { | 197 | } else if ( *it == "int" ) { |
199 | int i; | 198 | int i; |
200 | stream >> i; | 199 | stream >> i; |
201 | str = QString::number( i ); | 200 | str = QString::number( i ); |
202 | } else if ( *it == "bool" ) { | 201 | } else if ( *it == "bool" ) { |
203 | int i; | 202 | int i; |
204 | stream >> i; | 203 | stream >> i; |
205 | str = QString::number( i ); | 204 | str = QString::number( i ); |
206 | } else { | 205 | } else { |
207 | qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); | 206 | odebug << " cannot route the argument type " << (*it) << " throught the qcop bridge" << oendl; |
208 | return; | 207 | return; |
209 | } | 208 | } |
210 | QString estr; | 209 | QString estr; |
211 | for (int i=0; i<(int)str.length(); i++) { | 210 | for (int i=0; i<(int)str.length(); i++) { |
212 | QChar ch = str[i]; | 211 | QChar ch = str[i]; |
213 | if ( ch.row() ) | 212 | if ( ch.row() ) |
214 | goto quick; | 213 | goto quick; |
215 | switch (ch.cell()) { | 214 | switch (ch.cell()) { |
216 | case '&': | 215 | case '&': |
217 | estr.append( "&" ); | 216 | estr.append( "&" ); |
218 | break; | 217 | break; |
219 | case ' ': | 218 | case ' ': |
220 | estr.append( "&0x20;" ); | 219 | estr.append( "&0x20;" ); |
221 | break; | 220 | break; |
222 | case '\n': | 221 | case '\n': |
223 | estr.append( "&0x0d;" ); | 222 | estr.append( "&0x0d;" ); |
224 | break; | 223 | break; |
225 | case '\r': | 224 | case '\r': |
226 | estr.append( "&0x0a;" ); | 225 | estr.append( "&0x0a;" ); |
227 | break; | 226 | break; |
228 | default: quick: | 227 | default: quick: |
229 | estr.append(ch); | 228 | estr.append(ch); |
230 | } | 229 | } |
231 | } | 230 | } |
232 | data += " " + estr; | 231 | data += " " + estr; |
233 | } | 232 | } |
234 | } | 233 | } |
235 | QString sendCommand = QString(command.data()) + data; | 234 | QString sendCommand = QString(command.data()) + data; |
236 | 235 | ||
237 | 236 | ||
238 | // send the command to all open connections | 237 | // send the command to all open connections |
239 | QCopBridgePI *pi; | 238 | QCopBridgePI *pi; |
240 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) | 239 | for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) |
241 | pi->sendDesktopMessage( sendCommand ); | 240 | pi->sendDesktopMessage( sendCommand ); |
242 | 241 | ||
243 | } | 242 | } |
244 | #endif | 243 | #endif |
245 | 244 | ||
246 | 245 | ||
247 | void QCopBridge::timerEvent( QTimerEvent * ) | 246 | void QCopBridge::timerEvent( QTimerEvent * ) |
248 | { | 247 | { |
249 | sendSync = FALSE; | 248 | sendSync = FALSE; |
250 | killTimers(); | 249 | killTimers(); |
251 | } | 250 | } |
252 | 251 | ||
253 | 252 | ||
254 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) | 253 | QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) |
255 | : QSocket( parent, name ) | 254 | : QSocket( parent, name ) |
256 | { | 255 | { |
257 | setSocket( socket ); | 256 | setSocket( socket ); |
258 | 257 | ||
259 | peerport = peerPort(); | 258 | peerport = peerPort(); |
260 | peeraddress = peerAddress(); | 259 | peeraddress = peerAddress(); |
261 | 260 | ||
262 | #ifndef INSECURE | 261 | #ifndef INSECURE |
263 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 262 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
264 | state = Forbidden; | 263 | state = Forbidden; |
265 | close(); | 264 | close(); |
266 | } else | 265 | } else |
267 | #endif | 266 | #endif |
268 | { | 267 | { |
269 | state = Connected; | 268 | state = Connected; |
270 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 269 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
271 | QString intro="220 Qtopia "; | 270 | QString intro="220 Qtopia "; |
272 | intro += QPE_VERSION; intro += ";"; | 271 | intro += QPE_VERSION; intro += ";"; |
273 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr | 272 | intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr |
274 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; | 273 | intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; |
275 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; | 274 | intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; |
276 | send( intro ); | 275 | send( intro ); |
277 | state = Wait_USER; | 276 | state = Wait_USER; |
278 | } | 277 | } |
279 | sendSync = FALSE; | 278 | sendSync = FALSE; |
280 | connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); | 279 | connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); |
281 | 280 | ||
282 | // idle timer to close connections when not used anymore | 281 | // idle timer to close connections when not used anymore |
283 | timer = new QTimer(this); | 282 | timer = new QTimer(this); |
284 | connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); | 283 | connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); |
285 | timer->start( 300000, TRUE ); | 284 | timer->start( 300000, TRUE ); |
286 | } | 285 | } |
287 | 286 | ||
288 | 287 | ||
289 | QCopBridgePI::~QCopBridgePI() | 288 | QCopBridgePI::~QCopBridgePI() |
290 | { | 289 | { |
291 | } | 290 | } |
292 | 291 | ||
293 | bool QCopBridgePI::verifyAuthorised() | 292 | bool QCopBridgePI::verifyAuthorised() |
294 | { | 293 | { |
295 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 294 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
296 | state = Forbidden; | 295 | state = Forbidden; |
297 | return FALSE; | 296 | return FALSE; |
298 | } | 297 | } |
299 | return TRUE; | 298 | return TRUE; |
300 | } | 299 | } |
301 | 300 | ||
302 | void QCopBridgePI::myConnectionClosed() | 301 | void QCopBridgePI::myConnectionClosed() |
303 | { | 302 | { |
304 | emit connectionClosed( this ); | 303 | emit connectionClosed( this ); |
305 | } | 304 | } |
306 | 305 | ||
307 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) | 306 | void QCopBridgePI::sendDesktopMessage( const QString &msg ) |
308 | { | 307 | { |
309 | QString str = "CALL QPE/Desktop " + msg; // No tr | 308 | QString str = "CALL QPE/Desktop " + msg; // No tr |
310 | send ( str ); | 309 | send ( str ); |
311 | } | 310 | } |
312 | 311 | ||
313 | void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) | 312 | void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) |
314 | { | 313 | { |
315 | if ( !isOpen() ) // eg. Forbidden | 314 | if ( !isOpen() ) // eg. Forbidden |
316 | return; | 315 | return; |
317 | 316 | ||
318 | const char hdr[]="CALLB QPE/Desktop "; | 317 | const char hdr[]="CALLB QPE/Desktop "; |
319 | writeBlock(hdr,sizeof(hdr)-1); | 318 | writeBlock(hdr,sizeof(hdr)-1); |
320 | writeBlock(msg,msg.length()); | 319 | writeBlock(msg,msg.length()); |
321 | writeBlock(" ",1); | 320 | writeBlock(" ",1); |
322 | QByteArray b64 = OGlobal::encodeBase64(data); | 321 | QByteArray b64 = OGlobal::encodeBase64(data); |
323 | writeBlock(b64.data(),b64.size()); | 322 | writeBlock(b64.data(),b64.size()); |
324 | writeBlock("\r\n",2); | 323 | writeBlock("\r\n",2); |
325 | 324 | ||
326 | } | 325 | } |
327 | 326 | ||
328 | 327 | ||
329 | void QCopBridgePI::send( const QString& msg ) | 328 | void QCopBridgePI::send( const QString& msg ) |
330 | { | 329 | { |
331 | if ( !isOpen() ) // eg. Forbidden | 330 | if ( !isOpen() ) // eg. Forbidden |
332 | return; | 331 | return; |
333 | QTextStream os( this ); | 332 | QTextStream os( this ); |
334 | os << msg << endl; | 333 | os << msg << endl; |
335 | //qDebug( "sending qcop message: %s", msg.latin1() ); | 334 | //odebug << "sending qcop message: " << msg << "" << oendl; |
336 | } | 335 | } |
337 | 336 | ||
338 | void QCopBridgePI::read() | 337 | void QCopBridgePI::read() |
339 | { | 338 | { |
340 | while ( canReadLine() ) { | 339 | while ( canReadLine() ) { |
341 | timer->start( 300000, TRUE ); | 340 | timer->start( 300000, TRUE ); |
342 | process( readLine().stripWhiteSpace() ); | 341 | process( readLine().stripWhiteSpace() ); |
343 | } | 342 | } |
344 | } | 343 | } |
345 | 344 | ||
346 | void QCopBridgePI::process( const QString& message ) | 345 | void QCopBridgePI::process( const QString& message ) |
347 | { | 346 | { |
348 | //qDebug( "Command: %s", message.latin1() ); | 347 | //odebug << "Command: " << message << "" << oendl; |
349 | 348 | ||
350 | // split message using "," as separator | 349 | // split message using "," as separator |
351 | QStringList msg = QStringList::split( " ", message ); | 350 | QStringList msg = QStringList::split( " ", message ); |
352 | if ( msg.isEmpty() ) return; | 351 | if ( msg.isEmpty() ) return; |
353 | 352 | ||
354 | // command token | 353 | // command token |
355 | QString cmd = msg[0].upper(); | 354 | QString cmd = msg[0].upper(); |
356 | 355 | ||
357 | // argument token | 356 | // argument token |
358 | QString arg; | 357 | QString arg; |
359 | if ( msg.count() >= 2 ) | 358 | if ( msg.count() >= 2 ) |
360 | arg = msg[1]; | 359 | arg = msg[1]; |
361 | 360 | ||
362 | // we always respond to QUIT, regardless of state | 361 | // we always respond to QUIT, regardless of state |
363 | if ( cmd == "QUIT" ) { | 362 | if ( cmd == "QUIT" ) { |
364 | send( "211 Have a nice day!" ); // No tr | 363 | send( "211 Have a nice day!" ); // No tr |
365 | close(); | 364 | close(); |
366 | return; | 365 | return; |
367 | } | 366 | } |
368 | 367 | ||
369 | // connected to client | 368 | // connected to client |
370 | if ( Connected == state ) | 369 | if ( Connected == state ) |
371 | return; | 370 | return; |
372 | 371 | ||
373 | // waiting for user name | 372 | // waiting for user name |
374 | if ( Wait_USER == state ) { | 373 | if ( Wait_USER == state ) { |
375 | 374 | ||
376 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 375 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
377 | send( "530 Please login with USER and PASS" ); // No tr | 376 | send( "530 Please login with USER and PASS" ); // No tr |
378 | return; | 377 | return; |
379 | } | 378 | } |
380 | send( "331 User name ok, need password" ); // No tr | 379 | send( "331 User name ok, need password" ); // No tr |
381 | state = Wait_PASS; | 380 | state = Wait_PASS; |
382 | return; | 381 | return; |
383 | } | 382 | } |
384 | 383 | ||
385 | // waiting for password | 384 | // waiting for password |
386 | if ( Wait_PASS == state ) { | 385 | if ( Wait_PASS == state ) { |
387 | 386 | ||
388 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 387 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
389 | send( "530 Please login with USER and PASS" ); // No tr | 388 | send( "530 Please login with USER and PASS" ); // No tr |
390 | return; | 389 | return; |
391 | } | 390 | } |
392 | send( "230 User logged in, proceed" ); // No tr | 391 | send( "230 User logged in, proceed" ); // No tr |
393 | state = Ready; | 392 | state = Ready; |
394 | if ( sendSync ) { | 393 | if ( sendSync ) { |
395 | sendDesktopMessage( "startSync()" ); | 394 | sendDesktopMessage( "startSync()" ); |
396 | sendSync = FALSE; | 395 | sendSync = FALSE; |
397 | } | 396 | } |
398 | return; | 397 | return; |
399 | } | 398 | } |
400 | 399 | ||
401 | // noop (NOOP) | 400 | // noop (NOOP) |
402 | else if ( cmd == "NOOP" ) { | 401 | else if ( cmd == "NOOP" ) { |
403 | send( "200 Command okay" ); // No tr | 402 | send( "200 Command okay" ); // No tr |
404 | } | 403 | } |
405 | 404 | ||
406 | // call (CALL) | 405 | // call (CALL) |
407 | else if ( cmd == "CALL" ) { | 406 | else if ( cmd == "CALL" ) { |
408 | 407 | ||
409 | // example: call QPE/System execute(QString) addressbook | 408 | // example: call QPE/System execute(QString) addressbook |
410 | 409 | ||
411 | if ( msg.count() < 3 ) { | 410 | if ( msg.count() < 3 ) { |
412 | send( "500 Syntax error, command unrecognized" ); // No tr | 411 | send( "500 Syntax error, command unrecognized" ); // No tr |
413 | } | 412 | } |
414 | else { | 413 | else { |
415 | 414 | ||
416 | QString channel = msg[1]; | 415 | QString channel = msg[1]; |
417 | QString command = msg[2]; | 416 | QString command = msg[2]; |
418 | 417 | ||
419 | command.stripWhiteSpace(); | 418 | command.stripWhiteSpace(); |
420 | 419 | ||
421 | int paren = command.find( "(" ); | 420 | int paren = command.find( "(" ); |
422 | if ( paren <= 0 ) { | 421 | if ( paren <= 0 ) { |
423 | send( "500 Syntax error, command unrecognized" ); // No tr | 422 | send( "500 Syntax error, command unrecognized" ); // No tr |
424 | return; | 423 | return; |
425 | } | 424 | } |
426 | 425 | ||
427 | QString params = command.mid( paren + 1 ); | 426 | QString params = command.mid( paren + 1 ); |
428 | if ( params[(int)params.length()-1] != ')' ) { | 427 | if ( params[(int)params.length()-1] != ')' ) { |
429 | send( "500 Syntax error, command unrecognized" ); // No tr | 428 | send( "500 Syntax error, command unrecognized" ); // No tr |
430 | return; | 429 | return; |
431 | } | 430 | } |
432 | 431 | ||
433 | params.truncate( params.length()-1 ); | 432 | params.truncate( params.length()-1 ); |
434 | QByteArray buffer; | 433 | QByteArray buffer; |
435 | QDataStream ds( buffer, IO_WriteOnly ); | 434 | QDataStream ds( buffer, IO_WriteOnly ); |
436 | 435 | ||
437 | int msgId = 3; | 436 | int msgId = 3; |
438 | 437 | ||
439 | QStringList paramList = QStringList::split( ",", params ); | 438 | QStringList paramList = QStringList::split( ",", params ); |
440 | if ( paramList.count() > msg.count() - 3 ) { | 439 | if ( paramList.count() > msg.count() - 3 ) { |
441 | send( "500 Syntax error, command unrecognized" ); // No tr | 440 | send( "500 Syntax error, command unrecognized" ); // No tr |
442 | return; | 441 | return; |
443 | } | 442 | } |
444 | 443 | ||
445 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { | 444 | for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { |
446 | 445 | ||
447 | QString arg = msg[msgId]; | 446 | QString arg = msg[msgId]; |
448 | arg.replace( QRegExp("&0x20;"), " " ); | 447 | arg.replace( QRegExp("&0x20;"), " " ); |
449 | arg.replace( QRegExp("&"), "&" ); | 448 | arg.replace( QRegExp("&"), "&" ); |
450 | arg.replace( QRegExp("&0x0d;"), "\n" ); | 449 | arg.replace( QRegExp("&0x0d;"), "\n" ); |
451 | arg.replace( QRegExp("&0x0a;"), "\r" ); | 450 | arg.replace( QRegExp("&0x0a;"), "\r" ); |
452 | if ( *it == "QString" ) | 451 | if ( *it == "QString" ) |
453 | ds << arg; | 452 | ds << arg; |
454 | else if ( *it == "QCString" ) | 453 | else if ( *it == "QCString" ) |
455 | ds << arg.local8Bit(); | 454 | ds << arg.local8Bit(); |
456 | else if ( *it == "int" ) | 455 | else if ( *it == "int" ) |
457 | ds << arg.toInt(); | 456 | ds << arg.toInt(); |
458 | else if ( *it == "bool" ) | 457 | else if ( *it == "bool" ) |
459 | ds << arg.toInt(); | 458 | ds << arg.toInt(); |
460 | else { | 459 | else { |
461 | send( "500 Syntax error, command unrecognized" ); // No tr | 460 | send( "500 Syntax error, command unrecognized" ); // No tr |
462 | return; | 461 | return; |
463 | } | 462 | } |
464 | msgId++; | 463 | msgId++; |
465 | } | 464 | } |
466 | 465 | ||
467 | #ifndef QT_NO_COP | 466 | #ifndef QT_NO_COP |
468 | if ( !QCopChannel::isRegistered( channel.latin1() ) ) { | 467 | if ( !QCopChannel::isRegistered( channel.latin1() ) ) { |
469 | // send message back about it | 468 | // send message back about it |
470 | QString answer = "599 ChannelNotRegistered " + channel; | 469 | QString answer = "599 ChannelNotRegistered " + channel; |
471 | send( answer ); | 470 | send( answer ); |
472 | return; | 471 | return; |
473 | } | 472 | } |
474 | #endif | 473 | #endif |
475 | 474 | ||
476 | #ifndef QT_NO_COP | 475 | #ifndef QT_NO_COP |
477 | if ( paramList.count() ) | 476 | if ( paramList.count() ) |
478 | QCopChannel::send( channel.latin1(), command.latin1(), buffer ); | 477 | QCopChannel::send( channel.latin1(), command.latin1(), buffer ); |
479 | else | 478 | else |
480 | QCopChannel::send( channel.latin1(), command.latin1() ); | 479 | QCopChannel::send( channel.latin1(), command.latin1() ); |
481 | 480 | ||
482 | send( "200 Command okay" ); // No tr | 481 | send( "200 Command okay" ); // No tr |
483 | #endif | 482 | #endif |
484 | } | 483 | } |
485 | } | 484 | } |
486 | // not implemented | 485 | // not implemented |
487 | else | 486 | else |
488 | send( "502 Command not implemented" ); // No tr | 487 | send( "502 Command not implemented" ); // No tr |
489 | } | 488 | } |
490 | 489 | ||
491 | 490 | ||
diff --git a/core/launcher/qprocess.cpp b/core/launcher/qprocess.cpp index 97bd539..3fe1238 100644 --- a/core/launcher/qprocess.cpp +++ b/core/launcher/qprocess.cpp | |||
@@ -72,568 +72,568 @@ | |||
72 | 72 | ||
73 | \sa setArguments() addArgument() start() | 73 | \sa setArguments() addArgument() start() |
74 | */ | 74 | */ |
75 | QProcess::QProcess( QObject *parent, const char *name ) | 75 | QProcess::QProcess( QObject *parent, const char *name ) |
76 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), | 76 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), |
77 | wroteToStdinConnected( FALSE ), | 77 | wroteToStdinConnected( FALSE ), |
78 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), | 78 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), |
79 | comms( Stdin|Stdout|Stderr ) | 79 | comms( Stdin|Stdout|Stderr ) |
80 | { | 80 | { |
81 | init(); | 81 | init(); |
82 | } | 82 | } |
83 | 83 | ||
84 | /*! | 84 | /*! |
85 | Constructs a QProcess with \a arg0 as the command to be executed. The | 85 | Constructs a QProcess with \a arg0 as the command to be executed. The |
86 | \a parent and \a name parameters are passed to the QObject constructor. | 86 | \a parent and \a name parameters are passed to the QObject constructor. |
87 | 87 | ||
88 | The process is not started. You must call start() or launch() | 88 | The process is not started. You must call start() or launch() |
89 | to start the process. | 89 | to start the process. |
90 | 90 | ||
91 | \sa setArguments() addArgument() start() | 91 | \sa setArguments() addArgument() start() |
92 | */ | 92 | */ |
93 | QProcess::QProcess( const QString& arg0, QObject *parent, const char *name ) | 93 | QProcess::QProcess( const QString& arg0, QObject *parent, const char *name ) |
94 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), | 94 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), |
95 | wroteToStdinConnected( FALSE ), | 95 | wroteToStdinConnected( FALSE ), |
96 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), | 96 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), |
97 | comms( Stdin|Stdout|Stderr ) | 97 | comms( Stdin|Stdout|Stderr ) |
98 | { | 98 | { |
99 | init(); | 99 | init(); |
100 | addArgument( arg0 ); | 100 | addArgument( arg0 ); |
101 | } | 101 | } |
102 | 102 | ||
103 | /*! | 103 | /*! |
104 | Constructs a QProcess with \a args as the arguments of the process. The first | 104 | Constructs a QProcess with \a args as the arguments of the process. The first |
105 | element in the list is the command to be executed. The other elements in the | 105 | element in the list is the command to be executed. The other elements in the |
106 | list are the arguments to this command. The \a parent and \a name | 106 | list are the arguments to this command. The \a parent and \a name |
107 | parameters are passed to the QObject constructor. | 107 | parameters are passed to the QObject constructor. |
108 | 108 | ||
109 | The process is not started. You must call start() or launch() | 109 | The process is not started. You must call start() or launch() |
110 | to start the process. | 110 | to start the process. |
111 | 111 | ||
112 | \sa setArguments() addArgument() start() | 112 | \sa setArguments() addArgument() start() |
113 | */ | 113 | */ |
114 | QProcess::QProcess( const QStringList& args, QObject *parent, const char *name ) | 114 | QProcess::QProcess( const QStringList& args, QObject *parent, const char *name ) |
115 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), | 115 | : QObject( parent, name ), ioRedirection( FALSE ), notifyOnExit( FALSE ), |
116 | wroteToStdinConnected( FALSE ), | 116 | wroteToStdinConnected( FALSE ), |
117 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), | 117 | readStdoutCalled( FALSE ), readStderrCalled( FALSE ), |
118 | comms( Stdin|Stdout|Stderr ) | 118 | comms( Stdin|Stdout|Stderr ) |
119 | { | 119 | { |
120 | init(); | 120 | init(); |
121 | setArguments( args ); | 121 | setArguments( args ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | /*! | 125 | /*! |
126 | Returns the list of arguments that are set for the process. Arguments can be | 126 | Returns the list of arguments that are set for the process. Arguments can be |
127 | specified with the constructor or with the functions setArguments() and | 127 | specified with the constructor or with the functions setArguments() and |
128 | addArgument(). | 128 | addArgument(). |
129 | 129 | ||
130 | \sa setArguments() addArgument() | 130 | \sa setArguments() addArgument() |
131 | */ | 131 | */ |
132 | QStringList QProcess::arguments() const | 132 | QStringList QProcess::arguments() const |
133 | { | 133 | { |
134 | return _arguments; | 134 | return _arguments; |
135 | } | 135 | } |
136 | 136 | ||
137 | /*! | 137 | /*! |
138 | Clears the list of arguments that are set for the process. | 138 | Clears the list of arguments that are set for the process. |
139 | 139 | ||
140 | \sa setArguments() addArgument() | 140 | \sa setArguments() addArgument() |
141 | */ | 141 | */ |
142 | void QProcess::clearArguments() | 142 | void QProcess::clearArguments() |
143 | { | 143 | { |
144 | _arguments.clear(); | 144 | _arguments.clear(); |
145 | } | 145 | } |
146 | 146 | ||
147 | /*! | 147 | /*! |
148 | Sets \a args as the arguments for the process. The first element in the list | 148 | Sets \a args as the arguments for the process. The first element in the list |
149 | is the command to be executed. The other elements in the list are the | 149 | is the command to be executed. The other elements in the list are the |
150 | arguments to the command. Any previous arguments are deleted. | 150 | arguments to the command. Any previous arguments are deleted. |
151 | 151 | ||
152 | \sa arguments() addArgument() | 152 | \sa arguments() addArgument() |
153 | */ | 153 | */ |
154 | void QProcess::setArguments( const QStringList& args ) | 154 | void QProcess::setArguments( const QStringList& args ) |
155 | { | 155 | { |
156 | _arguments = args; | 156 | _arguments = args; |
157 | } | 157 | } |
158 | 158 | ||
159 | /*! | 159 | /*! |
160 | Adds \a arg to the end of the list of arguments. | 160 | Adds \a arg to the end of the list of arguments. |
161 | 161 | ||
162 | The first element in the list of arguments is the command to be | 162 | The first element in the list of arguments is the command to be |
163 | executed; the following elements are the arguments to the command. | 163 | executed; the following elements are the arguments to the command. |
164 | 164 | ||
165 | \sa arguments() setArguments() | 165 | \sa arguments() setArguments() |
166 | */ | 166 | */ |
167 | void QProcess::addArgument( const QString& arg ) | 167 | void QProcess::addArgument( const QString& arg ) |
168 | { | 168 | { |
169 | _arguments.append( arg ); | 169 | _arguments.append( arg ); |
170 | } | 170 | } |
171 | 171 | ||
172 | #ifndef QT_NO_DIR | 172 | #ifndef QT_NO_DIR |
173 | /*! | 173 | /*! |
174 | Returns the working directory that was set with | 174 | Returns the working directory that was set with |
175 | setWorkingDirectory(), or the current directory if none has been | 175 | setWorkingDirectory(), or the current directory if none has been |
176 | set. | 176 | set. |
177 | 177 | ||
178 | \sa setWorkingDirectory() QDir::current() | 178 | \sa setWorkingDirectory() QDir::current() |
179 | */ | 179 | */ |
180 | QDir QProcess::workingDirectory() const | 180 | QDir QProcess::workingDirectory() const |
181 | { | 181 | { |
182 | return workingDir; | 182 | return workingDir; |
183 | } | 183 | } |
184 | 184 | ||
185 | /*! | 185 | /*! |
186 | Sets \a dir as the working directory for a process. This does not affect | 186 | Sets \a dir as the working directory for a process. This does not affect |
187 | running processes; only processes that are started afterwards are affected. | 187 | running processes; only processes that are started afterwards are affected. |
188 | 188 | ||
189 | Setting the working directory is especially useful for processes that try to | 189 | Setting the working directory is especially useful for processes that try to |
190 | access files with relative filenames. | 190 | access files with relative filenames. |
191 | 191 | ||
192 | \sa workingDirectory() start() | 192 | \sa workingDirectory() start() |
193 | */ | 193 | */ |
194 | void QProcess::setWorkingDirectory( const QDir& dir ) | 194 | void QProcess::setWorkingDirectory( const QDir& dir ) |
195 | { | 195 | { |
196 | workingDir = dir; | 196 | workingDir = dir; |
197 | } | 197 | } |
198 | #endif //QT_NO_DIR | 198 | #endif //QT_NO_DIR |
199 | 199 | ||
200 | /*! | 200 | /*! |
201 | Returns the communication required with the process. | 201 | Returns the communication required with the process. |
202 | 202 | ||
203 | \sa setCommunication() | 203 | \sa setCommunication() |
204 | */ | 204 | */ |
205 | int QProcess::communication() const | 205 | int QProcess::communication() const |
206 | { | 206 | { |
207 | return comms; | 207 | return comms; |
208 | } | 208 | } |
209 | 209 | ||
210 | /*! | 210 | /*! |
211 | Sets \a commFlags as the communication required with the process. | 211 | Sets \a commFlags as the communication required with the process. |
212 | 212 | ||
213 | \a commFlags is a bitwise OR between the flags defined in \c Communication. | 213 | \a commFlags is a bitwise OR between the flags defined in \c Communication. |
214 | 214 | ||
215 | The default is \c{Stdin|Stdout|Stderr}. | 215 | The default is \c{Stdin|Stdout|Stderr}. |
216 | 216 | ||
217 | \sa communication() | 217 | \sa communication() |
218 | */ | 218 | */ |
219 | void QProcess::setCommunication( int commFlags ) | 219 | void QProcess::setCommunication( int commFlags ) |
220 | { | 220 | { |
221 | comms = commFlags; | 221 | comms = commFlags; |
222 | } | 222 | } |
223 | 223 | ||
224 | /*! | 224 | /*! |
225 | Returns TRUE if the process has exited normally; otherwise returns | 225 | Returns TRUE if the process has exited normally; otherwise returns |
226 | FALSE. This implies that this function returns FALSE if the process | 226 | FALSE. This implies that this function returns FALSE if the process |
227 | is still running. | 227 | is still running. |
228 | 228 | ||
229 | \sa isRunning() exitStatus() processExited() | 229 | \sa isRunning() exitStatus() processExited() |
230 | */ | 230 | */ |
231 | bool QProcess::normalExit() const | 231 | bool QProcess::normalExit() const |
232 | { | 232 | { |
233 | // isRunning() has the side effect that it determines the exit status! | 233 | // isRunning() has the side effect that it determines the exit status! |
234 | if ( isRunning() ) | 234 | if ( isRunning() ) |
235 | return FALSE; | 235 | return FALSE; |
236 | else | 236 | else |
237 | return exitNormal; | 237 | return exitNormal; |
238 | } | 238 | } |
239 | 239 | ||
240 | /*! | 240 | /*! |
241 | Returns the exit status of the process or 0 if the process is still | 241 | Returns the exit status of the process or 0 if the process is still |
242 | running. This function returns immediately and does not wait until | 242 | running. This function returns immediately and does not wait until |
243 | the process is finished. | 243 | the process is finished. |
244 | 244 | ||
245 | If normalExit() is FALSE (e.g. if the program was killed or | 245 | If normalExit() is FALSE (e.g. if the program was killed or |
246 | crashed), this function returns 0, so you should check the return | 246 | crashed), this function returns 0, so you should check the return |
247 | value of normalExit() before relying on this value. | 247 | value of normalExit() before relying on this value. |
248 | 248 | ||
249 | \sa normalExit() processExited() | 249 | \sa normalExit() processExited() |
250 | */ | 250 | */ |
251 | int QProcess::exitStatus() const | 251 | int QProcess::exitStatus() const |
252 | { | 252 | { |
253 | // isRunning() has the side effect that it determines the exit status! | 253 | // isRunning() has the side effect that it determines the exit status! |
254 | if ( isRunning() ) | 254 | if ( isRunning() ) |
255 | return 0; | 255 | return 0; |
256 | else | 256 | else |
257 | return exitStat; | 257 | return exitStat; |
258 | } | 258 | } |
259 | 259 | ||
260 | 260 | ||
261 | /*! | 261 | /*! |
262 | Reads the data that the process has written to standard output. When | 262 | Reads the data that the process has written to standard output. When |
263 | new data is written to standard output, the class emits the signal | 263 | new data is written to standard output, the class emits the signal |
264 | readyReadStdout(). | 264 | readyReadStdout(). |
265 | 265 | ||
266 | If there is no data to read, this function returns a QByteArray of | 266 | If there is no data to read, this function returns a QByteArray of |
267 | size 0: it does not wait until there is something to read. | 267 | size 0: it does not wait until there is something to read. |
268 | 268 | ||
269 | \sa readyReadStdout() readLineStdout() readStderr() writeToStdin() | 269 | \sa readyReadStdout() readLineStdout() readStderr() writeToStdin() |
270 | */ | 270 | */ |
271 | QByteArray QProcess::readStdout() | 271 | QByteArray QProcess::readStdout() |
272 | { | 272 | { |
273 | if ( readStdoutCalled ) { | 273 | if ( readStdoutCalled ) { |
274 | return QByteArray(); | 274 | return QByteArray(); |
275 | } | 275 | } |
276 | readStdoutCalled = TRUE; | 276 | readStdoutCalled = TRUE; |
277 | 277 | ||
278 | QByteArray buf = bufStdout()->copy(); | 278 | QByteArray buf = bufStdout()->copy(); |
279 | consumeBufStdout( -1 ); // consume everything | 279 | consumeBufStdout( -1 ); // consume everything |
280 | 280 | ||
281 | readStdoutCalled = FALSE; | 281 | readStdoutCalled = FALSE; |
282 | return buf; | 282 | return buf; |
283 | } | 283 | } |
284 | 284 | ||
285 | /*! | 285 | /*! |
286 | Reads the data that the process has written to standard error. When | 286 | Reads the data that the process has written to standard error. When |
287 | new data is written to standard error, the class emits the signal | 287 | new data is written to standard error, the class emits the signal |
288 | readyReadStderr(). | 288 | readyReadStderr(). |
289 | 289 | ||
290 | If there is no data to read, this function returns a QByteArray of | 290 | If there is no data to read, this function returns a QByteArray of |
291 | size 0: it does not wait until there is something to read. | 291 | size 0: it does not wait until there is something to read. |
292 | 292 | ||
293 | \sa readyReadStderr() readLineStderr() readStdout() writeToStdin() | 293 | \sa readyReadStderr() readLineStderr() readStdout() writeToStdin() |
294 | */ | 294 | */ |
295 | QByteArray QProcess::readStderr() | 295 | QByteArray QProcess::readStderr() |
296 | { | 296 | { |
297 | if ( readStderrCalled ) { | 297 | if ( readStderrCalled ) { |
298 | return QByteArray(); | 298 | return QByteArray(); |
299 | } | 299 | } |
300 | readStderrCalled = TRUE; | 300 | readStderrCalled = TRUE; |
301 | 301 | ||
302 | QByteArray buf = bufStderr()->copy(); | 302 | QByteArray buf = bufStderr()->copy(); |
303 | consumeBufStderr( -1 ); // consume everything | 303 | consumeBufStderr( -1 ); // consume everything |
304 | 304 | ||
305 | readStderrCalled = FALSE; | 305 | readStderrCalled = FALSE; |
306 | return buf; | 306 | return buf; |
307 | } | 307 | } |
308 | 308 | ||
309 | /*! | 309 | /*! |
310 | Returns TRUE if it's possible to read an entire line of text from | 310 | Returns TRUE if it's possible to read an entire line of text from |
311 | standard output at this time; otherwise returns FALSE. | 311 | standard output at this time; otherwise returns FALSE. |
312 | 312 | ||
313 | \sa readLineStdout() canReadLineStderr() | 313 | \sa readLineStdout() canReadLineStderr() |
314 | */ | 314 | */ |
315 | bool QProcess::canReadLineStdout() const | 315 | bool QProcess::canReadLineStdout() const |
316 | { | 316 | { |
317 | QProcess *that = (QProcess*)this; | 317 | QProcess *that = (QProcess*)this; |
318 | return that->scanNewline( TRUE, 0 ); | 318 | return that->scanNewline( TRUE, 0 ); |
319 | } | 319 | } |
320 | 320 | ||
321 | /*! | 321 | /*! |
322 | Returns TRUE if it's possible to read an entire line of text from | 322 | Returns TRUE if it's possible to read an entire line of text from |
323 | standard error at this time; otherwise returns FALSE. | 323 | standard error at this time; otherwise returns FALSE. |
324 | 324 | ||
325 | \sa readLineStderr() canReadLineStdout() | 325 | \sa readLineStderr() canReadLineStdout() |
326 | */ | 326 | */ |
327 | bool QProcess::canReadLineStderr() const | 327 | bool QProcess::canReadLineStderr() const |
328 | { | 328 | { |
329 | QProcess *that = (QProcess*)this; | 329 | QProcess *that = (QProcess*)this; |
330 | return that->scanNewline( FALSE, 0 ); | 330 | return that->scanNewline( FALSE, 0 ); |
331 | } | 331 | } |
332 | 332 | ||
333 | /*! | 333 | /*! |
334 | Reads a line of text from standard output, excluding any trailing newline or | 334 | Reads a line of text from standard output, excluding any trailing newline or |
335 | carriage return characters, and returns it. Returns QString::null if | 335 | carriage return characters, and returns it. Returns QString::null if |
336 | canReadLineStdout() returns FALSE. | 336 | canReadLineStdout() returns FALSE. |
337 | 337 | ||
338 | \sa canReadLineStdout() readyReadStdout() readStdout() readLineStderr() | 338 | \sa canReadLineStdout() readyReadStdout() readStdout() readLineStderr() |
339 | */ | 339 | */ |
340 | QString QProcess::readLineStdout() | 340 | QString QProcess::readLineStdout() |
341 | { | 341 | { |
342 | QByteArray a; | 342 | QByteArray a; |
343 | QString s; | 343 | QString s; |
344 | if ( scanNewline( TRUE, &a ) ) { | 344 | if ( scanNewline( TRUE, &a ) ) { |
345 | if ( a.isEmpty() ) | 345 | if ( a.isEmpty() ) |
346 | s = ""; | 346 | s = ""; |
347 | else | 347 | else |
348 | s = QString( a ); | 348 | s = QString( a ); |
349 | } | 349 | } |
350 | return s; | 350 | return s; |
351 | } | 351 | } |
352 | 352 | ||
353 | /*! | 353 | /*! |
354 | Reads a line of text from standard error, excluding any trailing newline or | 354 | Reads a line of text from standard error, excluding any trailing newline or |
355 | carriage return characters and returns it. Returns QString::null if | 355 | carriage return characters and returns it. Returns QString::null if |
356 | canReadLineStderr() returns FALSE. | 356 | canReadLineStderr() returns FALSE. |
357 | 357 | ||
358 | \sa canReadLineStderr() readyReadStderr() readStderr() readLineStdout() | 358 | \sa canReadLineStderr() readyReadStderr() readStderr() readLineStdout() |
359 | */ | 359 | */ |
360 | QString QProcess::readLineStderr() | 360 | QString QProcess::readLineStderr() |
361 | { | 361 | { |
362 | QByteArray a; | 362 | QByteArray a; |
363 | QString s; | 363 | QString s; |
364 | if ( scanNewline( FALSE, &a ) ) { | 364 | if ( scanNewline( FALSE, &a ) ) { |
365 | if ( a.isEmpty() ) | 365 | if ( a.isEmpty() ) |
366 | s = ""; | 366 | s = ""; |
367 | else | 367 | else |
368 | s = QString( a ); | 368 | s = QString( a ); |
369 | } | 369 | } |
370 | return s; | 370 | return s; |
371 | } | 371 | } |
372 | 372 | ||
373 | /*! | 373 | /*! |
374 | This private function scans for any occurrence of \n or \r\n in the | 374 | This private function scans for any occurrence of \n or \r\n in the |
375 | buffer \e buf. It stores the text in the byte array \a store if it is | 375 | buffer \e buf. It stores the text in the byte array \a store if it is |
376 | non-null. | 376 | non-null. |
377 | */ | 377 | */ |
378 | bool QProcess::scanNewline( bool stdOut, QByteArray *store ) | 378 | bool QProcess::scanNewline( bool stdOut, QByteArray *store ) |
379 | { | 379 | { |
380 | QByteArray *buf; | 380 | QByteArray *buf; |
381 | if ( stdOut ) | 381 | if ( stdOut ) |
382 | buf = bufStdout(); | 382 | buf = bufStdout(); |
383 | else | 383 | else |
384 | buf = bufStderr(); | 384 | buf = bufStderr(); |
385 | uint n = buf->size(); | 385 | uint n = buf->size(); |
386 | uint i; | 386 | uint i; |
387 | for ( i=0; i<n; i++ ) { | 387 | for ( i=0; i<n; i++ ) { |
388 | if ( buf->at(i) == '\n' ) { | 388 | if ( buf->at(i) == '\n' ) { |
389 | break; | 389 | break; |
390 | } | 390 | } |
391 | } | 391 | } |
392 | if ( i >= n ) | 392 | if ( i >= n ) |
393 | return FALSE; | 393 | return FALSE; |
394 | 394 | ||
395 | if ( store ) { | 395 | if ( store ) { |
396 | uint lineLength = i; | 396 | uint lineLength = i; |
397 | if ( lineLength>0 && buf->at(lineLength-1) == '\r' ) | 397 | if ( lineLength>0 && buf->at(lineLength-1) == '\r' ) |
398 | lineLength--; // (if there are two \r, let one stay) | 398 | lineLength--; // (if there are two \r, let one stay) |
399 | store->resize( lineLength ); | 399 | store->resize( lineLength ); |
400 | memcpy( store->data(), buf->data(), lineLength ); | 400 | memcpy( store->data(), buf->data(), lineLength ); |
401 | if ( stdOut ) | 401 | if ( stdOut ) |
402 | consumeBufStdout( i+1 ); | 402 | consumeBufStdout( i+1 ); |
403 | else | 403 | else |
404 | consumeBufStderr( i+1 ); | 404 | consumeBufStderr( i+1 ); |
405 | } | 405 | } |
406 | return TRUE; | 406 | return TRUE; |
407 | } | 407 | } |
408 | 408 | ||
409 | /*! | 409 | /*! |
410 | \fn void QProcess::launchFinished() | 410 | \fn void QProcess::launchFinished() |
411 | 411 | ||
412 | This signal is emitted when the process was started with launch(). | 412 | This signal is emitted when the process was started with launch(). |
413 | If the start was successful, this signal is emitted after all the | 413 | If the start was successful, this signal is emitted after all the |
414 | data has been written to standard input. If the start failed, then | 414 | data has been written to standard input. If the start failed, then |
415 | this signal is emitted immediately. | 415 | this signal is emitted immediately. |
416 | 416 | ||
417 | \sa launch() QObject::deleteLater() | 417 | \sa launch() QObject::deleteLater() |
418 | */ | 418 | */ |
419 | 419 | ||
420 | /*! | 420 | /*! |
421 | Runs the process and writes the data \a buf to the process's standard input. | 421 | Runs the process and writes the data \a buf to the process's standard input. |
422 | If all the data is written to standard input, standard input is | 422 | If all the data is written to standard input, standard input is |
423 | closed. The command is searched for in the path for executable programs; | 423 | closed. The command is searched for in the path for executable programs; |
424 | you can also use an absolute path in the command itself. | 424 | you can also use an absolute path in the command itself. |
425 | 425 | ||
426 | If \a env is null, then the process is started with the same environment as | 426 | If \a env is null, then the process is started with the same environment as |
427 | the starting process. If \a env is non-null, then the values in the | 427 | the starting process. If \a env is non-null, then the values in the |
428 | stringlist are interpreted as environment setttings of the form \c | 428 | stringlist are interpreted as environment setttings of the form \c |
429 | {key=value} and the process is started with these environment settings. For | 429 | {key=value} and the process is started with these environment settings. For |
430 | convenience, there is a small exception to this rule under Unix: if \a env | 430 | convenience, there is a small exception to this rule under Unix: if \a env |
431 | does not contain any settings for the environment variable \c | 431 | does not contain any settings for the environment variable \c |
432 | LD_LIBRARY_PATH, then this variable is inherited from the starting process. | 432 | LD_LIBRARY_PATH, then this variable is inherited from the starting process. |
433 | 433 | ||
434 | Returns TRUE if the process could be started; otherwise returns FALSE. | 434 | Returns TRUE if the process could be started; otherwise returns FALSE. |
435 | 435 | ||
436 | Note that you should not use the slots writeToStdin() and closeStdin() on | 436 | Note that you should not use the slots writeToStdin() and closeStdin() on |
437 | processes started with launch(), since the result is not well-defined. If you | 437 | processes started with launch(), since the result is not well-defined. If you |
438 | need these slots, use start() instead. | 438 | need these slots, use start() instead. |
439 | 439 | ||
440 | The process may or may not read the \a buf data sent to its standard | 440 | The process may or may not read the \a buf data sent to its standard |
441 | input. | 441 | input. |
442 | 442 | ||
443 | You can call this function even when a process that was started with | 443 | You can call this function even when a process that was started with |
444 | this instance is still running. Be aware that if you do this the | 444 | this instance is still running. Be aware that if you do this the |
445 | standard input of the process that was launched first will be | 445 | standard input of the process that was launched first will be |
446 | closed, with any pending data being deleted, and the process will be | 446 | closed, with any pending data being deleted, and the process will be |
447 | left to run out of your control. Similarly, if the process could not | 447 | left to run out of your control. Similarly, if the process could not |
448 | be started the standard input will be closed and the pending data | 448 | be started the standard input will be closed and the pending data |
449 | deleted. (On operating systems that have zombie processes, Qt will | 449 | deleted. (On operating systems that have zombie processes, Qt will |
450 | also wait() on the old process.) | 450 | also wait() on the old process.) |
451 | 451 | ||
452 | The object emits the signal launchFinished() when this function | 452 | The object emits the signal launchFinished() when this function |
453 | call is finished. If the start was successful, this signal is | 453 | call is finished. If the start was successful, this signal is |
454 | emitted after all the data has been written to standard input. If | 454 | emitted after all the data has been written to standard input. If |
455 | the start failed, then this signal is emitted immediately. | 455 | the start failed, then this signal is emitted immediately. |
456 | 456 | ||
457 | \sa start() launchFinished(); | 457 | \sa start() launchFinished(); |
458 | */ | 458 | */ |
459 | bool QProcess::launch( const QByteArray& buf, QStringList *env ) | 459 | bool QProcess::launch( const QByteArray& buf, QStringList *env ) |
460 | { | 460 | { |
461 | if ( start( env ) ) { | 461 | if ( start( env ) ) { |
462 | if ( !buf.isEmpty() ) { | 462 | if ( !buf.isEmpty() ) { |
463 | connect( this, SIGNAL(wroteToStdin()), | 463 | connect( this, SIGNAL(wroteToStdin()), |
464 | this, SLOT(closeStdinLaunch()) ); | 464 | this, SLOT(closeStdinLaunch()) ); |
465 | writeToStdin( buf ); | 465 | writeToStdin( buf ); |
466 | } else { | 466 | } else { |
467 | closeStdin(); | 467 | closeStdin(); |
468 | emit launchFinished(); | 468 | emit launchFinished(); |
469 | } | 469 | } |
470 | return TRUE; | 470 | return TRUE; |
471 | } else { | 471 | } else { |
472 | emit launchFinished(); | 472 | emit launchFinished(); |
473 | return FALSE; | 473 | return FALSE; |
474 | } | 474 | } |
475 | } | 475 | } |
476 | 476 | ||
477 | /*! \overload | 477 | /*! \overload |
478 | 478 | ||
479 | The data \a buf is written to standard input with writeToStdin() | 479 | The data \a buf is written to standard input with writeToStdin() |
480 | using the QString::local8Bit() representation of the strings. | 480 | using the QString::local8Bit() representation of the strings. |
481 | */ | 481 | */ |
482 | bool QProcess::launch( const QString& buf, QStringList *env ) | 482 | bool QProcess::launch( const QString& buf, QStringList *env ) |
483 | { | 483 | { |
484 | if ( start( env ) ) { | 484 | if ( start( env ) ) { |
485 | if ( !buf.isEmpty() ) { | 485 | if ( !buf.isEmpty() ) { |
486 | connect( this, SIGNAL(wroteToStdin()), | 486 | connect( this, SIGNAL(wroteToStdin()), |
487 | this, SLOT(closeStdinLaunch()) ); | 487 | this, SLOT(closeStdinLaunch()) ); |
488 | writeToStdin( buf ); | 488 | writeToStdin( buf ); |
489 | } else { | 489 | } else { |
490 | closeStdin(); | 490 | closeStdin(); |
491 | emit launchFinished(); | 491 | emit launchFinished(); |
492 | } | 492 | } |
493 | return TRUE; | 493 | return TRUE; |
494 | } else { | 494 | } else { |
495 | emit launchFinished(); | 495 | emit launchFinished(); |
496 | return FALSE; | 496 | return FALSE; |
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | /*! | 500 | /*! |
501 | This private slot is used by the launch() functions to close standard input. | 501 | This private slot is used by the launch() functions to close standard input. |
502 | */ | 502 | */ |
503 | void QProcess::closeStdinLaunch() | 503 | void QProcess::closeStdinLaunch() |
504 | { | 504 | { |
505 | disconnect( this, SIGNAL(wroteToStdin()), | 505 | disconnect( this, SIGNAL(wroteToStdin()), |
506 | this, SLOT(closeStdinLaunch()) ); | 506 | this, SLOT(closeStdinLaunch()) ); |
507 | closeStdin(); | 507 | closeStdin(); |
508 | emit launchFinished(); | 508 | emit launchFinished(); |
509 | } | 509 | } |
510 | 510 | ||
511 | 511 | ||
512 | /*! | 512 | /*! |
513 | \fn void QProcess::readyReadStdout() | 513 | \fn void QProcess::readyReadStdout() |
514 | 514 | ||
515 | This signal is emitted when the process has written data to standard output. | 515 | This signal is emitted when the process has written data to standard output. |
516 | You can read the data with readStdout(). | 516 | You can read the data with readStdout(). |
517 | 517 | ||
518 | Note that this signal is only emitted when there is new data and not | 518 | Note that this signal is only emitted when there is new data and not |
519 | when there is old, but unread data. In the slot connected to this signal, you | 519 | when there is old, but unread data. In the slot connected to this signal, you |
520 | should always read everything that is available at that moment to make sure | 520 | should always read everything that is available at that moment to make sure |
521 | that you don't lose any data. | 521 | that you don't lose any data. |
522 | 522 | ||
523 | \sa readStdout() readLineStdout() readyReadStderr() | 523 | \sa readStdout() readLineStdout() readyReadStderr() |
524 | */ | 524 | */ |
525 | /*! | 525 | /*! |
526 | \fn void QProcess::readyReadStderr() | 526 | \fn void QProcess::readyReadStderr() |
527 | 527 | ||
528 | This signal is emitted when the process has written data to standard error. | 528 | This signal is emitted when the process has written data to standard error. |
529 | You can read the data with readStderr(). | 529 | You can read the data with readStderr(). |
530 | 530 | ||
531 | Note that this signal is only emitted when there is new data and not | 531 | Note that this signal is only emitted when there is new data and not |
532 | when there is old, but unread data. In the slot connected to this signal, you | 532 | when there is old, but unread data. In the slot connected to this signal, you |
533 | should always read everything that is available at that moment to make sure | 533 | should always read everything that is available at that moment to make sure |
534 | that you don't lose any data. | 534 | that you don't lose any data. |
535 | 535 | ||
536 | \sa readStderr() readLineStderr() readyReadStdout() | 536 | \sa readStderr() readLineStderr() readyReadStdout() |
537 | */ | 537 | */ |
538 | /*! | 538 | /*! |
539 | \fn void QProcess::processExited() | 539 | \fn void QProcess::processExited() |
540 | 540 | ||
541 | This signal is emitted when the process has exited. | 541 | This signal is emitted when the process has exited. |
542 | 542 | ||
543 | \sa isRunning() normalExit() exitStatus() start() launch() | 543 | \sa isRunning() normalExit() exitStatus() start() launch() |
544 | */ | 544 | */ |
545 | /*! | 545 | /*! |
546 | \fn void QProcess::wroteToStdin() | 546 | \fn void QProcess::wroteToStdin() |
547 | 547 | ||
548 | This signal is emitted if the data sent to standard input (via | 548 | This signal is emitted if the data sent to standard input (via |
549 | writeToStdin()) was actually written to the process. This does not | 549 | writeToStdin()) was actually written to the process. This does not |
550 | imply that the process really read the data, since this class only detects | 550 | imply that the process really read the data, since this class only detects |
551 | when it was able to write the data to the operating system. But it is now | 551 | when it was able to write the data to the operating system. But it is now |
552 | safe to close standard input without losing pending data. | 552 | safe to close standard input without losing pending data. |
553 | 553 | ||
554 | \sa writeToStdin() closeStdin() | 554 | \sa writeToStdin() closeStdin() |
555 | */ | 555 | */ |
556 | 556 | ||
557 | 557 | ||
558 | /*! \overload | 558 | /*! \overload |
559 | 559 | ||
560 | The string \a buf is handled as text using | 560 | The string \a buf is handled as text using |
561 | the QString::local8Bit() representation. | 561 | the QString::local8Bit() representation. |
562 | */ | 562 | */ |
563 | void QProcess::writeToStdin( const QString& buf ) | 563 | void QProcess::writeToStdin( const QString& buf ) |
564 | { | 564 | { |
565 | QByteArray tmp = buf.local8Bit(); | 565 | QByteArray tmp = buf.local8Bit(); |
566 | tmp.resize( buf.length() ); | 566 | tmp.resize( buf.length() ); |
567 | writeToStdin( tmp ); | 567 | writeToStdin( tmp ); |
568 | } | 568 | } |
569 | 569 | ||
570 | 570 | ||
571 | /* | 571 | /* |
572 | * Under Windows the implementation is not so nice: it is not that easy to | 572 | * Under Windows the implementation is not so nice: it is not that easy to |
573 | * detect when one of the signals should be emitted; therefore there are some | 573 | * detect when one of the signals should be emitted; therefore there are some |
574 | * timers that query the information. | 574 | * timers that query the information. |
575 | * To keep it a little efficient, use the timers only when they are needed. | 575 | * To keep it a little efficient, use the timers only when they are needed. |
576 | * They are needed, if you are interested in the signals. So use | 576 | * They are needed, if you are interested in the signals. So use |
577 | * connectNotify() and disconnectNotify() to keep track of your interest. | 577 | * connectNotify() and disconnectNotify() to keep track of your interest. |
578 | */ | 578 | */ |
579 | /*! \reimp | 579 | /*! \reimp |
580 | */ | 580 | */ |
581 | void QProcess::connectNotify( const char * signal ) | 581 | void QProcess::connectNotify( const char * signal ) |
582 | { | 582 | { |
583 | #if defined(QT_QPROCESS_DEBUG) | 583 | #if defined(QT_QPROCESS_DEBUG) |
584 | qDebug( "QProcess::connectNotify(): signal %s has been connected", signal ); | 584 | odebug << "QProcess::connectNotify(): signal " << signal << " has been connected" << oendl; |
585 | #endif | 585 | #endif |
586 | if ( !ioRedirection ) | 586 | if ( !ioRedirection ) |
587 | if ( qstrcmp( signal, SIGNAL(readyReadStdout()) )==0 || | 587 | if ( qstrcmp( signal, SIGNAL(readyReadStdout()) )==0 || |
588 | qstrcmp( signal, SIGNAL(readyReadStderr()) )==0 | 588 | qstrcmp( signal, SIGNAL(readyReadStderr()) )==0 |
589 | ) { | 589 | ) { |
590 | #if defined(QT_QPROCESS_DEBUG) | 590 | #if defined(QT_QPROCESS_DEBUG) |
591 | qDebug( "QProcess::connectNotify(): set ioRedirection to TRUE" ); | 591 | odebug << "QProcess::connectNotify(): set ioRedirection to TRUE" << oendl; |
592 | #endif | 592 | #endif |
593 | setIoRedirection( TRUE ); | 593 | setIoRedirection( TRUE ); |
594 | return; | 594 | return; |
595 | } | 595 | } |
596 | if ( !notifyOnExit && qstrcmp( signal, SIGNAL(processExited()) )==0 ) { | 596 | if ( !notifyOnExit && qstrcmp( signal, SIGNAL(processExited()) )==0 ) { |
597 | #if defined(QT_QPROCESS_DEBUG) | 597 | #if defined(QT_QPROCESS_DEBUG) |
598 | qDebug( "QProcess::connectNotify(): set notifyOnExit to TRUE" ); | 598 | odebug << "QProcess::connectNotify(): set notifyOnExit to TRUE" << oendl; |
599 | #endif | 599 | #endif |
600 | setNotifyOnExit( TRUE ); | 600 | setNotifyOnExit( TRUE ); |
601 | return; | 601 | return; |
602 | } | 602 | } |
603 | if ( !wroteToStdinConnected && qstrcmp( signal, SIGNAL(wroteToStdin()) )==0 ) { | 603 | if ( !wroteToStdinConnected && qstrcmp( signal, SIGNAL(wroteToStdin()) )==0 ) { |
604 | #if defined(QT_QPROCESS_DEBUG) | 604 | #if defined(QT_QPROCESS_DEBUG) |
605 | qDebug( "QProcess::connectNotify(): set wroteToStdinConnected to TRUE" ); | 605 | odebug << "QProcess::connectNotify(): set wroteToStdinConnected to TRUE" << oendl; |
606 | #endif | 606 | #endif |
607 | setWroteStdinConnected( TRUE ); | 607 | setWroteStdinConnected( TRUE ); |
608 | return; | 608 | return; |
609 | } | 609 | } |
610 | } | 610 | } |
611 | 611 | ||
612 | /*! \reimp | 612 | /*! \reimp |
613 | */ | 613 | */ |
614 | void QProcess::disconnectNotify( const char * ) | 614 | void QProcess::disconnectNotify( const char * ) |
615 | { | 615 | { |
616 | if ( ioRedirection && | 616 | if ( ioRedirection && |
617 | receivers( SIGNAL(readyReadStdout()) ) ==0 && | 617 | receivers( SIGNAL(readyReadStdout()) ) ==0 && |
618 | receivers( SIGNAL(readyReadStderr()) ) ==0 | 618 | receivers( SIGNAL(readyReadStderr()) ) ==0 |
619 | ) { | 619 | ) { |
620 | #if defined(QT_QPROCESS_DEBUG) | 620 | #if defined(QT_QPROCESS_DEBUG) |
621 | qDebug( "QProcess::disconnectNotify(): set ioRedirection to FALSE" ); | 621 | odebug << "QProcess::disconnectNotify(): set ioRedirection to FALSE" << oendl; |
622 | #endif | 622 | #endif |
623 | setIoRedirection( FALSE ); | 623 | setIoRedirection( FALSE ); |
624 | } | 624 | } |
625 | if ( notifyOnExit && receivers( SIGNAL(processExited()) ) == 0 ) { | 625 | if ( notifyOnExit && receivers( SIGNAL(processExited()) ) == 0 ) { |
626 | #if defined(QT_QPROCESS_DEBUG) | 626 | #if defined(QT_QPROCESS_DEBUG) |
627 | qDebug( "QProcess::disconnectNotify(): set notifyOnExit to FALSE" ); | 627 | odebug << "QProcess::disconnectNotify(): set notifyOnExit to FALSE" << oendl; |
628 | #endif | 628 | #endif |
629 | setNotifyOnExit( FALSE ); | 629 | setNotifyOnExit( FALSE ); |
630 | } | 630 | } |
631 | if ( wroteToStdinConnected && receivers( SIGNAL(wroteToStdin()) ) == 0 ) { | 631 | if ( wroteToStdinConnected && receivers( SIGNAL(wroteToStdin()) ) == 0 ) { |
632 | #if defined(QT_QPROCESS_DEBUG) | 632 | #if defined(QT_QPROCESS_DEBUG) |
633 | qDebug( "QProcess::disconnectNotify(): set wroteToStdinConnected to FALSE" ); | 633 | odebug << "QProcess::disconnectNotify(): set wroteToStdinConnected to FALSE" << oendl; |
634 | #endif | 634 | #endif |
635 | setWroteStdinConnected( FALSE ); | 635 | setWroteStdinConnected( FALSE ); |
636 | } | 636 | } |
637 | } | 637 | } |
638 | 638 | ||
639 | #endif // QT_NO_PROCESS | 639 | #endif // QT_NO_PROCESS |
diff --git a/core/launcher/qprocess_unix.cpp b/core/launcher/qprocess_unix.cpp index 19a8c93..d62e4e6 100644 --- a/core/launcher/qprocess_unix.cpp +++ b/core/launcher/qprocess_unix.cpp | |||
@@ -1,1174 +1,1173 @@ | |||
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 | //#include "qplatformdefs.h" | ||
22 | |||
23 | // Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. | 21 | // Solaris redefines connect -> __xnet_connect with _XOPEN_SOURCE_EXTENDED. |
24 | #if defined(connect) | 22 | #if defined(connect) |
25 | #undef connect | 23 | #undef connect |
26 | #endif | 24 | #endif |
27 | 25 | ||
28 | #include "qprocess.h" | 26 | #include "qprocess.h" |
29 | 27 | ||
30 | #ifndef QT_NO_PROCESS | 28 | /* OPIE */ |
29 | #include <opie2/odebug.h> | ||
30 | using namespace Opie::Core; | ||
31 | 31 | ||
32 | #include "qapplication.h" | 32 | /* QT */ |
33 | #include "qqueue.h" | 33 | #ifndef QT_NO_PROCESS |
34 | #include "qlist.h" | 34 | #include <qapplication.h> |
35 | #include "qsocketnotifier.h" | 35 | #include <qqueue.h> |
36 | #include "qtimer.h" | 36 | #include <qlist.h> |
37 | #include "qregexp.h" | 37 | #include <qsocketnotifier.h> |
38 | #include <qtimer.h> | ||
39 | #include <qregexp.h> | ||
38 | 40 | ||
39 | #include "qcleanuphandler_p.h" | 41 | #include "qcleanuphandler_p.h" |
40 | 42 | ||
43 | /* STD */ | ||
41 | #include <stdlib.h> | 44 | #include <stdlib.h> |
42 | |||
43 | // ### FOR Qt 2.3 compat | ||
44 | #include <unistd.h> | 45 | #include <unistd.h> |
45 | #include <signal.h> | 46 | #include <signal.h> |
46 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |
47 | #include <sys/ioctl.h> | 48 | #include <sys/ioctl.h> |
48 | #include <sys/wait.h> | 49 | #include <sys/wait.h> |
49 | #include <sys/fcntl.h> | 50 | #include <sys/fcntl.h> |
50 | 51 | #include <sys/resource.h> | |
51 | #include <errno.h> | 52 | #include <errno.h> |
52 | |||
53 | #ifdef Q_OS_MACX | 53 | #ifdef Q_OS_MACX |
54 | #include <sys/time.h> | 54 | #include <sys/time.h> |
55 | #endif | 55 | #endif |
56 | #include <sys/resource.h> | ||
57 | 56 | ||
58 | #ifdef __MIPSEL__ | 57 | #ifdef __MIPSEL__ |
59 | # ifndef SOCK_DGRAM | 58 | # ifndef SOCK_DGRAM |
60 | # define SOCK_DGRAM 1 | 59 | # define SOCK_DGRAM 1 |
61 | # endif | 60 | # endif |
62 | # ifndef SOCK_STREAM | 61 | # ifndef SOCK_STREAM |
63 | # define SOCK_STREAM 2 | 62 | # define SOCK_STREAM 2 |
64 | # endif | 63 | # endif |
65 | #endif | 64 | #endif |
66 | 65 | ||
67 | //#define QT_QPROCESS_DEBUG | 66 | //#define QT_QPROCESS_DEBUG |
68 | 67 | ||
69 | 68 | ||
70 | #ifdef Q_C_CALLBACKS | 69 | #ifdef Q_C_CALLBACKS |
71 | extern "C" { | 70 | extern "C" { |
72 | #endif // Q_C_CALLBACKS | 71 | #endif // Q_C_CALLBACKS |
73 | 72 | ||
74 | #define QT_SIGNAL_RETTYPE void | 73 | #define QT_SIGNAL_RETTYPE void |
75 | #define QT_SIGNAL_ARGS int | 74 | #define QT_SIGNAL_ARGS int |
76 | #define QT_SIGNAL_IGNORE SIG_IGN | 75 | #define QT_SIGNAL_IGNORE SIG_IGN |
77 | 76 | ||
78 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd(QT_SIGNAL_ARGS); | 77 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd(QT_SIGNAL_ARGS); |
79 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd(QT_SIGNAL_ARGS); | 78 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd(QT_SIGNAL_ARGS); |
80 | 79 | ||
81 | #ifdef Q_C_CALLBACKS | 80 | #ifdef Q_C_CALLBACKS |
82 | } | 81 | } |
83 | #endif // Q_C_CALLBACKS | 82 | #endif // Q_C_CALLBACKS |
84 | 83 | ||
85 | 84 | ||
86 | class QProc; | 85 | class QProc; |
87 | class QProcessManager; | 86 | class QProcessManager; |
88 | class QProcessPrivate | 87 | class QProcessPrivate |
89 | { | 88 | { |
90 | public: | 89 | public: |
91 | QProcessPrivate(); | 90 | QProcessPrivate(); |
92 | ~QProcessPrivate(); | 91 | ~QProcessPrivate(); |
93 | 92 | ||
94 | void closeOpenSocketsForChild(); | 93 | void closeOpenSocketsForChild(); |
95 | void newProc( pid_t pid, QProcess *process ); | 94 | void newProc( pid_t pid, QProcess *process ); |
96 | 95 | ||
97 | QByteArray bufStdout; | 96 | QByteArray bufStdout; |
98 | QByteArray bufStderr; | 97 | QByteArray bufStderr; |
99 | 98 | ||
100 | QQueue<QByteArray> stdinBuf; | 99 | QQueue<QByteArray> stdinBuf; |
101 | 100 | ||
102 | QSocketNotifier *notifierStdin; | 101 | QSocketNotifier *notifierStdin; |
103 | QSocketNotifier *notifierStdout; | 102 | QSocketNotifier *notifierStdout; |
104 | QSocketNotifier *notifierStderr; | 103 | QSocketNotifier *notifierStderr; |
105 | 104 | ||
106 | ssize_t stdinBufRead; | 105 | ssize_t stdinBufRead; |
107 | QProc *proc; | 106 | QProc *proc; |
108 | 107 | ||
109 | bool exitValuesCalculated; | 108 | bool exitValuesCalculated; |
110 | bool socketReadCalled; | 109 | bool socketReadCalled; |
111 | 110 | ||
112 | static QProcessManager *procManager; | 111 | static QProcessManager *procManager; |
113 | }; | 112 | }; |
114 | 113 | ||
115 | 114 | ||
116 | /*********************************************************************** | 115 | /*********************************************************************** |
117 | * | 116 | * |
118 | * QProc | 117 | * QProc |
119 | * | 118 | * |
120 | **********************************************************************/ | 119 | **********************************************************************/ |
121 | /* | 120 | /* |
122 | The class QProcess does not necessarily map exactly to the running | 121 | The class QProcess does not necessarily map exactly to the running |
123 | child processes: if the process is finished, the QProcess class may still be | 122 | child processes: if the process is finished, the QProcess class may still be |
124 | there; furthermore a user can use QProcess to start more than one process. | 123 | there; furthermore a user can use QProcess to start more than one process. |
125 | 124 | ||
126 | The helper-class QProc has the semantics that one instance of this class maps | 125 | The helper-class QProc has the semantics that one instance of this class maps |
127 | directly to a running child process. | 126 | directly to a running child process. |
128 | */ | 127 | */ |
129 | class QProc | 128 | class QProc |
130 | { | 129 | { |
131 | public: | 130 | public: |
132 | QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc) | 131 | QProc( pid_t p, QProcess *proc=0 ) : pid(p), process(proc) |
133 | { | 132 | { |
134 | #if defined(QT_QPROCESS_DEBUG) | 133 | #if defined(QT_QPROCESS_DEBUG) |
135 | qDebug( "QProc: Constructor for pid %d and QProcess %p", pid, process ); | 134 | odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl; |
136 | #endif | 135 | #endif |
137 | socketStdin = 0; | 136 | socketStdin = 0; |
138 | socketStdout = 0; | 137 | socketStdout = 0; |
139 | socketStderr = 0; | 138 | socketStderr = 0; |
140 | } | 139 | } |
141 | ~QProc() | 140 | ~QProc() |
142 | { | 141 | { |
143 | #if defined(QT_QPROCESS_DEBUG) | 142 | #if defined(QT_QPROCESS_DEBUG) |
144 | qDebug( "QProc: Destructor for pid %d and QProcess %p", pid, process ); | 143 | odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl; |
145 | #endif | 144 | #endif |
146 | if ( process != 0 ) { | 145 | if ( process != 0 ) { |
147 | if ( process->d->notifierStdin ) | 146 | if ( process->d->notifierStdin ) |
148 | process->d->notifierStdin->setEnabled( FALSE ); | 147 | process->d->notifierStdin->setEnabled( FALSE ); |
149 | if ( process->d->notifierStdout ) | 148 | if ( process->d->notifierStdout ) |
150 | process->d->notifierStdout->setEnabled( FALSE ); | 149 | process->d->notifierStdout->setEnabled( FALSE ); |
151 | if ( process->d->notifierStderr ) | 150 | if ( process->d->notifierStderr ) |
152 | process->d->notifierStderr->setEnabled( FALSE ); | 151 | process->d->notifierStderr->setEnabled( FALSE ); |
153 | process->d->proc = 0; | 152 | process->d->proc = 0; |
154 | } | 153 | } |
155 | if( socketStdin != 0 ) | 154 | if( socketStdin != 0 ) |
156 | ::close( socketStdin ); | 155 | ::close( socketStdin ); |
157 | // ### close these sockets even on parent exit or is it better only on | 156 | // ### close these sockets even on parent exit or is it better only on |
158 | // sigchld (but what do I have to do with them on exit then)? | 157 | // sigchld (but what do I have to do with them on exit then)? |
159 | if( socketStdout != 0 ) | 158 | if( socketStdout != 0 ) |
160 | ::close( socketStdout ); | 159 | ::close( socketStdout ); |
161 | if( socketStderr != 0 ) | 160 | if( socketStderr != 0 ) |
162 | ::close( socketStderr ); | 161 | ::close( socketStderr ); |
163 | } | 162 | } |
164 | 163 | ||
165 | pid_t pid; | 164 | pid_t pid; |
166 | int socketStdin; | 165 | int socketStdin; |
167 | int socketStdout; | 166 | int socketStdout; |
168 | int socketStderr; | 167 | int socketStderr; |
169 | QProcess *process; | 168 | QProcess *process; |
170 | }; | 169 | }; |
171 | 170 | ||
172 | /*********************************************************************** | 171 | /*********************************************************************** |
173 | * | 172 | * |
174 | * QProcessManager | 173 | * QProcessManager |
175 | * | 174 | * |
176 | **********************************************************************/ | 175 | **********************************************************************/ |
177 | class QProcessManager : public QObject | 176 | class QProcessManager : public QObject |
178 | { | 177 | { |
179 | Q_OBJECT | 178 | Q_OBJECT |
180 | 179 | ||
181 | public: | 180 | public: |
182 | QProcessManager(); | 181 | QProcessManager(); |
183 | ~QProcessManager(); | 182 | ~QProcessManager(); |
184 | 183 | ||
185 | void append( QProc *p ); | 184 | void append( QProc *p ); |
186 | void remove( QProc *p ); | 185 | void remove( QProc *p ); |
187 | 186 | ||
188 | void cleanup(); | 187 | void cleanup(); |
189 | 188 | ||
190 | public slots: | 189 | public slots: |
191 | void removeMe(); | 190 | void removeMe(); |
192 | void sigchldHnd( int ); | 191 | void sigchldHnd( int ); |
193 | 192 | ||
194 | public: | 193 | public: |
195 | struct sigaction oldactChld; | 194 | struct sigaction oldactChld; |
196 | struct sigaction oldactPipe; | 195 | struct sigaction oldactPipe; |
197 | QList<QProc> *procList; | 196 | QList<QProc> *procList; |
198 | int sigchldFd[2]; | 197 | int sigchldFd[2]; |
199 | }; | 198 | }; |
200 | 199 | ||
201 | QCleanupHandler<QProcessManager> qprocess_cleanup_procmanager; | 200 | QCleanupHandler<QProcessManager> qprocess_cleanup_procmanager; |
202 | 201 | ||
203 | QProcessManager::QProcessManager() | 202 | QProcessManager::QProcessManager() |
204 | { | 203 | { |
205 | procList = new QList<QProc>; | 204 | procList = new QList<QProc>; |
206 | procList->setAutoDelete( TRUE ); | 205 | procList->setAutoDelete( TRUE ); |
207 | 206 | ||
208 | // The SIGCHLD handler writes to a socket to tell the manager that | 207 | // The SIGCHLD handler writes to a socket to tell the manager that |
209 | // something happened. This is done to get the processing in sync with the | 208 | // something happened. This is done to get the processing in sync with the |
210 | // event reporting. | 209 | // event reporting. |
211 | if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { | 210 | if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { |
212 | sigchldFd[0] = 0; | 211 | sigchldFd[0] = 0; |
213 | sigchldFd[1] = 0; | 212 | sigchldFd[1] = 0; |
214 | } else { | 213 | } else { |
215 | #if defined(QT_QPROCESS_DEBUG) | 214 | #if defined(QT_QPROCESS_DEBUG) |
216 | qDebug( "QProcessManager: install socket notifier (%d)", sigchldFd[1] ); | 215 | odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl; |
217 | #endif | 216 | #endif |
218 | QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], | 217 | QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], |
219 | QSocketNotifier::Read, this ); | 218 | QSocketNotifier::Read, this ); |
220 | connect( sn, SIGNAL(activated(int)), | 219 | connect( sn, SIGNAL(activated(int)), |
221 | this, SLOT(sigchldHnd(int)) ); | 220 | this, SLOT(sigchldHnd(int)) ); |
222 | sn->setEnabled( TRUE ); | 221 | sn->setEnabled( TRUE ); |
223 | } | 222 | } |
224 | 223 | ||
225 | // install a SIGCHLD handler and ignore SIGPIPE | 224 | // install a SIGCHLD handler and ignore SIGPIPE |
226 | struct sigaction act; | 225 | struct sigaction act; |
227 | 226 | ||
228 | #if defined(QT_QPROCESS_DEBUG) | 227 | #if defined(QT_QPROCESS_DEBUG) |
229 | qDebug( "QProcessManager: install a SIGCHLD handler" ); | 228 | odebug << "QProcessManager: install a SIGCHLD handler" << oendl; |
230 | #endif | 229 | #endif |
231 | act.sa_handler = qt_C_sigchldHnd; | 230 | act.sa_handler = qt_C_sigchldHnd; |
232 | sigemptyset( &(act.sa_mask) ); | 231 | sigemptyset( &(act.sa_mask) ); |
233 | sigaddset( &(act.sa_mask), SIGCHLD ); | 232 | sigaddset( &(act.sa_mask), SIGCHLD ); |
234 | act.sa_flags = SA_NOCLDSTOP; | 233 | act.sa_flags = SA_NOCLDSTOP; |
235 | #if defined(SA_RESTART) | 234 | #if defined(SA_RESTART) |
236 | act.sa_flags |= SA_RESTART; | 235 | act.sa_flags |= SA_RESTART; |
237 | #endif | 236 | #endif |
238 | if ( sigaction( SIGCHLD, &act, &oldactChld ) != 0 ) | 237 | if ( sigaction( SIGCHLD, &act, &oldactChld ) != 0 ) |
239 | qWarning( "Error installing SIGCHLD handler" ); | 238 | owarn << "Error installing SIGCHLD handler" << oendl; |
240 | 239 | ||
241 | #if defined(QT_QPROCESS_DEBUG) | 240 | #if defined(QT_QPROCESS_DEBUG) |
242 | qDebug( "QProcessManager: install a SIGPIPE handler (SIG_IGN)" ); | 241 | odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl; |
243 | #endif | 242 | #endif |
244 | /* | 243 | /* |
245 | Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround | 244 | Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround |
246 | for a strange problem where GNU tar (called by backuprestore) | 245 | for a strange problem where GNU tar (called by backuprestore) |
247 | would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd | 246 | would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd |
248 | is never even called, yet this avoids the hang. | 247 | is never even called, yet this avoids the hang. |
249 | */ | 248 | */ |
250 | act.sa_handler = qt_C_sigpipeHnd; | 249 | act.sa_handler = qt_C_sigpipeHnd; |
251 | sigemptyset( &(act.sa_mask) ); | 250 | sigemptyset( &(act.sa_mask) ); |
252 | sigaddset( &(act.sa_mask), SIGPIPE ); | 251 | sigaddset( &(act.sa_mask), SIGPIPE ); |
253 | act.sa_flags = 0; | 252 | act.sa_flags = 0; |
254 | if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 ) | 253 | if ( sigaction( SIGPIPE, &act, &oldactPipe ) != 0 ) |
255 | qWarning( "Error installing SIGPIPE handler" ); | 254 | owarn << "Error installing SIGPIPE handler" << oendl; |
256 | } | 255 | } |
257 | 256 | ||
258 | QProcessManager::~QProcessManager() | 257 | QProcessManager::~QProcessManager() |
259 | { | 258 | { |
260 | delete procList; | 259 | delete procList; |
261 | 260 | ||
262 | if ( sigchldFd[0] != 0 ) | 261 | if ( sigchldFd[0] != 0 ) |
263 | ::close( sigchldFd[0] ); | 262 | ::close( sigchldFd[0] ); |
264 | if ( sigchldFd[1] != 0 ) | 263 | if ( sigchldFd[1] != 0 ) |
265 | ::close( sigchldFd[1] ); | 264 | ::close( sigchldFd[1] ); |
266 | 265 | ||
267 | // restore SIGCHLD handler | 266 | // restore SIGCHLD handler |
268 | #if defined(QT_QPROCESS_DEBUG) | 267 | #if defined(QT_QPROCESS_DEBUG) |
269 | qDebug( "QProcessManager: restore old sigchild handler" ); | 268 | odebug << "QProcessManager: restore old sigchild handler" << oendl; |
270 | #endif | 269 | #endif |
271 | if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 ) | 270 | if ( sigaction( SIGCHLD, &oldactChld, 0 ) != 0 ) |
272 | qWarning( "Error restoring SIGCHLD handler" ); | 271 | owarn << "Error restoring SIGCHLD handler" << oendl; |
273 | 272 | ||
274 | #if defined(QT_QPROCESS_DEBUG) | 273 | #if defined(QT_QPROCESS_DEBUG) |
275 | qDebug( "QProcessManager: restore old sigpipe handler" ); | 274 | odebug << "QProcessManager: restore old sigpipe handler" << oendl; |
276 | #endif | 275 | #endif |
277 | if ( sigaction( SIGPIPE, &oldactPipe, 0 ) != 0 ) | 276 | if ( sigaction( SIGPIPE, &oldactPipe, 0 ) != 0 ) |
278 | qWarning( "Error restoring SIGPIPE handler" ); | 277 | owarn << "Error restoring SIGPIPE handler" << oendl; |
279 | } | 278 | } |
280 | 279 | ||
281 | void QProcessManager::append( QProc *p ) | 280 | void QProcessManager::append( QProc *p ) |
282 | { | 281 | { |
283 | procList->append( p ); | 282 | procList->append( p ); |
284 | #if defined(QT_QPROCESS_DEBUG) | 283 | #if defined(QT_QPROCESS_DEBUG) |
285 | qDebug( "QProcessManager: append process (procList.count(): %d)", procList->count() ); | 284 | odebug << "QProcessManager: append process (procList.count(): " << procList->count() << ")" << oendl; |
286 | #endif | 285 | #endif |
287 | } | 286 | } |
288 | 287 | ||
289 | void QProcessManager::remove( QProc *p ) | 288 | void QProcessManager::remove( QProc *p ) |
290 | { | 289 | { |
291 | procList->remove( p ); | 290 | procList->remove( p ); |
292 | #if defined(QT_QPROCESS_DEBUG) | 291 | #if defined(QT_QPROCESS_DEBUG) |
293 | qDebug( "QProcessManager: remove process (procList.count(): %d)", procList->count() ); | 292 | odebug << "QProcessManager: remove process (procList.count(): " << procList->count() << ")" << oendl; |
294 | #endif | 293 | #endif |
295 | cleanup(); | 294 | cleanup(); |
296 | } | 295 | } |
297 | 296 | ||
298 | void QProcessManager::cleanup() | 297 | void QProcessManager::cleanup() |
299 | { | 298 | { |
300 | if ( procList->count() == 0 ) { | 299 | if ( procList->count() == 0 ) { |
301 | QTimer::singleShot( 0, this, SLOT(removeMe()) ); | 300 | QTimer::singleShot( 0, this, SLOT(removeMe()) ); |
302 | } | 301 | } |
303 | } | 302 | } |
304 | 303 | ||
305 | void QProcessManager::removeMe() | 304 | void QProcessManager::removeMe() |
306 | { | 305 | { |
307 | if ( procList->count() == 0 ) { | 306 | if ( procList->count() == 0 ) { |
308 | qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); | 307 | qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); |
309 | QProcessPrivate::procManager = 0; | 308 | QProcessPrivate::procManager = 0; |
310 | delete this; | 309 | delete this; |
311 | } | 310 | } |
312 | } | 311 | } |
313 | 312 | ||
314 | void QProcessManager::sigchldHnd( int fd ) | 313 | void QProcessManager::sigchldHnd( int fd ) |
315 | { | 314 | { |
316 | char tmp; | 315 | char tmp; |
317 | ::read( fd, &tmp, sizeof(tmp) ); | 316 | ::read( fd, &tmp, sizeof(tmp) ); |
318 | #if defined(QT_QPROCESS_DEBUG) | 317 | #if defined(QT_QPROCESS_DEBUG) |
319 | qDebug( "QProcessManager::sigchldHnd()" ); | 318 | odebug << "QProcessManager::sigchldHnd()" << oendl; |
320 | #endif | 319 | #endif |
321 | QProc *proc; | 320 | QProc *proc; |
322 | QProcess *process; | 321 | QProcess *process; |
323 | bool removeProc; | 322 | bool removeProc; |
324 | proc = procList->first(); | 323 | proc = procList->first(); |
325 | while ( proc != 0 ) { | 324 | while ( proc != 0 ) { |
326 | removeProc = FALSE; | 325 | removeProc = FALSE; |
327 | process = proc->process; | 326 | process = proc->process; |
328 | QProcess *process_exit_notify=0; | 327 | QProcess *process_exit_notify=0; |
329 | if ( process != 0 ) { | 328 | if ( process != 0 ) { |
330 | if ( !process->isRunning() ) { | 329 | if ( !process->isRunning() ) { |
331 | #if defined(QT_QPROCESS_DEBUG) | 330 | #if defined(QT_QPROCESS_DEBUG) |
332 | qDebug( "QProcessManager::sigchldHnd() (PID: %d): process exited (QProcess available)", proc->pid ); | 331 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl; |
333 | #endif | 332 | #endif |
334 | // read pending data | 333 | // read pending data |
335 | int nbytes = 0; | 334 | int nbytes = 0; |
336 | if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { | 335 | if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { |
337 | #if defined(QT_QPROCESS_DEBUG) | 336 | #if defined(QT_QPROCESS_DEBUG) |
338 | qDebug( "QProcessManager::sigchldHnd() (PID: %d): reading %d bytes of pending data on stdout", proc->pid, nbytes ); | 337 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl; |
339 | #endif | 338 | #endif |
340 | process->socketRead( proc->socketStdout ); | 339 | process->socketRead( proc->socketStdout ); |
341 | } | 340 | } |
342 | nbytes = 0; | 341 | nbytes = 0; |
343 | if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { | 342 | if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { |
344 | #if defined(QT_QPROCESS_DEBUG) | 343 | #if defined(QT_QPROCESS_DEBUG) |
345 | qDebug( "QProcessManager::sigchldHnd() (PID: %d): reading %d bytes of pending data on stderr", proc->pid, nbytes ); | 344 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl; |
346 | #endif | 345 | #endif |
347 | process->socketRead( proc->socketStderr ); | 346 | process->socketRead( proc->socketStderr ); |
348 | } | 347 | } |
349 | 348 | ||
350 | if ( process->notifyOnExit ) | 349 | if ( process->notifyOnExit ) |
351 | process_exit_notify = process; | 350 | process_exit_notify = process; |
352 | 351 | ||
353 | removeProc = TRUE; | 352 | removeProc = TRUE; |
354 | } | 353 | } |
355 | } else { | 354 | } else { |
356 | int status; | 355 | int status; |
357 | if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { | 356 | if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { |
358 | #if defined(QT_QPROCESS_DEBUG) | 357 | #if defined(QT_QPROCESS_DEBUG) |
359 | qDebug( "QProcessManager::sigchldHnd() (PID: %d): process exited (QProcess not available)", proc->pid ); | 358 | odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl; |
360 | #endif | 359 | #endif |
361 | removeProc = TRUE; | 360 | removeProc = TRUE; |
362 | } | 361 | } |
363 | } | 362 | } |
364 | if ( removeProc ) { | 363 | if ( removeProc ) { |
365 | QProc *oldproc = proc; | 364 | QProc *oldproc = proc; |
366 | proc = procList->next(); | 365 | proc = procList->next(); |
367 | remove( oldproc ); | 366 | remove( oldproc ); |
368 | } else { | 367 | } else { |
369 | proc = procList->next(); | 368 | proc = procList->next(); |
370 | } | 369 | } |
371 | if ( process_exit_notify ) | 370 | if ( process_exit_notify ) |
372 | emit process_exit_notify->processExited(); | 371 | emit process_exit_notify->processExited(); |
373 | } | 372 | } |
374 | } | 373 | } |
375 | 374 | ||
376 | #include "qprocess_unix.moc" | 375 | #include "qprocess_unix.moc" |
377 | 376 | ||
378 | 377 | ||
379 | /*********************************************************************** | 378 | /*********************************************************************** |
380 | * | 379 | * |
381 | * QProcessPrivate | 380 | * QProcessPrivate |
382 | * | 381 | * |
383 | **********************************************************************/ | 382 | **********************************************************************/ |
384 | QProcessManager *QProcessPrivate::procManager = 0; | 383 | QProcessManager *QProcessPrivate::procManager = 0; |
385 | 384 | ||
386 | QProcessPrivate::QProcessPrivate() | 385 | QProcessPrivate::QProcessPrivate() |
387 | { | 386 | { |
388 | #if defined(QT_QPROCESS_DEBUG) | 387 | #if defined(QT_QPROCESS_DEBUG) |
389 | qDebug( "QProcessPrivate: Constructor" ); | 388 | odebug << "QProcessPrivate: Constructor" << oendl; |
390 | #endif | 389 | #endif |
391 | stdinBufRead = 0; | 390 | stdinBufRead = 0; |
392 | 391 | ||
393 | notifierStdin = 0; | 392 | notifierStdin = 0; |
394 | notifierStdout = 0; | 393 | notifierStdout = 0; |
395 | notifierStderr = 0; | 394 | notifierStderr = 0; |
396 | 395 | ||
397 | exitValuesCalculated = FALSE; | 396 | exitValuesCalculated = FALSE; |
398 | socketReadCalled = FALSE; | 397 | socketReadCalled = FALSE; |
399 | 398 | ||
400 | proc = 0; | 399 | proc = 0; |
401 | } | 400 | } |
402 | 401 | ||
403 | QProcessPrivate::~QProcessPrivate() | 402 | QProcessPrivate::~QProcessPrivate() |
404 | { | 403 | { |
405 | #if defined(QT_QPROCESS_DEBUG) | 404 | #if defined(QT_QPROCESS_DEBUG) |
406 | qDebug( "QProcessPrivate: Destructor" ); | 405 | odebug << "QProcessPrivate: Destructor" << oendl; |
407 | #endif | 406 | #endif |
408 | 407 | ||
409 | if ( proc != 0 ) { | 408 | if ( proc != 0 ) { |
410 | if ( proc->socketStdin != 0 ) { | 409 | if ( proc->socketStdin != 0 ) { |
411 | ::close( proc->socketStdin ); | 410 | ::close( proc->socketStdin ); |
412 | proc->socketStdin = 0; | 411 | proc->socketStdin = 0; |
413 | } | 412 | } |
414 | proc->process = 0; | 413 | proc->process = 0; |
415 | } | 414 | } |
416 | 415 | ||
417 | while ( !stdinBuf.isEmpty() ) { | 416 | while ( !stdinBuf.isEmpty() ) { |
418 | delete stdinBuf.dequeue(); | 417 | delete stdinBuf.dequeue(); |
419 | } | 418 | } |
420 | delete notifierStdin; | 419 | delete notifierStdin; |
421 | delete notifierStdout; | 420 | delete notifierStdout; |
422 | delete notifierStderr; | 421 | delete notifierStderr; |
423 | } | 422 | } |
424 | 423 | ||
425 | /* | 424 | /* |
426 | Closes all open sockets in the child process that are not needed by the child | 425 | Closes all open sockets in the child process that are not needed by the child |
427 | process. Otherwise one child may have an open socket on standard input, etc. | 426 | process. Otherwise one child may have an open socket on standard input, etc. |
428 | of another child. | 427 | of another child. |
429 | */ | 428 | */ |
430 | void QProcessPrivate::closeOpenSocketsForChild() | 429 | void QProcessPrivate::closeOpenSocketsForChild() |
431 | { | 430 | { |
432 | if ( procManager != 0 ) { | 431 | if ( procManager != 0 ) { |
433 | if ( procManager->sigchldFd[0] != 0 ) | 432 | if ( procManager->sigchldFd[0] != 0 ) |
434 | ::close( procManager->sigchldFd[0] ); | 433 | ::close( procManager->sigchldFd[0] ); |
435 | if ( procManager->sigchldFd[1] != 0 ) | 434 | if ( procManager->sigchldFd[1] != 0 ) |
436 | ::close( procManager->sigchldFd[1] ); | 435 | ::close( procManager->sigchldFd[1] ); |
437 | 436 | ||
438 | // close also the sockets from other QProcess instances | 437 | // close also the sockets from other QProcess instances |
439 | QProc *proc; | 438 | QProc *proc; |
440 | for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { | 439 | for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { |
441 | ::close( proc->socketStdin ); | 440 | ::close( proc->socketStdin ); |
442 | ::close( proc->socketStdout ); | 441 | ::close( proc->socketStdout ); |
443 | ::close( proc->socketStderr ); | 442 | ::close( proc->socketStderr ); |
444 | } | 443 | } |
445 | } | 444 | } |
446 | } | 445 | } |
447 | 446 | ||
448 | void QProcessPrivate::newProc( pid_t pid, QProcess *process ) | 447 | void QProcessPrivate::newProc( pid_t pid, QProcess *process ) |
449 | { | 448 | { |
450 | proc = new QProc( pid, process ); | 449 | proc = new QProc( pid, process ); |
451 | if ( procManager == 0 ) { | 450 | if ( procManager == 0 ) { |
452 | procManager = new QProcessManager; | 451 | procManager = new QProcessManager; |
453 | qprocess_cleanup_procmanager.add( &procManager ); | 452 | qprocess_cleanup_procmanager.add( &procManager ); |
454 | } | 453 | } |
455 | // the QProcessManager takes care of deleting the QProc instances | 454 | // the QProcessManager takes care of deleting the QProc instances |
456 | procManager->append( proc ); | 455 | procManager->append( proc ); |
457 | } | 456 | } |
458 | 457 | ||
459 | /*********************************************************************** | 458 | /*********************************************************************** |
460 | * | 459 | * |
461 | * sigchld handler callback | 460 | * sigchld handler callback |
462 | * | 461 | * |
463 | **********************************************************************/ | 462 | **********************************************************************/ |
464 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) | 463 | QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) |
465 | { | 464 | { |
466 | if ( QProcessPrivate::procManager == 0 ) | 465 | if ( QProcessPrivate::procManager == 0 ) |
467 | return; | 466 | return; |
468 | if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) | 467 | if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) |
469 | return; | 468 | return; |
470 | 469 | ||
471 | char a = 1; | 470 | char a = 1; |
472 | ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); | 471 | ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); |
473 | } | 472 | } |
474 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS ) | 473 | QT_SIGNAL_RETTYPE qt_C_sigpipeHnd( QT_SIGNAL_ARGS ) |
475 | { | 474 | { |
476 | // Ignore (but in a way somehow different to SIG_IGN). | 475 | // Ignore (but in a way somehow different to SIG_IGN). |
477 | } | 476 | } |
478 | 477 | ||
479 | 478 | ||
480 | /*********************************************************************** | 479 | /*********************************************************************** |
481 | * | 480 | * |
482 | * QProcess | 481 | * QProcess |
483 | * | 482 | * |
484 | **********************************************************************/ | 483 | **********************************************************************/ |
485 | /*! | 484 | /*! |
486 | This private class does basic initialization. | 485 | This private class does basic initialization. |
487 | */ | 486 | */ |
488 | void QProcess::init() | 487 | void QProcess::init() |
489 | { | 488 | { |
490 | d = new QProcessPrivate(); | 489 | d = new QProcessPrivate(); |
491 | exitStat = 0; | 490 | exitStat = 0; |
492 | exitNormal = FALSE; | 491 | exitNormal = FALSE; |
493 | } | 492 | } |
494 | 493 | ||
495 | /*! | 494 | /*! |
496 | This private class resets the process variables, etc. so that it can be used | 495 | This private class resets the process variables, etc. so that it can be used |
497 | for another process to start. | 496 | for another process to start. |
498 | */ | 497 | */ |
499 | void QProcess::reset() | 498 | void QProcess::reset() |
500 | { | 499 | { |
501 | delete d; | 500 | delete d; |
502 | d = new QProcessPrivate(); | 501 | d = new QProcessPrivate(); |
503 | exitStat = 0; | 502 | exitStat = 0; |
504 | exitNormal = FALSE; | 503 | exitNormal = FALSE; |
505 | d->bufStdout.resize( 0 ); | 504 | d->bufStdout.resize( 0 ); |
506 | d->bufStderr.resize( 0 ); | 505 | d->bufStderr.resize( 0 ); |
507 | } | 506 | } |
508 | 507 | ||
509 | QByteArray* QProcess::bufStdout() | 508 | QByteArray* QProcess::bufStdout() |
510 | { | 509 | { |
511 | if ( d->proc && d->proc->socketStdout ) { | 510 | if ( d->proc && d->proc->socketStdout ) { |
512 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see | 511 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see |
513 | // if data is available)? | 512 | // if data is available)? |
514 | socketRead( d->proc->socketStdout ); | 513 | socketRead( d->proc->socketStdout ); |
515 | } | 514 | } |
516 | return &d->bufStdout; | 515 | return &d->bufStdout; |
517 | } | 516 | } |
518 | 517 | ||
519 | QByteArray* QProcess::bufStderr() | 518 | QByteArray* QProcess::bufStderr() |
520 | { | 519 | { |
521 | if ( d->proc && d->proc->socketStderr ) { | 520 | if ( d->proc && d->proc->socketStderr ) { |
522 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see | 521 | // ### can this cause a blocking behaviour (maybe do a ioctl() to see |
523 | // if data is available)? | 522 | // if data is available)? |
524 | socketRead( d->proc->socketStderr ); | 523 | socketRead( d->proc->socketStderr ); |
525 | } | 524 | } |
526 | return &d->bufStderr; | 525 | return &d->bufStderr; |
527 | } | 526 | } |
528 | 527 | ||
529 | void QProcess::consumeBufStdout( int consume ) | 528 | void QProcess::consumeBufStdout( int consume ) |
530 | { | 529 | { |
531 | uint n = d->bufStdout.size(); | 530 | uint n = d->bufStdout.size(); |
532 | if ( consume==-1 || (uint)consume >= n ) { | 531 | if ( consume==-1 || (uint)consume >= n ) { |
533 | d->bufStdout.resize( 0 ); | 532 | d->bufStdout.resize( 0 ); |
534 | } else { | 533 | } else { |
535 | QByteArray tmp( n - consume ); | 534 | QByteArray tmp( n - consume ); |
536 | memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); | 535 | memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); |
537 | d->bufStdout = tmp; | 536 | d->bufStdout = tmp; |
538 | } | 537 | } |
539 | } | 538 | } |
540 | 539 | ||
541 | void QProcess::consumeBufStderr( int consume ) | 540 | void QProcess::consumeBufStderr( int consume ) |
542 | { | 541 | { |
543 | uint n = d->bufStderr.size(); | 542 | uint n = d->bufStderr.size(); |
544 | if ( consume==-1 || (uint)consume >= n ) { | 543 | if ( consume==-1 || (uint)consume >= n ) { |
545 | d->bufStderr.resize( 0 ); | 544 | d->bufStderr.resize( 0 ); |
546 | } else { | 545 | } else { |
547 | QByteArray tmp( n - consume ); | 546 | QByteArray tmp( n - consume ); |
548 | memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); | 547 | memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); |
549 | d->bufStderr = tmp; | 548 | d->bufStderr = tmp; |
550 | } | 549 | } |
551 | } | 550 | } |
552 | 551 | ||
553 | /*! | 552 | /*! |
554 | Destroys the class. | 553 | Destroys the class. |
555 | 554 | ||
556 | If the process is running, it is NOT terminated! Standard input, standard | 555 | If the process is running, it is NOT terminated! Standard input, standard |
557 | output and standard error of the process are closed. | 556 | output and standard error of the process are closed. |
558 | 557 | ||
559 | You can connect the destroyed() signal to the kill() slot, if you want the | 558 | You can connect the destroyed() signal to the kill() slot, if you want the |
560 | process to be terminated automatically when the class is destroyed. | 559 | process to be terminated automatically when the class is destroyed. |
561 | 560 | ||
562 | \sa tryTerminate() kill() | 561 | \sa tryTerminate() kill() |
563 | */ | 562 | */ |
564 | QProcess::~QProcess() | 563 | QProcess::~QProcess() |
565 | { | 564 | { |
566 | delete d; | 565 | delete d; |
567 | } | 566 | } |
568 | 567 | ||
569 | /*! | 568 | /*! |
570 | Tries to run a process for the command and arguments that were specified with | 569 | Tries to run a process for the command and arguments that were specified with |
571 | setArguments(), addArgument() or that were specified in the constructor. The | 570 | setArguments(), addArgument() or that were specified in the constructor. The |
572 | command is searched in the path for executable programs; you can also use an | 571 | command is searched in the path for executable programs; you can also use an |
573 | absolute path to the command. | 572 | absolute path to the command. |
574 | 573 | ||
575 | If \a env is null, then the process is started with the same environment as | 574 | If \a env is null, then the process is started with the same environment as |
576 | the starting process. If \a env is non-null, then the values in the | 575 | the starting process. If \a env is non-null, then the values in the |
577 | stringlist are interpreted as environment setttings of the form \c | 576 | stringlist are interpreted as environment setttings of the form \c |
578 | {key=value} and the process is started in these environment settings. For | 577 | {key=value} and the process is started in these environment settings. For |
579 | convenience, there is a small exception to this rule: under Unix, if \a env | 578 | convenience, there is a small exception to this rule: under Unix, if \a env |
580 | does not contain any settings for the environment variable \c | 579 | does not contain any settings for the environment variable \c |
581 | LD_LIBRARY_PATH, then this variable is inherited from the starting process; | 580 | LD_LIBRARY_PATH, then this variable is inherited from the starting process; |
582 | under Windows the same applies for the enverionment varialbe \c PATH. | 581 | under Windows the same applies for the enverionment varialbe \c PATH. |
583 | 582 | ||
584 | Returns TRUE if the process could be started, otherwise FALSE. | 583 | Returns TRUE if the process could be started, otherwise FALSE. |
585 | 584 | ||
586 | You can write data to standard input of the process with | 585 | You can write data to standard input of the process with |
587 | writeToStdin(), you can close standard input with closeStdin() and you can | 586 | writeToStdin(), you can close standard input with closeStdin() and you can |
588 | terminate the process tryTerminate() resp. kill(). | 587 | terminate the process tryTerminate() resp. kill(). |
589 | 588 | ||
590 | You can call this function even when there already is a running | 589 | You can call this function even when there already is a running |
591 | process in this object. In this case, QProcess closes standard input | 590 | process in this object. In this case, QProcess closes standard input |
592 | of the old process and deletes pending data, i.e., you loose all | 591 | of the old process and deletes pending data, i.e., you loose all |
593 | control over that process, but the process is not terminated. This applies | 592 | control over that process, but the process is not terminated. This applies |
594 | also if the process could not be started. (On operating systems that have | 593 | also if the process could not be started. (On operating systems that have |
595 | zombie processes, Qt will also wait() on the old process.) | 594 | zombie processes, Qt will also wait() on the old process.) |
596 | 595 | ||
597 | \sa launch() closeStdin() | 596 | \sa launch() closeStdin() |
598 | */ | 597 | */ |
599 | bool QProcess::start( QStringList *env ) | 598 | bool QProcess::start( QStringList *env ) |
600 | { | 599 | { |
601 | #if defined(QT_QPROCESS_DEBUG) | 600 | #if defined(QT_QPROCESS_DEBUG) |
602 | qDebug( "QProcess::start()" ); | 601 | odebug << "QProcess::start()" << oendl; |
603 | #endif | 602 | #endif |
604 | reset(); | 603 | reset(); |
605 | 604 | ||
606 | int sStdin[2]; | 605 | int sStdin[2]; |
607 | int sStdout[2]; | 606 | int sStdout[2]; |
608 | int sStderr[2]; | 607 | int sStderr[2]; |
609 | 608 | ||
610 | // open sockets for piping | 609 | // open sockets for piping |
611 | if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { | 610 | if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { |
612 | return FALSE; | 611 | return FALSE; |
613 | } | 612 | } |
614 | if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { | 613 | if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { |
615 | return FALSE; | 614 | return FALSE; |
616 | } | 615 | } |
617 | if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { | 616 | if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { |
618 | return FALSE; | 617 | return FALSE; |
619 | } | 618 | } |
620 | 619 | ||
621 | // the following pipe is only used to determine if the process could be | 620 | // the following pipe is only used to determine if the process could be |
622 | // started | 621 | // started |
623 | int fd[2]; | 622 | int fd[2]; |
624 | if ( pipe( fd ) < 0 ) { | 623 | if ( pipe( fd ) < 0 ) { |
625 | // non critical error, go on | 624 | // non critical error, go on |
626 | fd[0] = 0; | 625 | fd[0] = 0; |
627 | fd[1] = 0; | 626 | fd[1] = 0; |
628 | } | 627 | } |
629 | 628 | ||
630 | // construct the arguments for exec | 629 | // construct the arguments for exec |
631 | QCString *arglistQ = new QCString[ _arguments.count() + 1 ]; | 630 | QCString *arglistQ = new QCString[ _arguments.count() + 1 ]; |
632 | const char** arglist = new const char*[ _arguments.count() + 1 ]; | 631 | const char** arglist = new const char*[ _arguments.count() + 1 ]; |
633 | int i = 0; | 632 | int i = 0; |
634 | for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { | 633 | for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { |
635 | arglistQ[i] = (*it).local8Bit(); | 634 | arglistQ[i] = (*it).local8Bit(); |
636 | arglist[i] = arglistQ[i]; | 635 | arglist[i] = arglistQ[i]; |
637 | #if defined(QT_QPROCESS_DEBUG) | 636 | #if defined(QT_QPROCESS_DEBUG) |
638 | qDebug( "QProcess::start(): arg %d = %s", i, arglist[i] ); | 637 | odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl; |
639 | #endif | 638 | #endif |
640 | i++; | 639 | i++; |
641 | } | 640 | } |
642 | arglist[i] = 0; | 641 | arglist[i] = 0; |
643 | 642 | ||
644 | // Must make sure signal handlers are installed before exec'ing | 643 | // Must make sure signal handlers are installed before exec'ing |
645 | // in case the process exits quickly. | 644 | // in case the process exits quickly. |
646 | if ( d->procManager == 0 ) { | 645 | if ( d->procManager == 0 ) { |
647 | d->procManager = new QProcessManager; | 646 | d->procManager = new QProcessManager; |
648 | qprocess_cleanup_procmanager.add( &d->procManager ); | 647 | qprocess_cleanup_procmanager.add( &d->procManager ); |
649 | } | 648 | } |
650 | 649 | ||
651 | // fork and exec | 650 | // fork and exec |
652 | QApplication::flushX(); | 651 | QApplication::flushX(); |
653 | pid_t pid = fork(); | 652 | pid_t pid = fork(); |
654 | if ( pid == 0 ) { | 653 | if ( pid == 0 ) { |
655 | // child | 654 | // child |
656 | d->closeOpenSocketsForChild(); | 655 | d->closeOpenSocketsForChild(); |
657 | if ( comms & Stdin ) { | 656 | if ( comms & Stdin ) { |
658 | ::close( sStdin[1] ); | 657 | ::close( sStdin[1] ); |
659 | ::dup2( sStdin[0], STDIN_FILENO ); | 658 | ::dup2( sStdin[0], STDIN_FILENO ); |
660 | } | 659 | } |
661 | if ( comms & Stdout ) { | 660 | if ( comms & Stdout ) { |
662 | ::close( sStdout[0] ); | 661 | ::close( sStdout[0] ); |
663 | ::dup2( sStdout[1], STDOUT_FILENO ); | 662 | ::dup2( sStdout[1], STDOUT_FILENO ); |
664 | } | 663 | } |
665 | if ( comms & Stderr ) { | 664 | if ( comms & Stderr ) { |
666 | ::close( sStderr[0] ); | 665 | ::close( sStderr[0] ); |
667 | ::dup2( sStderr[1], STDERR_FILENO ); | 666 | ::dup2( sStderr[1], STDERR_FILENO ); |
668 | } | 667 | } |
669 | if ( comms & DupStderr ) { | 668 | if ( comms & DupStderr ) { |
670 | ::dup2( STDOUT_FILENO, STDERR_FILENO ); | 669 | ::dup2( STDOUT_FILENO, STDERR_FILENO ); |
671 | } | 670 | } |
672 | #ifndef QT_NO_DIR | 671 | #ifndef QT_NO_DIR |
673 | ::chdir( workingDir.absPath().latin1() ); | 672 | ::chdir( workingDir.absPath().latin1() ); |
674 | #endif | 673 | #endif |
675 | if ( fd[0] ) | 674 | if ( fd[0] ) |
676 | ::close( fd[0] ); | 675 | ::close( fd[0] ); |
677 | if ( fd[1] ) | 676 | if ( fd[1] ) |
678 | ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess | 677 | ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess |
679 | 678 | ||
680 | if ( env == 0 ) { // inherit environment and start process | 679 | if ( env == 0 ) { // inherit environment and start process |
681 | ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice | 680 | ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice |
682 | } else { // start process with environment settins as specified in env | 681 | } else { // start process with environment settins as specified in env |
683 | // construct the environment for exec | 682 | // construct the environment for exec |
684 | int numEntries = env->count(); | 683 | int numEntries = env->count(); |
685 | bool setLibraryPath = | 684 | bool setLibraryPath = |
686 | env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && | 685 | env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && |
687 | getenv( "LD_LIBRARY_PATH" ) != 0; | 686 | getenv( "LD_LIBRARY_PATH" ) != 0; |
688 | if ( setLibraryPath ) | 687 | if ( setLibraryPath ) |
689 | numEntries++; | 688 | numEntries++; |
690 | QCString *envlistQ = new QCString[ numEntries + 1 ]; | 689 | QCString *envlistQ = new QCString[ numEntries + 1 ]; |
691 | const char** envlist = new const char*[ numEntries + 1 ]; | 690 | const char** envlist = new const char*[ numEntries + 1 ]; |
692 | int i = 0; | 691 | int i = 0; |
693 | if ( setLibraryPath ) { | 692 | if ( setLibraryPath ) { |
694 | envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); | 693 | envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); |
695 | envlist[i] = envlistQ[i]; | 694 | envlist[i] = envlistQ[i]; |
696 | i++; | 695 | i++; |
697 | } | 696 | } |
698 | for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { | 697 | for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { |
699 | envlistQ[i] = (*it).local8Bit(); | 698 | envlistQ[i] = (*it).local8Bit(); |
700 | envlist[i] = envlistQ[i]; | 699 | envlist[i] = envlistQ[i]; |
701 | i++; | 700 | i++; |
702 | } | 701 | } |
703 | envlist[i] = 0; | 702 | envlist[i] = 0; |
704 | 703 | ||
705 | // look for the executable in the search path | 704 | // look for the executable in the search path |
706 | if ( _arguments.count()>0 && getenv("PATH")!=0 ) { | 705 | if ( _arguments.count()>0 && getenv("PATH")!=0 ) { |
707 | QString command = _arguments[0]; | 706 | QString command = _arguments[0]; |
708 | if ( !command.contains( '/' ) ) { | 707 | if ( !command.contains( '/' ) ) { |
709 | QStringList pathList = QStringList::split( ':', getenv( "PATH" ) ); | 708 | QStringList pathList = QStringList::split( ':', getenv( "PATH" ) ); |
710 | for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) { | 709 | for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) { |
711 | QString dir = *it; | 710 | QString dir = *it; |
712 | #ifdef Q_OS_MACX | 711 | #ifdef Q_OS_MACX |
713 | if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle | 712 | if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle |
714 | dir += "/" + command + ".app/Contents/MacOS"; | 713 | dir += "/" + command + ".app/Contents/MacOS"; |
715 | #endif | 714 | #endif |
716 | #ifndef QT_NO_DIR | 715 | #ifndef QT_NO_DIR |
717 | QFileInfo fileInfo( dir, command ); | 716 | QFileInfo fileInfo( dir, command ); |
718 | #else | 717 | #else |
719 | QFileInfo fileInfo( dir + "/" + command ); | 718 | QFileInfo fileInfo( dir + "/" + command ); |
720 | #endif | 719 | #endif |
721 | if ( fileInfo.isExecutable() ) { | 720 | if ( fileInfo.isExecutable() ) { |
722 | arglistQ[0] = fileInfo.filePath().local8Bit(); | 721 | arglistQ[0] = fileInfo.filePath().local8Bit(); |
723 | arglist[0] = arglistQ[0]; | 722 | arglist[0] = arglistQ[0]; |
724 | break; | 723 | break; |
725 | } | 724 | } |
726 | } | 725 | } |
727 | } | 726 | } |
728 | } | 727 | } |
729 | ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice | 728 | ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice |
730 | } | 729 | } |
731 | if ( fd[1] ) { | 730 | if ( fd[1] ) { |
732 | char buf = 0; | 731 | char buf = 0; |
733 | ::write( fd[1], &buf, 1 ); | 732 | ::write( fd[1], &buf, 1 ); |
734 | ::close( fd[1] ); | 733 | ::close( fd[1] ); |
735 | } | 734 | } |
736 | ::exit( -1 ); | 735 | ::exit( -1 ); |
737 | } else if ( pid == -1 ) { | 736 | } else if ( pid == -1 ) { |
738 | // error forking | 737 | // error forking |
739 | goto error; | 738 | goto error; |
740 | } | 739 | } |
741 | 740 | ||
742 | // test if exec was successful | 741 | // test if exec was successful |
743 | if ( fd[1] ) | 742 | if ( fd[1] ) |
744 | ::close( fd[1] ); | 743 | ::close( fd[1] ); |
745 | if ( fd[0] ) { | 744 | if ( fd[0] ) { |
746 | char buf; | 745 | char buf; |
747 | for ( ;; ) { | 746 | for ( ;; ) { |
748 | int n = ::read( fd[0], &buf, 1 ); | 747 | int n = ::read( fd[0], &buf, 1 ); |
749 | if ( n==1 ) { | 748 | if ( n==1 ) { |
750 | // socket was not closed => error | 749 | // socket was not closed => error |
751 | d->proc = 0; | 750 | d->proc = 0; |
752 | goto error; | 751 | goto error; |
753 | } else if ( n==-1 ) { | 752 | } else if ( n==-1 ) { |
754 | if ( errno==EAGAIN || errno==EINTR ) | 753 | if ( errno==EAGAIN || errno==EINTR ) |
755 | // try it again | 754 | // try it again |
756 | continue; | 755 | continue; |
757 | } | 756 | } |
758 | break; | 757 | break; |
759 | } | 758 | } |
760 | ::close( fd[0] ); | 759 | ::close( fd[0] ); |
761 | } | 760 | } |
762 | 761 | ||
763 | d->newProc( pid, this ); | 762 | d->newProc( pid, this ); |
764 | 763 | ||
765 | if ( comms & Stdin ) { | 764 | if ( comms & Stdin ) { |
766 | ::close( sStdin[0] ); | 765 | ::close( sStdin[0] ); |
767 | d->proc->socketStdin = sStdin[1]; | 766 | d->proc->socketStdin = sStdin[1]; |
768 | d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write ); | 767 | d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write ); |
769 | connect( d->notifierStdin, SIGNAL(activated(int)), | 768 | connect( d->notifierStdin, SIGNAL(activated(int)), |
770 | this, SLOT(socketWrite(int)) ); | 769 | this, SLOT(socketWrite(int)) ); |
771 | // setup notifiers for the sockets | 770 | // setup notifiers for the sockets |
772 | if ( !d->stdinBuf.isEmpty() ) { | 771 | if ( !d->stdinBuf.isEmpty() ) { |
773 | d->notifierStdin->setEnabled( TRUE ); | 772 | d->notifierStdin->setEnabled( TRUE ); |
774 | } | 773 | } |
775 | } | 774 | } |
776 | if ( comms & Stdout ) { | 775 | if ( comms & Stdout ) { |
777 | ::close( sStdout[1] ); | 776 | ::close( sStdout[1] ); |
778 | d->proc->socketStdout = sStdout[0]; | 777 | d->proc->socketStdout = sStdout[0]; |
779 | d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read ); | 778 | d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read ); |
780 | connect( d->notifierStdout, SIGNAL(activated(int)), | 779 | connect( d->notifierStdout, SIGNAL(activated(int)), |
781 | this, SLOT(socketRead(int)) ); | 780 | this, SLOT(socketRead(int)) ); |
782 | if ( ioRedirection ) | 781 | if ( ioRedirection ) |
783 | d->notifierStdout->setEnabled( TRUE ); | 782 | d->notifierStdout->setEnabled( TRUE ); |
784 | } | 783 | } |
785 | if ( comms & Stderr ) { | 784 | if ( comms & Stderr ) { |
786 | ::close( sStderr[1] ); | 785 | ::close( sStderr[1] ); |
787 | d->proc->socketStderr = sStderr[0]; | 786 | d->proc->socketStderr = sStderr[0]; |
788 | d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read ); | 787 | d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read ); |
789 | connect( d->notifierStderr, SIGNAL(activated(int)), | 788 | connect( d->notifierStderr, SIGNAL(activated(int)), |
790 | this, SLOT(socketRead(int)) ); | 789 | this, SLOT(socketRead(int)) ); |
791 | if ( ioRedirection ) | 790 | if ( ioRedirection ) |
792 | d->notifierStderr->setEnabled( TRUE ); | 791 | d->notifierStderr->setEnabled( TRUE ); |
793 | } | 792 | } |
794 | 793 | ||
795 | // cleanup and return | 794 | // cleanup and return |
796 | delete[] arglistQ; | 795 | delete[] arglistQ; |
797 | delete[] arglist; | 796 | delete[] arglist; |
798 | return TRUE; | 797 | return TRUE; |
799 | 798 | ||
800 | error: | 799 | error: |
801 | #if defined(QT_QPROCESS_DEBUG) | 800 | #if defined(QT_QPROCESS_DEBUG) |
802 | qDebug( "QProcess::start(): error starting process" ); | 801 | odebug << "QProcess::start(): error starting process" << oendl; |
803 | #endif | 802 | #endif |
804 | if ( d->procManager ) | 803 | if ( d->procManager ) |
805 | d->procManager->cleanup(); | 804 | d->procManager->cleanup(); |
806 | if ( comms & Stdin ) { | 805 | if ( comms & Stdin ) { |
807 | ::close( sStdin[1] ); | 806 | ::close( sStdin[1] ); |
808 | ::close( sStdin[0] ); | 807 | ::close( sStdin[0] ); |
809 | } | 808 | } |
810 | if ( comms & Stdout ) { | 809 | if ( comms & Stdout ) { |
811 | ::close( sStdout[0] ); | 810 | ::close( sStdout[0] ); |
812 | ::close( sStdout[1] ); | 811 | ::close( sStdout[1] ); |
813 | } | 812 | } |
814 | if ( comms & Stderr ) { | 813 | if ( comms & Stderr ) { |
815 | ::close( sStderr[0] ); | 814 | ::close( sStderr[0] ); |
816 | ::close( sStderr[1] ); | 815 | ::close( sStderr[1] ); |
817 | } | 816 | } |
818 | ::close( fd[0] ); | 817 | ::close( fd[0] ); |
819 | ::close( fd[1] ); | 818 | ::close( fd[1] ); |
820 | delete[] arglistQ; | 819 | delete[] arglistQ; |
821 | delete[] arglist; | 820 | delete[] arglist; |
822 | return FALSE; | 821 | return FALSE; |
823 | } | 822 | } |
824 | 823 | ||
825 | 824 | ||
826 | /*! | 825 | /*! |
827 | Asks the process to terminate. Processes can ignore this wish. If you want to | 826 | Asks the process to terminate. Processes can ignore this wish. If you want to |
828 | be sure that the process really terminates, you must use kill() instead. | 827 | be sure that the process really terminates, you must use kill() instead. |
829 | 828 | ||
830 | The slot returns immediately: it does not wait until the process has | 829 | The slot returns immediately: it does not wait until the process has |
831 | finished. When the process really exited, the signal processExited() is | 830 | finished. When the process really exited, the signal processExited() is |
832 | emitted. | 831 | emitted. |
833 | 832 | ||
834 | \sa kill() processExited() | 833 | \sa kill() processExited() |
835 | */ | 834 | */ |
836 | void QProcess::tryTerminate() const | 835 | void QProcess::tryTerminate() const |
837 | { | 836 | { |
838 | if ( d->proc != 0 ) | 837 | if ( d->proc != 0 ) |
839 | ::kill( d->proc->pid, SIGTERM ); | 838 | ::kill( d->proc->pid, SIGTERM ); |
840 | } | 839 | } |
841 | 840 | ||
842 | /*! | 841 | /*! |
843 | Terminates the process. This is not a safe way to end a process since the | 842 | Terminates the process. This is not a safe way to end a process since the |
844 | process will not be able to do cleanup. tryTerminate() is a safer way to do | 843 | process will not be able to do cleanup. tryTerminate() is a safer way to do |
845 | it, but processes might ignore a tryTerminate(). | 844 | it, but processes might ignore a tryTerminate(). |
846 | 845 | ||
847 | The nice way to end a process and to be sure that it is finished, is doing | 846 | The nice way to end a process and to be sure that it is finished, is doing |
848 | something like this: | 847 | something like this: |
849 | \code | 848 | \code |
850 | process->tryTerminate(); | 849 | process->tryTerminate(); |
851 | QTimer::singleShot( 5000, process, SLOT( kill() ) ); | 850 | QTimer::singleShot( 5000, process, SLOT( kill() ) ); |
852 | \endcode | 851 | \endcode |
853 | 852 | ||
854 | This tries to terminate the process the nice way. If the process is still | 853 | This tries to terminate the process the nice way. If the process is still |
855 | running after 5 seconds, it terminates the process the hard way. The timeout | 854 | running after 5 seconds, it terminates the process the hard way. The timeout |
856 | should be chosen depending on the time the process needs to do all the | 855 | should be chosen depending on the time the process needs to do all the |
857 | cleanup: use a higher value if the process is likely to do heavy computation | 856 | cleanup: use a higher value if the process is likely to do heavy computation |
858 | on cleanup. | 857 | on cleanup. |
859 | 858 | ||
860 | The slot returns immediately: it does not wait until the process has | 859 | The slot returns immediately: it does not wait until the process has |
861 | finished. When the process really exited, the signal processExited() is | 860 | finished. When the process really exited, the signal processExited() is |
862 | emitted. | 861 | emitted. |
863 | 862 | ||
864 | \sa tryTerminate() processExited() | 863 | \sa tryTerminate() processExited() |
865 | */ | 864 | */ |
866 | void QProcess::kill() const | 865 | void QProcess::kill() const |
867 | { | 866 | { |
868 | if ( d->proc != 0 ) | 867 | if ( d->proc != 0 ) |
869 | ::kill( d->proc->pid, SIGKILL ); | 868 | ::kill( d->proc->pid, SIGKILL ); |
870 | } | 869 | } |
871 | 870 | ||
872 | /*! | 871 | /*! |
873 | Returns TRUE if the process is running, otherwise FALSE. | 872 | Returns TRUE if the process is running, otherwise FALSE. |
874 | 873 | ||
875 | \sa normalExit() exitStatus() processExited() | 874 | \sa normalExit() exitStatus() processExited() |
876 | */ | 875 | */ |
877 | bool QProcess::isRunning() const | 876 | bool QProcess::isRunning() const |
878 | { | 877 | { |
879 | if ( d->exitValuesCalculated ) { | 878 | if ( d->exitValuesCalculated ) { |
880 | #if defined(QT_QPROCESS_DEBUG) | 879 | #if defined(QT_QPROCESS_DEBUG) |
881 | qDebug( "QProcess::isRunning(): FALSE (already computed)" ); | 880 | odebug << "QProcess::isRunning(): FALSE (already computed)" << oendl; |
882 | #endif | 881 | #endif |
883 | return FALSE; | 882 | return FALSE; |
884 | } | 883 | } |
885 | if ( d->proc == 0 ) | 884 | if ( d->proc == 0 ) |
886 | return FALSE; | 885 | return FALSE; |
887 | int status; | 886 | int status; |
888 | if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid ) | 887 | if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid ) |
889 | { | 888 | { |
890 | // compute the exit values | 889 | // compute the exit values |
891 | QProcess *that = (QProcess*)this; // mutable | 890 | QProcess *that = (QProcess*)this; // mutable |
892 | that->exitNormal = WIFEXITED( status ) != 0; | 891 | that->exitNormal = WIFEXITED( status ) != 0; |
893 | if ( exitNormal ) { | 892 | if ( exitNormal ) { |
894 | that->exitStat = (char)WEXITSTATUS( status ); | 893 | that->exitStat = (char)WEXITSTATUS( status ); |
895 | } | 894 | } |
896 | d->exitValuesCalculated = TRUE; | 895 | d->exitValuesCalculated = TRUE; |
897 | #if defined(QT_QPROCESS_DEBUG) | 896 | #if defined(QT_QPROCESS_DEBUG) |
898 | qDebug( "QProcess::isRunning() (PID: %d): FALSE", d->proc->pid ); | 897 | odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): FALSE" << oendl; |
899 | #endif | 898 | #endif |
900 | return FALSE; | 899 | return FALSE; |
901 | } | 900 | } |
902 | #if defined(QT_QPROCESS_DEBUG) | 901 | #if defined(QT_QPROCESS_DEBUG) |
903 | qDebug( "QProcess::isRunning() (PID: %d): TRUE", d->proc->pid ); | 902 | odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): TRUE" << oendl; |
904 | #endif | 903 | #endif |
905 | return TRUE; | 904 | return TRUE; |
906 | } | 905 | } |
907 | 906 | ||
908 | /*! | 907 | /*! |
909 | Writes the data \a buf to the standard input of the process. The process may | 908 | Writes the data \a buf to the standard input of the process. The process may |
910 | or may not read this data. | 909 | or may not read this data. |
911 | 910 | ||
912 | This function returns immediately; the QProcess class might write the data at | 911 | This function returns immediately; the QProcess class might write the data at |
913 | a later point (you have to enter the event loop for that). When all the data | 912 | a later point (you have to enter the event loop for that). When all the data |
914 | is written to the process, the signal wroteToStdin() is emitted. This does | 913 | is written to the process, the signal wroteToStdin() is emitted. This does |
915 | not mean that the process really read the data, since this class only detects | 914 | not mean that the process really read the data, since this class only detects |
916 | when it was able to write the data to the operating system. | 915 | when it was able to write the data to the operating system. |
917 | 916 | ||
918 | \sa wroteToStdin() closeStdin() readStdout() readStderr() | 917 | \sa wroteToStdin() closeStdin() readStdout() readStderr() |
919 | */ | 918 | */ |
920 | void QProcess::writeToStdin( const QByteArray& buf ) | 919 | void QProcess::writeToStdin( const QByteArray& buf ) |
921 | { | 920 | { |
922 | #if defined(QT_QPROCESS_DEBUG) | 921 | #if defined(QT_QPROCESS_DEBUG) |
923 | // qDebug( "QProcess::writeToStdin(): write to stdin (%d)", d->socketStdin ); | 922 | // odebug << "QProcess::writeToStdin(): write to stdin (" << d->socketStdin << ")" << oendl; |
924 | #endif | 923 | #endif |
925 | d->stdinBuf.enqueue( new QByteArray(buf) ); | 924 | d->stdinBuf.enqueue( new QByteArray(buf) ); |
926 | if ( d->notifierStdin != 0 ) | 925 | if ( d->notifierStdin != 0 ) |
927 | d->notifierStdin->setEnabled( TRUE ); | 926 | d->notifierStdin->setEnabled( TRUE ); |
928 | } | 927 | } |
929 | 928 | ||
930 | 929 | ||
931 | /*! | 930 | /*! |
932 | Closes standard input of the process. | 931 | Closes standard input of the process. |
933 | 932 | ||
934 | This function also deletes pending data that is not written to standard input | 933 | This function also deletes pending data that is not written to standard input |
935 | yet. | 934 | yet. |
936 | 935 | ||
937 | \sa wroteToStdin() | 936 | \sa wroteToStdin() |
938 | */ | 937 | */ |
939 | void QProcess::closeStdin() | 938 | void QProcess::closeStdin() |
940 | { | 939 | { |
941 | if ( d->proc == 0 ) | 940 | if ( d->proc == 0 ) |
942 | return; | 941 | return; |
943 | if ( d->proc->socketStdin !=0 ) { | 942 | if ( d->proc->socketStdin !=0 ) { |
944 | while ( !d->stdinBuf.isEmpty() ) { | 943 | while ( !d->stdinBuf.isEmpty() ) { |
945 | delete d->stdinBuf.dequeue(); | 944 | delete d->stdinBuf.dequeue(); |
946 | } | 945 | } |
947 | delete d->notifierStdin; | 946 | delete d->notifierStdin; |
948 | d->notifierStdin = 0; | 947 | d->notifierStdin = 0; |
949 | if ( ::close( d->proc->socketStdin ) != 0 ) { | 948 | if ( ::close( d->proc->socketStdin ) != 0 ) { |
950 | qWarning( "Could not close stdin of child process" ); | 949 | owarn << "Could not close stdin of child process" << oendl; |
951 | } | 950 | } |
952 | #if defined(QT_QPROCESS_DEBUG) | 951 | #if defined(QT_QPROCESS_DEBUG) |
953 | qDebug( "QProcess::closeStdin(): stdin (%d) closed", d->proc->socketStdin ); | 952 | odebug << "QProcess::closeStdin(): stdin (" << d->proc->socketStdin << ") closed" << oendl; |
954 | #endif | 953 | #endif |
955 | d->proc->socketStdin = 0; | 954 | d->proc->socketStdin = 0; |
956 | } | 955 | } |
957 | } | 956 | } |
958 | 957 | ||
959 | 958 | ||
960 | /* | 959 | /* |
961 | This private slot is called when the process has outputted data to either | 960 | This private slot is called when the process has outputted data to either |
962 | standard output or standard error. | 961 | standard output or standard error. |
963 | */ | 962 | */ |
964 | void QProcess::socketRead( int fd ) | 963 | void QProcess::socketRead( int fd ) |
965 | { | 964 | { |
966 | if ( d->socketReadCalled ) { | 965 | if ( d->socketReadCalled ) { |
967 | // the slots that are connected to the readyRead...() signals might | 966 | // the slots that are connected to the readyRead...() signals might |
968 | // trigger a recursive call of socketRead(). Avoid this since you get a | 967 | // trigger a recursive call of socketRead(). Avoid this since you get a |
969 | // blocking read otherwise. | 968 | // blocking read otherwise. |
970 | return; | 969 | return; |
971 | } | 970 | } |
972 | #if defined(QT_QPROCESS_DEBUG) | 971 | #if defined(QT_QPROCESS_DEBUG) |
973 | qDebug( "QProcess::socketRead(): %d", fd ); | 972 | odebug << "QProcess::socketRead(): " << fd << "" << oendl; |
974 | #endif | 973 | #endif |
975 | if ( fd == 0 ) | 974 | if ( fd == 0 ) |
976 | return; | 975 | return; |
977 | const int bufsize = 4096; | 976 | const int bufsize = 4096; |
978 | QByteArray *buffer = 0; | 977 | QByteArray *buffer = 0; |
979 | uint oldSize; | 978 | uint oldSize; |
980 | int n; | 979 | int n; |
981 | if ( fd == d->proc->socketStdout ) { | 980 | if ( fd == d->proc->socketStdout ) { |
982 | buffer = &d->bufStdout; | 981 | buffer = &d->bufStdout; |
983 | } else if ( fd == d->proc->socketStderr ) { | 982 | } else if ( fd == d->proc->socketStderr ) { |
984 | buffer = &d->bufStderr; | 983 | buffer = &d->bufStderr; |
985 | } else { | 984 | } else { |
986 | // this case should never happen, but just to be safe | 985 | // this case should never happen, but just to be safe |
987 | return; | 986 | return; |
988 | } | 987 | } |
989 | 988 | ||
990 | // read data | 989 | // read data |
991 | oldSize = buffer->size(); | 990 | oldSize = buffer->size(); |
992 | buffer->resize( oldSize + bufsize ); | 991 | buffer->resize( oldSize + bufsize ); |
993 | n = ::read( fd, buffer->data()+oldSize, bufsize ); | 992 | n = ::read( fd, buffer->data()+oldSize, bufsize ); |
994 | if ( n > 0 ) | 993 | if ( n > 0 ) |
995 | buffer->resize( oldSize + n ); | 994 | buffer->resize( oldSize + n ); |
996 | else | 995 | else |
997 | buffer->resize( oldSize ); | 996 | buffer->resize( oldSize ); |
998 | // eof or error? | 997 | // eof or error? |
999 | if ( n == 0 || n == -1 ) { | 998 | if ( n == 0 || n == -1 ) { |
1000 | if ( fd == d->proc->socketStdout ) { | 999 | if ( fd == d->proc->socketStdout ) { |
1001 | #if defined(QT_QPROCESS_DEBUG) | 1000 | #if defined(QT_QPROCESS_DEBUG) |
1002 | qDebug( "QProcess::socketRead(): stdout (%d) closed", fd ); | 1001 | odebug << "QProcess::socketRead(): stdout (" << fd << ") closed" << oendl; |
1003 | #endif | 1002 | #endif |
1004 | d->notifierStdout->setEnabled( FALSE ); | 1003 | d->notifierStdout->setEnabled( FALSE ); |
1005 | delete d->notifierStdout; | 1004 | delete d->notifierStdout; |
1006 | d->notifierStdout = 0; | 1005 | d->notifierStdout = 0; |
1007 | ::close( d->proc->socketStdout ); | 1006 | ::close( d->proc->socketStdout ); |
1008 | d->proc->socketStdout = 0; | 1007 | d->proc->socketStdout = 0; |
1009 | return; | 1008 | return; |
1010 | } else if ( fd == d->proc->socketStderr ) { | 1009 | } else if ( fd == d->proc->socketStderr ) { |
1011 | #if defined(QT_QPROCESS_DEBUG) | 1010 | #if defined(QT_QPROCESS_DEBUG) |
1012 | qDebug( "QProcess::socketRead(): stderr (%d) closed", fd ); | 1011 | odebug << "QProcess::socketRead(): stderr (" << fd << ") closed" << oendl; |
1013 | #endif | 1012 | #endif |
1014 | d->notifierStderr->setEnabled( FALSE ); | 1013 | d->notifierStderr->setEnabled( FALSE ); |
1015 | delete d->notifierStderr; | 1014 | delete d->notifierStderr; |
1016 | d->notifierStderr = 0; | 1015 | d->notifierStderr = 0; |
1017 | ::close( d->proc->socketStderr ); | 1016 | ::close( d->proc->socketStderr ); |
1018 | d->proc->socketStderr = 0; | 1017 | d->proc->socketStderr = 0; |
1019 | return; | 1018 | return; |
1020 | } | 1019 | } |
1021 | } | 1020 | } |
1022 | // read all data that is available | 1021 | // read all data that is available |
1023 | while ( n == bufsize ) { | 1022 | while ( n == bufsize ) { |
1024 | oldSize = buffer->size(); | 1023 | oldSize = buffer->size(); |
1025 | buffer->resize( oldSize + bufsize ); | 1024 | buffer->resize( oldSize + bufsize ); |
1026 | n = ::read( fd, buffer->data()+oldSize, bufsize ); | 1025 | n = ::read( fd, buffer->data()+oldSize, bufsize ); |
1027 | if ( n > 0 ) | 1026 | if ( n > 0 ) |
1028 | buffer->resize( oldSize + n ); | 1027 | buffer->resize( oldSize + n ); |
1029 | else | 1028 | else |
1030 | buffer->resize( oldSize ); | 1029 | buffer->resize( oldSize ); |
1031 | } | 1030 | } |
1032 | 1031 | ||
1033 | d->socketReadCalled = TRUE; | 1032 | d->socketReadCalled = TRUE; |
1034 | if ( fd == d->proc->socketStdout ) { | 1033 | if ( fd == d->proc->socketStdout ) { |
1035 | #if defined(QT_QPROCESS_DEBUG) | 1034 | #if defined(QT_QPROCESS_DEBUG) |
1036 | qDebug( "QProcess::socketRead(): %d bytes read from stdout (%d)", | 1035 | qDebug( "QProcess::socketRead(): %d bytes read from stdout (%d)", |
1037 | buffer->size()-oldSize, fd ); | 1036 | buffer->size()-oldSize, fd ); |
1038 | #endif | 1037 | #endif |
1039 | emit readyReadStdout(); | 1038 | emit readyReadStdout(); |
1040 | } else if ( fd == d->proc->socketStderr ) { | 1039 | } else if ( fd == d->proc->socketStderr ) { |
1041 | #if defined(QT_QPROCESS_DEBUG) | 1040 | #if defined(QT_QPROCESS_DEBUG) |
1042 | qDebug( "QProcess::socketRead(): %d bytes read from stderr (%d)", | 1041 | qDebug( "QProcess::socketRead(): %d bytes read from stderr (%d)", |
1043 | buffer->size()-oldSize, fd ); | 1042 | buffer->size()-oldSize, fd ); |
1044 | #endif | 1043 | #endif |
1045 | emit readyReadStderr(); | 1044 | emit readyReadStderr(); |
1046 | } | 1045 | } |
1047 | d->socketReadCalled = FALSE; | 1046 | d->socketReadCalled = FALSE; |
1048 | } | 1047 | } |
1049 | 1048 | ||
1050 | 1049 | ||
1051 | /* | 1050 | /* |
1052 | This private slot is called when the process tries to read data from standard | 1051 | This private slot is called when the process tries to read data from standard |
1053 | input. | 1052 | input. |
1054 | */ | 1053 | */ |
1055 | void QProcess::socketWrite( int fd ) | 1054 | void QProcess::socketWrite( int fd ) |
1056 | { | 1055 | { |
1057 | if ( fd != d->proc->socketStdin || d->proc->socketStdin == 0 ) | 1056 | if ( fd != d->proc->socketStdin || d->proc->socketStdin == 0 ) |
1058 | return; | 1057 | return; |
1059 | if ( d->stdinBuf.isEmpty() ) { | 1058 | if ( d->stdinBuf.isEmpty() ) { |
1060 | d->notifierStdin->setEnabled( FALSE ); | 1059 | d->notifierStdin->setEnabled( FALSE ); |
1061 | return; | 1060 | return; |
1062 | } | 1061 | } |
1063 | #if defined(QT_QPROCESS_DEBUG) | 1062 | #if defined(QT_QPROCESS_DEBUG) |
1064 | qDebug( "QProcess::socketWrite(): write to stdin (%d)", fd ); | 1063 | odebug << "QProcess::socketWrite(): write to stdin (" << fd << ")" << oendl; |
1065 | #endif | 1064 | #endif |
1066 | ssize_t ret = ::write( fd, | 1065 | ssize_t ret = ::write( fd, |
1067 | d->stdinBuf.head()->data() + d->stdinBufRead, | 1066 | d->stdinBuf.head()->data() + d->stdinBufRead, |
1068 | d->stdinBuf.head()->size() - d->stdinBufRead ); | 1067 | d->stdinBuf.head()->size() - d->stdinBufRead ); |
1069 | if ( ret > 0 ) | 1068 | if ( ret > 0 ) |
1070 | d->stdinBufRead += ret; | 1069 | d->stdinBufRead += ret; |
1071 | if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) { | 1070 | if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) { |
1072 | d->stdinBufRead = 0; | 1071 | d->stdinBufRead = 0; |
1073 | delete d->stdinBuf.dequeue(); | 1072 | delete d->stdinBuf.dequeue(); |
1074 | if ( wroteToStdinConnected && d->stdinBuf.isEmpty() ) | 1073 | if ( wroteToStdinConnected && d->stdinBuf.isEmpty() ) |
1075 | emit wroteToStdin(); | 1074 | emit wroteToStdin(); |
1076 | socketWrite( fd ); | 1075 | socketWrite( fd ); |
1077 | } | 1076 | } |
1078 | } | 1077 | } |
1079 | 1078 | ||
1080 | /*! | 1079 | /*! |
1081 | \internal | 1080 | \internal |
1082 | Flushes standard input. This is useful if you want to use QProcess in a | 1081 | Flushes standard input. This is useful if you want to use QProcess in a |
1083 | synchronous manner. | 1082 | synchronous manner. |
1084 | 1083 | ||
1085 | This function should probably go into the public API. | 1084 | This function should probably go into the public API. |
1086 | */ | 1085 | */ |
1087 | void QProcess::flushStdin() | 1086 | void QProcess::flushStdin() |
1088 | { | 1087 | { |
1089 | socketWrite( d->proc->socketStdin ); | 1088 | socketWrite( d->proc->socketStdin ); |
1090 | } | 1089 | } |
1091 | 1090 | ||
1092 | /* | 1091 | /* |
1093 | This private slot is only used under Windows (but moc does not know about #if | 1092 | This private slot is only used under Windows (but moc does not know about #if |
1094 | defined()). | 1093 | defined()). |
1095 | */ | 1094 | */ |
1096 | void QProcess::timeout() | 1095 | void QProcess::timeout() |
1097 | { | 1096 | { |
1098 | } | 1097 | } |
1099 | 1098 | ||
1100 | 1099 | ||
1101 | /* | 1100 | /* |
1102 | This private function is used by connectNotify() and disconnectNotify() to | 1101 | This private function is used by connectNotify() and disconnectNotify() to |
1103 | change the value of ioRedirection (and related behaviour) | 1102 | change the value of ioRedirection (and related behaviour) |
1104 | */ | 1103 | */ |
1105 | void QProcess::setIoRedirection( bool value ) | 1104 | void QProcess::setIoRedirection( bool value ) |
1106 | { | 1105 | { |
1107 | ioRedirection = value; | 1106 | ioRedirection = value; |
1108 | if ( ioRedirection ) { | 1107 | if ( ioRedirection ) { |
1109 | if ( d->notifierStdout ) | 1108 | if ( d->notifierStdout ) |
1110 | d->notifierStdout->setEnabled( TRUE ); | 1109 | d->notifierStdout->setEnabled( TRUE ); |
1111 | if ( d->notifierStderr ) | 1110 | if ( d->notifierStderr ) |
1112 | d->notifierStderr->setEnabled( TRUE ); | 1111 | d->notifierStderr->setEnabled( TRUE ); |
1113 | } else { | 1112 | } else { |
1114 | if ( d->notifierStdout ) | 1113 | if ( d->notifierStdout ) |
1115 | d->notifierStdout->setEnabled( FALSE ); | 1114 | d->notifierStdout->setEnabled( FALSE ); |
1116 | if ( d->notifierStderr ) | 1115 | if ( d->notifierStderr ) |
1117 | d->notifierStderr->setEnabled( FALSE ); | 1116 | d->notifierStderr->setEnabled( FALSE ); |
1118 | } | 1117 | } |
1119 | } | 1118 | } |
1120 | 1119 | ||
1121 | /* | 1120 | /* |
1122 | This private function is used by connectNotify() and | 1121 | This private function is used by connectNotify() and |
1123 | disconnectNotify() to change the value of notifyOnExit (and related | 1122 | disconnectNotify() to change the value of notifyOnExit (and related |
1124 | behaviour) | 1123 | behaviour) |
1125 | */ | 1124 | */ |
1126 | void QProcess::setNotifyOnExit( bool value ) | 1125 | void QProcess::setNotifyOnExit( bool value ) |
1127 | { | 1126 | { |
1128 | notifyOnExit = value; | 1127 | notifyOnExit = value; |
1129 | } | 1128 | } |
1130 | 1129 | ||
1131 | /* | 1130 | /* |
1132 | This private function is used by connectNotify() and disconnectNotify() to | 1131 | This private function is used by connectNotify() and disconnectNotify() to |
1133 | change the value of wroteToStdinConnected (and related behaviour) | 1132 | change the value of wroteToStdinConnected (and related behaviour) |
1134 | */ | 1133 | */ |
1135 | void QProcess::setWroteStdinConnected( bool value ) | 1134 | void QProcess::setWroteStdinConnected( bool value ) |
1136 | { | 1135 | { |
1137 | wroteToStdinConnected = value; | 1136 | wroteToStdinConnected = value; |
1138 | } | 1137 | } |
1139 | 1138 | ||
1140 | /*! \enum QProcess::PID | 1139 | /*! \enum QProcess::PID |
1141 | \internal | 1140 | \internal |
1142 | */ | 1141 | */ |
1143 | /*! | 1142 | /*! |
1144 | Returns platform dependent information about the process. This can be used | 1143 | Returns platform dependent information about the process. This can be used |
1145 | together with platform specific system calls. | 1144 | together with platform specific system calls. |
1146 | 1145 | ||
1147 | Under Unix the return value is the PID of the process, or -1 if no process is | 1146 | Under Unix the return value is the PID of the process, or -1 if no process is |
1148 | belonging to this object. | 1147 | belonging to this object. |
1149 | 1148 | ||
1150 | Under Windows it is a pointer to the \c PROCESS_INFORMATION struct, or 0 if | 1149 | Under Windows it is a pointer to the \c PROCESS_INFORMATION struct, or 0 if |
1151 | no process is belonging to this object. | 1150 | no process is belonging to this object. |
1152 | */ | 1151 | */ |
1153 | QProcess::PID QProcess::processIdentifier() | 1152 | QProcess::PID QProcess::processIdentifier() |
1154 | { | 1153 | { |
1155 | if ( d->proc == 0 ) | 1154 | if ( d->proc == 0 ) |
1156 | return -1; | 1155 | return -1; |
1157 | return d->proc->pid; | 1156 | return d->proc->pid; |
1158 | } | 1157 | } |
1159 | 1158 | ||
1160 | int QProcess::priority() const | 1159 | int QProcess::priority() const |
1161 | { | 1160 | { |
1162 | if ( d->proc ) | 1161 | if ( d->proc ) |
1163 | return getpriority(PRIO_PROCESS,d->proc->pid); | 1162 | return getpriority(PRIO_PROCESS,d->proc->pid); |
1164 | return 0; | 1163 | return 0; |
1165 | } | 1164 | } |
1166 | 1165 | ||
1167 | void QProcess::setPriority(int p) | 1166 | void QProcess::setPriority(int p) |
1168 | { | 1167 | { |
1169 | if ( d->proc ) | 1168 | if ( d->proc ) |
1170 | setpriority(PRIO_PROCESS,d->proc->pid,p); | 1169 | setpriority(PRIO_PROCESS,d->proc->pid,p); |
1171 | } | 1170 | } |
1172 | 1171 | ||
1173 | 1172 | ||
1174 | #endif // QT_NO_PROCESS | 1173 | #endif // QT_NO_PROCESS |
diff --git a/core/launcher/runningappbar.cpp b/core/launcher/runningappbar.cpp index 2e9d2a9..a25963f 100644 --- a/core/launcher/runningappbar.cpp +++ b/core/launcher/runningappbar.cpp | |||
@@ -1,172 +1,176 @@ | |||
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 | #define QTOPIA_INTERNAL_PRELOADACCESS | 21 | #define QTOPIA_INTERNAL_PRELOADACCESS |
22 | 22 | ||
23 | #include "runningappbar.h" | ||
24 | #include "serverinterface.h" | ||
23 | 25 | ||
24 | #include <stdlib.h> | 26 | /* OPIE */ |
27 | #include <opie2/odebug.h> | ||
28 | #include <qtopia/qcopenvelope_qws.h> | ||
29 | using namespace Opie::Core; | ||
25 | 30 | ||
31 | /* QT */ | ||
26 | #include <qpainter.h> | 32 | #include <qpainter.h> |
27 | 33 | ||
28 | #include <qtopia/qcopenvelope_qws.h> | 34 | /* STD */ |
29 | 35 | #include <stdlib.h> | |
30 | #include "runningappbar.h" | ||
31 | #include "serverinterface.h" | ||
32 | 36 | ||
33 | RunningAppBar::RunningAppBar(QWidget* parent) | 37 | RunningAppBar::RunningAppBar(QWidget* parent) |
34 | : QFrame(parent), selectedAppIndex(-1) | 38 | : QFrame(parent), selectedAppIndex(-1) |
35 | { | 39 | { |
36 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); | 40 | QCopChannel* channel = new QCopChannel( "QPE/System", this ); |
37 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 41 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
38 | this, SLOT(received(const QCString&,const QByteArray&)) ); | 42 | this, SLOT(received(const QCString&,const QByteArray&)) ); |
39 | 43 | ||
40 | spacing = AppLnk::smallIconSize()+3; | 44 | spacing = AppLnk::smallIconSize()+3; |
41 | } | 45 | } |
42 | 46 | ||
43 | RunningAppBar::~RunningAppBar() | 47 | RunningAppBar::~RunningAppBar() |
44 | { | 48 | { |
45 | } | 49 | } |
46 | 50 | ||
47 | void RunningAppBar::received(const QCString& msg, const QByteArray& data) { | 51 | void RunningAppBar::received(const QCString& msg, const QByteArray& data) { |
48 | // Since fast apps appear and disappear without disconnecting from their | 52 | // Since fast apps appear and disappear without disconnecting from their |
49 | // channel we need to watch for the showing/hiding events and update according. | 53 | // channel we need to watch for the showing/hiding events and update according. |
50 | QDataStream stream( data, IO_ReadOnly ); | 54 | QDataStream stream( data, IO_ReadOnly ); |
51 | if ( msg == "fastAppShowing(QString)") { | 55 | if ( msg == "fastAppShowing(QString)") { |
52 | QString appName; | 56 | QString appName; |
53 | stream >> appName; | 57 | stream >> appName; |
54 | // qDebug("fastAppShowing %s", appName.data() ); | 58 | // odebug << "fastAppShowing " << appName.data() << "" << oendl; |
55 | const AppLnk* f = ServerInterface::appLnks().findExec(appName); | 59 | const AppLnk* f = ServerInterface::appLnks().findExec(appName); |
56 | if ( f ) addTask(*f); | 60 | if ( f ) addTask(*f); |
57 | } else if ( msg == "fastAppHiding(QString)") { | 61 | } else if ( msg == "fastAppHiding(QString)") { |
58 | QString appName; | 62 | QString appName; |
59 | stream >> appName; | 63 | stream >> appName; |
60 | const AppLnk* f = ServerInterface::appLnks().findExec(appName); | 64 | const AppLnk* f = ServerInterface::appLnks().findExec(appName); |
61 | if ( f ) removeTask(*f); | 65 | if ( f ) removeTask(*f); |
62 | } | 66 | } |
63 | } | 67 | } |
64 | 68 | ||
65 | void RunningAppBar::addTask(const AppLnk& appLnk) { | 69 | void RunningAppBar::addTask(const AppLnk& appLnk) { |
66 | qDebug("Added %s to app list.", appLnk.name().latin1()); | 70 | odebug << "Added " << appLnk.name() << " to app list." << oendl; |
67 | AppLnk* newApp = new AppLnk(appLnk); | 71 | AppLnk* newApp = new AppLnk(appLnk); |
68 | newApp->setExec(appLnk.exec()); | 72 | newApp->setExec(appLnk.exec()); |
69 | appList.prepend(newApp); | 73 | appList.prepend(newApp); |
70 | update(); | 74 | update(); |
71 | } | 75 | } |
72 | 76 | ||
73 | void RunningAppBar::removeTask(const AppLnk& appLnk) { | 77 | void RunningAppBar::removeTask(const AppLnk& appLnk) { |
74 | unsigned int i = 0; | 78 | unsigned int i = 0; |
75 | for (; i < appList.count() ; i++) { | 79 | for (; i < appList.count() ; i++) { |
76 | AppLnk* target = appList.at(i); | 80 | AppLnk* target = appList.at(i); |
77 | if (target->exec() == appLnk.exec()) { | 81 | if (target->exec() == appLnk.exec()) { |
78 | qDebug("Removing %s from app list.", appLnk.name().latin1()); | 82 | odebug << "Removing " << appLnk.name() << " from app list." << oendl; |
79 | appList.remove(); | 83 | appList.remove(); |
80 | delete target; | 84 | delete target; |
81 | } | 85 | } |
82 | } | 86 | } |
83 | update(); | 87 | update(); |
84 | } | 88 | } |
85 | 89 | ||
86 | void RunningAppBar::mousePressEvent(QMouseEvent *e) | 90 | void RunningAppBar::mousePressEvent(QMouseEvent *e) |
87 | { | 91 | { |
88 | // Find out if the user is clicking on an app icon... | 92 | // Find out if the user is clicking on an app icon... |
89 | // If so, snag the index so when we repaint we show it | 93 | // If so, snag the index so when we repaint we show it |
90 | // as highlighed. | 94 | // as highlighed. |
91 | selectedAppIndex = 0; | 95 | selectedAppIndex = 0; |
92 | int x=0; | 96 | int x=0; |
93 | QListIterator<AppLnk> it( appList ); | 97 | QListIterator<AppLnk> it( appList ); |
94 | for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) { | 98 | for ( ; it.current(); ++it,++selectedAppIndex,x+=spacing ) { |
95 | if ( x + spacing <= width() ) { | 99 | if ( x + spacing <= width() ) { |
96 | if ( e->x() >= x && e->x() < x+spacing ) { | 100 | if ( e->x() >= x && e->x() < x+spacing ) { |
97 | if ( selectedAppIndex < (int)appList.count() ) { | 101 | if ( selectedAppIndex < (int)appList.count() ) { |
98 | repaint(FALSE); | 102 | repaint(FALSE); |
99 | return; | 103 | return; |
100 | } | 104 | } |
101 | } | 105 | } |
102 | } else { | 106 | } else { |
103 | break; | 107 | break; |
104 | } | 108 | } |
105 | } | 109 | } |
106 | selectedAppIndex = -1; | 110 | selectedAppIndex = -1; |
107 | repaint( FALSE ); | 111 | repaint( FALSE ); |
108 | } | 112 | } |
109 | 113 | ||
110 | void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) | 114 | void RunningAppBar::mouseReleaseEvent(QMouseEvent *e) |
111 | { | 115 | { |
112 | if (e->button() == QMouseEvent::RightButton) | 116 | if (e->button() == QMouseEvent::RightButton) |
113 | return; | 117 | return; |
114 | if ( selectedAppIndex >= 0 ) { | 118 | if ( selectedAppIndex >= 0 ) { |
115 | QString app = appList.at(selectedAppIndex)->exec(); | 119 | QString app = appList.at(selectedAppIndex)->exec(); |
116 | QCopEnvelope e("QPE/System", "raise(QString)"); | 120 | QCopEnvelope e("QPE/System", "raise(QString)"); |
117 | e << app; | 121 | e << app; |
118 | selectedAppIndex = -1; | 122 | selectedAppIndex = -1; |
119 | update(); | 123 | update(); |
120 | } | 124 | } |
121 | } | 125 | } |
122 | 126 | ||
123 | void RunningAppBar::paintEvent( QPaintEvent * ) | 127 | void RunningAppBar::paintEvent( QPaintEvent * ) |
124 | { | 128 | { |
125 | QPainter p( this ); | 129 | QPainter p( this ); |
126 | AppLnk *curApp; | 130 | AppLnk *curApp; |
127 | int x = 0; | 131 | int x = 0; |
128 | int y = (height() - AppLnk::smallIconSize()) / 2; | 132 | int y = (height() - AppLnk::smallIconSize()) / 2; |
129 | int i = 0; | 133 | int i = 0; |
130 | 134 | ||
131 | p.fillRect( 0, 0, width(), height(), colorGroup().background() ); | 135 | p.fillRect( 0, 0, width(), height(), colorGroup().background() ); |
132 | 136 | ||
133 | QListIterator<AppLnk> it(appList); | 137 | QListIterator<AppLnk> it(appList); |
134 | 138 | ||
135 | for (; it.current(); i++, ++it ) { | 139 | for (; it.current(); i++, ++it ) { |
136 | if ( x + spacing <= width() ) { | 140 | if ( x + spacing <= width() ) { |
137 | curApp = it.current(); | 141 | curApp = it.current(); |
138 | qWarning("Drawing %s", curApp->name().latin1() ); | 142 | owarn << "Drawing " << curApp->name() << "" << oendl; |
139 | if ( (int)i == selectedAppIndex ) | 143 | if ( (int)i == selectedAppIndex ) |
140 | p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() ); | 144 | p.fillRect( x, y, spacing, curApp->pixmap().height()+1, colorGroup().highlight() ); |
141 | else | 145 | else |
142 | p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); | 146 | p.eraseRect( x, y, spacing, curApp->pixmap().height()+1 ); |
143 | p.drawPixmap( x, y, curApp->pixmap() ); | 147 | p.drawPixmap( x, y, curApp->pixmap() ); |
144 | x += spacing; | 148 | x += spacing; |
145 | } | 149 | } |
146 | } | 150 | } |
147 | } | 151 | } |
148 | 152 | ||
149 | QSize RunningAppBar::sizeHint() const | 153 | QSize RunningAppBar::sizeHint() const |
150 | { | 154 | { |
151 | return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); | 155 | return QSize( frameWidth(), AppLnk::smallIconSize()+frameWidth()*2+3 ); |
152 | } | 156 | } |
153 | 157 | ||
154 | void RunningAppBar::applicationLaunched(const QString &appName) | 158 | void RunningAppBar::applicationLaunched(const QString &appName) |
155 | { | 159 | { |
156 | qDebug("desktop:: app: %s launched with pid ", appName.data() ); | 160 | odebug << "desktop:: app: " << appName.data() << " launched with pid " << oendl; |
157 | const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName); | 161 | const AppLnk* newGuy = ServerInterface::appLnks().findExec(appName); |
158 | if ( newGuy && !newGuy->isPreloaded() ) { | 162 | if ( newGuy && !newGuy->isPreloaded() ) { |
159 | addTask( *newGuy ); | 163 | addTask( *newGuy ); |
160 | } | 164 | } |
161 | } | 165 | } |
162 | 166 | ||
163 | void RunningAppBar::applicationTerminated(const QString &app) | 167 | void RunningAppBar::applicationTerminated(const QString &app) |
164 | { | 168 | { |
165 | const AppLnk* gone = ServerInterface::appLnks().findExec(app); | 169 | const AppLnk* gone = ServerInterface::appLnks().findExec(app); |
166 | if ( gone ) { | 170 | if ( gone ) { |
167 | removeTask(*gone); | 171 | removeTask(*gone); |
168 | } | 172 | } |
169 | } | 173 | } |
170 | 174 | ||
171 | 175 | ||
172 | 176 | ||
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index 6aaab3a..a7d23c4 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp | |||
@@ -1,328 +1,328 @@ | |||
1 | 1 | ||
2 | #include "screensaver.h" | 2 | #include "screensaver.h" |
3 | 3 | ||
4 | #include <qpe/config.h> | 4 | #include <qpe/config.h> |
5 | #include <qpe/network.h> | 5 | #include <qpe/network.h> |
6 | 6 | ||
7 | #include <opie2/odevice.h> | 7 | #include <opie2/odevice.h> |
8 | 8 | ||
9 | 9 | ||
10 | using namespace Opie::Core; | 10 | using namespace Opie::Core; |
11 | 11 | ||
12 | 12 | ||
13 | 13 | ||
14 | OpieScreenSaver::OpieScreenSaver ( ) | 14 | OpieScreenSaver::OpieScreenSaver ( ) |
15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) | 15 | : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) |
16 | { | 16 | { |
17 | m_disable_suspend = 100; | 17 | m_disable_suspend = 100; |
18 | m_enable_dim = false; | 18 | m_enable_dim = false; |
19 | m_enable_lightoff = false; | 19 | m_enable_lightoff = false; |
20 | m_enable_suspend = false; | 20 | m_enable_suspend = false; |
21 | m_onlylcdoff = false; | 21 | m_onlylcdoff = false; |
22 | 22 | ||
23 | m_enable_dim_ac = false; | 23 | m_enable_dim_ac = false; |
24 | m_enable_lightoff_ac = false; | 24 | m_enable_lightoff_ac = false; |
25 | m_enable_suspend_ac = false; | 25 | m_enable_suspend_ac = false; |
26 | m_onlylcdoff_ac = false; | 26 | m_onlylcdoff_ac = false; |
27 | 27 | ||
28 | m_use_light_sensor = false; | 28 | m_use_light_sensor = false; |
29 | m_backlight_sensor = -1; | 29 | m_backlight_sensor = -1; |
30 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); | 30 | ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); |
31 | 31 | ||
32 | m_lcd_status = true; | 32 | m_lcd_status = true; |
33 | 33 | ||
34 | m_backlight_normal = -1; | 34 | m_backlight_normal = -1; |
35 | m_backlight_current = -1; | 35 | m_backlight_current = -1; |
36 | m_backlight_forcedoff = false; | 36 | m_backlight_forcedoff = false; |
37 | 37 | ||
38 | m_on_ac = false; | 38 | m_on_ac = false; |
39 | 39 | ||
40 | m_level = -1; | 40 | m_level = -1; |
41 | 41 | ||
42 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) | 42 | // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) |
43 | ODevice::inst ( )-> setDisplayStatus ( true ); | 43 | ODevice::inst ( )-> setDisplayStatus ( true ); |
44 | setBacklight ( -1 ); | 44 | setBacklight ( -1 ); |
45 | } | 45 | } |
46 | 46 | ||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Stops the screen saver | 49 | * Stops the screen saver |
50 | */ | 50 | */ |
51 | void OpieScreenSaver::restore() | 51 | void OpieScreenSaver::restore() |
52 | { | 52 | { |
53 | m_level = -1; | 53 | m_level = -1; |
54 | 54 | ||
55 | if ( !m_lcd_status ) { // We must have turned it off | 55 | if ( !m_lcd_status ) { // We must have turned it off |
56 | ODevice::inst ( ) -> setDisplayStatus ( true ); | 56 | ODevice::inst ( ) -> setDisplayStatus ( true ); |
57 | m_lcd_status = true; | 57 | m_lcd_status = true; |
58 | } | 58 | } |
59 | 59 | ||
60 | setBacklightInternal ( -1 ); | 60 | setBacklightInternal ( -1 ); |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Starts the screen saver | 65 | * Starts the screen saver |
66 | * | 66 | * |
67 | * @param level what level of screen saving should happen (0=lowest non-off, 1=off, | 67 | * @param level what level of screen saving should happen (0=lowest non-off, 1=off, |
68 | * 2=suspend whole machine) | 68 | * 2=suspend whole machine) |
69 | * @returns true on success | 69 | * @returns true on success |
70 | */ | 70 | */ |
71 | bool OpieScreenSaver::save( int level ) | 71 | bool OpieScreenSaver::save( int level ) |
72 | { | 72 | { |
73 | m_level = level; | 73 | m_level = level; |
74 | 74 | ||
75 | switch ( level ) { | 75 | switch ( level ) { |
76 | case 0: | 76 | case 0: |
77 | if (( m_on_ac && m_enable_dim_ac ) || | 77 | if (( m_on_ac && m_enable_dim_ac ) || |
78 | ( !m_on_ac && m_enable_dim )) { | 78 | ( !m_on_ac && m_enable_dim )) { |
79 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) | 79 | if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) |
80 | setBacklightInternal ( 1 ); // lowest non-off | 80 | setBacklightInternal ( 1 ); // lowest non-off |
81 | } | 81 | } |
82 | return true; | 82 | return true; |
83 | break; | 83 | break; |
84 | 84 | ||
85 | case 1: | 85 | case 1: |
86 | if (( m_on_ac && m_enable_lightoff_ac ) || | 86 | if (( m_on_ac && m_enable_lightoff_ac ) || |
87 | ( !m_on_ac && m_enable_lightoff )) { | 87 | ( !m_on_ac && m_enable_lightoff )) { |
88 | if ( m_disable_suspend > 1 ) | 88 | if ( m_disable_suspend > 1 ) |
89 | setBacklightInternal ( 0 ); // off | 89 | setBacklightInternal ( 0 ); // off |
90 | } | 90 | } |
91 | return true; | 91 | return true; |
92 | break; | 92 | break; |
93 | 93 | ||
94 | case 2: | 94 | case 2: |
95 | if (( m_on_ac && !m_enable_suspend_ac ) || | 95 | if (( m_on_ac && !m_enable_suspend_ac ) || |
96 | ( !m_on_ac && !m_enable_suspend )) { | 96 | ( !m_on_ac && !m_enable_suspend )) { |
97 | return true; | 97 | return true; |
98 | } | 98 | } |
99 | 99 | ||
100 | if (( m_on_ac && m_onlylcdoff_ac ) || | 100 | if (( m_on_ac && m_onlylcdoff_ac ) || |
101 | ( !m_on_ac && m_onlylcdoff )) { | 101 | ( !m_on_ac && m_onlylcdoff )) { |
102 | ODevice::inst ( ) -> setDisplayStatus ( false ); | 102 | ODevice::inst ( ) -> setDisplayStatus ( false ); |
103 | m_lcd_status = false; | 103 | m_lcd_status = false; |
104 | return true; | 104 | return true; |
105 | } | 105 | } |
106 | 106 | ||
107 | // We're going to suspend the whole machine | 107 | // We're going to suspend the whole machine |
108 | 108 | ||
109 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { | 109 | if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { |
110 | // TODO: why is this key F34 hard coded? -- schurig | 110 | // TODO: why is this key F34 hard coded? -- schurig |
111 | // Does this now only work an devices with a ODevice::filter? | 111 | // Does this now only work an devices with a ODevice::filter? |
112 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); | 112 | QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); |
113 | return true; | 113 | return true; |
114 | } | 114 | } |
115 | 115 | ||
116 | break; | 116 | break; |
117 | } | 117 | } |
118 | return false; | 118 | return false; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * Set intervals in seconds for automatic dimming, light off and suspend | 123 | * Set intervals in seconds for automatic dimming, light off and suspend |
124 | * | 124 | * |
125 | * This function also sets the member variables m_m_enable_dim[_ac], | 125 | * This function also sets the member variables m_m_enable_dim[_ac], |
126 | * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] | 126 | * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] |
127 | * | 127 | * |
128 | * @param dim time in seconds to dim, -1 to read value from config file, | 128 | * @param dim time in seconds to dim, -1 to read value from config file, |
129 | * 0 to disable | 129 | * 0 to disable |
130 | * @param lightoff time in seconds to turn LCD backlight off, -1 to | 130 | * @param lightoff time in seconds to turn LCD backlight off, -1 to |
131 | * read value from config file, 0 to disable | 131 | * read value from config file, 0 to disable |
132 | * @param suspend time in seconds to do an APM suspend, -1 to | 132 | * @param suspend time in seconds to do an APM suspend, -1 to |
133 | * read value from config file, 0 to disable | 133 | * read value from config file, 0 to disable |
134 | */ | 134 | */ |
135 | void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) | 135 | void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) |
136 | { | 136 | { |
137 | Config config ( "apm" ); | 137 | Config config ( "apm" ); |
138 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 138 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
139 | 139 | ||
140 | int v[ 4 ]; | 140 | int v[ 4 ]; |
141 | if ( dim < 0 ) | 141 | if ( dim < 0 ) |
142 | dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); | 142 | dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); |
143 | if ( lightoff < 0 ) | 143 | if ( lightoff < 0 ) |
144 | lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); | 144 | lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); |
145 | if ( suspend < 0 ) | 145 | if ( suspend < 0 ) |
146 | suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); | 146 | suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); |
147 | 147 | ||
148 | if ( m_on_ac ) { | 148 | if ( m_on_ac ) { |
149 | m_enable_dim_ac = ( dim > 0 ); | 149 | m_enable_dim_ac = ( dim > 0 ); |
150 | m_enable_lightoff_ac = ( lightoff > 0 ); | 150 | m_enable_lightoff_ac = ( lightoff > 0 ); |
151 | m_enable_suspend_ac = ( suspend > 0 ); | 151 | m_enable_suspend_ac = ( suspend > 0 ); |
152 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); | 152 | m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); |
153 | } | 153 | } |
154 | else { | 154 | else { |
155 | m_enable_dim = ( dim > 0 ); | 155 | m_enable_dim = ( dim > 0 ); |
156 | m_enable_lightoff = ( lightoff > 0 ); | 156 | m_enable_lightoff = ( lightoff > 0 ); |
157 | m_enable_suspend = ( suspend > 0 ); | 157 | m_enable_suspend = ( suspend > 0 ); |
158 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); | 158 | m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); |
159 | } | 159 | } |
160 | 160 | ||
161 | //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); | 161 | //odebug << "screen saver intervals: " << dim << " " << lightoff << " " << suspend << "" << oendl; |
162 | 162 | ||
163 | v [ 0 ] = QMAX( 1000 * dim, 100 ); | 163 | v [ 0 ] = QMAX( 1000 * dim, 100 ); |
164 | v [ 1 ] = QMAX( 1000 * lightoff, 100 ); | 164 | v [ 1 ] = QMAX( 1000 * lightoff, 100 ); |
165 | v [ 2 ] = QMAX( 1000 * suspend, 100 ); | 165 | v [ 2 ] = QMAX( 1000 * suspend, 100 ); |
166 | v [ 3 ] = 0; | 166 | v [ 3 ] = 0; |
167 | 167 | ||
168 | if ( !dim && !lightoff && !suspend ) | 168 | if ( !dim && !lightoff && !suspend ) |
169 | QWSServer::setScreenSaverInterval( 0 ); | 169 | QWSServer::setScreenSaverInterval( 0 ); |
170 | else | 170 | else |
171 | QWSServer::setScreenSaverIntervals( v ); | 171 | QWSServer::setScreenSaverIntervals( v ); |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | /** | 175 | /** |
176 | * Set suspend time. Will read the dim and lcd-off times from the config file. | 176 | * Set suspend time. Will read the dim and lcd-off times from the config file. |
177 | * | 177 | * |
178 | * @param suspend time in seconds to go into APM suspend, -1 to | 178 | * @param suspend time in seconds to go into APM suspend, -1 to |
179 | * read value from config file, 0 to disable | 179 | * read value from config file, 0 to disable |
180 | */ | 180 | */ |
181 | void OpieScreenSaver::setInterval ( int interval ) | 181 | void OpieScreenSaver::setInterval ( int interval ) |
182 | { | 182 | { |
183 | setIntervals ( -1, -1, interval ); | 183 | setIntervals ( -1, -1, interval ); |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | void OpieScreenSaver::setMode ( int mode ) | 187 | void OpieScreenSaver::setMode ( int mode ) |
188 | { | 188 | { |
189 | if ( mode > m_disable_suspend ) | 189 | if ( mode > m_disable_suspend ) |
190 | setInterval ( -1 ); | 190 | setInterval ( -1 ); |
191 | m_disable_suspend = mode; | 191 | m_disable_suspend = mode; |
192 | } | 192 | } |
193 | 193 | ||
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Set display brightness | 196 | * Set display brightness |
197 | * | 197 | * |
198 | * Get's default values for backlight, contrast and light sensor from config file. | 198 | * Get's default values for backlight, contrast and light sensor from config file. |
199 | * | 199 | * |
200 | * @param bright desired brighness (-1 to use automatic sensor data or value | 200 | * @param bright desired brighness (-1 to use automatic sensor data or value |
201 | * from config file, -2 to toggle backlight on and off, -3 to | 201 | * from config file, -2 to toggle backlight on and off, -3 to |
202 | * force backlight off) | 202 | * force backlight off) |
203 | */ | 203 | */ |
204 | void OpieScreenSaver::setBacklight ( int bright ) | 204 | void OpieScreenSaver::setBacklight ( int bright ) |
205 | { | 205 | { |
206 | // Read from config | 206 | // Read from config |
207 | Config config ( "apm" ); | 207 | Config config ( "apm" ); |
208 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); | 208 | config. setGroup ( m_on_ac ? "AC" : "Battery" ); |
209 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); | 209 | m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); |
210 | int contrast = config. readNumEntry ( "Contrast", 127); | 210 | int contrast = config. readNumEntry ( "Contrast", 127); |
211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); | 211 | m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); |
212 | 212 | ||
213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); | 213 | //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); |
214 | 214 | ||
215 | killTimers ( ); | 215 | killTimers ( ); |
216 | if (( bright < 0 ) && m_use_light_sensor ) { | 216 | if (( bright < 0 ) && m_use_light_sensor ) { |
217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); | 217 | QStringList sl = config. readListEntry ( "LightSensorData", ';' ); |
218 | 218 | ||
219 | m_sensordata [LS_SensorMin] = 40; | 219 | m_sensordata [LS_SensorMin] = 40; |
220 | m_sensordata [LS_SensorMax] = 215; | 220 | m_sensordata [LS_SensorMax] = 215; |
221 | m_sensordata [LS_LightMin] = 1; | 221 | m_sensordata [LS_LightMin] = 1; |
222 | m_sensordata [LS_LightMax] = 255; | 222 | m_sensordata [LS_LightMax] = 255; |
223 | m_sensordata [LS_Steps] = 12; | 223 | m_sensordata [LS_Steps] = 12; |
224 | m_sensordata [LS_Interval] = 2000; | 224 | m_sensordata [LS_Interval] = 2000; |
225 | 225 | ||
226 | for ( uint i = 0; i < LS_Count; i++ ) { | 226 | for ( uint i = 0; i < LS_Count; i++ ) { |
227 | if ( i < sl. count ( )) | 227 | if ( i < sl. count ( )) |
228 | m_sensordata [i] = sl [i]. toInt ( ); | 228 | m_sensordata [i] = sl [i]. toInt ( ); |
229 | } | 229 | } |
230 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE | 230 | if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE |
231 | m_sensordata [LS_Steps] = 2; | 231 | m_sensordata [LS_Steps] = 2; |
232 | 232 | ||
233 | timerEvent ( 0 ); | 233 | timerEvent ( 0 ); |
234 | startTimer ( m_sensordata [LS_Interval] ); | 234 | startTimer ( m_sensordata [LS_Interval] ); |
235 | } | 235 | } |
236 | 236 | ||
237 | setBacklightInternal ( bright ); | 237 | setBacklightInternal ( bright ); |
238 | ODevice::inst ( )-> setDisplayContrast(contrast); | 238 | ODevice::inst ( )-> setDisplayContrast(contrast); |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | /** | 242 | /** |
243 | * Internal brightness setting method | 243 | * Internal brightness setting method |
244 | * | 244 | * |
245 | * Get's default values for backlight and light sensor from config file. | 245 | * Get's default values for backlight and light sensor from config file. |
246 | * | 246 | * |
247 | * @param bright desired brighness (-1 to use automatic sensor data or value | 247 | * @param bright desired brighness (-1 to use automatic sensor data or value |
248 | * from config file, -2 to toggle backlight on and off, -3 to | 248 | * from config file, -2 to toggle backlight on and off, -3 to |
249 | * force backlight off) | 249 | * force backlight off) |
250 | */ | 250 | */ |
251 | void OpieScreenSaver::setBacklightInternal ( int bright ) | 251 | void OpieScreenSaver::setBacklightInternal ( int bright ) |
252 | { | 252 | { |
253 | if ( bright == -3 ) { | 253 | if ( bright == -3 ) { |
254 | // Forced on | 254 | // Forced on |
255 | m_backlight_forcedoff = false; | 255 | m_backlight_forcedoff = false; |
256 | bright = -1; | 256 | bright = -1; |
257 | } | 257 | } |
258 | if ( m_backlight_forcedoff && bright != -2 ) | 258 | if ( m_backlight_forcedoff && bright != -2 ) |
259 | return ; | 259 | return ; |
260 | if ( bright == -2 ) { | 260 | if ( bright == -2 ) { |
261 | // Toggle between off and on | 261 | // Toggle between off and on |
262 | bright = m_backlight_current ? 0 : -1; | 262 | bright = m_backlight_current ? 0 : -1; |
263 | m_backlight_forcedoff = !bright; | 263 | m_backlight_forcedoff = !bright; |
264 | } | 264 | } |
265 | if ( bright == -1 ) | 265 | if ( bright == -1 ) |
266 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; | 266 | bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; |
267 | 267 | ||
268 | if ( bright != m_backlight_current ) { | 268 | if ( bright != m_backlight_current ) { |
269 | ODevice::inst ( )-> setDisplayBrightness ( bright ); | 269 | ODevice::inst ( )-> setDisplayBrightness ( bright ); |
270 | m_backlight_current = bright; | 270 | m_backlight_current = bright; |
271 | } | 271 | } |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | /** | 275 | /** |
276 | * Timer event used for automatic setting the backlight according to a light sensor | 276 | * Timer event used for automatic setting the backlight according to a light sensor |
277 | * and to set the default brightness | 277 | * and to set the default brightness |
278 | */ | 278 | */ |
279 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) | 279 | void OpieScreenSaver::timerEvent ( QTimerEvent * ) |
280 | { | 280 | { |
281 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); | 281 | int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); |
282 | 282 | ||
283 | if ( s < m_sensordata [LS_SensorMin] ) | 283 | if ( s < m_sensordata [LS_SensorMin] ) |
284 | m_backlight_sensor = m_sensordata [LS_LightMax]; | 284 | m_backlight_sensor = m_sensordata [LS_LightMax]; |
285 | else if ( s >= m_sensordata [LS_SensorMax] ) | 285 | else if ( s >= m_sensordata [LS_SensorMax] ) |
286 | m_backlight_sensor = m_sensordata [LS_LightMin]; | 286 | m_backlight_sensor = m_sensordata [LS_LightMin]; |
287 | else { | 287 | else { |
288 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; | 288 | int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; |
289 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; | 289 | int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; |
290 | 290 | ||
291 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 | 291 | int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 |
292 | 292 | ||
293 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); | 293 | m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); |
294 | } | 294 | } |
295 | 295 | ||
296 | //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); | 296 | //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); |
297 | 297 | ||
298 | if ( m_level <= 0 ) | 298 | if ( m_level <= 0 ) |
299 | setBacklightInternal ( -1 ); | 299 | setBacklightInternal ( -1 ); |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | /** | 303 | /** |
304 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. | 304 | * Like ODevice::setDisplayStatus(), but keep current state in m_lcd_status. |
305 | */ | 305 | */ |
306 | void OpieScreenSaver::setDisplayState ( bool on ) | 306 | void OpieScreenSaver::setDisplayState ( bool on ) |
307 | { | 307 | { |
308 | if ( m_lcd_status != on ) { | 308 | if ( m_lcd_status != on ) { |
309 | ODevice::inst ( ) -> setDisplayStatus ( on ); | 309 | ODevice::inst ( ) -> setDisplayStatus ( on ); |
310 | m_lcd_status = on; | 310 | m_lcd_status = on; |
311 | } | 311 | } |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | /** | 315 | /** |
316 | * Set display to default ac/battery settings when power status changed. | 316 | * Set display to default ac/battery settings when power status changed. |
317 | */ | 317 | */ |
318 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) | 318 | void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) |
319 | { | 319 | { |
320 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); | 320 | bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); |
321 | 321 | ||
322 | if ( newonac != m_on_ac ) { | 322 | if ( newonac != m_on_ac ) { |
323 | m_on_ac = newonac; | 323 | m_on_ac = newonac; |
324 | setInterval ( -1 ); | 324 | setInterval ( -1 ); |
325 | setBacklight ( -1 ); | 325 | setBacklight ( -1 ); |
326 | restore ( ); | 326 | restore ( ); |
327 | } | 327 | } |
328 | } | 328 | } |
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp index 9a86a80..b9fa1e5 100644 --- a/core/launcher/server.cpp +++ b/core/launcher/server.cpp | |||
@@ -1,729 +1,729 @@ | |||
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 | #include "server.h" | 21 | #include "server.h" |
22 | #include "serverapp.h" | 22 | #include "serverapp.h" |
23 | #include "startmenu.h" | 23 | #include "startmenu.h" |
24 | #include "launcher.h" | 24 | #include "launcher.h" |
25 | #include "transferserver.h" | 25 | #include "transferserver.h" |
26 | #include "qcopbridge.h" | 26 | #include "qcopbridge.h" |
27 | #include "irserver.h" | 27 | #include "irserver.h" |
28 | #include "packageslave.h" | 28 | #include "packageslave.h" |
29 | #include "calibrate.h" | 29 | #include "calibrate.h" |
30 | #include "qrsync.h" | 30 | #include "qrsync.h" |
31 | #include "syncdialog.h" | 31 | #include "syncdialog.h" |
32 | #include "shutdownimpl.h" | 32 | #include "shutdownimpl.h" |
33 | #include "applauncher.h" | 33 | #include "applauncher.h" |
34 | #if 0 | 34 | #if 0 |
35 | #include "suspendmonitor.h" | 35 | #include "suspendmonitor.h" |
36 | #endif | 36 | #endif |
37 | #include "documentlist.h" | 37 | #include "documentlist.h" |
38 | 38 | ||
39 | /* OPIE */ | ||
40 | #include <opie2/odebug.h> | ||
41 | #include <opie2/odevicebutton.h> | ||
42 | #include <opie2/odevice.h> | ||
39 | #include <qtopia/applnk.h> | 43 | #include <qtopia/applnk.h> |
40 | #include <qtopia/private/categories.h> | 44 | #include <qtopia/private/categories.h> |
41 | #include <qtopia/mimetype.h> | 45 | #include <qtopia/mimetype.h> |
42 | #include <qtopia/config.h> | 46 | #include <qtopia/config.h> |
43 | #include <qtopia/resource.h> | 47 | #include <qtopia/resource.h> |
44 | #include <qtopia/version.h> | 48 | #include <qtopia/version.h> |
45 | #include <qtopia/storage.h> | 49 | #include <qtopia/storage.h> |
46 | |||
47 | #include <qtopia/qcopenvelope_qws.h> | 50 | #include <qtopia/qcopenvelope_qws.h> |
48 | #include <qwindowsystem_qws.h> | ||
49 | #include <qgfx_qws.h> | ||
50 | #include <qtopia/global.h> | 51 | #include <qtopia/global.h> |
51 | //#include <qtopia/custom.h> | 52 | using namespace Opie::Core; |
52 | |||
53 | #include <opie2/odevicebutton.h> | ||
54 | #include <opie2/odevice.h> | ||
55 | 53 | ||
56 | #include <unistd.h> | 54 | /* QT */ |
57 | #include <qmainwindow.h> | 55 | #include <qmainwindow.h> |
58 | #include <qmessagebox.h> | 56 | #include <qmessagebox.h> |
59 | #include <qtimer.h> | 57 | #include <qtimer.h> |
60 | #include <qtextstream.h> | 58 | #include <qtextstream.h> |
59 | #include <qwindowsystem_qws.h> | ||
60 | #include <qgfx_qws.h> | ||
61 | 61 | ||
62 | /* STD */ | ||
63 | #include <unistd.h> | ||
62 | #include <stdlib.h> | 64 | #include <stdlib.h> |
63 | 65 | ||
64 | extern QRect qt_maxWindowRect; | 66 | extern QRect qt_maxWindowRect; |
65 | 67 | ||
66 | |||
67 | using namespace Opie::Core; | ||
68 | static QWidget *calibrate(bool) | 68 | static QWidget *calibrate(bool) |
69 | { | 69 | { |
70 | #ifdef Q_WS_QWS | 70 | #ifdef Q_WS_QWS |
71 | Calibrate *c = new Calibrate; | 71 | Calibrate *c = new Calibrate; |
72 | c->show(); | 72 | c->show(); |
73 | return c; | 73 | return c; |
74 | #else | 74 | #else |
75 | return 0; | 75 | return 0; |
76 | #endif | 76 | #endif |
77 | } | 77 | } |
78 | 78 | ||
79 | #define FACTORY(T) \ | 79 | #define FACTORY(T) \ |
80 | static QWidget *new##T( bool maximized ) { \ | 80 | static QWidget *new##T( bool maximized ) { \ |
81 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ | 81 | QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ |
82 | if ( maximized ) { \ | 82 | if ( maximized ) { \ |
83 | if ( qApp->desktop()->width() <= 350 ) { \ | 83 | if ( qApp->desktop()->width() <= 350 ) { \ |
84 | w->showMaximized(); \ | 84 | w->showMaximized(); \ |
85 | } else { \ | 85 | } else { \ |
86 | w->resize( QSize( 300, 300 ) ); \ | 86 | w->resize( QSize( 300, 300 ) ); \ |
87 | } \ | 87 | } \ |
88 | } \ | 88 | } \ |
89 | w->show(); \ | 89 | w->show(); \ |
90 | return w; \ | 90 | return w; \ |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | #ifdef SINGLE_APP | 94 | #ifdef SINGLE_APP |
95 | #define APP(a,b,c,d) FACTORY(b) | 95 | #define APP(a,b,c,d) FACTORY(b) |
96 | #include "apps.h" | 96 | #include "apps.h" |
97 | #undef APP | 97 | #undef APP |
98 | #endif // SINGLE_APP | 98 | #endif // SINGLE_APP |
99 | 99 | ||
100 | static Global::Command builtins[] = { | 100 | static Global::Command builtins[] = { |
101 | 101 | ||
102 | #ifdef SINGLE_APP | 102 | #ifdef SINGLE_APP |
103 | #define APP(a,b,c,d) { a, new##b, c, d }, | 103 | #define APP(a,b,c,d) { a, new##b, c, d }, |
104 | #include "apps.h" | 104 | #include "apps.h" |
105 | #undef APP | 105 | #undef APP |
106 | #endif | 106 | #endif |
107 | 107 | ||
108 | /* FIXME defines need to be defined*/ | 108 | /* FIXME defines need to be defined*/ |
109 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) | 109 | #if !defined(OPIE_NO_BUILTIN_CALIBRATE) |
110 | { "calibrate", calibrate, 1, 0 }, // No tr | 110 | { "calibrate", calibrate, 1, 0 }, // No tr |
111 | #endif | 111 | #endif |
112 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) | 112 | #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) |
113 | { "shutdown", Global::shutdown, 1, 0 }, // No tr | 113 | { "shutdown", Global::shutdown, 1, 0 }, // No tr |
114 | // { "run", run, 1, 0 }, // No tr | 114 | // { "run", run, 1, 0 }, // No tr |
115 | #endif | 115 | #endif |
116 | 116 | ||
117 | { 0, calibrate,0, 0 }, | 117 | { 0, calibrate,0, 0 }, |
118 | }; | 118 | }; |
119 | 119 | ||
120 | 120 | ||
121 | //--------------------------------------------------------------------------- | 121 | //--------------------------------------------------------------------------- |
122 | 122 | ||
123 | 123 | ||
124 | //=========================================================================== | 124 | //=========================================================================== |
125 | 125 | ||
126 | Server::Server() : | 126 | Server::Server() : |
127 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), | 127 | QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), |
128 | qcopBridge( 0 ), | 128 | qcopBridge( 0 ), |
129 | transferServer( 0 ), | 129 | transferServer( 0 ), |
130 | packageHandler( 0 ), | 130 | packageHandler( 0 ), |
131 | syncDialog( 0 ) | 131 | syncDialog( 0 ) |
132 | { | 132 | { |
133 | Global::setBuiltinCommands(builtins); | 133 | Global::setBuiltinCommands(builtins); |
134 | 134 | ||
135 | tid_xfer = 0; | 135 | tid_xfer = 0; |
136 | /* ### FIXME ### */ | 136 | /* ### FIXME ### */ |
137 | /* tid_today = startTimer(3600*2*1000);*/ | 137 | /* tid_today = startTimer(3600*2*1000);*/ |
138 | last_today_show = QDate::currentDate(); | 138 | last_today_show = QDate::currentDate(); |
139 | 139 | ||
140 | #if 0 | 140 | #if 0 |
141 | tsmMonitor = new TempScreenSaverMode(); | 141 | tsmMonitor = new TempScreenSaverMode(); |
142 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); | 142 | connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | serverGui = new Launcher; | 145 | serverGui = new Launcher; |
146 | serverGui->createGUI(); | 146 | serverGui->createGUI(); |
147 | 147 | ||
148 | docList = new DocumentList( serverGui ); | 148 | docList = new DocumentList( serverGui ); |
149 | appLauncher = new AppLauncher(this); | 149 | appLauncher = new AppLauncher(this); |
150 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); | 150 | connect(appLauncher, SIGNAL(launched(int,const QString&)), this, SLOT(applicationLaunched(int,const QString&)) ); |
151 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); | 151 | connect(appLauncher, SIGNAL(terminated(int,const QString&)), this, SLOT(applicationTerminated(int,const QString&)) ); |
152 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); | 152 | connect(appLauncher, SIGNAL(connected(const QString&)), this, SLOT(applicationConnected(const QString&)) ); |
153 | 153 | ||
154 | storage = new StorageInfo( this ); | 154 | storage = new StorageInfo( this ); |
155 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); | 155 | connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); |
156 | 156 | ||
157 | // start services | 157 | // start services |
158 | startTransferServer(); | 158 | startTransferServer(); |
159 | (void) new IrServer( this ); | 159 | (void) new IrServer( this ); |
160 | 160 | ||
161 | packageHandler = new PackageHandler( this ); | 161 | packageHandler = new PackageHandler( this ); |
162 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 162 | connect(qApp, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
163 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); | 163 | this,SLOT(activate(const Opie::Core::ODeviceButton*,bool))); |
164 | 164 | ||
165 | setGeometry( -10, -10, 9, 9 ); | 165 | setGeometry( -10, -10, 9, 9 ); |
166 | 166 | ||
167 | QCopChannel *channel = new QCopChannel("QPE/System", this); | 167 | QCopChannel *channel = new QCopChannel("QPE/System", this); |
168 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), | 168 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), |
169 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); | 169 | this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); |
170 | 170 | ||
171 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); | 171 | QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); |
172 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), | 172 | connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), |
173 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); | 173 | this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); |
174 | 174 | ||
175 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); | 175 | connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); |
176 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); | 176 | connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); |
177 | 177 | ||
178 | preloadApps(); | 178 | preloadApps(); |
179 | } | 179 | } |
180 | 180 | ||
181 | void Server::show() | 181 | void Server::show() |
182 | { | 182 | { |
183 | ServerApplication::login(TRUE); | 183 | ServerApplication::login(TRUE); |
184 | QWidget::show(); | 184 | QWidget::show(); |
185 | } | 185 | } |
186 | 186 | ||
187 | Server::~Server() | 187 | Server::~Server() |
188 | { | 188 | { |
189 | serverGui->destroyGUI(); | 189 | serverGui->destroyGUI(); |
190 | delete docList; | 190 | delete docList; |
191 | delete qcopBridge; | 191 | delete qcopBridge; |
192 | delete transferServer; | 192 | delete transferServer; |
193 | delete serverGui; | 193 | delete serverGui; |
194 | #if 0 | 194 | #if 0 |
195 | delete tsmMonitor; | 195 | delete tsmMonitor; |
196 | #endif | 196 | #endif |
197 | } | 197 | } |
198 | 198 | ||
199 | static bool hasVisibleWindow(const QString& clientname, bool partial) | 199 | static bool hasVisibleWindow(const QString& clientname, bool partial) |
200 | { | 200 | { |
201 | #ifdef QWS | 201 | #ifdef QWS |
202 | const QList<QWSWindow> &list = qwsServer->clientWindows(); | 202 | const QList<QWSWindow> &list = qwsServer->clientWindows(); |
203 | QWSWindow* w; | 203 | QWSWindow* w; |
204 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { | 204 | for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { |
205 | if ( w->client()->identity() == clientname ) { | 205 | if ( w->client()->identity() == clientname ) { |
206 | if ( partial && !w->isFullyObscured() ) | 206 | if ( partial && !w->isFullyObscured() ) |
207 | return TRUE; | 207 | return TRUE; |
208 | if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { | 208 | if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { |
209 | # if QT_VERSION < 0x030000 | 209 | # if QT_VERSION < 0x030000 |
210 | QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, | 210 | QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, |
211 | QSize(qt_screen->width(),qt_screen->height()) ); | 211 | QSize(qt_screen->width(),qt_screen->height()) ); |
212 | # else | 212 | # else |
213 | QRect mwr = qt_maxWindowRect; | 213 | QRect mwr = qt_maxWindowRect; |
214 | # endif | 214 | # endif |
215 | if ( mwr.contains(w->requested().boundingRect()) ) | 215 | if ( mwr.contains(w->requested().boundingRect()) ) |
216 | return TRUE; | 216 | return TRUE; |
217 | } | 217 | } |
218 | } | 218 | } |
219 | } | 219 | } |
220 | #endif | 220 | #endif |
221 | return FALSE; | 221 | return FALSE; |
222 | } | 222 | } |
223 | 223 | ||
224 | void Server::activate(const ODeviceButton* button, bool held) | 224 | void Server::activate(const ODeviceButton* button, bool held) |
225 | { | 225 | { |
226 | Global::terminateBuiltin("calibrate"); // No tr | 226 | Global::terminateBuiltin("calibrate"); // No tr |
227 | OQCopMessage om; | 227 | OQCopMessage om; |
228 | if ( held ) { | 228 | if ( held ) { |
229 | om = button->heldAction(); | 229 | om = button->heldAction(); |
230 | } else { | 230 | } else { |
231 | om = button->pressedAction(); | 231 | om = button->pressedAction(); |
232 | } | 232 | } |
233 | 233 | ||
234 | if ( om.channel() != "ignore" ) | 234 | if ( om.channel() != "ignore" ) |
235 | om.send(); | 235 | om.send(); |
236 | 236 | ||
237 | // A button with no action defined, will return a null ServiceRequest. Don't attempt | 237 | // A button with no action defined, will return a null ServiceRequest. Don't attempt |
238 | // to send/do anything with this as it will crash | 238 | // to send/do anything with this as it will crash |
239 | /* ### FIXME */ | 239 | /* ### FIXME */ |
240 | #if 0 | 240 | #if 0 |
241 | if ( !sr.isNull() ) { | 241 | if ( !sr.isNull() ) { |
242 | QString app = sr.app(); | 242 | QString app = sr.app(); |
243 | bool vis = hasVisibleWindow(app, app != "qpe"); | 243 | bool vis = hasVisibleWindow(app, app != "qpe"); |
244 | if ( sr.message() == "raise()" && vis ) { | 244 | if ( sr.message() == "raise()" && vis ) { |
245 | sr.setMessage("nextView()"); | 245 | sr.setMessage("nextView()"); |
246 | } else { | 246 | } else { |
247 | // "back door" | 247 | // "back door" |
248 | sr << (int)vis; | 248 | sr << (int)vis; |
249 | } | 249 | } |
250 | 250 | ||
251 | sr.send(); | 251 | sr.send(); |
252 | } | 252 | } |
253 | #endif | 253 | #endif |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
257 | #ifdef Q_WS_QWS | 257 | #ifdef Q_WS_QWS |
258 | 258 | ||
259 | 259 | ||
260 | typedef struct KeyOverride { | 260 | typedef struct KeyOverride { |
261 | ushort scan_code; | 261 | ushort scan_code; |
262 | QWSServer::KeyMap map; | 262 | QWSServer::KeyMap map; |
263 | }; | 263 | }; |
264 | 264 | ||
265 | 265 | ||
266 | static const KeyOverride jp109keys[] = { | 266 | static const KeyOverride jp109keys[] = { |
267 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, | 267 | { 0x03, { Qt::Key_2, '2' , 0x22 , 0xffff } }, |
268 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, | 268 | { 0x07, { Qt::Key_6, '6' , '&' , 0xffff } }, |
269 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, | 269 | { 0x08, { Qt::Key_7, '7' , '\'' , 0xffff } }, |
270 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, | 270 | { 0x09, { Qt::Key_8, '8' , '(' , 0xffff } }, |
271 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, | 271 | { 0x0a, { Qt::Key_9, '9' , ')' , 0xffff } }, |
272 | { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } }, | 272 | { 0x0b, { Qt::Key_0, '0' , 0xffff , 0xffff } }, |
273 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, | 273 | { 0x0c, { Qt::Key_Minus, '-' , '=' , 0xffff } }, |
274 | { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } }, | 274 | { 0x0d, { Qt::Key_AsciiCircum,'^' , '~' , '^' - 64 } }, |
275 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, | 275 | { 0x1a, { Qt::Key_At, '@' , '`' , 0xffff } }, |
276 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } }, | 276 | { 0x1b, { Qt::Key_BraceLeft, '[' , '{' , '[' - 64 } }, |
277 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, | 277 | { 0x27, { Qt::Key_Semicolon, ';' , '+' , 0xffff } }, |
278 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, | 278 | { 0x28, { Qt::Key_Colon, ':' , '*' , 0xffff } }, |
279 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } }, | 279 | { 0x29, { Qt::Key_Zenkaku_Hankaku, 0xffff , 0xffff , 0xffff } }, |
280 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, | 280 | { 0x2b, { Qt::Key_BraceRight, ']' , '}' , ']'-64 } }, |
281 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } }, | 281 | { 0x70, { Qt::Key_Hiragana_Katakana, 0xffff , 0xffff , 0xffff } }, |
282 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, | 282 | { 0x73, { Qt::Key_Backslash, '\\' , '_' , 0xffff } }, |
283 | { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } }, | 283 | { 0x79, { Qt::Key_Henkan, 0xffff , 0xffff , 0xffff } }, |
284 | { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } }, | 284 | { 0x7b, { Qt::Key_Muhenkan, 0xffff , 0xffff , 0xffff } }, |
285 | { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } }, | 285 | { 0x7d, { Qt::Key_yen, 0x00a5 , '|' , 0xffff } }, |
286 | { 0x00, { 0, 0xffff , 0xffff , 0xffff } } | 286 | { 0x00, { 0, 0xffff , 0xffff , 0xffff } } |
287 | }; | 287 | }; |
288 | 288 | ||
289 | bool Server::setKeyboardLayout( const QString &kb ) | 289 | bool Server::setKeyboardLayout( const QString &kb ) |
290 | { | 290 | { |
291 | //quick demo version that can be extended | 291 | //quick demo version that can be extended |
292 | 292 | ||
293 | QIntDict<QWSServer::KeyMap> *om = 0; | 293 | QIntDict<QWSServer::KeyMap> *om = 0; |
294 | if ( kb == "us101" ) { // No tr | 294 | if ( kb == "us101" ) { // No tr |
295 | om = 0; | 295 | om = 0; |
296 | } else if ( kb == "jp109" ) { | 296 | } else if ( kb == "jp109" ) { |
297 | om = new QIntDict<QWSServer::KeyMap>(37); | 297 | om = new QIntDict<QWSServer::KeyMap>(37); |
298 | const KeyOverride *k = jp109keys; | 298 | const KeyOverride *k = jp109keys; |
299 | while ( k->scan_code ) { | 299 | while ( k->scan_code ) { |
300 | om->insert( k->scan_code, &k->map ); | 300 | om->insert( k->scan_code, &k->map ); |
301 | k++; | 301 | k++; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | QWSServer::setOverrideKeys( om ); | 304 | QWSServer::setOverrideKeys( om ); |
305 | 305 | ||
306 | return TRUE; | 306 | return TRUE; |
307 | } | 307 | } |
308 | 308 | ||
309 | #endif | 309 | #endif |
310 | 310 | ||
311 | void Server::systemMsg(const QCString &msg, const QByteArray &data) | 311 | void Server::systemMsg(const QCString &msg, const QByteArray &data) |
312 | { | 312 | { |
313 | QDataStream stream( data, IO_ReadOnly ); | 313 | QDataStream stream( data, IO_ReadOnly ); |
314 | 314 | ||
315 | if ( msg == "securityChanged()" ) { | 315 | if ( msg == "securityChanged()" ) { |
316 | if ( transferServer ) | 316 | if ( transferServer ) |
317 | transferServer->authorizeConnections(); | 317 | transferServer->authorizeConnections(); |
318 | if ( qcopBridge ) | 318 | if ( qcopBridge ) |
319 | qcopBridge->authorizeConnections(); | 319 | qcopBridge->authorizeConnections(); |
320 | } | 320 | } |
321 | /* ### FIXME support TempScreenSaverMode */ | 321 | /* ### FIXME support TempScreenSaverMode */ |
322 | #if 0 | 322 | #if 0 |
323 | else if ( msg == "setTempScreenSaverMode(int,int)" ) { | 323 | else if ( msg == "setTempScreenSaverMode(int,int)" ) { |
324 | int mode, pid; | 324 | int mode, pid; |
325 | stream >> mode >> pid; | 325 | stream >> mode >> pid; |
326 | tsmMonitor->setTempMode(mode, pid); | 326 | tsmMonitor->setTempMode(mode, pid); |
327 | } | 327 | } |
328 | #endif | 328 | #endif |
329 | else if ( msg == "linkChanged(QString)" ) { | 329 | else if ( msg == "linkChanged(QString)" ) { |
330 | QString link; | 330 | QString link; |
331 | stream >> link; | 331 | stream >> link; |
332 | qDebug( "desktop.cpp systemMsg -> linkchanged( %s )", link.latin1() ); | 332 | odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; |
333 | docList->linkChanged(link); | 333 | docList->linkChanged(link); |
334 | } else if ( msg == "serviceChanged(QString)" ) { | 334 | } else if ( msg == "serviceChanged(QString)" ) { |
335 | MimeType::updateApplications(); | 335 | MimeType::updateApplications(); |
336 | } else if ( msg == "mkdir(QString)" ) { | 336 | } else if ( msg == "mkdir(QString)" ) { |
337 | QString dir; | 337 | QString dir; |
338 | stream >> dir; | 338 | stream >> dir; |
339 | if ( !dir.isEmpty() ) | 339 | if ( !dir.isEmpty() ) |
340 | mkdir( dir ); | 340 | mkdir( dir ); |
341 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { | 341 | } else if ( msg == "rdiffGenSig(QString,QString)" ) { |
342 | QString baseFile, sigFile; | 342 | QString baseFile, sigFile; |
343 | stream >> baseFile >> sigFile; | 343 | stream >> baseFile >> sigFile; |
344 | QRsync::generateSignature( baseFile, sigFile ); | 344 | QRsync::generateSignature( baseFile, sigFile ); |
345 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { | 345 | } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { |
346 | QString baseFile, sigFile, deltaFile; | 346 | QString baseFile, sigFile, deltaFile; |
347 | stream >> baseFile >> sigFile >> deltaFile; | 347 | stream >> baseFile >> sigFile >> deltaFile; |
348 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); | 348 | QRsync::generateDiff( baseFile, sigFile, deltaFile ); |
349 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { | 349 | } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { |
350 | QString baseFile, deltaFile; | 350 | QString baseFile, deltaFile; |
351 | stream >> baseFile >> deltaFile; | 351 | stream >> baseFile >> deltaFile; |
352 | if ( !QFile::exists( baseFile ) ) { | 352 | if ( !QFile::exists( baseFile ) ) { |
353 | QFile f( baseFile ); | 353 | QFile f( baseFile ); |
354 | f.open( IO_WriteOnly ); | 354 | f.open( IO_WriteOnly ); |
355 | f.close(); | 355 | f.close(); |
356 | } | 356 | } |
357 | QRsync::applyDiff( baseFile, deltaFile ); | 357 | QRsync::applyDiff( baseFile, deltaFile ); |
358 | #ifndef QT_NO_COP | 358 | #ifndef QT_NO_COP |
359 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); | 359 | QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); |
360 | e << baseFile; | 360 | e << baseFile; |
361 | #endif | 361 | #endif |
362 | } else if ( msg == "rdiffCleanup()" ) { | 362 | } else if ( msg == "rdiffCleanup()" ) { |
363 | mkdir( "/tmp/rdiff" ); | 363 | mkdir( "/tmp/rdiff" ); |
364 | QDir dir; | 364 | QDir dir; |
365 | dir.setPath( "/tmp/rdiff" ); | 365 | dir.setPath( "/tmp/rdiff" ); |
366 | QStringList entries = dir.entryList(); | 366 | QStringList entries = dir.entryList(); |
367 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) | 367 | for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) |
368 | dir.remove( *it ); | 368 | dir.remove( *it ); |
369 | } else if ( msg == "sendHandshakeInfo()" ) { | 369 | } else if ( msg == "sendHandshakeInfo()" ) { |
370 | QString home = getenv( "HOME" ); | 370 | QString home = getenv( "HOME" ); |
371 | #ifndef QT_NO_COP | 371 | #ifndef QT_NO_COP |
372 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); | 372 | QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); |
373 | e << home; | 373 | e << home; |
374 | int locked = (int) ServerApplication::screenLocked(); | 374 | int locked = (int) ServerApplication::screenLocked(); |
375 | e << locked; | 375 | e << locked; |
376 | #endif | 376 | #endif |
377 | 377 | ||
378 | } | 378 | } |
379 | /* | 379 | /* |
380 | * QtopiaDesktop relies on the major number | 380 | * QtopiaDesktop relies on the major number |
381 | * to start with 1. We're at 0.9 | 381 | * to start with 1. We're at 0.9 |
382 | * so wee need to fake at least 1.4 to be able | 382 | * so wee need to fake at least 1.4 to be able |
383 | * to sync with QtopiaDesktop1.6 | 383 | * to sync with QtopiaDesktop1.6 |
384 | */ | 384 | */ |
385 | else if ( msg == "sendVersionInfo()" ) { | 385 | else if ( msg == "sendVersionInfo()" ) { |
386 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); | 386 | QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); |
387 | /* ### FIXME Architecture ### */ | 387 | /* ### FIXME Architecture ### */ |
388 | e << QString::fromLatin1("1.7") << "Uncustomized Device"; | 388 | e << QString::fromLatin1("1.7") << "Uncustomized Device"; |
389 | } else if ( msg == "sendCardInfo()" ) { | 389 | } else if ( msg == "sendCardInfo()" ) { |
390 | #ifndef QT_NO_COP | 390 | #ifndef QT_NO_COP |
391 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); | 391 | QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); |
392 | #endif | 392 | #endif |
393 | storage->update(); | 393 | storage->update(); |
394 | const QList<FileSystem> &fs = storage->fileSystems(); | 394 | const QList<FileSystem> &fs = storage->fileSystems(); |
395 | QListIterator<FileSystem> it ( fs ); | 395 | QListIterator<FileSystem> it ( fs ); |
396 | QString s; | 396 | QString s; |
397 | QString homeDir = getenv("HOME"); | 397 | QString homeDir = getenv("HOME"); |
398 | QString homeFs, homeFsPath; | 398 | QString homeFs, homeFsPath; |
399 | for ( ; it.current(); ++it ) { | 399 | for ( ; it.current(); ++it ) { |
400 | int k4 = (*it)->blockSize()/256; | 400 | int k4 = (*it)->blockSize()/256; |
401 | if ( (*it)->isRemovable() ) { | 401 | if ( (*it)->isRemovable() ) { |
402 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr | 402 | s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr |
403 | + QString::number( (*it)->availBlocks() * k4/4 ) | 403 | + QString::number( (*it)->availBlocks() * k4/4 ) |
404 | + "K " + (*it)->options() + ";"; | 404 | + "K " + (*it)->options() + ";"; |
405 | } else if ( homeDir.contains( (*it)->path() ) && | 405 | } else if ( homeDir.contains( (*it)->path() ) && |
406 | (*it)->path().length() > homeFsPath.length() ) { | 406 | (*it)->path().length() > homeFsPath.length() ) { |
407 | homeFsPath = (*it)->path(); | 407 | homeFsPath = (*it)->path(); |
408 | homeFs = | 408 | homeFs = |
409 | (*it)->name() + "=" + homeDir + "/Documents " // No tr | 409 | (*it)->name() + "=" + homeDir + "/Documents " // No tr |
410 | + QString::number( (*it)->availBlocks() * k4/4 ) | 410 | + QString::number( (*it)->availBlocks() * k4/4 ) |
411 | + "K " + (*it)->options() + ";"; | 411 | + "K " + (*it)->options() + ";"; |
412 | } | 412 | } |
413 | } | 413 | } |
414 | if ( !homeFs.isEmpty() ) | 414 | if ( !homeFs.isEmpty() ) |
415 | s += homeFs; | 415 | s += homeFs; |
416 | 416 | ||
417 | #ifndef QT_NO_COP | 417 | #ifndef QT_NO_COP |
418 | e << s; | 418 | e << s; |
419 | #endif | 419 | #endif |
420 | } else if ( msg == "sendSyncDate(QString)" ) { | 420 | } else if ( msg == "sendSyncDate(QString)" ) { |
421 | QString app; | 421 | QString app; |
422 | stream >> app; | 422 | stream >> app; |
423 | Config cfg( "qpe" ); | 423 | Config cfg( "qpe" ); |
424 | cfg.setGroup("SyncDate"); | 424 | cfg.setGroup("SyncDate"); |
425 | #ifndef QT_NO_COP | 425 | #ifndef QT_NO_COP |
426 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); | 426 | QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); |
427 | e << app << cfg.readEntry( app ); | 427 | e << app << cfg.readEntry( app ); |
428 | #endif | 428 | #endif |
429 | //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), | 429 | //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), |
430 | //cfg.readEntry( app ).latin1() ); | 430 | //cfg.readEntry( app ).latin1() ); |
431 | } else if ( msg == "setSyncDate(QString,QString)" ) { | 431 | } else if ( msg == "setSyncDate(QString,QString)" ) { |
432 | QString app, date; | 432 | QString app, date; |
433 | stream >> app >> date; | 433 | stream >> app >> date; |
434 | Config cfg( "qpe" ); | 434 | Config cfg( "qpe" ); |
435 | cfg.setGroup("SyncDate"); | 435 | cfg.setGroup("SyncDate"); |
436 | cfg.writeEntry( app, date ); | 436 | cfg.writeEntry( app, date ); |
437 | //qDebug("setSyncDate(QString,QString) %s %s", app.latin1(), date.latin1()); | 437 | //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; |
438 | } else if ( msg == "startSync(QString)" ) { | 438 | } else if ( msg == "startSync(QString)" ) { |
439 | QString what; | 439 | QString what; |
440 | stream >> what; | 440 | stream >> what; |
441 | delete syncDialog; | 441 | delete syncDialog; |
442 | syncDialog = new SyncDialog( this, what ); | 442 | syncDialog = new SyncDialog( this, what ); |
443 | syncDialog->show(); | 443 | syncDialog->show(); |
444 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); | 444 | connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); |
445 | } else if ( msg == "stopSync()") { | 445 | } else if ( msg == "stopSync()") { |
446 | delete syncDialog; | 446 | delete syncDialog; |
447 | syncDialog = 0; | 447 | syncDialog = 0; |
448 | } else if (msg == "restoreDone(QString)") { | 448 | } else if (msg == "restoreDone(QString)") { |
449 | docList->restoreDone(); | 449 | docList->restoreDone(); |
450 | } else if ( msg == "getAllDocLinks()" ) { | 450 | } else if ( msg == "getAllDocLinks()" ) { |
451 | docList->sendAllDocLinks(); | 451 | docList->sendAllDocLinks(); |
452 | } | 452 | } |
453 | #ifdef Q_WS_QWS | 453 | #ifdef Q_WS_QWS |
454 | else if ( msg == "setMouseProto(QString)" ) { | 454 | else if ( msg == "setMouseProto(QString)" ) { |
455 | QString mice; | 455 | QString mice; |
456 | stream >> mice; | 456 | stream >> mice; |
457 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); | 457 | setenv("QWS_MOUSE_PROTO",mice.latin1(),1); |
458 | qwsServer->openMouse(); | 458 | qwsServer->openMouse(); |
459 | } else if ( msg == "setKeyboard(QString)" ) { | 459 | } else if ( msg == "setKeyboard(QString)" ) { |
460 | QString kb; | 460 | QString kb; |
461 | stream >> kb; | 461 | stream >> kb; |
462 | setenv("QWS_KEYBOARD",kb.latin1(),1); | 462 | setenv("QWS_KEYBOARD",kb.latin1(),1); |
463 | qwsServer->openKeyboard(); | 463 | qwsServer->openKeyboard(); |
464 | 464 | ||
465 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { | 465 | } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { |
466 | int delay, period; | 466 | int delay, period; |
467 | stream >> delay >> period; | 467 | stream >> delay >> period; |
468 | qwsSetKeyboardAutoRepeat( delay, period ); | 468 | qwsSetKeyboardAutoRepeat( delay, period ); |
469 | Config cfg( "qpe" ); | 469 | Config cfg( "qpe" ); |
470 | cfg.setGroup("Keyboard"); | 470 | cfg.setGroup("Keyboard"); |
471 | cfg.writeEntry( "RepeatDelay", delay ); | 471 | cfg.writeEntry( "RepeatDelay", delay ); |
472 | cfg.writeEntry( "RepeatPeriod", period ); | 472 | cfg.writeEntry( "RepeatPeriod", period ); |
473 | } else if ( msg == "setKeyboardLayout(QString)" ) { | 473 | } else if ( msg == "setKeyboardLayout(QString)" ) { |
474 | QString kb; | 474 | QString kb; |
475 | stream >> kb; | 475 | stream >> kb; |
476 | setKeyboardLayout( kb ); | 476 | setKeyboardLayout( kb ); |
477 | Config cfg( "qpe" ); | 477 | Config cfg( "qpe" ); |
478 | cfg.setGroup("Keyboard"); | 478 | cfg.setGroup("Keyboard"); |
479 | cfg.writeEntry( "Layout", kb ); | 479 | cfg.writeEntry( "Layout", kb ); |
480 | } else if ( msg == "autoStart(QString)" ) { | 480 | } else if ( msg == "autoStart(QString)" ) { |
481 | QString appName; | 481 | QString appName; |
482 | stream >> appName; | 482 | stream >> appName; |
483 | Config cfg( "autostart" ); | 483 | Config cfg( "autostart" ); |
484 | cfg.setGroup( "AutoStart" ); | 484 | cfg.setGroup( "AutoStart" ); |
485 | if ( appName.compare("clear") == 0){ | 485 | if ( appName.compare("clear") == 0){ |
486 | cfg.writeEntry("Apps", ""); | 486 | cfg.writeEntry("Apps", ""); |
487 | } | 487 | } |
488 | } else if ( msg == "autoStart(QString,QString)" ) { | 488 | } else if ( msg == "autoStart(QString,QString)" ) { |
489 | QString modifier, appName; | 489 | QString modifier, appName; |
490 | stream >> modifier >> appName; | 490 | stream >> modifier >> appName; |
491 | Config cfg( "autostart" ); | 491 | Config cfg( "autostart" ); |
492 | cfg.setGroup( "AutoStart" ); | 492 | cfg.setGroup( "AutoStart" ); |
493 | if ( modifier.compare("add") == 0 ){ | 493 | if ( modifier.compare("add") == 0 ){ |
494 | // only add if appname is entered | 494 | // only add if appname is entered |
495 | if (!appName.isEmpty()) { | 495 | if (!appName.isEmpty()) { |
496 | cfg.writeEntry("Apps", appName); | 496 | cfg.writeEntry("Apps", appName); |
497 | } | 497 | } |
498 | } else if (modifier.compare("remove") == 0 ) { | 498 | } else if (modifier.compare("remove") == 0 ) { |
499 | // need to change for multiple entries | 499 | // need to change for multiple entries |
500 | // actually remove is right now simular to clear, but in future there | 500 | // actually remove is right now simular to clear, but in future there |
501 | // should be multiple apps in autostart possible. | 501 | // should be multiple apps in autostart possible. |
502 | QString checkName; | 502 | QString checkName; |
503 | checkName = cfg.readEntry("Apps", ""); | 503 | checkName = cfg.readEntry("Apps", ""); |
504 | if (checkName == appName) { | 504 | if (checkName == appName) { |
505 | cfg.writeEntry("Apps", ""); | 505 | cfg.writeEntry("Apps", ""); |
506 | } | 506 | } |
507 | } | 507 | } |
508 | // case the autostart feature should be delayed | 508 | // case the autostart feature should be delayed |
509 | } else if ( msg == "autoStart(QString,QString,QString)") { | 509 | } else if ( msg == "autoStart(QString,QString,QString)") { |
510 | QString modifier, appName, delay; | 510 | QString modifier, appName, delay; |
511 | stream >> modifier >> appName >> delay; | 511 | stream >> modifier >> appName >> delay; |
512 | Config cfg( "autostart" ); | 512 | Config cfg( "autostart" ); |
513 | 513 | ||
514 | cfg.setGroup( "AutoStart" ); | 514 | cfg.setGroup( "AutoStart" ); |
515 | if ( modifier.compare("add") == 0 ){ | 515 | if ( modifier.compare("add") == 0 ){ |
516 | // only add it appname is entered | 516 | // only add it appname is entered |
517 | if (!appName.isEmpty()) { | 517 | if (!appName.isEmpty()) { |
518 | cfg.writeEntry("Apps", appName); | 518 | cfg.writeEntry("Apps", appName); |
519 | cfg.writeEntry("Delay", delay); | 519 | cfg.writeEntry("Delay", delay); |
520 | } | 520 | } |
521 | } else { | 521 | } else { |
522 | } | 522 | } |
523 | } | 523 | } |
524 | #endif | 524 | #endif |
525 | } | 525 | } |
526 | 526 | ||
527 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) | 527 | void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) |
528 | { | 528 | { |
529 | QDataStream stream( data, IO_ReadOnly ); | 529 | QDataStream stream( data, IO_ReadOnly ); |
530 | 530 | ||
531 | if ( msg == "reloadApps()" ) { | 531 | if ( msg == "reloadApps()" ) { |
532 | docList->reloadAppLnks(); | 532 | docList->reloadAppLnks(); |
533 | } else if ( msg == "soundAlarm()" ) { | 533 | } else if ( msg == "soundAlarm()" ) { |
534 | ServerApplication::soundAlarm(); | 534 | ServerApplication::soundAlarm(); |
535 | } | 535 | } |
536 | else if ( msg == "setLed(int,bool)" ) { | 536 | else if ( msg == "setLed(int,bool)" ) { |
537 | int led, status; | 537 | int led, status; |
538 | stream >> led >> status; | 538 | stream >> led >> status; |
539 | 539 | ||
540 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); | 540 | QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); |
541 | if ( ll. count ( )){ | 541 | if ( ll. count ( )){ |
542 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; | 542 | OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; |
543 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); | 543 | bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); |
544 | 544 | ||
545 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); | 545 | ODevice::inst ( )-> setLedState ( l, status ? ( canblink ? Led_BlinkSlow : Led_On ) : Led_Off ); |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | void Server::cancelSync() | 550 | void Server::cancelSync() |
551 | { | 551 | { |
552 | #ifndef QT_NO_COP | 552 | #ifndef QT_NO_COP |
553 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); | 553 | QCopEnvelope e( "QPE/Desktop", "cancelSync()" ); |
554 | #endif | 554 | #endif |
555 | delete syncDialog; | 555 | delete syncDialog; |
556 | syncDialog = 0; | 556 | syncDialog = 0; |
557 | } | 557 | } |
558 | 558 | ||
559 | bool Server::mkdir(const QString &localPath) | 559 | bool Server::mkdir(const QString &localPath) |
560 | { | 560 | { |
561 | QDir fullDir(localPath); | 561 | QDir fullDir(localPath); |
562 | if (fullDir.exists()) | 562 | if (fullDir.exists()) |
563 | return true; | 563 | return true; |
564 | 564 | ||
565 | // at this point the directory doesn't exist | 565 | // at this point the directory doesn't exist |
566 | // go through the directory tree and start creating the direcotories | 566 | // go through the directory tree and start creating the direcotories |
567 | // that don't exist; if we can't create the directories, return false | 567 | // that don't exist; if we can't create the directories, return false |
568 | 568 | ||
569 | QString dirSeps = "/"; | 569 | QString dirSeps = "/"; |
570 | int dirIndex = localPath.find(dirSeps); | 570 | int dirIndex = localPath.find(dirSeps); |
571 | QString checkedPath; | 571 | QString checkedPath; |
572 | 572 | ||
573 | // didn't find any seps; weird, use the cur dir instead | 573 | // didn't find any seps; weird, use the cur dir instead |
574 | if (dirIndex == -1) { | 574 | if (dirIndex == -1) { |
575 | //qDebug("No seperators found in path %s", localPath.latin1()); | 575 | //odebug << "No seperators found in path " << localPath << "" << oendl; |
576 | checkedPath = QDir::currentDirPath(); | 576 | checkedPath = QDir::currentDirPath(); |
577 | } | 577 | } |
578 | 578 | ||
579 | while (checkedPath != localPath) { | 579 | while (checkedPath != localPath) { |
580 | // no more seperators found, use the local path | 580 | // no more seperators found, use the local path |
581 | if (dirIndex == -1) | 581 | if (dirIndex == -1) |
582 | checkedPath = localPath; | 582 | checkedPath = localPath; |
583 | else { | 583 | else { |
584 | // the next directory to check | 584 | // the next directory to check |
585 | checkedPath = localPath.left(dirIndex) + "/"; | 585 | checkedPath = localPath.left(dirIndex) + "/"; |
586 | // advance the iterator; the next dir seperator | 586 | // advance the iterator; the next dir seperator |
587 | dirIndex = localPath.find(dirSeps, dirIndex+1); | 587 | dirIndex = localPath.find(dirSeps, dirIndex+1); |
588 | } | 588 | } |
589 | 589 | ||
590 | QDir checkDir(checkedPath); | 590 | QDir checkDir(checkedPath); |
591 | if (!checkDir.exists()) { | 591 | if (!checkDir.exists()) { |
592 | //qDebug("mkdir making dir %s", checkedPath.latin1()); | 592 | //odebug << "mkdir making dir " << checkedPath << "" << oendl; |
593 | 593 | ||
594 | if (!checkDir.mkdir(checkedPath)) { | 594 | if (!checkDir.mkdir(checkedPath)) { |
595 | qDebug("Unable to make directory %s", checkedPath.latin1()); | 595 | odebug << "Unable to make directory " << checkedPath << "" << oendl; |
596 | return FALSE; | 596 | return FALSE; |
597 | } | 597 | } |
598 | } | 598 | } |
599 | 599 | ||
600 | } | 600 | } |
601 | return TRUE; | 601 | return TRUE; |
602 | } | 602 | } |
603 | 603 | ||
604 | void Server::styleChange( QStyle &s ) | 604 | void Server::styleChange( QStyle &s ) |
605 | { | 605 | { |
606 | QWidget::styleChange( s ); | 606 | QWidget::styleChange( s ); |
607 | } | 607 | } |
608 | 608 | ||
609 | void Server::startTransferServer() | 609 | void Server::startTransferServer() |
610 | { | 610 | { |
611 | if ( !qcopBridge ) { | 611 | if ( !qcopBridge ) { |
612 | // start qcop bridge server | 612 | // start qcop bridge server |
613 | qcopBridge = new QCopBridge( 4243 ); | 613 | qcopBridge = new QCopBridge( 4243 ); |
614 | if ( qcopBridge->ok() ) { | 614 | if ( qcopBridge->ok() ) { |
615 | // ... OK | 615 | // ... OK |
616 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), | 616 | connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), |
617 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); | 617 | this, SLOT(syncConnectionClosed(const QHostAddress&)) ); |
618 | } else { | 618 | } else { |
619 | delete qcopBridge; | 619 | delete qcopBridge; |
620 | qcopBridge = 0; | 620 | qcopBridge = 0; |
621 | } | 621 | } |
622 | } | 622 | } |
623 | if ( !transferServer ) { | 623 | if ( !transferServer ) { |
624 | // start transfer server | 624 | // start transfer server |
625 | transferServer = new TransferServer( 4242 ); | 625 | transferServer = new TransferServer( 4242 ); |
626 | if ( transferServer->ok() ) { | 626 | if ( transferServer->ok() ) { |
627 | // ... OK | 627 | // ... OK |
628 | } else { | 628 | } else { |
629 | delete transferServer; | 629 | delete transferServer; |
630 | transferServer = 0; | 630 | transferServer = 0; |
631 | } | 631 | } |
632 | } | 632 | } |
633 | if ( !transferServer || !qcopBridge ) | 633 | if ( !transferServer || !qcopBridge ) |
634 | tid_xfer = startTimer( 2000 ); | 634 | tid_xfer = startTimer( 2000 ); |
635 | } | 635 | } |
636 | 636 | ||
637 | void Server::timerEvent( QTimerEvent *e ) | 637 | void Server::timerEvent( QTimerEvent *e ) |
638 | { | 638 | { |
639 | if ( e->timerId() == tid_xfer ) { | 639 | if ( e->timerId() == tid_xfer ) { |
640 | killTimer( tid_xfer ); | 640 | killTimer( tid_xfer ); |
641 | tid_xfer = 0; | 641 | tid_xfer = 0; |
642 | startTransferServer(); | 642 | startTransferServer(); |
643 | } | 643 | } |
644 | /* ### FIXME today startin */ | 644 | /* ### FIXME today startin */ |
645 | #if 0 | 645 | #if 0 |
646 | else if ( e->timerId() == tid_today ) { | 646 | else if ( e->timerId() == tid_today ) { |
647 | QDate today = QDate::currentDate(); | 647 | QDate today = QDate::currentDate(); |
648 | if ( today != last_today_show ) { | 648 | if ( today != last_today_show ) { |
649 | last_today_show = today; | 649 | last_today_show = today; |
650 | Config cfg("today"); | 650 | Config cfg("today"); |
651 | cfg.setGroup("Start"); | 651 | cfg.setGroup("Start"); |
652 | #ifndef QPE_DEFAULT_TODAY_MODE | 652 | #ifndef QPE_DEFAULT_TODAY_MODE |
653 | #define QPE_DEFAULT_TODAY_MODE "Never" | 653 | #define QPE_DEFAULT_TODAY_MODE "Never" |
654 | #endif | 654 | #endif |
655 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { | 655 | if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { |
656 | QCopEnvelope env(Service::channel("today"),"raise()"); | 656 | QCopEnvelope env(Service::channel("today"),"raise()"); |
657 | } | 657 | } |
658 | } | 658 | } |
659 | } | 659 | } |
660 | #endif | 660 | #endif |
661 | } | 661 | } |
662 | 662 | ||
663 | void Server::terminateServers() | 663 | void Server::terminateServers() |
664 | { | 664 | { |
665 | delete transferServer; | 665 | delete transferServer; |
666 | delete qcopBridge; | 666 | delete qcopBridge; |
667 | transferServer = 0; | 667 | transferServer = 0; |
668 | qcopBridge = 0; | 668 | qcopBridge = 0; |
669 | } | 669 | } |
670 | 670 | ||
671 | void Server::syncConnectionClosed( const QHostAddress & ) | 671 | void Server::syncConnectionClosed( const QHostAddress & ) |
672 | { | 672 | { |
673 | qDebug( "Lost sync connection" ); | 673 | odebug << "Lost sync connection" << oendl; |
674 | delete syncDialog; | 674 | delete syncDialog; |
675 | syncDialog = 0; | 675 | syncDialog = 0; |
676 | } | 676 | } |
677 | 677 | ||
678 | void Server::pokeTimeMonitors() | 678 | void Server::pokeTimeMonitors() |
679 | { | 679 | { |
680 | #if 0 | 680 | #if 0 |
681 | // inform all TimeMonitors | 681 | // inform all TimeMonitors |
682 | QStrList tms = Service::channels("TimeMonitor"); | 682 | QStrList tms = Service::channels("TimeMonitor"); |
683 | for (const char* ch = tms.first(); ch; ch=tms.next()) { | 683 | for (const char* ch = tms.first(); ch; ch=tms.next()) { |
684 | QString t = getenv("TZ"); | 684 | QString t = getenv("TZ"); |
685 | QCopEnvelope e(ch, "timeChange(QString)"); | 685 | QCopEnvelope e(ch, "timeChange(QString)"); |
686 | e << t; | 686 | e << t; |
687 | } | 687 | } |
688 | #endif | 688 | #endif |
689 | } | 689 | } |
690 | 690 | ||
691 | void Server::applicationLaunched(int, const QString &app) | 691 | void Server::applicationLaunched(int, const QString &app) |
692 | { | 692 | { |
693 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); | 693 | serverGui->applicationStateChanged( app, ServerInterface::Launching ); |
694 | } | 694 | } |
695 | 695 | ||
696 | void Server::applicationTerminated(int pid, const QString &app) | 696 | void Server::applicationTerminated(int pid, const QString &app) |
697 | { | 697 | { |
698 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); | 698 | serverGui->applicationStateChanged( app, ServerInterface::Terminated ); |
699 | #if 0 | 699 | #if 0 |
700 | tsmMonitor->applicationTerminated( pid ); | 700 | tsmMonitor->applicationTerminated( pid ); |
701 | #endif | 701 | #endif |
702 | } | 702 | } |
703 | 703 | ||
704 | void Server::applicationConnected(const QString &app) | 704 | void Server::applicationConnected(const QString &app) |
705 | { | 705 | { |
706 | serverGui->applicationStateChanged( app, ServerInterface::Running ); | 706 | serverGui->applicationStateChanged( app, ServerInterface::Running ); |
707 | } | 707 | } |
708 | 708 | ||
709 | void Server::storageChanged() | 709 | void Server::storageChanged() |
710 | { | 710 | { |
711 | system( "opie-update-symlinks" ); | 711 | system( "opie-update-symlinks" ); |
712 | serverGui->storageChanged( storage->fileSystems() ); | 712 | serverGui->storageChanged( storage->fileSystems() ); |
713 | docList->storageChanged(); | 713 | docList->storageChanged(); |
714 | } | 714 | } |
715 | 715 | ||
716 | 716 | ||
717 | 717 | ||
718 | void Server::preloadApps() | 718 | void Server::preloadApps() |
719 | { | 719 | { |
720 | Config cfg("Launcher"); | 720 | Config cfg("Launcher"); |
721 | cfg.setGroup("Preload"); | 721 | cfg.setGroup("Preload"); |
722 | QStringList apps = cfg.readListEntry("Apps",','); | 722 | QStringList apps = cfg.readListEntry("Apps",','); |
723 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { | 723 | for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { |
724 | #ifndef QT_NO_COP | 724 | #ifndef QT_NO_COP |
725 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); | 725 | QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); |
726 | #endif | 726 | #endif |
727 | } | 727 | } |
728 | } | 728 | } |
729 | 729 | ||
diff --git a/core/launcher/serverapp.cpp b/core/launcher/serverapp.cpp index e4e16f2..cf543ce 100644 --- a/core/launcher/serverapp.cpp +++ b/core/launcher/serverapp.cpp | |||
@@ -1,863 +1,863 @@ | |||
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 "serverapp.h" | 21 | #include "serverapp.h" |
22 | #include "screensaver.h" | ||
22 | 23 | ||
24 | /* OPIE */ | ||
25 | #include <opie2/odebug.h> | ||
23 | #include <opie2/odevice.h> | 26 | #include <opie2/odevice.h> |
24 | |||
25 | #include <qtopia/password.h> | 27 | #include <qtopia/password.h> |
26 | #include <qtopia/config.h> | 28 | #include <qtopia/config.h> |
27 | #include <qtopia/power.h> | 29 | #include <qtopia/power.h> |
28 | 30 | ||
29 | #ifdef Q_WS_QWS | 31 | #ifdef Q_WS_QWS |
30 | #include <qtopia/qcopenvelope_qws.h> | 32 | #include <qtopia/qcopenvelope_qws.h> |
31 | #endif | 33 | #endif |
32 | #include <qtopia/global.h> | 34 | #include <qtopia/global.h> |
33 | //#include <qtopia/custom.h> | 35 | using namespace Opie::Core; |
34 | 36 | ||
37 | /* QT */ | ||
35 | #ifdef Q_WS_QWS | 38 | #ifdef Q_WS_QWS |
36 | #include <qgfx_qws.h> | 39 | #include <qgfx_qws.h> |
37 | #endif | 40 | #endif |
38 | #ifdef Q_OS_WIN32 | ||
39 | #include <io.h> | ||
40 | #include <process.h> | ||
41 | #else | ||
42 | #include <unistd.h> | ||
43 | #endif | ||
44 | #include <qmessagebox.h> | 41 | #include <qmessagebox.h> |
45 | #include <qtimer.h> | 42 | #include <qtimer.h> |
46 | #include <qpainter.h> | 43 | #include <qpainter.h> |
47 | #include <qfile.h> | 44 | #include <qfile.h> |
48 | #include <qpixmapcache.h> | 45 | #include <qpixmapcache.h> |
49 | 46 | ||
47 | /* STD */ | ||
48 | #ifdef Q_OS_WIN32 | ||
49 | #include <io.h> | ||
50 | #include <process.h> | ||
51 | #else | ||
52 | #include <unistd.h> | ||
53 | #endif | ||
50 | #include <stdlib.h> | 54 | #include <stdlib.h> |
51 | #include "screensaver.h" | ||
52 | 55 | ||
53 | static ServerApplication *serverApp = 0; | 56 | static ServerApplication *serverApp = 0; |
54 | static int loggedin=0; | 57 | static int loggedin=0; |
55 | 58 | ||
56 | using namespace Opie; | ||
57 | |||
58 | using namespace Opie::Core; | ||
59 | QCopKeyRegister::QCopKeyRegister() | 59 | QCopKeyRegister::QCopKeyRegister() |
60 | : m_keyCode( 0 ) { | 60 | : m_keyCode( 0 ) { |
61 | } | 61 | } |
62 | 62 | ||
63 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) | 63 | QCopKeyRegister::QCopKeyRegister( int k, const QCString& c, const QCString& m ) |
64 | :m_keyCode( k ), m_channel( c ), m_message( m ) { | 64 | :m_keyCode( k ), m_channel( c ), m_message( m ) { |
65 | } | 65 | } |
66 | 66 | ||
67 | int QCopKeyRegister::keyCode()const { | 67 | int QCopKeyRegister::keyCode()const { |
68 | return m_keyCode; | 68 | return m_keyCode; |
69 | } | 69 | } |
70 | 70 | ||
71 | QCString QCopKeyRegister::channel()const { | 71 | QCString QCopKeyRegister::channel()const { |
72 | return m_channel; | 72 | return m_channel; |
73 | } | 73 | } |
74 | 74 | ||
75 | QCString QCopKeyRegister::message()const { | 75 | QCString QCopKeyRegister::message()const { |
76 | return m_message; | 76 | return m_message; |
77 | } | 77 | } |
78 | 78 | ||
79 | bool QCopKeyRegister::send() { | 79 | bool QCopKeyRegister::send() { |
80 | if (m_channel.isNull() ) | 80 | if (m_channel.isNull() ) |
81 | return false; | 81 | return false; |
82 | 82 | ||
83 | QCopEnvelope( m_channel, m_message ); | 83 | QCopEnvelope( m_channel, m_message ); |
84 | 84 | ||
85 | return true; | 85 | return true; |
86 | } | 86 | } |
87 | 87 | ||
88 | //--------------------------------------------------------------------------- | 88 | //--------------------------------------------------------------------------- |
89 | 89 | ||
90 | /* | 90 | /* |
91 | Priority is number of alerts that are needed to pop up | 91 | Priority is number of alerts that are needed to pop up |
92 | alert. | 92 | alert. |
93 | */ | 93 | */ |
94 | class DesktopPowerAlerter : public QMessageBox | 94 | class DesktopPowerAlerter : public QMessageBox |
95 | { | 95 | { |
96 | Q_OBJECT | 96 | Q_OBJECT |
97 | public: | 97 | public: |
98 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) | 98 | DesktopPowerAlerter( QWidget *parent, const char *name = 0 ) |
99 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), | 99 | : QMessageBox( tr("Battery Status"), tr("Low Battery"), |
100 | QMessageBox::Critical, | 100 | QMessageBox::Critical, |
101 | QMessageBox::Ok | QMessageBox::Default, | 101 | QMessageBox::Ok | QMessageBox::Default, |
102 | QMessageBox::NoButton, QMessageBox::NoButton, | 102 | QMessageBox::NoButton, QMessageBox::NoButton, |
103 | parent, name, FALSE ) | 103 | parent, name, FALSE ) |
104 | { | 104 | { |
105 | currentPriority = INT_MAX; | 105 | currentPriority = INT_MAX; |
106 | alertCount = 0; | 106 | alertCount = 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | void alert( const QString &text, int priority ); | 109 | void alert( const QString &text, int priority ); |
110 | void hideEvent( QHideEvent * ); | 110 | void hideEvent( QHideEvent * ); |
111 | private: | 111 | private: |
112 | int currentPriority; | 112 | int currentPriority; |
113 | int alertCount; | 113 | int alertCount; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | void DesktopPowerAlerter::alert( const QString &text, int priority ) | 116 | void DesktopPowerAlerter::alert( const QString &text, int priority ) |
117 | { | 117 | { |
118 | alertCount++; | 118 | alertCount++; |
119 | if ( alertCount < priority ) | 119 | if ( alertCount < priority ) |
120 | return; | 120 | return; |
121 | if ( priority > currentPriority ) | 121 | if ( priority > currentPriority ) |
122 | return; | 122 | return; |
123 | currentPriority = priority; | 123 | currentPriority = priority; |
124 | setText( text ); | 124 | setText( text ); |
125 | show(); | 125 | show(); |
126 | } | 126 | } |
127 | 127 | ||
128 | 128 | ||
129 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) | 129 | void DesktopPowerAlerter::hideEvent( QHideEvent *e ) |
130 | { | 130 | { |
131 | QMessageBox::hideEvent( e ); | 131 | QMessageBox::hideEvent( e ); |
132 | alertCount = 0; | 132 | alertCount = 0; |
133 | currentPriority = INT_MAX; | 133 | currentPriority = INT_MAX; |
134 | } | 134 | } |
135 | 135 | ||
136 | //--------------------------------------------------------------------------- | 136 | //--------------------------------------------------------------------------- |
137 | 137 | ||
138 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0) | 138 | KeyFilter::KeyFilter(QObject* parent) : QObject(parent), held_tid(0), heldButton(0) |
139 | { | 139 | { |
140 | /* We don't do this cause it would interfere with ODevice */ | 140 | /* We don't do this cause it would interfere with ODevice */ |
141 | #if 0 | 141 | #if 0 |
142 | qwsServer->setKeyboardFilter(this); | 142 | qwsServer->setKeyboardFilter(this); |
143 | #endif | 143 | #endif |
144 | } | 144 | } |
145 | 145 | ||
146 | void KeyFilter::timerEvent(QTimerEvent* e) | 146 | void KeyFilter::timerEvent(QTimerEvent* e) |
147 | { | 147 | { |
148 | if ( e->timerId() == held_tid ) { | 148 | if ( e->timerId() == held_tid ) { |
149 | killTimer(held_tid); | 149 | killTimer(held_tid); |
150 | // button held | 150 | // button held |
151 | if ( heldButton ) { | 151 | if ( heldButton ) { |
152 | emit activate(heldButton, TRUE); | 152 | emit activate(heldButton, TRUE); |
153 | heldButton = 0; | 153 | heldButton = 0; |
154 | } | 154 | } |
155 | held_tid = 0; | 155 | held_tid = 0; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | 158 | ||
159 | void KeyFilter::registerKey( const QCopKeyRegister& key ) { | 159 | void KeyFilter::registerKey( const QCopKeyRegister& key ) { |
160 | m_keys.insert( key.keyCode(), key ); | 160 | m_keys.insert( key.keyCode(), key ); |
161 | } | 161 | } |
162 | 162 | ||
163 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) { | 163 | void KeyFilter::unregisterKey( const QCopKeyRegister& key ) { |
164 | m_keys.remove( key.keyCode() ); | 164 | m_keys.remove( key.keyCode() ); |
165 | } | 165 | } |
166 | 166 | ||
167 | bool KeyFilter::keyRegistered( int key ) { | 167 | bool KeyFilter::keyRegistered( int key ) { |
168 | /* | 168 | /* |
169 | * Check if we've a key registered | 169 | * Check if we've a key registered |
170 | */ | 170 | */ |
171 | if ( !m_keys[key].send()) | 171 | if ( !m_keys[key].send()) |
172 | return false; | 172 | return false; |
173 | else | 173 | else |
174 | return true; | 174 | return true; |
175 | 175 | ||
176 | } | 176 | } |
177 | 177 | ||
178 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) | 178 | bool KeyFilter::checkButtonAction(bool db, int keycode, int press, int autoRepeat) |
179 | { | 179 | { |
180 | if ( !loggedin | 180 | if ( !loggedin |
181 | // Permitted keys | 181 | // Permitted keys |
182 | && keycode != Key_F34 // power | 182 | && keycode != Key_F34 // power |
183 | && keycode != Key_F30 // select | 183 | && keycode != Key_F30 // select |
184 | && keycode != Key_Enter | 184 | && keycode != Key_Enter |
185 | && keycode != Key_Return | 185 | && keycode != Key_Return |
186 | && keycode != Key_Space | 186 | && keycode != Key_Space |
187 | && keycode != Key_Left | 187 | && keycode != Key_Left |
188 | && keycode != Key_Right | 188 | && keycode != Key_Right |
189 | && keycode != Key_Up | 189 | && keycode != Key_Up |
190 | && keycode != Key_Down ) | 190 | && keycode != Key_Down ) |
191 | return TRUE; | 191 | return TRUE; |
192 | 192 | ||
193 | /* check if it was registered */ | 193 | /* check if it was registered */ |
194 | if (!db ) { | 194 | if (!db ) { |
195 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) | 195 | if (keycode != 0 &&press && !autoRepeat && keyRegistered(keycode) ) |
196 | return true; | 196 | return true; |
197 | }else { | 197 | }else { |
198 | 198 | ||
199 | 199 | ||
200 | // First check to see if DeviceButtonManager knows something about this button: | 200 | // First check to see if DeviceButtonManager knows something about this button: |
201 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); | 201 | const ODeviceButton* button = ODevice::inst()->buttonForKeycode(keycode); |
202 | if (button && !autoRepeat) { | 202 | if (button && !autoRepeat) { |
203 | if ( held_tid ) { | 203 | if ( held_tid ) { |
204 | killTimer(held_tid); | 204 | killTimer(held_tid); |
205 | held_tid = 0; | 205 | held_tid = 0; |
206 | } | 206 | } |
207 | if ( button->heldAction().isNull() ) { | 207 | if ( button->heldAction().isNull() ) { |
208 | if ( press ) | 208 | if ( press ) |
209 | emit activate(button, FALSE); | 209 | emit activate(button, FALSE); |
210 | } else if ( press ) { | 210 | } else if ( press ) { |
211 | heldButton = button; | 211 | heldButton = button; |
212 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); | 212 | held_tid = startTimer( ODevice::inst ()->buttonHoldTime () ); |
213 | } else if ( heldButton ) { | 213 | } else if ( heldButton ) { |
214 | heldButton = 0; | 214 | heldButton = 0; |
215 | emit activate(button, FALSE); | 215 | emit activate(button, FALSE); |
216 | } | 216 | } |
217 | QWSServer::screenSaverActivate(FALSE); | 217 | QWSServer::screenSaverActivate(FALSE); |
218 | return TRUE; | 218 | return TRUE; |
219 | } | 219 | } |
220 | return false; | 220 | return false; |
221 | } | 221 | } |
222 | if ( keycode == HardKey_Suspend ) { | 222 | if ( keycode == HardKey_Suspend ) { |
223 | if ( press ) emit power(); | 223 | if ( press ) emit power(); |
224 | return TRUE; | 224 | return TRUE; |
225 | } | 225 | } |
226 | if ( keycode == HardKey_Backlight ) { | 226 | if ( keycode == HardKey_Backlight ) { |
227 | if ( press ) emit backlight(); | 227 | if ( press ) emit backlight(); |
228 | return TRUE; | 228 | return TRUE; |
229 | } | 229 | } |
230 | if ( keycode == Key_F32 ) { | 230 | if ( keycode == Key_F32 ) { |
231 | #ifndef QT_NO_COP | 231 | #ifndef QT_NO_COP |
232 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); | 232 | if ( press ) QCopEnvelope e( "QPE/Desktop", "startSync()" ); |
233 | #endif | 233 | #endif |
234 | return TRUE; | 234 | return TRUE; |
235 | } | 235 | } |
236 | if ( keycode == Key_F31 ) { | 236 | if ( keycode == Key_F31 ) { |
237 | if ( press ) emit symbol(); | 237 | if ( press ) emit symbol(); |
238 | QWSServer::screenSaverActivate(FALSE); | 238 | QWSServer::screenSaverActivate(FALSE); |
239 | return TRUE; | 239 | return TRUE; |
240 | } | 240 | } |
241 | 241 | ||
242 | if ( keycode == Key_NumLock ) | 242 | if ( keycode == Key_NumLock ) |
243 | if ( press ) emit numLockStateToggle(); | 243 | if ( press ) emit numLockStateToggle(); |
244 | 244 | ||
245 | if ( keycode == Key_CapsLock ) | 245 | if ( keycode == Key_CapsLock ) |
246 | if ( press ) emit capsLockStateToggle(); | 246 | if ( press ) emit capsLockStateToggle(); |
247 | 247 | ||
248 | if ( serverApp ) | 248 | if ( serverApp ) |
249 | serverApp->keyClick(keycode,press,autoRepeat); | 249 | serverApp->keyClick(keycode,press,autoRepeat); |
250 | 250 | ||
251 | return FALSE; | 251 | return FALSE; |
252 | } | 252 | } |
253 | 253 | ||
254 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; | 254 | enum MemState { MemUnknown, MemVeryLow, MemLow, MemNormal } memstate=MemUnknown; |
255 | 255 | ||
256 | #if defined(QPE_HAVE_MEMALERTER) | 256 | #if defined(QPE_HAVE_MEMALERTER) |
257 | QPE_MEMALERTER_IMPL | 257 | QPE_MEMALERTER_IMPL |
258 | #endif | 258 | #endif |
259 | 259 | ||
260 | 260 | ||
261 | 261 | ||
262 | //--------------------------------------------------------------------------- | 262 | //--------------------------------------------------------------------------- |
263 | 263 | ||
264 | bool ServerApplication::doRestart = FALSE; | 264 | bool ServerApplication::doRestart = FALSE; |
265 | bool ServerApplication::allowRestart = TRUE; | 265 | bool ServerApplication::allowRestart = TRUE; |
266 | bool ServerApplication::ms_is_starting = TRUE; | 266 | bool ServerApplication::ms_is_starting = TRUE; |
267 | 267 | ||
268 | void ServerApplication::switchLCD( bool on ) { | 268 | void ServerApplication::switchLCD( bool on ) { |
269 | if ( !qApp ) | 269 | if ( !qApp ) |
270 | return; | 270 | return; |
271 | 271 | ||
272 | ServerApplication *dapp = ServerApplication::me() ; | 272 | ServerApplication *dapp = ServerApplication::me() ; |
273 | 273 | ||
274 | if ( !dapp-> m_screensaver ) | 274 | if ( !dapp-> m_screensaver ) |
275 | return; | 275 | return; |
276 | 276 | ||
277 | if ( on ) { | 277 | if ( on ) { |
278 | dapp-> m_screensaver-> setDisplayState ( true ); | 278 | dapp-> m_screensaver-> setDisplayState ( true ); |
279 | dapp-> m_screensaver-> setBacklight ( -3 ); | 279 | dapp-> m_screensaver-> setBacklight ( -3 ); |
280 | }else | 280 | }else |
281 | dapp-> m_screensaver-> setDisplayState ( false ); | 281 | dapp-> m_screensaver-> setDisplayState ( false ); |
282 | 282 | ||
283 | 283 | ||
284 | } | 284 | } |
285 | 285 | ||
286 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) | 286 | ServerApplication::ServerApplication( int& argc, char **argv, Type t ) |
287 | : QPEApplication( argc, argv, t ) | 287 | : QPEApplication( argc, argv, t ) |
288 | { | 288 | { |
289 | ms_is_starting = true; | 289 | ms_is_starting = true; |
290 | 290 | ||
291 | // We know we'll have lots of cached pixmaps due to App/DocLnks | 291 | // We know we'll have lots of cached pixmaps due to App/DocLnks |
292 | QPixmapCache::setCacheLimit(512); | 292 | QPixmapCache::setCacheLimit(512); |
293 | 293 | ||
294 | m_ps = new PowerStatus; | 294 | m_ps = new PowerStatus; |
295 | m_ps_last = new PowerStatus; | 295 | m_ps_last = new PowerStatus; |
296 | pa = new DesktopPowerAlerter( 0 ); | 296 | pa = new DesktopPowerAlerter( 0 ); |
297 | 297 | ||
298 | m_apm_timer = new QTimer( this ); | 298 | m_apm_timer = new QTimer( this ); |
299 | connect(m_apm_timer, SIGNAL( timeout() ), | 299 | connect(m_apm_timer, SIGNAL( timeout() ), |
300 | this, SLOT( apmTimeout() ) ); | 300 | this, SLOT( apmTimeout() ) ); |
301 | 301 | ||
302 | reloadPowerWarnSettings(); | 302 | reloadPowerWarnSettings(); |
303 | 303 | ||
304 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 304 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
305 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 305 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
306 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); | 306 | this, SLOT(systemMessage(const QCString&,const QByteArray&) ) ); |
307 | 307 | ||
308 | channel = new QCopChannel("QPE/Launcher", this ); | 308 | channel = new QCopChannel("QPE/Launcher", this ); |
309 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), | 309 | connect(channel, SIGNAL(received(const QCString&,const QByteArray&) ), |
310 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); | 310 | this, SLOT(launcherMessage(const QCString&,const QByteArray&) ) ); |
311 | 311 | ||
312 | m_screensaver = new OpieScreenSaver(); | 312 | m_screensaver = new OpieScreenSaver(); |
313 | m_screensaver->setInterval( -1 ); | 313 | m_screensaver->setInterval( -1 ); |
314 | QWSServer::setScreenSaver( m_screensaver ); | 314 | QWSServer::setScreenSaver( m_screensaver ); |
315 | 315 | ||
316 | connect( qApp, SIGNAL( volumeChanged(bool) ), | 316 | connect( qApp, SIGNAL( volumeChanged(bool) ), |
317 | this, SLOT( rereadVolumes() ) ); | 317 | this, SLOT( rereadVolumes() ) ); |
318 | 318 | ||
319 | 319 | ||
320 | /* ### PluginLoader libqtopia SafeMode */ | 320 | /* ### PluginLoader libqtopia SafeMode */ |
321 | #if 0 | 321 | #if 0 |
322 | if ( PluginLoader::inSafeMode() ) | 322 | if ( PluginLoader::inSafeMode() ) |
323 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); | 323 | QTimer::singleShot(500, this, SLOT(showSafeMode()) ); |
324 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); | 324 | QTimer::singleShot(20*1000, this, SLOT(clearSafeMode()) ); |
325 | #endif | 325 | #endif |
326 | 326 | ||
327 | kf = new KeyFilter(this); | 327 | kf = new KeyFilter(this); |
328 | 328 | ||
329 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); | 329 | connect( kf, SIGNAL(launch()), this, SIGNAL(launch()) ); |
330 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); | 330 | connect( kf, SIGNAL(power()), this, SIGNAL(power()) ); |
331 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); | 331 | connect( kf, SIGNAL(backlight()), this, SIGNAL(backlight()) ); |
332 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); | 332 | connect( kf, SIGNAL(symbol()), this, SIGNAL(symbol())); |
333 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); | 333 | connect( kf, SIGNAL(numLockStateToggle()), this,SIGNAL(numLockStateToggle())); |
334 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); | 334 | connect( kf, SIGNAL(capsLockStateToggle()), this,SIGNAL(capsLockStateToggle())); |
335 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), | 335 | connect( kf, SIGNAL(activate(const Opie::Core::ODeviceButton*,bool)), |
336 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); | 336 | this,SIGNAL(activate(const Opie::Core::ODeviceButton*,bool))); |
337 | 337 | ||
338 | 338 | ||
339 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); | 339 | connect( kf, SIGNAL(backlight()), this, SLOT(toggleLight()) ); |
340 | 340 | ||
341 | connect( this, SIGNAL(power() ), | 341 | connect( this, SIGNAL(power() ), |
342 | SLOT(togglePower() ) ); | 342 | SLOT(togglePower() ) ); |
343 | 343 | ||
344 | rereadVolumes(); | 344 | rereadVolumes(); |
345 | 345 | ||
346 | serverApp = this; | 346 | serverApp = this; |
347 | 347 | ||
348 | apmTimeout(); | 348 | apmTimeout(); |
349 | grabKeyboard(); | 349 | grabKeyboard(); |
350 | 350 | ||
351 | /* make sure the event filter is installed */ | 351 | /* make sure the event filter is installed */ |
352 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); | 352 | const ODeviceButton* but = ODevice::inst()->buttonForKeycode( -1 ); |
353 | } | 353 | } |
354 | 354 | ||
355 | 355 | ||
356 | ServerApplication::~ServerApplication() | 356 | ServerApplication::~ServerApplication() |
357 | { | 357 | { |
358 | ungrabKeyboard(); | 358 | ungrabKeyboard(); |
359 | 359 | ||
360 | 360 | ||
361 | delete pa; | 361 | delete pa; |
362 | delete m_ps; | 362 | delete m_ps; |
363 | delete m_ps_last; | 363 | delete m_ps_last; |
364 | } | 364 | } |
365 | 365 | ||
366 | void ServerApplication::apmTimeout() { | 366 | void ServerApplication::apmTimeout() { |
367 | serverApp-> checkMemory( ); // in case no events are generated | 367 | serverApp-> checkMemory( ); // in case no events are generated |
368 | *m_ps_last = *m_ps; | 368 | *m_ps_last = *m_ps; |
369 | *m_ps = PowerStatusManager::readStatus(); | 369 | *m_ps = PowerStatusManager::readStatus(); |
370 | 370 | ||
371 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) | 371 | if ( m_ps->acStatus() != m_ps_last-> acStatus() ) |
372 | m_screensaver-> powerStatusChanged( *m_ps ); | 372 | m_screensaver-> powerStatusChanged( *m_ps ); |
373 | 373 | ||
374 | if ( m_ps->acStatus() == PowerStatus::Online ) { | 374 | if ( m_ps->acStatus() == PowerStatus::Online ) { |
375 | return; | 375 | return; |
376 | } | 376 | } |
377 | 377 | ||
378 | int bat = m_ps-> batteryPercentRemaining(); | 378 | int bat = m_ps-> batteryPercentRemaining(); |
379 | 379 | ||
380 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { | 380 | if ( bat < m_ps_last-> batteryPercentRemaining() ) { |
381 | if ( bat <= m_powerCritical ) { | 381 | if ( bat <= m_powerCritical ) { |
382 | QMessageBox battlow( | 382 | QMessageBox battlow( |
383 | tr("WARNING"), | 383 | tr("WARNING"), |
384 | tr("<p>The battery level is critical!" | 384 | tr("<p>The battery level is critical!" |
385 | "<p>Keep power off until AC is restored"), | 385 | "<p>Keep power off until AC is restored"), |
386 | QMessageBox::Warning, | 386 | QMessageBox::Warning, |
387 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 387 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
388 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 388 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
389 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 389 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
390 | battlow.exec(); | 390 | battlow.exec(); |
391 | } else if ( bat <= m_powerVeryLow ) | 391 | } else if ( bat <= m_powerVeryLow ) |
392 | pa->alert( tr( "The battery is running very low. "), 2 ); | 392 | pa->alert( tr( "The battery is running very low. "), 2 ); |
393 | } | 393 | } |
394 | 394 | ||
395 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { | 395 | if ( m_ps-> backupBatteryStatus() == PowerStatus::VeryLow ) { |
396 | QMessageBox battlow( | 396 | QMessageBox battlow( |
397 | tr("WARNING"), | 397 | tr("WARNING"), |
398 | tr("<p>The Back-up battery is very low" | 398 | tr("<p>The Back-up battery is very low" |
399 | "<p>Please charge the back-up battery"), | 399 | "<p>Please charge the back-up battery"), |
400 | QMessageBox::Warning, | 400 | QMessageBox::Warning, |
401 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 401 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
402 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 402 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
403 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); | 403 | battlow.setButtonText(QMessageBox::Cancel, tr("Ok")); |
404 | battlow.exec(); | 404 | battlow.exec(); |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | void ServerApplication::systemMessage( const QCString& msg, | 408 | void ServerApplication::systemMessage( const QCString& msg, |
409 | const QByteArray& data ) { | 409 | const QByteArray& data ) { |
410 | QDataStream stream ( data, IO_ReadOnly ); | 410 | QDataStream stream ( data, IO_ReadOnly ); |
411 | 411 | ||
412 | if ( msg == "setScreenSaverInterval(int)" ) { | 412 | if ( msg == "setScreenSaverInterval(int)" ) { |
413 | int time; | 413 | int time; |
414 | stream >> time; | 414 | stream >> time; |
415 | m_screensaver-> setInterval( time ); | 415 | m_screensaver-> setInterval( time ); |
416 | } | 416 | } |
417 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { | 417 | else if ( msg == "setScreenSaverIntervals(int,int,int)" ) { |
418 | int t1, t2, t3; | 418 | int t1, t2, t3; |
419 | stream >> t1 >> t2 >> t3; | 419 | stream >> t1 >> t2 >> t3; |
420 | m_screensaver-> setIntervals( t1, t2, t3 ); | 420 | m_screensaver-> setIntervals( t1, t2, t3 ); |
421 | } | 421 | } |
422 | else if ( msg == "setBacklight(int)" ) { | 422 | else if ( msg == "setBacklight(int)" ) { |
423 | int bright; | 423 | int bright; |
424 | stream >> bright; | 424 | stream >> bright; |
425 | m_screensaver-> setBacklight( bright ); | 425 | m_screensaver-> setBacklight( bright ); |
426 | } | 426 | } |
427 | else if ( msg == "setScreenSaverMode(int)" ) { | 427 | else if ( msg == "setScreenSaverMode(int)" ) { |
428 | int mode; | 428 | int mode; |
429 | stream >> mode; | 429 | stream >> mode; |
430 | m_screensaver-> setMode ( mode ); | 430 | m_screensaver-> setMode ( mode ); |
431 | } | 431 | } |
432 | else if ( msg == "reloadPowerWarnSettings()" ) { | 432 | else if ( msg == "reloadPowerWarnSettings()" ) { |
433 | reloadPowerWarnSettings(); | 433 | reloadPowerWarnSettings(); |
434 | } | 434 | } |
435 | else if ( msg == "setDisplayState(int)" ) { | 435 | else if ( msg == "setDisplayState(int)" ) { |
436 | int state; | 436 | int state; |
437 | stream >> state; | 437 | stream >> state; |
438 | m_screensaver-> setDisplayState ( state != 0 ); | 438 | m_screensaver-> setDisplayState ( state != 0 ); |
439 | } | 439 | } |
440 | else if ( msg == "suspend()" ) { | 440 | else if ( msg == "suspend()" ) { |
441 | emit power(); | 441 | emit power(); |
442 | } | 442 | } |
443 | else if ( msg == "sendBusinessCard()" ) { | 443 | else if ( msg == "sendBusinessCard()" ) { |
444 | QString card = ::getenv ( "HOME" ); | 444 | QString card = ::getenv ( "HOME" ); |
445 | card += "/Applications/addressbook/businesscard.vcf"; | 445 | card += "/Applications/addressbook/businesscard.vcf"; |
446 | 446 | ||
447 | if ( QFile::exists( card ) ) { | 447 | if ( QFile::exists( card ) ) { |
448 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); | 448 | QCopEnvelope e ( "QPE/Obex", "send(QString,QString,QString)" ); |
449 | QString mimetype = "text/x-vCard"; | 449 | QString mimetype = "text/x-vCard"; |
450 | e << tr( "business card" ) << card << mimetype; | 450 | e << tr( "business card" ) << card << mimetype; |
451 | } | 451 | } |
452 | } | 452 | } |
453 | } | 453 | } |
454 | 454 | ||
455 | void ServerApplication::reloadPowerWarnSettings ( ) | 455 | void ServerApplication::reloadPowerWarnSettings ( ) |
456 | { | 456 | { |
457 | Config cfg ( "apm" ); | 457 | Config cfg ( "apm" ); |
458 | cfg. setGroup ( "Warnings" ); | 458 | cfg. setGroup ( "Warnings" ); |
459 | 459 | ||
460 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); | 460 | int iv = cfg. readNumEntry ( "checkinterval", 10000 ); |
461 | 461 | ||
462 | m_apm_timer-> stop ( ); | 462 | m_apm_timer-> stop ( ); |
463 | if ( iv ) | 463 | if ( iv ) |
464 | m_apm_timer-> start ( iv ); | 464 | m_apm_timer-> start ( iv ); |
465 | 465 | ||
466 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); | 466 | m_powerVeryLow = cfg. readNumEntry ( "powerverylow", 10 ); |
467 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); | 467 | m_powerCritical = cfg. readNumEntry ( "powervcritical", 5 ); |
468 | } | 468 | } |
469 | 469 | ||
470 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) | 470 | void ServerApplication::launcherMessage( const QCString & msg, const QByteArray & data ) |
471 | { | 471 | { |
472 | QDataStream stream ( data, IO_ReadOnly ); | 472 | QDataStream stream ( data, IO_ReadOnly ); |
473 | 473 | ||
474 | if ( msg == "deviceButton(int,int,int)" ) { | 474 | if ( msg == "deviceButton(int,int,int)" ) { |
475 | int keycode, press, autoRepeat; | 475 | int keycode, press, autoRepeat; |
476 | stream >> keycode >> press >> autoRepeat; | 476 | stream >> keycode >> press >> autoRepeat; |
477 | 477 | ||
478 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); | 478 | kf->checkButtonAction ( true, keycode, press, autoRepeat ); |
479 | } | 479 | } |
480 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { | 480 | else if ( msg == "keyRegister(int,QCString,QCString)" ) { |
481 | int k; | 481 | int k; |
482 | QCString c, m; | 482 | QCString c, m; |
483 | stream >> k >> c >> m; | 483 | stream >> k >> c >> m; |
484 | 484 | ||
485 | kf -> registerKey( QCopKeyRegister(k, c, m) ); | 485 | kf -> registerKey( QCopKeyRegister(k, c, m) ); |
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
489 | 489 | ||
490 | bool ServerApplication::screenLocked() | 490 | bool ServerApplication::screenLocked() |
491 | { | 491 | { |
492 | return loggedin == 0; | 492 | return loggedin == 0; |
493 | } | 493 | } |
494 | 494 | ||
495 | void ServerApplication::login(bool at_poweron) | 495 | void ServerApplication::login(bool at_poweron) |
496 | { | 496 | { |
497 | if ( !loggedin ) { | 497 | if ( !loggedin ) { |
498 | Global::terminateBuiltin("calibrate"); // No tr | 498 | Global::terminateBuiltin("calibrate"); // No tr |
499 | Password::authenticate(at_poweron); | 499 | Password::authenticate(at_poweron); |
500 | loggedin=1; | 500 | loggedin=1; |
501 | #ifndef QT_NO_COP | 501 | #ifndef QT_NO_COP |
502 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); | 502 | QCopEnvelope e( "QPE/Desktop", "unlocked()" ); |
503 | #endif | 503 | #endif |
504 | } | 504 | } |
505 | } | 505 | } |
506 | 506 | ||
507 | #if defined(QPE_HAVE_TOGGLELIGHT) | 507 | #if defined(QPE_HAVE_TOGGLELIGHT) |
508 | #include <qtopia/config.h> | 508 | #include <qtopia/config.h> |
509 | 509 | ||
510 | #include <sys/ioctl.h> | 510 | #include <sys/ioctl.h> |
511 | #include <sys/types.h> | 511 | #include <sys/types.h> |
512 | #include <fcntl.h> | 512 | #include <fcntl.h> |
513 | #include <unistd.h> | 513 | #include <unistd.h> |
514 | #include <errno.h> | 514 | #include <errno.h> |
515 | #include <linux/ioctl.h> | 515 | #include <linux/ioctl.h> |
516 | #include <time.h> | 516 | #include <time.h> |
517 | #endif | 517 | #endif |
518 | 518 | ||
519 | #if 0 | 519 | #if 0 |
520 | static bool blanked=FALSE; | 520 | static bool blanked=FALSE; |
521 | 521 | ||
522 | static void blankScreen() | 522 | static void blankScreen() |
523 | { | 523 | { |
524 | #ifdef QWS | 524 | #ifdef QWS |
525 | QWidget w(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop | Qt::WPaintUnclipped); | 525 | QWidget w(0, 0, Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop | Qt::WPaintUnclipped); |
526 | w.resize( qt_screen->width(), qt_screen->height() ); | 526 | w.resize( qt_screen->width(), qt_screen->height() ); |
527 | w.move(0, 0); | 527 | w.move(0, 0); |
528 | 528 | ||
529 | QPainter p(&w); | 529 | QPainter p(&w); |
530 | p.fillRect(w.rect(), QBrush(QColor(255,255,255)) ); | 530 | p.fillRect(w.rect(), QBrush(QColor(255,255,255)) ); |
531 | p.end(); | 531 | p.end(); |
532 | w.repaint(); | 532 | w.repaint(); |
533 | 533 | ||
534 | blanked = TRUE; | 534 | blanked = TRUE; |
535 | #endif | 535 | #endif |
536 | } | 536 | } |
537 | 537 | ||
538 | static void darkScreen() | 538 | static void darkScreen() |
539 | { | 539 | { |
540 | /* ### Screen blanking ODevice */ | 540 | /* ### Screen blanking ODevice */ |
541 | #if 0 | 541 | #if 0 |
542 | qpe_setBacklight(0); // force off | 542 | qpe_setBacklight(0); // force off |
543 | #endif | 543 | #endif |
544 | } | 544 | } |
545 | #endif | 545 | #endif |
546 | 546 | ||
547 | namespace { | 547 | namespace { |
548 | void execAutoStart(const QDateTime& suspendTime ) { | 548 | void execAutoStart(const QDateTime& suspendTime ) { |
549 | QString appName; | 549 | QString appName; |
550 | int delay; | 550 | int delay; |
551 | QDateTime now = QDateTime::currentDateTime(); | 551 | QDateTime now = QDateTime::currentDateTime(); |
552 | 552 | ||
553 | Config cfg( "autostart" ); | 553 | Config cfg( "autostart" ); |
554 | cfg.setGroup( "AutoStart" ); | 554 | cfg.setGroup( "AutoStart" ); |
555 | appName = cfg.readEntry( "Apps", "" ); | 555 | appName = cfg.readEntry( "Apps", "" ); |
556 | delay = cfg.readNumEntry( "Delay", 0 ); | 556 | delay = cfg.readNumEntry( "Delay", 0 ); |
557 | 557 | ||
558 | // If the time between suspend and resume was longer then the | 558 | // If the time between suspend and resume was longer then the |
559 | // value saved as delay, start the app | 559 | // value saved as delay, start the app |
560 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { | 560 | if ( suspendTime.secsTo( now ) >= ( delay * 60 ) && !appName.isEmpty() ) { |
561 | QCopEnvelope e( "QPE/System", "execute(QString)" ); | 561 | QCopEnvelope e( "QPE/System", "execute(QString)" ); |
562 | e << QString( appName ); | 562 | e << QString( appName ); |
563 | } | 563 | } |
564 | } | 564 | } |
565 | } | 565 | } |
566 | 566 | ||
567 | 567 | ||
568 | void ServerApplication::togglePower() | 568 | void ServerApplication::togglePower() |
569 | { | 569 | { |
570 | static bool excllock = false; | 570 | static bool excllock = false; |
571 | 571 | ||
572 | if ( excllock ) | 572 | if ( excllock ) |
573 | return ; | 573 | return ; |
574 | 574 | ||
575 | excllock = true; | 575 | excllock = true; |
576 | 576 | ||
577 | bool wasloggedin = loggedin; | 577 | bool wasloggedin = loggedin; |
578 | loggedin = 0; | 578 | loggedin = 0; |
579 | m_suspendTime = QDateTime::currentDateTime(); | 579 | m_suspendTime = QDateTime::currentDateTime(); |
580 | 580 | ||
581 | #ifdef QWS | 581 | #ifdef QWS |
582 | 582 | ||
583 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { | 583 | if ( Password::needToAuthenticate ( true ) && qt_screen ) { |
584 | // Should use a big black window instead. | 584 | // Should use a big black window instead. |
585 | // But this would not show up fast enough | 585 | // But this would not show up fast enough |
586 | QGfx *g = qt_screen-> screenGfx ( ); | 586 | QGfx *g = qt_screen-> screenGfx ( ); |
587 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); | 587 | g-> fillRect ( 0, 0, qt_screen-> width ( ), qt_screen-> height ( )); |
588 | delete g; | 588 | delete g; |
589 | } | 589 | } |
590 | #endif | 590 | #endif |
591 | 591 | ||
592 | ODevice::inst ( )-> suspend ( ); | 592 | ODevice::inst ( )-> suspend ( ); |
593 | 593 | ||
594 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call | 594 | ServerApplication::switchLCD ( true ); // force LCD on without slow qcop call |
595 | QWSServer::screenSaverActivate ( false ); | 595 | QWSServer::screenSaverActivate ( false ); |
596 | 596 | ||
597 | { | 597 | { |
598 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep | 598 | QCopEnvelope( "QPE/Card", "mtabChanged()" ); // might have changed while asleep |
599 | } | 599 | } |
600 | 600 | ||
601 | if ( wasloggedin ) | 601 | if ( wasloggedin ) |
602 | login ( true ); | 602 | login ( true ); |
603 | 603 | ||
604 | execAutoStart(m_suspendTime); | 604 | execAutoStart(m_suspendTime); |
605 | //qcopBridge->closeOpenConnections(); | 605 | //qcopBridge->closeOpenConnections(); |
606 | 606 | ||
607 | excllock = false; | 607 | excllock = false; |
608 | } | 608 | } |
609 | 609 | ||
610 | void ServerApplication::toggleLight() | 610 | void ServerApplication::toggleLight() |
611 | { | 611 | { |
612 | #ifndef QT_NO_COP | 612 | #ifndef QT_NO_COP |
613 | QCopEnvelope e("QPE/System", "setBacklight(int)"); | 613 | QCopEnvelope e("QPE/System", "setBacklight(int)"); |
614 | e << -2; // toggle | 614 | e << -2; // toggle |
615 | #endif | 615 | #endif |
616 | } | 616 | } |
617 | 617 | ||
618 | 618 | ||
619 | /* | 619 | /* |
620 | * We still listen to key events but handle them in | 620 | * We still listen to key events but handle them in |
621 | * a special class | 621 | * a special class |
622 | */ | 622 | */ |
623 | 623 | ||
624 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { | 624 | bool ServerApplication::eventFilter( QObject *o, QEvent *e) { |
625 | if ( e->type() != QEvent::KeyPress && | 625 | if ( e->type() != QEvent::KeyPress && |
626 | e->type() != QEvent::KeyRelease ) | 626 | e->type() != QEvent::KeyRelease ) |
627 | return QPEApplication::eventFilter( o, e ); | 627 | return QPEApplication::eventFilter( o, e ); |
628 | 628 | ||
629 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); | 629 | QKeyEvent *ke = static_cast<QKeyEvent*>( e ); |
630 | if ( kf->checkButtonAction( true, ke->key(), | 630 | if ( kf->checkButtonAction( true, ke->key(), |
631 | e->type() == QEvent::KeyPress, | 631 | e->type() == QEvent::KeyPress, |
632 | ke-> isAutoRepeat() )) | 632 | ke-> isAutoRepeat() )) |
633 | return true; | 633 | return true; |
634 | 634 | ||
635 | return QPEApplication::eventFilter( o, e ); | 635 | return QPEApplication::eventFilter( o, e ); |
636 | 636 | ||
637 | } | 637 | } |
638 | 638 | ||
639 | #ifdef Q_WS_QWS | 639 | #ifdef Q_WS_QWS |
640 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) | 640 | bool ServerApplication::qwsEventFilter( QWSEvent *e ) |
641 | { | 641 | { |
642 | checkMemory(); | 642 | checkMemory(); |
643 | 643 | ||
644 | if ( e->type == QWSEvent::Mouse ) { | 644 | if ( e->type == QWSEvent::Mouse ) { |
645 | QWSMouseEvent *me = (QWSMouseEvent *)e; | 645 | QWSMouseEvent *me = (QWSMouseEvent *)e; |
646 | static bool up = TRUE; | 646 | static bool up = TRUE; |
647 | if ( me->simpleData.state&LeftButton ) { | 647 | if ( me->simpleData.state&LeftButton ) { |
648 | if ( up ) { | 648 | if ( up ) { |
649 | up = FALSE; | 649 | up = FALSE; |
650 | screenClick(TRUE); | 650 | screenClick(TRUE); |
651 | } | 651 | } |
652 | } else if ( !up ) { | 652 | } else if ( !up ) { |
653 | up = TRUE; | 653 | up = TRUE; |
654 | screenClick(FALSE); | 654 | screenClick(FALSE); |
655 | } | 655 | } |
656 | }else if ( e->type == QWSEvent::Key ) { | 656 | }else if ( e->type == QWSEvent::Key ) { |
657 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); | 657 | QWSKeyEvent * ke = static_cast<QWSKeyEvent*>( e ); |
658 | if ( kf->checkButtonAction( false, | 658 | if ( kf->checkButtonAction( false, |
659 | ke-> simpleData.keycode, | 659 | ke-> simpleData.keycode, |
660 | ke-> simpleData.is_press, | 660 | ke-> simpleData.is_press, |
661 | ke-> simpleData.is_auto_repeat ) ) | 661 | ke-> simpleData.is_auto_repeat ) ) |
662 | return true; | 662 | return true; |
663 | } | 663 | } |
664 | 664 | ||
665 | return QPEApplication::qwsEventFilter( e ); | 665 | return QPEApplication::qwsEventFilter( e ); |
666 | } | 666 | } |
667 | #endif | 667 | #endif |
668 | 668 | ||
669 | 669 | ||
670 | /* ### FIXME libqtopia Plugin Safe Mode */ | 670 | /* ### FIXME libqtopia Plugin Safe Mode */ |
671 | 671 | ||
672 | void ServerApplication::showSafeMode() | 672 | void ServerApplication::showSafeMode() |
673 | { | 673 | { |
674 | #if 0 | 674 | #if 0 |
675 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " | 675 | if ( QMessageBox::warning(0, tr("Safe Mode"), tr("<P>A system startup error occurred, " |
676 | "and the system is now in Safe Mode. " | 676 | "and the system is now in Safe Mode. " |
677 | "Plugins are not loaded in Safe Mode. " | 677 | "Plugins are not loaded in Safe Mode. " |
678 | "You can use the Plugin Manager to " | 678 | "You can use the Plugin Manager to " |
679 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) { | 679 | "disable plugins that cause system error."), tr("OK"), tr("Plugin Manager..."), 0) == 1 ) { |
680 | Global::execute( "pluginmanager" ); | 680 | Global::execute( "pluginmanager" ); |
681 | } | 681 | } |
682 | #endif | 682 | #endif |
683 | } | 683 | } |
684 | 684 | ||
685 | void ServerApplication::clearSafeMode() | 685 | void ServerApplication::clearSafeMode() |
686 | { | 686 | { |
687 | #if 0 | 687 | #if 0 |
688 | // If we've been running OK for a while then we won't bother going into | 688 | // If we've been running OK for a while then we won't bother going into |
689 | // safe mode immediately on the next crash. | 689 | // safe mode immediately on the next crash. |
690 | Config cfg( "PluginLoader" ); | 690 | Config cfg( "PluginLoader" ); |
691 | cfg.setGroup( "Global" ); | 691 | cfg.setGroup( "Global" ); |
692 | QString mode = cfg.readEntry( "Mode", "Normal" ); | 692 | QString mode = cfg.readEntry( "Mode", "Normal" ); |
693 | if ( mode == "MaybeSafe" ) { | 693 | if ( mode == "MaybeSafe" ) { |
694 | cfg.writeEntry( "Mode", "Normal" ); | 694 | cfg.writeEntry( "Mode", "Normal" ); |
695 | } | 695 | } |
696 | #endif | 696 | #endif |
697 | } | 697 | } |
698 | 698 | ||
699 | 699 | ||
700 | void ServerApplication::shutdown() | 700 | void ServerApplication::shutdown() |
701 | { | 701 | { |
702 | if ( type() != GuiServer ) | 702 | if ( type() != GuiServer ) |
703 | return; | 703 | return; |
704 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); | 704 | ShutdownImpl *sd = new ShutdownImpl( 0, 0, WDestructiveClose ); |
705 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), | 705 | connect( sd, SIGNAL(shutdown(ShutdownImpl::Type)), |
706 | this, SLOT(shutdown(ShutdownImpl::Type)) ); | 706 | this, SLOT(shutdown(ShutdownImpl::Type)) ); |
707 | QPEApplication::showWidget( sd ); | 707 | QPEApplication::showWidget( sd ); |
708 | } | 708 | } |
709 | 709 | ||
710 | void ServerApplication::shutdown( ShutdownImpl::Type t ) | 710 | void ServerApplication::shutdown( ShutdownImpl::Type t ) |
711 | { | 711 | { |
712 | char *opt = 0; | 712 | char *opt = 0; |
713 | 713 | ||
714 | switch ( t ) { | 714 | switch ( t ) { |
715 | case ShutdownImpl::ShutdownSystem: | 715 | case ShutdownImpl::ShutdownSystem: |
716 | opt = "-h"; | 716 | opt = "-h"; |
717 | // fall through | 717 | // fall through |
718 | case ShutdownImpl::RebootSystem: | 718 | case ShutdownImpl::RebootSystem: |
719 | if ( opt == 0 ) | 719 | if ( opt == 0 ) |
720 | opt = "-r"; | 720 | opt = "-r"; |
721 | 721 | ||
722 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) | 722 | if ( execl( "/sbin/shutdown", "shutdown", opt, "now", ( void* ) 0) < 0 ) |
723 | perror("shutdown"); | 723 | perror("shutdown"); |
724 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); | 724 | // ::syslog ( LOG_ERR, "Erroring execing shutdown\n" ); |
725 | 725 | ||
726 | break; | 726 | break; |
727 | case ShutdownImpl::RestartDesktop: | 727 | case ShutdownImpl::RestartDesktop: |
728 | restart(); | 728 | restart(); |
729 | break; | 729 | break; |
730 | case ShutdownImpl::TerminateDesktop: | 730 | case ShutdownImpl::TerminateDesktop: |
731 | prepareForTermination( FALSE ); | 731 | prepareForTermination( FALSE ); |
732 | 732 | ||
733 | // This is a workaround for a Qt bug | 733 | // This is a workaround for a Qt bug |
734 | // clipboard applet has to stop its poll timer, or Qt/E | 734 | // clipboard applet has to stop its poll timer, or Qt/E |
735 | // will hang on quit() right before it emits aboutToQuit() | 735 | // will hang on quit() right before it emits aboutToQuit() |
736 | emit aboutToQuit ( ); | 736 | emit aboutToQuit ( ); |
737 | 737 | ||
738 | quit(); | 738 | quit(); |
739 | break; | 739 | break; |
740 | } | 740 | } |
741 | } | 741 | } |
742 | 742 | ||
743 | void ServerApplication::restart() | 743 | void ServerApplication::restart() |
744 | { | 744 | { |
745 | if ( allowRestart ) { | 745 | if ( allowRestart ) { |
746 | 746 | ||
747 | /* | 747 | /* |
748 | * Applets and restart is a problem. Some applets delete | 748 | * Applets and restart is a problem. Some applets delete |
749 | * their widgets even if ownership gets transfered to the | 749 | * their widgets even if ownership gets transfered to the |
750 | * parent (Systray ) but deleting the applet may be unsafe | 750 | * parent (Systray ) but deleting the applet may be unsafe |
751 | * as well ( double deletion ). Some have topLevel widgets | 751 | * as well ( double deletion ). Some have topLevel widgets |
752 | * and when we dlclose and then delete the widget we will | 752 | * and when we dlclose and then delete the widget we will |
753 | * crash and an crash during restart is not nice | 753 | * crash and an crash during restart is not nice |
754 | */ | 754 | */ |
755 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED | 755 | #ifdef ALL_APPLETS_ON_THIS_WORLD_ARE_FIXED |
756 | /* same as above */ | 756 | /* same as above */ |
757 | emit aboutToQuit(); | 757 | emit aboutToQuit(); |
758 | prepareForTermination(TRUE); | 758 | prepareForTermination(TRUE); |
759 | doRestart = TRUE; | 759 | doRestart = TRUE; |
760 | quit(); | 760 | quit(); |
761 | #else | 761 | #else |
762 | prepareForTermination( true ); | 762 | prepareForTermination( true ); |
763 | for ( int fd = 3; fd < 100; fd++ ) | 763 | for ( int fd = 3; fd < 100; fd++ ) |
764 | close( fd ); | 764 | close( fd ); |
765 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); | 765 | execl( ( qpeDir() + "/bin/qpe" ).latin1(), "qpe", 0 ); |
766 | exit( 1 ); | 766 | exit( 1 ); |
767 | #endif | 767 | #endif |
768 | } | 768 | } |
769 | } | 769 | } |
770 | 770 | ||
771 | void ServerApplication::rereadVolumes() | 771 | void ServerApplication::rereadVolumes() |
772 | { | 772 | { |
773 | Config cfg( "qpe" ); | 773 | Config cfg( "qpe" ); |
774 | cfg. setGroup ( "Volume" ); | 774 | cfg. setGroup ( "Volume" ); |
775 | 775 | ||
776 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); | 776 | m_screentap_sound = cfg. readBoolEntry ( "TouchSound" ); |
777 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); | 777 | m_keyclick_sound = cfg. readBoolEntry ( "KeySound" ); |
778 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); | 778 | m_alarm_sound = cfg. readBoolEntry ( "AlarmSound" ); |
779 | } | 779 | } |
780 | 780 | ||
781 | 781 | ||
782 | void ServerApplication::checkMemory() | 782 | void ServerApplication::checkMemory() |
783 | { | 783 | { |
784 | #if defined(QPE_HAVE_MEMALERTER) | 784 | #if defined(QPE_HAVE_MEMALERTER) |
785 | static bool ignoreNormal=TRUE; | 785 | static bool ignoreNormal=TRUE; |
786 | static bool existingMessage=FALSE; | 786 | static bool existingMessage=FALSE; |
787 | 787 | ||
788 | if(existingMessage) | 788 | if(existingMessage) |
789 | return; // don't show a second message while still on first | 789 | return; // don't show a second message while still on first |
790 | 790 | ||
791 | existingMessage = TRUE; | 791 | existingMessage = TRUE; |
792 | switch ( memstate ) { | 792 | switch ( memstate ) { |
793 | case MemUnknown: | 793 | case MemUnknown: |
794 | break; | 794 | break; |
795 | case MemLow: | 795 | case MemLow: |
796 | memstate = MemUnknown; | 796 | memstate = MemUnknown; |
797 | if ( !recoverMemory() ) { | 797 | if ( !recoverMemory() ) { |
798 | QMessageBox::warning( 0 , tr("Memory Status"), | 798 | QMessageBox::warning( 0 , tr("Memory Status"), |
799 | tr("Memory Low\nPlease save data.") ); | 799 | tr("Memory Low\nPlease save data.") ); |
800 | ignoreNormal = FALSE; | 800 | ignoreNormal = FALSE; |
801 | } | 801 | } |
802 | break; | 802 | break; |
803 | case MemNormal: | 803 | case MemNormal: |
804 | memstate = MemUnknown; | 804 | memstate = MemUnknown; |
805 | if ( !ignoreNormal ) { | 805 | if ( !ignoreNormal ) { |
806 | ignoreNormal = TRUE; | 806 | ignoreNormal = TRUE; |
807 | QMessageBox::information ( 0 , tr("Memory Status"), | 807 | QMessageBox::information ( 0 , tr("Memory Status"), |
808 | "Memory OK" ); | 808 | "Memory OK" ); |
809 | } | 809 | } |
810 | break; | 810 | break; |
811 | case MemVeryLow: | 811 | case MemVeryLow: |
812 | memstate = MemUnknown; | 812 | memstate = MemUnknown; |
813 | QMessageBox::critical( 0 , tr("Memory Status"), | 813 | QMessageBox::critical( 0 , tr("Memory Status"), |
814 | tr("Critical Memory Shortage\n" | 814 | tr("Critical Memory Shortage\n" |
815 | "Please end this application\n" | 815 | "Please end this application\n" |
816 | "immediately.") ); | 816 | "immediately.") ); |
817 | recoverMemory(); | 817 | recoverMemory(); |
818 | } | 818 | } |
819 | existingMessage = FALSE; | 819 | existingMessage = FALSE; |
820 | #endif | 820 | #endif |
821 | } | 821 | } |
822 | 822 | ||
823 | bool ServerApplication::recoverMemory() | 823 | bool ServerApplication::recoverMemory() |
824 | { | 824 | { |
825 | return FALSE; | 825 | return FALSE; |
826 | } | 826 | } |
827 | 827 | ||
828 | void ServerApplication::keyClick(int , bool press, bool ) | 828 | void ServerApplication::keyClick(int , bool press, bool ) |
829 | { | 829 | { |
830 | if ( press && m_keyclick_sound ) | 830 | if ( press && m_keyclick_sound ) |
831 | ODevice::inst() -> playKeySound(); | 831 | ODevice::inst() -> playKeySound(); |
832 | 832 | ||
833 | } | 833 | } |
834 | 834 | ||
835 | void ServerApplication::screenClick(bool press) | 835 | void ServerApplication::screenClick(bool press) |
836 | { | 836 | { |
837 | if ( press && m_screentap_sound ) | 837 | if ( press && m_screentap_sound ) |
838 | ODevice::inst() -> playTouchSound(); | 838 | ODevice::inst() -> playTouchSound(); |
839 | } | 839 | } |
840 | 840 | ||
841 | void ServerApplication::soundAlarm() { | 841 | void ServerApplication::soundAlarm() { |
842 | if ( me ()->m_alarm_sound ) | 842 | if ( me ()->m_alarm_sound ) |
843 | ODevice::inst()->playAlarmSound(); | 843 | ODevice::inst()->playAlarmSound(); |
844 | } | 844 | } |
845 | 845 | ||
846 | ServerApplication *ServerApplication::me ( ) | 846 | ServerApplication *ServerApplication::me ( ) |
847 | { | 847 | { |
848 | return static_cast<ServerApplication*>( qApp ); | 848 | return static_cast<ServerApplication*>( qApp ); |
849 | } | 849 | } |
850 | 850 | ||
851 | bool ServerApplication::isStarting() | 851 | bool ServerApplication::isStarting() |
852 | { | 852 | { |
853 | return ms_is_starting; | 853 | return ms_is_starting; |
854 | } | 854 | } |
855 | 855 | ||
856 | int ServerApplication::exec() | 856 | int ServerApplication::exec() |
857 | { | 857 | { |
858 | ms_is_starting = true; | 858 | ms_is_starting = true; |
859 | qDebug("Serverapp - exec"); | 859 | odebug << "Serverapp - exec" << oendl; |
860 | return QPEApplication::exec(); | 860 | return QPEApplication::exec(); |
861 | } | 861 | } |
862 | 862 | ||
863 | #include "serverapp.moc" | 863 | #include "serverapp.moc" |
diff --git a/core/launcher/suspendmonitor.cpp b/core/launcher/suspendmonitor.cpp index f555e84..50bc56f 100644 --- a/core/launcher/suspendmonitor.cpp +++ b/core/launcher/suspendmonitor.cpp | |||
@@ -1,167 +1,167 @@ | |||
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 | #include <qtopia/qcopenvelope_qws.h> | 20 | #include <qtopia/qcopenvelope_qws.h> |
21 | #include <qtopia/qpeapplication.h> | 21 | #include <qtopia/qpeapplication.h> |
22 | #include "suspendmonitor.h" | 22 | #include "suspendmonitor.h" |
23 | 23 | ||
24 | 24 | ||
25 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME | 25 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME |
26 | #define QTOPIA_MIN_SCREEN_DISABLE_TIME ((int) 300) // min 5 minutes before forced suspend kicks in | 26 | #define QTOPIA_MIN_SCREEN_DISABLE_TIME ((int) 300) // min 5 minutes before forced suspend kicks in |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | 29 | ||
30 | TempScreenSaverMonitor::TempScreenSaverMonitor(QObject *parent, const char *name) | 30 | TempScreenSaverMonitor::TempScreenSaverMonitor(QObject *parent, const char *name) |
31 | : QObject(parent, name) | 31 | : QObject(parent, name) |
32 | { | 32 | { |
33 | currentMode = QPEApplication::Enable; | 33 | currentMode = QPEApplication::Enable; |
34 | timerId = 0; | 34 | timerId = 0; |
35 | } | 35 | } |
36 | 36 | ||
37 | void TempScreenSaverMonitor::setTempMode(int mode, int pid) | 37 | void TempScreenSaverMonitor::setTempMode(int mode, int pid) |
38 | { | 38 | { |
39 | removeOld(pid); | 39 | removeOld(pid); |
40 | switch(mode) { | 40 | switch(mode) { |
41 | case QPEApplication::Disable: | 41 | case QPEApplication::Disable: |
42 | sStatus[0].append(pid); | 42 | sStatus[0].append(pid); |
43 | break; | 43 | break; |
44 | case QPEApplication::DisableLightOff: | 44 | case QPEApplication::DisableLightOff: |
45 | sStatus[1].append(pid); | 45 | sStatus[1].append(pid); |
46 | break; | 46 | break; |
47 | case QPEApplication::DisableSuspend: | 47 | case QPEApplication::DisableSuspend: |
48 | sStatus[2].append(pid); | 48 | sStatus[2].append(pid); |
49 | break; | 49 | break; |
50 | case QPEApplication::Enable: | 50 | case QPEApplication::Enable: |
51 | break; | 51 | break; |
52 | default: | 52 | default: |
53 | qWarning("Unrecognized temp power setting. Ignored"); | 53 | owarn << "Unrecognized temp power setting. Ignored" << oendl; |
54 | return; | 54 | return; |
55 | } | 55 | } |
56 | updateAll(); | 56 | updateAll(); |
57 | } | 57 | } |
58 | 58 | ||
59 | // Returns true if app had set a temp Mode earlier | 59 | // Returns true if app had set a temp Mode earlier |
60 | bool TempScreenSaverMonitor::removeOld(int pid) | 60 | bool TempScreenSaverMonitor::removeOld(int pid) |
61 | { | 61 | { |
62 | QValueList<int>::Iterator it; | 62 | QValueList<int>::Iterator it; |
63 | for (int i = 0; i < 3; i++) { | 63 | for (int i = 0; i < 3; i++) { |
64 | it = sStatus[i].find(pid); | 64 | it = sStatus[i].find(pid); |
65 | if ( it != sStatus[i].end() ) { | 65 | if ( it != sStatus[i].end() ) { |
66 | sStatus[i].remove( it ); | 66 | sStatus[i].remove( it ); |
67 | return TRUE; | 67 | return TRUE; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | return FALSE; | 70 | return FALSE; |
71 | } | 71 | } |
72 | 72 | ||
73 | void TempScreenSaverMonitor::updateAll() | 73 | void TempScreenSaverMonitor::updateAll() |
74 | { | 74 | { |
75 | int mode = QPEApplication::Enable; | 75 | int mode = QPEApplication::Enable; |
76 | if ( sStatus[0].count() ) { | 76 | if ( sStatus[0].count() ) { |
77 | mode = QPEApplication::Disable; | 77 | mode = QPEApplication::Disable; |
78 | } else if ( sStatus[1].count() ) { | 78 | } else if ( sStatus[1].count() ) { |
79 | mode = QPEApplication::DisableLightOff; | 79 | mode = QPEApplication::DisableLightOff; |
80 | } else if ( sStatus[2].count() ) { | 80 | } else if ( sStatus[2].count() ) { |
81 | mode = QPEApplication::DisableSuspend; | 81 | mode = QPEApplication::DisableSuspend; |
82 | } | 82 | } |
83 | 83 | ||
84 | if ( mode != currentMode ) { | 84 | if ( mode != currentMode ) { |
85 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME | 85 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME |
86 | if ( currentMode == QPEApplication::Enable) { | 86 | if ( currentMode == QPEApplication::Enable) { |
87 | int tid = timerValue(); | 87 | int tid = timerValue(); |
88 | if ( tid ) | 88 | if ( tid ) |
89 | timerId = startTimer( tid * 1000 ); | 89 | timerId = startTimer( tid * 1000 ); |
90 | } else if ( mode == QPEApplication::Enable ) { | 90 | } else if ( mode == QPEApplication::Enable ) { |
91 | if ( timerId ) { | 91 | if ( timerId ) { |
92 | killTimer(timerId); | 92 | killTimer(timerId); |
93 | timerId = 0; | 93 | timerId = 0; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | #endif | 96 | #endif |
97 | currentMode = mode; | 97 | currentMode = mode; |
98 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)") << mode; | 98 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)") << mode; |
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void TempScreenSaverMonitor::applicationTerminated(int pid) | 102 | void TempScreenSaverMonitor::applicationTerminated(int pid) |
103 | { | 103 | { |
104 | if ( removeOld(pid) ) | 104 | if ( removeOld(pid) ) |
105 | updateAll(); | 105 | updateAll(); |
106 | } | 106 | } |
107 | 107 | ||
108 | int TempScreenSaverMonitor::timerValue() | 108 | int TempScreenSaverMonitor::timerValue() |
109 | { | 109 | { |
110 | int tid = 0; | 110 | int tid = 0; |
111 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME | 111 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME |
112 | tid = QTOPIA_MAX_SCREEN_DISABLE_TIME; | 112 | tid = QTOPIA_MAX_SCREEN_DISABLE_TIME; |
113 | 113 | ||
114 | char *env = getenv("QTOPIA_DISABLED_APM_TIMEOUT"); | 114 | char *env = getenv("QTOPIA_DISABLED_APM_TIMEOUT"); |
115 | if ( !env ) | 115 | if ( !env ) |
116 | return tid; | 116 | return tid; |
117 | 117 | ||
118 | QString strEnv = env; | 118 | QString strEnv = env; |
119 | bool ok = FALSE; | 119 | bool ok = FALSE; |
120 | int envTime = strEnv.toInt(&ok); | 120 | int envTime = strEnv.toInt(&ok); |
121 | 121 | ||
122 | if ( ok ) { | 122 | if ( ok ) { |
123 | if ( envTime < 0 ) | 123 | if ( envTime < 0 ) |
124 | return 0; | 124 | return 0; |
125 | else if ( envTime <= QTOPIA_MIN_SCREEN_DISABLE_TIME ) | 125 | else if ( envTime <= QTOPIA_MIN_SCREEN_DISABLE_TIME ) |
126 | return tid; | 126 | return tid; |
127 | else | 127 | else |
128 | return envTime; | 128 | return envTime; |
129 | } | 129 | } |
130 | #endif | 130 | #endif |
131 | 131 | ||
132 | return tid; | 132 | return tid; |
133 | } | 133 | } |
134 | 134 | ||
135 | void TempScreenSaverMonitor::timerEvent(QTimerEvent *t) | 135 | void TempScreenSaverMonitor::timerEvent(QTimerEvent *t) |
136 | { | 136 | { |
137 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME | 137 | #ifdef QTOPIA_MAX_SCREEN_DISABLE_TIME |
138 | if ( timerId && (t->timerId() == timerId) ) { | 138 | if ( timerId && (t->timerId() == timerId) ) { |
139 | 139 | ||
140 | /* Clean up*/ | 140 | /* Clean up*/ |
141 | killTimer(timerId); | 141 | killTimer(timerId); |
142 | timerId = 0; | 142 | timerId = 0; |
143 | currentMode = QPEApplication::Enable; | 143 | currentMode = QPEApplication::Enable; |
144 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)") << currentMode; | 144 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)") << currentMode; |
145 | 145 | ||
146 | // signal starts on a merry-go-round, which ends up in Desktop::togglePower() | 146 | // signal starts on a merry-go-round, which ends up in Desktop::togglePower() |
147 | emit forceSuspend(); | 147 | emit forceSuspend(); |
148 | // if we have apm we are asleep at this point, next line will be executed when we | 148 | // if we have apm we are asleep at this point, next line will be executed when we |
149 | // awake from suspend. | 149 | // awake from suspend. |
150 | if ( QFile::exists( "/proc/apm" ) ) { | 150 | if ( QFile::exists( "/proc/apm" ) ) { |
151 | QTime t; | 151 | QTime t; |
152 | t = t.addSecs( timerValue() ); | 152 | t = t.addSecs( timerValue() ); |
153 | QString str = tr("<qt>The running applications disabled the screen saver for more than the allowed time (%1).<p>The system was forced to suspend</p></qt>").arg( t.toString() ); | 153 | QString str = tr("<qt>The running applications disabled the screen saver for more than the allowed time (%1).<p>The system was forced to suspend</p></qt>").arg( t.toString() ); |
154 | QMessageBox::information(0, tr("Forced suspend"), str); | 154 | QMessageBox::information(0, tr("Forced suspend"), str); |
155 | } | 155 | } |
156 | 156 | ||
157 | // Reset all requests. | 157 | // Reset all requests. |
158 | for (int i = 0; i < 3; i++) | 158 | for (int i = 0; i < 3; i++) |
159 | sStatus[i].clear(); | 159 | sStatus[i].clear(); |
160 | 160 | ||
161 | updateAll(); | 161 | updateAll(); |
162 | } | 162 | } |
163 | #else | 163 | #else |
164 | Q_UNUSED(t); | 164 | Q_UNUSED(t); |
165 | #endif | 165 | #endif |
166 | } | 166 | } |
167 | 167 | ||
diff --git a/core/launcher/systray.cpp b/core/launcher/systray.cpp index 6cc1446..3c72d25 100644 --- a/core/launcher/systray.cpp +++ b/core/launcher/systray.cpp | |||
@@ -1,152 +1,150 @@ | |||
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 | #include "systray.h" | ||
22 | |||
23 | /* OPIE */ | ||
24 | #include <opie2/odebug.h> | ||
21 | #include <qtopia/qpeapplication.h> | 25 | #include <qtopia/qpeapplication.h> |
22 | #include <qtopia/qlibrary.h> | 26 | #include <qtopia/qlibrary.h> |
23 | #include <qtopia/config.h> | 27 | #include <qtopia/config.h> |
28 | using namespace Opie::Core; | ||
24 | 29 | ||
30 | /* QT */ | ||
25 | #include <qlayout.h> | 31 | #include <qlayout.h> |
26 | #include <qdir.h> | 32 | #include <qdir.h> |
27 | 33 | ||
28 | #include "systray.h" | 34 | /* STD */ |
29 | |||
30 | #include <stdlib.h> | 35 | #include <stdlib.h> |
31 | 36 | ||
32 | /* ### Single build floppies ### */ | ||
33 | #if 0 | ||
34 | #ifdef QT_NO_COMPONENTS | ||
35 | #include "../plugins/applets/clockapplet/clockappletimpl.h" | ||
36 | #endif | ||
37 | #endif | ||
38 | |||
39 | SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) | 37 | SysTray::SysTray( QWidget *parent ) : QFrame( parent ), layout(0) |
40 | { | 38 | { |
41 | //setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 39 | //setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
42 | loadApplets(); | 40 | loadApplets(); |
43 | } | 41 | } |
44 | 42 | ||
45 | SysTray::~SysTray() | 43 | SysTray::~SysTray() |
46 | { | 44 | { |
47 | clearApplets(); | 45 | clearApplets(); |
48 | } | 46 | } |
49 | 47 | ||
50 | static int compareAppletPositions(const void *a, const void *b) | 48 | static int compareAppletPositions(const void *a, const void *b) |
51 | { | 49 | { |
52 | const TaskbarApplet* aa = *(const TaskbarApplet**)a; | 50 | const TaskbarApplet* aa = *(const TaskbarApplet**)a; |
53 | const TaskbarApplet* ab = *(const TaskbarApplet**)b; | 51 | const TaskbarApplet* ab = *(const TaskbarApplet**)b; |
54 | int d = ab->iface->position() - aa->iface->position(); | 52 | int d = ab->iface->position() - aa->iface->position(); |
55 | if ( d ) return d; | 53 | if ( d ) return d; |
56 | return QString::compare(ab->name,aa->name); | 54 | return QString::compare(ab->name,aa->name); |
57 | } | 55 | } |
58 | 56 | ||
59 | void SysTray::loadApplets() | 57 | void SysTray::loadApplets() |
60 | { | 58 | { |
61 | hide(); | 59 | hide(); |
62 | clearApplets(); | 60 | clearApplets(); |
63 | addApplets(); | 61 | addApplets(); |
64 | } | 62 | } |
65 | 63 | ||
66 | void SysTray::clearApplets() | 64 | void SysTray::clearApplets() |
67 | { | 65 | { |
68 | #ifndef QT_NO_COMPONENTS | 66 | #ifndef QT_NO_COMPONENTS |
69 | 67 | ||
70 | /* | 68 | /* |
71 | * Note on clearing. SOme applets delete their | 69 | * Note on clearing. SOme applets delete their |
72 | * applets themselves some don't do it | 70 | * applets themselves some don't do it |
73 | * and on restart this can crash. If we delete it | 71 | * and on restart this can crash. If we delete it |
74 | * here we might end up in a double deletion. We could | 72 | * here we might end up in a double deletion. We could |
75 | * use QGuardedPtr but that would be one QOBject | 73 | * use QGuardedPtr but that would be one QOBject |
76 | * for every applet more but only useful for restart | 74 | * for every applet more but only useful for restart |
77 | */ | 75 | */ |
78 | QValueList<TaskbarApplet>::Iterator mit; | 76 | QValueList<TaskbarApplet>::Iterator mit; |
79 | for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) { | 77 | for ( mit = appletList.begin(); mit != appletList.end(); ++mit ) { |
80 | (*mit).iface->release(); | 78 | (*mit).iface->release(); |
81 | (*mit).library->unload(); | 79 | (*mit).library->unload(); |
82 | delete (*mit).library; | 80 | delete (*mit).library; |
83 | } | 81 | } |
84 | 82 | ||
85 | #endif | 83 | #endif |
86 | appletList.clear(); | 84 | appletList.clear(); |
87 | if ( layout ) | 85 | if ( layout ) |
88 | delete layout; | 86 | delete layout; |
89 | layout = new QHBoxLayout( this, 0, 1 ); | 87 | layout = new QHBoxLayout( this, 0, 1 ); |
90 | layout->setAutoAdd(TRUE); | 88 | layout->setAutoAdd(TRUE); |
91 | } | 89 | } |
92 | 90 | ||
93 | void SysTray::addApplets() | 91 | void SysTray::addApplets() |
94 | { | 92 | { |
95 | hide(); | 93 | hide(); |
96 | #ifndef QT_NO_COMPONENTS | 94 | #ifndef QT_NO_COMPONENTS |
97 | Config cfg( "Taskbar" ); | 95 | Config cfg( "Taskbar" ); |
98 | cfg.setGroup( "Applets" ); | 96 | cfg.setGroup( "Applets" ); |
99 | QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); | 97 | QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); |
100 | 98 | ||
101 | QString lang = getenv( "LANG" ); | 99 | QString lang = getenv( "LANG" ); |
102 | QString path = QPEApplication::qpeDir() + "/plugins/applets"; | 100 | QString path = QPEApplication::qpeDir() + "/plugins/applets"; |
103 | #ifdef Q_OS_MACX | 101 | #ifdef Q_OS_MACX |
104 | QDir dir( path, "lib*.dylib" ); | 102 | QDir dir( path, "lib*.dylib" ); |
105 | #else | 103 | #else |
106 | QDir dir( path, "lib*.so" ); | 104 | QDir dir( path, "lib*.so" ); |
107 | #endif /* Q_OS_MACX */ | 105 | #endif /* Q_OS_MACX */ |
108 | QStringList list = dir.entryList(); | 106 | QStringList list = dir.entryList(); |
109 | QStringList::Iterator it; | 107 | QStringList::Iterator it; |
110 | int napplets=0; | 108 | int napplets=0; |
111 | TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; | 109 | TaskbarApplet* *applets = new TaskbarApplet*[list.count()]; |
112 | for ( it = list.begin(); it != list.end(); ++it ) { | 110 | for ( it = list.begin(); it != list.end(); ++it ) { |
113 | if ( exclude.find( *it ) != exclude.end() ) | 111 | if ( exclude.find( *it ) != exclude.end() ) |
114 | continue; | 112 | continue; |
115 | qWarning( "Found Applet: %s", (*it).latin1() ); | 113 | owarn << "Found Applet: " << (*it) << "" << oendl; |
116 | TaskbarAppletInterface *iface = 0; | 114 | TaskbarAppletInterface *iface = 0; |
117 | QLibrary *lib = new QLibrary( path + "/" + *it ); | 115 | QLibrary *lib = new QLibrary( path + "/" + *it ); |
118 | if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { | 116 | if (( lib->queryInterface( IID_TaskbarApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { |
119 | TaskbarApplet *applet = new TaskbarApplet; | 117 | TaskbarApplet *applet = new TaskbarApplet; |
120 | applets[napplets++] = applet; | 118 | applets[napplets++] = applet; |
121 | applet->library = lib; | 119 | applet->library = lib; |
122 | applet->iface = iface; | 120 | applet->iface = iface; |
123 | 121 | ||
124 | QTranslator *trans = new QTranslator(qApp); | 122 | QTranslator *trans = new QTranslator(qApp); |
125 | QString type = (*it).left( (*it).find(".") ); | 123 | QString type = (*it).left( (*it).find(".") ); |
126 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; | 124 | QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; |
127 | if ( trans->load( tfn )) | 125 | if ( trans->load( tfn )) |
128 | qApp->installTranslator( trans ); | 126 | qApp->installTranslator( trans ); |
129 | else | 127 | else |
130 | delete trans; | 128 | delete trans; |
131 | } else { | 129 | } else { |
132 | exclude += *it; | 130 | exclude += *it; |
133 | delete lib; | 131 | delete lib; |
134 | } | 132 | } |
135 | } | 133 | } |
136 | cfg.writeEntry( "ExcludeApplets", exclude, ',' ); | 134 | cfg.writeEntry( "ExcludeApplets", exclude, ',' ); |
137 | qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); | 135 | qsort(applets,napplets,sizeof(applets[0]),compareAppletPositions); |
138 | while (napplets--) { | 136 | while (napplets--) { |
139 | TaskbarApplet *applet = applets[napplets]; | 137 | TaskbarApplet *applet = applets[napplets]; |
140 | applet->applet = applet->iface->applet( this ); | 138 | applet->applet = applet->iface->applet( this ); |
141 | appletList.append(*applet); | 139 | appletList.append(*applet); |
142 | } | 140 | } |
143 | delete [] applets; | 141 | delete [] applets; |
144 | #else /* ## FIXME single app */ | 142 | #else /* ## FIXME single app */ |
145 | TaskbarApplet * const applet = new TaskbarApplet(); | 143 | TaskbarApplet * const applet = new TaskbarApplet(); |
146 | applet->iface = new ClockAppletImpl(); | 144 | applet->iface = new ClockAppletImpl(); |
147 | applet->applet = applet->iface->applet( this ); | 145 | applet->applet = applet->iface->applet( this ); |
148 | appletList.append( applet ); | 146 | appletList.append( applet ); |
149 | #endif | 147 | #endif |
150 | show(); | 148 | show(); |
151 | } | 149 | } |
152 | 150 | ||
diff --git a/core/launcher/taskbar.cpp b/core/launcher/taskbar.cpp index 91e2f20..86e0d0d 100644 --- a/core/launcher/taskbar.cpp +++ b/core/launcher/taskbar.cpp | |||
@@ -1,377 +1,380 @@ | |||
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 | #include "startmenu.h" | 21 | #include "startmenu.h" |
22 | #include "inputmethods.h" | 22 | #include "inputmethods.h" |
23 | #include "runningappbar.h" | 23 | #include "runningappbar.h" |
24 | #include "systray.h" | 24 | #include "systray.h" |
25 | #include "wait.h" | 25 | #include "wait.h" |
26 | #include "appicons.h" | 26 | #include "appicons.h" |
27 | 27 | ||
28 | #include "taskbar.h" | 28 | #include "taskbar.h" |
29 | #include "server.h" | 29 | #include "server.h" |
30 | 30 | ||
31 | /* OPIE */ | ||
32 | #include <opie2/odebug.h> | ||
31 | #include <qtopia/config.h> | 33 | #include <qtopia/config.h> |
32 | #include <qtopia/qpeapplication.h> | 34 | #include <qtopia/qpeapplication.h> |
33 | #ifdef QWS | 35 | #ifdef QWS |
34 | #include <qtopia/qcopenvelope_qws.h> | 36 | #include <qtopia/qcopenvelope_qws.h> |
35 | #endif | 37 | #endif |
36 | #include <qtopia/global.h> | 38 | #include <qtopia/global.h> |
37 | //#include <qtopia/custom.h> | 39 | using namespace Opie::Core; |
38 | 40 | ||
41 | /* QT */ | ||
39 | #include <qlabel.h> | 42 | #include <qlabel.h> |
40 | #include <qlayout.h> | 43 | #include <qlayout.h> |
41 | #include <qtimer.h> | 44 | #include <qtimer.h> |
42 | #ifdef QWS | 45 | #ifdef QWS |
43 | #include <qwindowsystem_qws.h> | 46 | #include <qwindowsystem_qws.h> |
44 | #endif | 47 | #endif |
45 | #include <qwidgetstack.h> | 48 | #include <qwidgetstack.h> |
46 | 49 | ||
47 | #if defined( Q_WS_QWS ) | 50 | #if defined( Q_WS_QWS ) |
48 | #include <qwsdisplay_qws.h> | 51 | #include <qwsdisplay_qws.h> |
49 | #include <qgfx_qws.h> | 52 | #include <qgfx_qws.h> |
50 | #endif | 53 | #endif |
51 | 54 | ||
52 | 55 | ||
53 | static bool initNumLock() | 56 | static bool initNumLock() |
54 | { | 57 | { |
55 | #ifdef QPE_INITIAL_NUMLOCK_STATE | 58 | #ifdef QPE_INITIAL_NUMLOCK_STATE |
56 | QPE_INITIAL_NUMLOCK_STATE | 59 | QPE_INITIAL_NUMLOCK_STATE |
57 | #endif | 60 | #endif |
58 | return FALSE; | 61 | return FALSE; |
59 | } | 62 | } |
60 | 63 | ||
61 | //--------------------------------------------------------------------------- | 64 | //--------------------------------------------------------------------------- |
62 | 65 | ||
63 | class SafeMode : public QWidget | 66 | class SafeMode : public QWidget |
64 | { | 67 | { |
65 | Q_OBJECT | 68 | Q_OBJECT |
66 | public: | 69 | public: |
67 | SafeMode( QWidget *parent ) : QWidget( parent ), menu(0) | 70 | SafeMode( QWidget *parent ) : QWidget( parent ), menu(0) |
68 | { | 71 | { |
69 | message = tr("Safe Mode"); | 72 | message = tr("Safe Mode"); |
70 | QFont f( font() ); | 73 | QFont f( font() ); |
71 | f.setWeight( QFont::Bold ); | 74 | f.setWeight( QFont::Bold ); |
72 | setFont( f ); | 75 | setFont( f ); |
73 | } | 76 | } |
74 | 77 | ||
75 | void mousePressEvent( QMouseEvent *); | 78 | void mousePressEvent( QMouseEvent *); |
76 | QSize sizeHint() const; | 79 | QSize sizeHint() const; |
77 | void paintEvent( QPaintEvent* ); | 80 | void paintEvent( QPaintEvent* ); |
78 | 81 | ||
79 | private slots: | 82 | private slots: |
80 | void action(int i); | 83 | void action(int i); |
81 | 84 | ||
82 | private: | 85 | private: |
83 | QString message; | 86 | QString message; |
84 | QPopupMenu *menu; | 87 | QPopupMenu *menu; |
85 | }; | 88 | }; |
86 | 89 | ||
87 | void SafeMode::mousePressEvent( QMouseEvent *) | 90 | void SafeMode::mousePressEvent( QMouseEvent *) |
88 | { | 91 | { |
89 | if ( !menu ) { | 92 | if ( !menu ) { |
90 | menu = new QPopupMenu(this); | 93 | menu = new QPopupMenu(this); |
91 | menu->insertItem( tr("Plugin Manager..."), 0 ); | 94 | menu->insertItem( tr("Plugin Manager..."), 0 ); |
92 | menu->insertItem( tr("Restart Qtopia"), 1 ); | 95 | menu->insertItem( tr("Restart Qtopia"), 1 ); |
93 | menu->insertItem( tr("Help..."), 2 ); | 96 | menu->insertItem( tr("Help..."), 2 ); |
94 | connect(menu, SIGNAL(activated(int)), this, SLOT(action(int))); | 97 | connect(menu, SIGNAL(activated(int)), this, SLOT(action(int))); |
95 | } | 98 | } |
96 | QPoint curPos = mapToGlobal( QPoint(0,0) ); | 99 | QPoint curPos = mapToGlobal( QPoint(0,0) ); |
97 | QSize sh = menu->sizeHint(); | 100 | QSize sh = menu->sizeHint(); |
98 | menu->popup( curPos-QPoint((sh.width()-width())/2,sh.height()) ); | 101 | menu->popup( curPos-QPoint((sh.width()-width())/2,sh.height()) ); |
99 | } | 102 | } |
100 | 103 | ||
101 | void SafeMode::action(int i) | 104 | void SafeMode::action(int i) |
102 | { | 105 | { |
103 | switch (i) { | 106 | switch (i) { |
104 | case 0: | 107 | case 0: |
105 | Global::execute( "pluginmanager" ); | 108 | Global::execute( "pluginmanager" ); |
106 | break; | 109 | break; |
107 | case 1: | 110 | case 1: |
108 | Global::restart(); | 111 | Global::restart(); |
109 | break; | 112 | break; |
110 | case 2: | 113 | case 2: |
111 | Global::execute( "helpbrowser", "safemode.html" ); | 114 | Global::execute( "helpbrowser", "safemode.html" ); |
112 | break; | 115 | break; |
113 | } | 116 | } |
114 | } | 117 | } |
115 | 118 | ||
116 | QSize SafeMode::sizeHint() const | 119 | QSize SafeMode::sizeHint() const |
117 | { | 120 | { |
118 | QFontMetrics fm = fontMetrics(); | 121 | QFontMetrics fm = fontMetrics(); |
119 | 122 | ||
120 | return QSize( fm.width(message), fm.height() ); | 123 | return QSize( fm.width(message), fm.height() ); |
121 | } | 124 | } |
122 | 125 | ||
123 | void SafeMode::paintEvent( QPaintEvent* ) | 126 | void SafeMode::paintEvent( QPaintEvent* ) |
124 | { | 127 | { |
125 | QPainter p(this); | 128 | QPainter p(this); |
126 | p.drawText( rect(), AlignCenter, message ); | 129 | p.drawText( rect(), AlignCenter, message ); |
127 | } | 130 | } |
128 | 131 | ||
129 | //--------------------------------------------------------------------------- | 132 | //--------------------------------------------------------------------------- |
130 | 133 | ||
131 | class LockKeyState : public QWidget | 134 | class LockKeyState : public QWidget |
132 | { | 135 | { |
133 | public: | 136 | public: |
134 | LockKeyState( QWidget *parent ) : | 137 | LockKeyState( QWidget *parent ) : |
135 | QWidget(parent), | 138 | QWidget(parent), |
136 | nl(initNumLock()), cl(FALSE) | 139 | nl(initNumLock()), cl(FALSE) |
137 | { | 140 | { |
138 | nl_pm = Resource::loadPixmap("numlock"); | 141 | nl_pm = Resource::loadPixmap("numlock"); |
139 | cl_pm = Resource::loadPixmap("capslock"); | 142 | cl_pm = Resource::loadPixmap("capslock"); |
140 | } | 143 | } |
141 | QSize sizeHint() const | 144 | QSize sizeHint() const |
142 | { | 145 | { |
143 | return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); | 146 | return QSize(nl_pm.width()+2,nl_pm.width()+nl_pm.height()+1); |
144 | } | 147 | } |
145 | void toggleNumLockState() | 148 | void toggleNumLockState() |
146 | { | 149 | { |
147 | nl = !nl; repaint(); | 150 | nl = !nl; repaint(); |
148 | } | 151 | } |
149 | void toggleCapsLockState() | 152 | void toggleCapsLockState() |
150 | { | 153 | { |
151 | cl = !cl; repaint(); | 154 | cl = !cl; repaint(); |
152 | } | 155 | } |
153 | void paintEvent( QPaintEvent * ) | 156 | void paintEvent( QPaintEvent * ) |
154 | { | 157 | { |
155 | int y = (height()-sizeHint().height())/2; | 158 | int y = (height()-sizeHint().height())/2; |
156 | QPainter p(this); | 159 | QPainter p(this); |
157 | if ( nl ) | 160 | if ( nl ) |
158 | p.drawPixmap(1,y,nl_pm); | 161 | p.drawPixmap(1,y,nl_pm); |
159 | if ( cl ) | 162 | if ( cl ) |
160 | p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); | 163 | p.drawPixmap(1,y+nl_pm.height()+1,cl_pm); |
161 | } | 164 | } |
162 | private: | 165 | private: |
163 | QPixmap nl_pm, cl_pm; | 166 | QPixmap nl_pm, cl_pm; |
164 | bool nl, cl; | 167 | bool nl, cl; |
165 | }; | 168 | }; |
166 | 169 | ||
167 | //--------------------------------------------------------------------------- | 170 | //--------------------------------------------------------------------------- |
168 | 171 | ||
169 | TaskBar::~TaskBar() | 172 | TaskBar::~TaskBar() |
170 | { | 173 | { |
171 | } | 174 | } |
172 | 175 | ||
173 | 176 | ||
174 | TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) | 177 | TaskBar::TaskBar() : QHBox(0, 0, WStyle_Customize | WStyle_Tool | WStyle_StaysOnTop | WGroupLeader) |
175 | { | 178 | { |
176 | Config cfg( "Launcher" ); | 179 | Config cfg( "Launcher" ); |
177 | cfg.setGroup( "InputMethods" ); | 180 | cfg.setGroup( "InputMethods" ); |
178 | resizeRunningApp = cfg.readBoolEntry( "Resize", true ); | 181 | resizeRunningApp = cfg.readBoolEntry( "Resize", true ); |
179 | 182 | ||
180 | sm = new StartMenu( this ); | 183 | sm = new StartMenu( this ); |
181 | connect( sm, SIGNAL(tabSelected(const QString&)), this, | 184 | connect( sm, SIGNAL(tabSelected(const QString&)), this, |
182 | SIGNAL(tabSelected(const QString&)) ); | 185 | SIGNAL(tabSelected(const QString&)) ); |
183 | 186 | ||
184 | inputMethods = new InputMethods( this ); | 187 | inputMethods = new InputMethods( this ); |
185 | connect( inputMethods, SIGNAL(inputToggled(bool)), | 188 | connect( inputMethods, SIGNAL(inputToggled(bool)), |
186 | this, SLOT(calcMaxWindowRect()) ); | 189 | this, SLOT(calcMaxWindowRect()) ); |
187 | 190 | ||
188 | stack = new QWidgetStack( this ); | 191 | stack = new QWidgetStack( this ); |
189 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 192 | stack->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
190 | label = new QLabel(stack); | 193 | label = new QLabel(stack); |
191 | 194 | ||
192 | runningAppBar = new RunningAppBar(stack); | 195 | runningAppBar = new RunningAppBar(stack); |
193 | stack->raiseWidget(runningAppBar); | 196 | stack->raiseWidget(runningAppBar); |
194 | 197 | ||
195 | waitIcon = new Wait( this ); | 198 | waitIcon = new Wait( this ); |
196 | (void) new AppIcons( this ); | 199 | (void) new AppIcons( this ); |
197 | 200 | ||
198 | sysTray = new SysTray( this ); | 201 | sysTray = new SysTray( this ); |
199 | 202 | ||
200 | /* ### FIXME plugin loader and safe mode */ | 203 | /* ### FIXME plugin loader and safe mode */ |
201 | #if 0 | 204 | #if 0 |
202 | if (PluginLoader::inSafeMode()) | 205 | if (PluginLoader::inSafeMode()) |
203 | (void)new SafeMode( this ); | 206 | (void)new SafeMode( this ); |
204 | #endif | 207 | #endif |
205 | 208 | ||
206 | // ## make customizable in some way? | 209 | // ## make customizable in some way? |
207 | #ifdef QT_QWS_CUSTOM | 210 | #ifdef QT_QWS_CUSTOM |
208 | lockState = new LockKeyState( this ); | 211 | lockState = new LockKeyState( this ); |
209 | #else | 212 | #else |
210 | lockState = 0; | 213 | lockState = 0; |
211 | #endif | 214 | #endif |
212 | 215 | ||
213 | #if defined(Q_WS_QWS) | 216 | #if defined(Q_WS_QWS) |
214 | #if !defined(QT_NO_COP) | 217 | #if !defined(QT_NO_COP) |
215 | QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); | 218 | QCopChannel *channel = new QCopChannel( "QPE/TaskBar", this ); |
216 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), | 219 | connect( channel, SIGNAL(received(const QCString&,const QByteArray&)), |
217 | this, SLOT(receive(const QCString&,const QByteArray&)) ); | 220 | this, SLOT(receive(const QCString&,const QByteArray&)) ); |
218 | #endif | 221 | #endif |
219 | #endif | 222 | #endif |
220 | waitTimer = new QTimer( this ); | 223 | waitTimer = new QTimer( this ); |
221 | connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); | 224 | connect( waitTimer, SIGNAL( timeout() ), this, SLOT( stopWait() ) ); |
222 | clearer = new QTimer( this ); | 225 | clearer = new QTimer( this ); |
223 | QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); | 226 | QObject::connect(clearer, SIGNAL(timeout()), SLOT(clearStatusBar())); |
224 | 227 | ||
225 | connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); | 228 | connect( qApp, SIGNAL(symbol()), this, SLOT(toggleSymbolInput()) ); |
226 | connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); | 229 | connect( qApp, SIGNAL(numLockStateToggle()), this, SLOT(toggleNumLockState()) ); |
227 | connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); | 230 | connect( qApp, SIGNAL(capsLockStateToggle()), this, SLOT(toggleCapsLockState()) ); |
228 | } | 231 | } |
229 | 232 | ||
230 | void TaskBar::setStatusMessage( const QString &text ) | 233 | void TaskBar::setStatusMessage( const QString &text ) |
231 | { | 234 | { |
232 | if ( !text.isEmpty() ) { | 235 | if ( !text.isEmpty() ) { |
233 | label->setText( text ); | 236 | label->setText( text ); |
234 | stack->raiseWidget( label ); | 237 | stack->raiseWidget( label ); |
235 | if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) ) | 238 | if ( sysTray && ( label->fontMetrics().width( text ) > label->width() ) ) |
236 | sysTray->hide(); | 239 | sysTray->hide(); |
237 | clearer->start( 3000, TRUE ); | 240 | clearer->start( 3000, TRUE ); |
238 | } else { | 241 | } else { |
239 | clearStatusBar(); | 242 | clearStatusBar(); |
240 | } | 243 | } |
241 | } | 244 | } |
242 | 245 | ||
243 | void TaskBar::clearStatusBar() | 246 | void TaskBar::clearStatusBar() |
244 | { | 247 | { |
245 | label->clear(); | 248 | label->clear(); |
246 | stack->raiseWidget(runningAppBar); | 249 | stack->raiseWidget(runningAppBar); |
247 | if ( sysTray ) | 250 | if ( sysTray ) |
248 | sysTray->show(); | 251 | sysTray->show(); |
249 | // stack->raiseWidget( mru ); | 252 | // stack->raiseWidget( mru ); |
250 | } | 253 | } |
251 | 254 | ||
252 | void TaskBar::startWait() | 255 | void TaskBar::startWait() |
253 | { | 256 | { |
254 | waitIcon->setWaiting( true ); | 257 | waitIcon->setWaiting( true ); |
255 | // a catchall stop after 10 seconds... | 258 | // a catchall stop after 10 seconds... |
256 | waitTimer->start( 10 * 1000, true ); | 259 | waitTimer->start( 10 * 1000, true ); |
257 | } | 260 | } |
258 | 261 | ||
259 | void TaskBar::stopWait(const QString&) | 262 | void TaskBar::stopWait(const QString&) |
260 | { | 263 | { |
261 | waitTimer->stop(); | 264 | waitTimer->stop(); |
262 | waitIcon->setWaiting( false ); | 265 | waitIcon->setWaiting( false ); |
263 | } | 266 | } |
264 | 267 | ||
265 | void TaskBar::stopWait() | 268 | void TaskBar::stopWait() |
266 | { | 269 | { |
267 | waitTimer->stop(); | 270 | waitTimer->stop(); |
268 | waitIcon->setWaiting( false ); | 271 | waitIcon->setWaiting( false ); |
269 | } | 272 | } |
270 | 273 | ||
271 | /* | 274 | /* |
272 | * This resizeEvent will be captured by | 275 | * This resizeEvent will be captured by |
273 | * the ServerInterface and it'll layout | 276 | * the ServerInterface and it'll layout |
274 | * and calc rect. Now if we go from bigger | 277 | * and calc rect. Now if we go from bigger |
275 | * to smaller screen the SysTray is out of | 278 | * to smaller screen the SysTray is out of |
276 | * bounds and repaint() won't trigger an Event | 279 | * bounds and repaint() won't trigger an Event |
277 | */ | 280 | */ |
278 | void TaskBar::resizeEvent( QResizeEvent *e ) | 281 | void TaskBar::resizeEvent( QResizeEvent *e ) |
279 | { | 282 | { |
280 | if ( sysTray ) | 283 | if ( sysTray ) |
281 | sysTray->hide(); | 284 | sysTray->hide(); |
282 | 285 | ||
283 | QHBox::resizeEvent( e ); | 286 | QHBox::resizeEvent( e ); |
284 | 287 | ||
285 | if ( sysTray ) | 288 | if ( sysTray ) |
286 | sysTray->show(); | 289 | sysTray->show(); |
287 | 290 | ||
288 | qWarning("TaskBar::resize event"); | 291 | owarn << "TaskBar::resize event" << oendl; |
289 | } | 292 | } |
290 | 293 | ||
291 | void TaskBar::styleChange( QStyle &s ) | 294 | void TaskBar::styleChange( QStyle &s ) |
292 | { | 295 | { |
293 | QHBox::styleChange( s ); | 296 | QHBox::styleChange( s ); |
294 | calcMaxWindowRect(); | 297 | calcMaxWindowRect(); |
295 | } | 298 | } |
296 | 299 | ||
297 | void TaskBar::calcMaxWindowRect() | 300 | void TaskBar::calcMaxWindowRect() |
298 | { | 301 | { |
299 | if ( resizeRunningApp ) | 302 | if ( resizeRunningApp ) |
300 | { | 303 | { |
301 | #if defined(Q_WS_QWS) | 304 | #if defined(Q_WS_QWS) |
302 | QRect wr; | 305 | QRect wr; |
303 | int displayWidth = qApp->desktop()->width(); | 306 | int displayWidth = qApp->desktop()->width(); |
304 | QRect ir = inputMethods->inputRect(); | 307 | QRect ir = inputMethods->inputRect(); |
305 | if ( ir.isValid() ) { | 308 | if ( ir.isValid() ) { |
306 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); | 309 | wr.setCoords( 0, 0, displayWidth-1, ir.top()-1 ); |
307 | } else { | 310 | } else { |
308 | wr.setCoords( 0, 0, displayWidth-1, y()-1 ); | 311 | wr.setCoords( 0, 0, displayWidth-1, y()-1 ); |
309 | } | 312 | } |
310 | #if QT_VERSION < 0x030000 | 313 | #if QT_VERSION < 0x030000 |
311 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,QSize(qt_screen->width(),qt_screen->height())) ); | 314 | QWSServer::setMaxWindowRect( qt_screen->mapToDevice(wr,QSize(qt_screen->width(),qt_screen->height())) ); |
312 | #else | 315 | #else |
313 | QWSServer::setMaxWindowRect( wr ); | 316 | QWSServer::setMaxWindowRect( wr ); |
314 | #endif | 317 | #endif |
315 | #endif | 318 | #endif |
316 | } | 319 | } |
317 | } | 320 | } |
318 | 321 | ||
319 | void TaskBar::receive( const QCString &msg, const QByteArray &data ) | 322 | void TaskBar::receive( const QCString &msg, const QByteArray &data ) |
320 | { | 323 | { |
321 | QDataStream stream( data, IO_ReadOnly ); | 324 | QDataStream stream( data, IO_ReadOnly ); |
322 | if ( msg == "message(QString)" ) { | 325 | if ( msg == "message(QString)" ) { |
323 | QString text; | 326 | QString text; |
324 | stream >> text; | 327 | stream >> text; |
325 | setStatusMessage( text ); | 328 | setStatusMessage( text ); |
326 | } else if ( msg == "hideInputMethod()" ) { | 329 | } else if ( msg == "hideInputMethod()" ) { |
327 | inputMethods->hideInputMethod(); | 330 | inputMethods->hideInputMethod(); |
328 | } else if ( msg == "showInputMethod()" ) { | 331 | } else if ( msg == "showInputMethod()" ) { |
329 | inputMethods->showInputMethod(); | 332 | inputMethods->showInputMethod(); |
330 | } else if ( msg == "showInputMethod(QString)" ) { | 333 | } else if ( msg == "showInputMethod(QString)" ) { |
331 | QString name; | 334 | QString name; |
332 | stream >> name; | 335 | stream >> name; |
333 | inputMethods->showInputMethod(name); | 336 | inputMethods->showInputMethod(name); |
334 | } else if ( msg == "reloadInputMethods()" ) { | 337 | } else if ( msg == "reloadInputMethods()" ) { |
335 | inputMethods->loadInputMethods(); | 338 | inputMethods->loadInputMethods(); |
336 | } else if ( msg == "reloadApplets()" ) { | 339 | } else if ( msg == "reloadApplets()" ) { |
337 | sysTray->clearApplets(); | 340 | sysTray->clearApplets(); |
338 | sm->createMenu(); | 341 | sm->createMenu(); |
339 | sysTray->addApplets(); | 342 | sysTray->addApplets(); |
340 | }else if ( msg == "toggleMenu()" ) { | 343 | }else if ( msg == "toggleMenu()" ) { |
341 | if ( sm-> launchMenu-> isVisible() ) | 344 | if ( sm-> launchMenu-> isVisible() ) |
342 | sm-> launch(); | 345 | sm-> launch(); |
343 | else | 346 | else |
344 | QCopEnvelope e( "QPE/System", "toggleApplicationMenu()" ); | 347 | QCopEnvelope e( "QPE/System", "toggleApplicationMenu()" ); |
345 | }else if ( msg == "toggleStartMenu()" ) | 348 | }else if ( msg == "toggleStartMenu()" ) |
346 | sm->launch(); | 349 | sm->launch(); |
347 | } | 350 | } |
348 | 351 | ||
349 | void TaskBar::setApplicationState( const QString &name, ServerInterface::ApplicationState state ) | 352 | void TaskBar::setApplicationState( const QString &name, ServerInterface::ApplicationState state ) |
350 | { | 353 | { |
351 | if ( state == ServerInterface::Launching ) | 354 | if ( state == ServerInterface::Launching ) |
352 | runningAppBar->applicationLaunched( name ); | 355 | runningAppBar->applicationLaunched( name ); |
353 | else if ( state == ServerInterface::Terminated ) | 356 | else if ( state == ServerInterface::Terminated ) |
354 | runningAppBar->applicationTerminated( name ); | 357 | runningAppBar->applicationTerminated( name ); |
355 | } | 358 | } |
356 | 359 | ||
357 | void TaskBar::toggleNumLockState() | 360 | void TaskBar::toggleNumLockState() |
358 | { | 361 | { |
359 | if ( lockState ) lockState->toggleNumLockState(); | 362 | if ( lockState ) lockState->toggleNumLockState(); |
360 | } | 363 | } |
361 | 364 | ||
362 | void TaskBar::toggleCapsLockState() | 365 | void TaskBar::toggleCapsLockState() |
363 | { | 366 | { |
364 | if ( lockState ) lockState->toggleCapsLockState(); | 367 | if ( lockState ) lockState->toggleCapsLockState(); |
365 | } | 368 | } |
366 | 369 | ||
367 | void TaskBar::toggleSymbolInput() | 370 | void TaskBar::toggleSymbolInput() |
368 | { | 371 | { |
369 | QString unicodeInput = qApp->translate( "InputMethods", "Unicode" ); | 372 | QString unicodeInput = qApp->translate( "InputMethods", "Unicode" ); |
370 | if ( inputMethods->currentShown() == unicodeInput ) { | 373 | if ( inputMethods->currentShown() == unicodeInput ) { |
371 | inputMethods->hideInputMethod(); | 374 | inputMethods->hideInputMethod(); |
372 | } else { | 375 | } else { |
373 | inputMethods->showInputMethod( unicodeInput ); | 376 | inputMethods->showInputMethod( unicodeInput ); |
374 | } | 377 | } |
375 | } | 378 | } |
376 | 379 | ||
377 | #include "taskbar.moc" | 380 | #include "taskbar.moc" |
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index e32cf41..4b764e3 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp | |||
@@ -1,1442 +1,1431 @@ | |||
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 | //#define _XOPEN_SOURCE | 20 | #include "transferserver.h" |
21 | 21 | ||
22 | /* OPIE */ | ||
23 | #include <opie2/odebug.h> | ||
22 | #include <opie2/oglobal.h> | 24 | #include <opie2/oglobal.h> |
25 | #include <qtopia/qprocess.h> | ||
26 | #include <qtopia/process.h> | ||
27 | #include <qtopia/private/contact.h> | ||
28 | #include <qtopia/version.h> | ||
29 | #ifdef Q_WS_QWS | ||
30 | #include <qtopia/qcopenvelope_qws.h> | ||
31 | #endif | ||
32 | using namespace Opie::Core; | ||
23 | 33 | ||
24 | #ifndef Q_OS_WIN32 | 34 | /* QT */ |
35 | #include <qtextstream.h> | ||
36 | #include <qmessagebox.h> | ||
37 | |||
38 | /* STD */ | ||
25 | #include <pwd.h> | 39 | #include <pwd.h> |
26 | #include <sys/types.h> | 40 | #include <sys/types.h> |
27 | #include <unistd.h> | 41 | #include <unistd.h> |
28 | #include <stdlib.h> | 42 | #include <stdlib.h> |
29 | #include <time.h> | 43 | #include <time.h> |
30 | 44 | ||
31 | #ifndef Q_OS_MACX | 45 | #ifndef Q_OS_MACX |
32 | #include <shadow.h> | 46 | #include <shadow.h> |
33 | #include <crypt.h> | 47 | #include <crypt.h> |
34 | #endif /* Q_OS_MACX */ | 48 | #endif /* Q_OS_MACX */ |
35 | 49 | ||
36 | #else | ||
37 | #include <stdlib.h> | ||
38 | #include <time.h> | ||
39 | #endif | ||
40 | |||
41 | |||
42 | #if defined(_OS_LINUX_) | ||
43 | #include <shadow.h> | ||
44 | #endif | ||
45 | |||
46 | #include <qtextstream.h> | ||
47 | #include <qmessagebox.h> | ||
48 | //#include <qtopia/qcopchannel_qws.h> | ||
49 | #include <qtopia/process.h> | ||
50 | #include <qtopia/private/contact.h> | ||
51 | #include <qtopia/version.h> | ||
52 | #ifdef Q_WS_QWS | ||
53 | #include <qtopia/qcopenvelope_qws.h> | ||
54 | #endif | ||
55 | |||
56 | |||
57 | #include "transferserver.h" | ||
58 | #include <qtopia/qprocess.h> | ||
59 | |||
60 | const int block_size = 51200; | 50 | const int block_size = 51200; |
61 | 51 | ||
62 | using namespace Opie::Core; | ||
63 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, | 52 | TransferServer::TransferServer( Q_UINT16 port, QObject *parent, |
64 | const char* name) | 53 | const char* name) |
65 | : QServerSocket( port, 1, parent, name ) | 54 | : QServerSocket( port, 1, parent, name ) |
66 | { | 55 | { |
67 | connections.setAutoDelete( TRUE ); | 56 | connections.setAutoDelete( TRUE ); |
68 | if ( !ok() ) | 57 | if ( !ok() ) |
69 | qWarning( "Failed to bind to port %d", port ); | 58 | owarn << "Failed to bind to port " << port << "" << oendl; |
70 | } | 59 | } |
71 | 60 | ||
72 | void TransferServer::authorizeConnections() | 61 | void TransferServer::authorizeConnections() |
73 | { | 62 | { |
74 | QListIterator<ServerPI> it(connections); | 63 | QListIterator<ServerPI> it(connections); |
75 | while ( it.current() ) { | 64 | while ( it.current() ) { |
76 | if ( !it.current()->verifyAuthorised() ) { | 65 | if ( !it.current()->verifyAuthorised() ) { |
77 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); | 66 | disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); |
78 | connections.removeRef( it.current() ); | 67 | connections.removeRef( it.current() ); |
79 | } else | 68 | } else |
80 | ++it; | 69 | ++it; |
81 | } | 70 | } |
82 | } | 71 | } |
83 | 72 | ||
84 | void TransferServer::closed(ServerPI *item) | 73 | void TransferServer::closed(ServerPI *item) |
85 | { | 74 | { |
86 | connections.removeRef(item); | 75 | connections.removeRef(item); |
87 | } | 76 | } |
88 | 77 | ||
89 | TransferServer::~TransferServer() | 78 | TransferServer::~TransferServer() |
90 | { | 79 | { |
91 | } | 80 | } |
92 | 81 | ||
93 | void TransferServer::newConnection( int socket ) | 82 | void TransferServer::newConnection( int socket ) |
94 | { | 83 | { |
95 | ServerPI *ptr = new ServerPI( socket, this ); | 84 | ServerPI *ptr = new ServerPI( socket, this ); |
96 | connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); | 85 | connect( ptr, SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); |
97 | connections.append( ptr ); | 86 | connections.append( ptr ); |
98 | } | 87 | } |
99 | 88 | ||
100 | QString SyncAuthentication::serverId() | 89 | QString SyncAuthentication::serverId() |
101 | { | 90 | { |
102 | Config cfg("Security"); | 91 | Config cfg("Security"); |
103 | cfg.setGroup("Sync"); | 92 | cfg.setGroup("Sync"); |
104 | QString r = cfg.readEntry("serverid"); | 93 | QString r = cfg.readEntry("serverid"); |
105 | 94 | ||
106 | if ( r.isEmpty() ) { | 95 | if ( r.isEmpty() ) { |
107 | r = OGlobal::generateUuid(); | 96 | r = OGlobal::generateUuid(); |
108 | cfg.writeEntry("serverid", r ); | 97 | cfg.writeEntry("serverid", r ); |
109 | } | 98 | } |
110 | return r; | 99 | return r; |
111 | } | 100 | } |
112 | 101 | ||
113 | QString SyncAuthentication::ownerName() | 102 | QString SyncAuthentication::ownerName() |
114 | { | 103 | { |
115 | QString vfilename = Global::applicationFileName("addressbook", | 104 | QString vfilename = Global::applicationFileName("addressbook", |
116 | "businesscard.vcf"); | 105 | "businesscard.vcf"); |
117 | if (QFile::exists(vfilename)) { | 106 | if (QFile::exists(vfilename)) { |
118 | Contact c; | 107 | Contact c; |
119 | c = Contact::readVCard( vfilename )[0]; | 108 | c = Contact::readVCard( vfilename )[0]; |
120 | return c.fullName(); | 109 | return c.fullName(); |
121 | } | 110 | } |
122 | 111 | ||
123 | return QString::null; | 112 | return QString::null; |
124 | } | 113 | } |
125 | 114 | ||
126 | QString SyncAuthentication::loginName() | 115 | QString SyncAuthentication::loginName() |
127 | { | 116 | { |
128 | struct passwd *pw = 0L; | 117 | struct passwd *pw = 0L; |
129 | #ifndef Q_OS_WIN32 | 118 | #ifndef Q_OS_WIN32 |
130 | pw = getpwuid( geteuid() ); | 119 | pw = getpwuid( geteuid() ); |
131 | return QString::fromLocal8Bit( pw->pw_name ); | 120 | return QString::fromLocal8Bit( pw->pw_name ); |
132 | #else | 121 | #else |
133 | //### revise | 122 | //### revise |
134 | return QString(); | 123 | return QString(); |
135 | #endif | 124 | #endif |
136 | } | 125 | } |
137 | 126 | ||
138 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) | 127 | int SyncAuthentication::isAuthorized(QHostAddress peeraddress) |
139 | { | 128 | { |
140 | Config cfg("Security"); | 129 | Config cfg("Security"); |
141 | cfg.setGroup("Sync"); | 130 | cfg.setGroup("Sync"); |
142 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); | 131 | // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); |
143 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); | 132 | uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); |
144 | 133 | ||
145 | // QHostAddress allowed; | 134 | // QHostAddress allowed; |
146 | // allowed.setAddress(allowedstr); | 135 | // allowed.setAddress(allowedstr); |
147 | // uint auth_peer = allowed.ip4Addr(); | 136 | // uint auth_peer = allowed.ip4Addr(); |
148 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); | 137 | uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); |
149 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined | 138 | uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined |
150 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); | 139 | ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); |
151 | 140 | ||
152 | return (peeraddress.ip4Addr() & mask) == auth_peer; | 141 | return (peeraddress.ip4Addr() & mask) == auth_peer; |
153 | } | 142 | } |
154 | 143 | ||
155 | bool SyncAuthentication::checkUser( const QString& user ) | 144 | bool SyncAuthentication::checkUser( const QString& user ) |
156 | { | 145 | { |
157 | if ( user.isEmpty() ) return FALSE; | 146 | if ( user.isEmpty() ) return FALSE; |
158 | QString euser = loginName(); | 147 | QString euser = loginName(); |
159 | return user == euser; | 148 | return user == euser; |
160 | } | 149 | } |
161 | 150 | ||
162 | bool SyncAuthentication::checkPassword( const QString& password ) | 151 | bool SyncAuthentication::checkPassword( const QString& password ) |
163 | { | 152 | { |
164 | #ifdef ALLOW_UNIX_USER_FTP | 153 | #ifdef ALLOW_UNIX_USER_FTP |
165 | // First, check system password... | 154 | // First, check system password... |
166 | 155 | ||
167 | struct passwd *pw = 0; | 156 | struct passwd *pw = 0; |
168 | struct spwd *spw = 0; | 157 | struct spwd *spw = 0; |
169 | 158 | ||
170 | pw = getpwuid( geteuid() ); | 159 | pw = getpwuid( geteuid() ); |
171 | spw = getspnam( pw->pw_name ); | 160 | spw = getspnam( pw->pw_name ); |
172 | 161 | ||
173 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); | 162 | QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); |
174 | if ( cpwd == "x" && spw ) | 163 | if ( cpwd == "x" && spw ) |
175 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); | 164 | cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); |
176 | 165 | ||
177 | // Note: some systems use more than crypt for passwords. | 166 | // Note: some systems use more than crypt for passwords. |
178 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); | 167 | QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); |
179 | if ( cpwd == cpassword ) | 168 | if ( cpwd == cpassword ) |
180 | return TRUE; | 169 | return TRUE; |
181 | #endif | 170 | #endif |
182 | 171 | ||
183 | static int lastdenial=0; | 172 | static int lastdenial=0; |
184 | static int denials=0; | 173 | static int denials=0; |
185 | int now = time(0); | 174 | int now = time(0); |
186 | 175 | ||
187 | Config cfg("Security"); | 176 | Config cfg("Security"); |
188 | cfg.setGroup("SyncMode"); | 177 | cfg.setGroup("SyncMode"); |
189 | int mode = cfg.readNumEntry("Mode", 0x02 ); | 178 | int mode = cfg.readNumEntry("Mode", 0x02 ); |
190 | 179 | ||
191 | //No pass word needed if the user really needs it | 180 | //No pass word needed if the user really needs it |
192 | if (mode & 0x04) { | 181 | if (mode & 0x04) { |
193 | QMessageBox unauth( | 182 | QMessageBox unauth( |
194 | tr("Sync Connection"), | 183 | tr("Sync Connection"), |
195 | tr("<qt><p>An unauthorized system is requesting access to this device." | 184 | tr("<qt><p>An unauthorized system is requesting access to this device." |
196 | "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ), | 185 | "<p>You chose IntelliSync so you may I allow or deny this connection.</qt>" ), |
197 | QMessageBox::Warning, | 186 | QMessageBox::Warning, |
198 | QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton, | 187 | QMessageBox::Ok, QMessageBox::Cancel|QMessageBox::Default, QMessageBox::NoButton, |
199 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 188 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
200 | unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) ); | 189 | unauth.setButtonText(QMessageBox::Ok, tr("Allow" ) ); |
201 | unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); | 190 | unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); |
202 | switch( unauth.exec() ) { | 191 | switch( unauth.exec() ) { |
203 | case QMessageBox::Ok: | 192 | case QMessageBox::Ok: |
204 | return TRUE; | 193 | return TRUE; |
205 | break; | 194 | break; |
206 | case QMessageBox::Cancel: | 195 | case QMessageBox::Cancel: |
207 | default: | 196 | default: |
208 | denials++; | 197 | denials++; |
209 | lastdenial=now; | 198 | lastdenial=now; |
210 | return FALSE; | 199 | return FALSE; |
211 | } | 200 | } |
212 | } | 201 | } |
213 | 202 | ||
214 | // Detect old Qtopia Desktop (no password) and fail | 203 | // Detect old Qtopia Desktop (no password) and fail |
215 | if ( password.isEmpty() ) { | 204 | if ( password.isEmpty() ) { |
216 | if ( denials < 3 || now > lastdenial+600 ) { | 205 | if ( denials < 3 || now > lastdenial+600 ) { |
217 | QMessageBox unauth( | 206 | QMessageBox unauth( |
218 | tr("Sync Connection"), | 207 | tr("Sync Connection"), |
219 | tr("<p>An unauthorized system is requesting access to this device." | 208 | tr("<p>An unauthorized system is requesting access to this device." |
220 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " | 209 | "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " |
221 | "please upgrade or change the security setting to use IntelliSync." ), | 210 | "please upgrade or change the security setting to use IntelliSync." ), |
222 | QMessageBox::Warning, | 211 | QMessageBox::Warning, |
223 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, | 212 | QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, |
224 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 213 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
225 | unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); | 214 | unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); |
226 | unauth.exec(); | 215 | unauth.exec(); |
227 | 216 | ||
228 | denials++; | 217 | denials++; |
229 | lastdenial=now; | 218 | lastdenial=now; |
230 | } | 219 | } |
231 | return FALSE; | 220 | return FALSE; |
232 | 221 | ||
233 | } | 222 | } |
234 | 223 | ||
235 | // Second, check sync password... | 224 | // Second, check sync password... |
236 | 225 | ||
237 | static int lock=0; | 226 | static int lock=0; |
238 | if ( lock ) return FALSE; | 227 | if ( lock ) return FALSE; |
239 | 228 | ||
240 | ++lock; | 229 | ++lock; |
241 | 230 | ||
242 | /* | 231 | /* |
243 | * we need to support old Sync software and QtopiaDesktop | 232 | * we need to support old Sync software and QtopiaDesktop |
244 | */ | 233 | */ |
245 | if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { | 234 | if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { |
246 | Config cfg( "Security" ); | 235 | Config cfg( "Security" ); |
247 | cfg.setGroup("Sync"); | 236 | cfg.setGroup("Sync"); |
248 | QStringList pwds = cfg.readListEntry("Passwords",' '); | 237 | QStringList pwds = cfg.readListEntry("Passwords",' '); |
249 | for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { | 238 | for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { |
250 | #ifndef Q_OS_WIN32 | 239 | #ifndef Q_OS_WIN32 |
251 | QString cpassword = QString::fromLocal8Bit( | 240 | QString cpassword = QString::fromLocal8Bit( |
252 | crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); | 241 | crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); |
253 | #else | 242 | #else |
254 | // ### revise | 243 | // ### revise |
255 | QString cpassword(""); | 244 | QString cpassword(""); |
256 | #endif | 245 | #endif |
257 | if ( *it == cpassword ) { | 246 | if ( *it == cpassword ) { |
258 | lock--; | 247 | lock--; |
259 | return TRUE; | 248 | return TRUE; |
260 | } | 249 | } |
261 | } | 250 | } |
262 | 251 | ||
263 | // Unrecognized system. Be careful... | 252 | // Unrecognized system. Be careful... |
264 | QMessageBox unrecbox( | 253 | QMessageBox unrecbox( |
265 | tr("Sync Connection"), | 254 | tr("Sync Connection"), |
266 | tr("<p>An unrecognized system is requesting access to this device." | 255 | tr("<p>An unrecognized system is requesting access to this device." |
267 | "<p>If you have just initiated a Sync for the first time, this is normal."), | 256 | "<p>If you have just initiated a Sync for the first time, this is normal."), |
268 | QMessageBox::Warning, | 257 | QMessageBox::Warning, |
269 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, | 258 | QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, |
270 | 0, QString::null, TRUE, WStyle_StaysOnTop); | 259 | 0, QString::null, TRUE, WStyle_StaysOnTop); |
271 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); | 260 | unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); |
272 | unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); | 261 | unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); |
273 | 262 | ||
274 | if ( (denials > 2 && now < lastdenial+600) | 263 | if ( (denials > 2 && now < lastdenial+600) |
275 | || unrecbox.exec() != QMessageBox::Yes) | 264 | || unrecbox.exec() != QMessageBox::Yes) |
276 | { | 265 | { |
277 | denials++; | 266 | denials++; |
278 | lastdenial=now; | 267 | lastdenial=now; |
279 | lock--; | 268 | lock--; |
280 | return FALSE; | 269 | return FALSE; |
281 | } else { | 270 | } else { |
282 | const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; | 271 | const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; |
283 | char salt[2]; | 272 | char salt[2]; |
284 | salt[0]= salty[rand() % (sizeof(salty)-1)]; | 273 | salt[0]= salty[rand() % (sizeof(salty)-1)]; |
285 | salt[1]= salty[rand() % (sizeof(salty)-1)]; | 274 | salt[1]= salty[rand() % (sizeof(salty)-1)]; |
286 | #ifndef Q_OS_WIN32 | 275 | #ifndef Q_OS_WIN32 |
287 | QString cpassword = QString::fromLocal8Bit( | 276 | QString cpassword = QString::fromLocal8Bit( |
288 | crypt( password.mid(8).local8Bit(), salt ) ); | 277 | crypt( password.mid(8).local8Bit(), salt ) ); |
289 | #else | 278 | #else |
290 | //### revise | 279 | //### revise |
291 | QString cpassword(""); | 280 | QString cpassword(""); |
292 | #endif | 281 | #endif |
293 | denials=0; | 282 | denials=0; |
294 | pwds.prepend(cpassword); | 283 | pwds.prepend(cpassword); |
295 | cfg.writeEntry("Passwords",pwds,' '); | 284 | cfg.writeEntry("Passwords",pwds,' '); |
296 | lock--; | 285 | lock--; |
297 | return TRUE; | 286 | return TRUE; |
298 | } | 287 | } |
299 | } | 288 | } |
300 | lock--; | 289 | lock--; |
301 | 290 | ||
302 | return FALSE; | 291 | return FALSE; |
303 | } | 292 | } |
304 | 293 | ||
305 | 294 | ||
306 | ServerPI::ServerPI( int socket, QObject *parent, const char* name ) | 295 | ServerPI::ServerPI( int socket, QObject *parent, const char* name ) |
307 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), | 296 | : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), |
308 | storFileSize(-1) | 297 | storFileSize(-1) |
309 | { | 298 | { |
310 | state = Connected; | 299 | state = Connected; |
311 | 300 | ||
312 | setSocket( socket ); | 301 | setSocket( socket ); |
313 | 302 | ||
314 | peerport = peerPort(); | 303 | peerport = peerPort(); |
315 | peeraddress = peerAddress(); | 304 | peeraddress = peerAddress(); |
316 | 305 | ||
317 | #ifndef INSECURE | 306 | #ifndef INSECURE |
318 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { | 307 | if ( !SyncAuthentication::isAuthorized(peeraddress) ) { |
319 | state = Forbidden; | 308 | state = Forbidden; |
320 | startTimer( 0 ); | 309 | startTimer( 0 ); |
321 | } else | 310 | } else |
322 | #endif | 311 | #endif |
323 | { | 312 | { |
324 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); | 313 | connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); |
325 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 314 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
326 | 315 | ||
327 | passiv = FALSE; | 316 | passiv = FALSE; |
328 | for( int i = 0; i < 4; i++ ) | 317 | for( int i = 0; i < 4; i++ ) |
329 | wait[i] = FALSE; | 318 | wait[i] = FALSE; |
330 | 319 | ||
331 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr | 320 | send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr |
332 | state = Wait_USER; | 321 | state = Wait_USER; |
333 | 322 | ||
334 | dtp = new ServerDTP( this ); | 323 | dtp = new ServerDTP( this ); |
335 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); | 324 | connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); |
336 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); | 325 | connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); |
337 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); | 326 | connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); |
338 | 327 | ||
339 | 328 | ||
340 | directory = QDir::currentDirPath(); | 329 | directory = QDir::currentDirPath(); |
341 | 330 | ||
342 | static int p = 1024; | 331 | static int p = 1024; |
343 | 332 | ||
344 | while ( !serversocket || !serversocket->ok() ) { | 333 | while ( !serversocket || !serversocket->ok() ) { |
345 | delete serversocket; | 334 | delete serversocket; |
346 | serversocket = new ServerSocket( ++p, this ); | 335 | serversocket = new ServerSocket( ++p, this ); |
347 | } | 336 | } |
348 | connect( serversocket, SIGNAL( newIncomming(int) ), | 337 | connect( serversocket, SIGNAL( newIncomming(int) ), |
349 | SLOT( newConnection(int) ) ); | 338 | SLOT( newConnection(int) ) ); |
350 | } | 339 | } |
351 | } | 340 | } |
352 | 341 | ||
353 | ServerPI::~ServerPI() | 342 | ServerPI::~ServerPI() |
354 | { | 343 | { |
355 | close(); | 344 | close(); |
356 | 345 | ||
357 | if ( dtp ) | 346 | if ( dtp ) |
358 | dtp->close(); | 347 | dtp->close(); |
359 | delete dtp; | 348 | delete dtp; |
360 | delete serversocket; | 349 | delete serversocket; |
361 | } | 350 | } |
362 | 351 | ||
363 | bool ServerPI::verifyAuthorised() | 352 | bool ServerPI::verifyAuthorised() |
364 | { | 353 | { |
365 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { | 354 | if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { |
366 | state = Forbidden; | 355 | state = Forbidden; |
367 | return FALSE; | 356 | return FALSE; |
368 | } | 357 | } |
369 | return TRUE; | 358 | return TRUE; |
370 | } | 359 | } |
371 | 360 | ||
372 | void ServerPI::connectionClosed() | 361 | void ServerPI::connectionClosed() |
373 | { | 362 | { |
374 | // qDebug( "Debug: Connection closed" ); | 363 | // odebug << "Debug: Connection closed" << oendl; |
375 | emit connectionClosed(this); | 364 | emit connectionClosed(this); |
376 | } | 365 | } |
377 | 366 | ||
378 | void ServerPI::send( const QString& msg ) | 367 | void ServerPI::send( const QString& msg ) |
379 | { | 368 | { |
380 | QTextStream os( this ); | 369 | QTextStream os( this ); |
381 | os << msg << endl; | 370 | os << msg << endl; |
382 | //qDebug( "Reply: %s", msg.latin1() ); | 371 | //odebug << "Reply: " << msg << "" << oendl; |
383 | } | 372 | } |
384 | 373 | ||
385 | void ServerPI::read() | 374 | void ServerPI::read() |
386 | { | 375 | { |
387 | while ( canReadLine() ) | 376 | while ( canReadLine() ) |
388 | process( readLine().stripWhiteSpace() ); | 377 | process( readLine().stripWhiteSpace() ); |
389 | } | 378 | } |
390 | 379 | ||
391 | bool ServerPI::checkReadFile( const QString& file ) | 380 | bool ServerPI::checkReadFile( const QString& file ) |
392 | { | 381 | { |
393 | QString filename; | 382 | QString filename; |
394 | 383 | ||
395 | if ( file[0] != "/" ) | 384 | if ( file[0] != "/" ) |
396 | filename = directory.path() + "/" + file; | 385 | filename = directory.path() + "/" + file; |
397 | else | 386 | else |
398 | filename = file; | 387 | filename = file; |
399 | 388 | ||
400 | QFileInfo fi( filename ); | 389 | QFileInfo fi( filename ); |
401 | return ( fi.exists() && fi.isReadable() ); | 390 | return ( fi.exists() && fi.isReadable() ); |
402 | } | 391 | } |
403 | 392 | ||
404 | bool ServerPI::checkWriteFile( const QString& file ) | 393 | bool ServerPI::checkWriteFile( const QString& file ) |
405 | { | 394 | { |
406 | QString filename; | 395 | QString filename; |
407 | 396 | ||
408 | if ( file[0] != "/" ) | 397 | if ( file[0] != "/" ) |
409 | filename = directory.path() + "/" + file; | 398 | filename = directory.path() + "/" + file; |
410 | else | 399 | else |
411 | filename = file; | 400 | filename = file; |
412 | 401 | ||
413 | QFileInfo fi( filename ); | 402 | QFileInfo fi( filename ); |
414 | 403 | ||
415 | if ( fi.exists() ) | 404 | if ( fi.exists() ) |
416 | if ( !QFile( filename ).remove() ) | 405 | if ( !QFile( filename ).remove() ) |
417 | return FALSE; | 406 | return FALSE; |
418 | return TRUE; | 407 | return TRUE; |
419 | } | 408 | } |
420 | 409 | ||
421 | void ServerPI::process( const QString& message ) | 410 | void ServerPI::process( const QString& message ) |
422 | { | 411 | { |
423 | //qDebug( "Command: %s", message.latin1() ); | 412 | //odebug << "Command: " << message << "" << oendl; |
424 | 413 | ||
425 | // split message using "," as separator | 414 | // split message using "," as separator |
426 | QStringList msg = QStringList::split( " ", message ); | 415 | QStringList msg = QStringList::split( " ", message ); |
427 | if ( msg.isEmpty() ) return; | 416 | if ( msg.isEmpty() ) return; |
428 | 417 | ||
429 | // command token | 418 | // command token |
430 | QString cmd = msg[0].upper(); | 419 | QString cmd = msg[0].upper(); |
431 | 420 | ||
432 | // argument token | 421 | // argument token |
433 | QString arg; | 422 | QString arg; |
434 | if ( msg.count() >= 2 ) | 423 | if ( msg.count() >= 2 ) |
435 | arg = msg[1]; | 424 | arg = msg[1]; |
436 | 425 | ||
437 | // full argument string | 426 | // full argument string |
438 | QString args; | 427 | QString args; |
439 | if ( msg.count() >= 2 ) { | 428 | if ( msg.count() >= 2 ) { |
440 | QStringList copy( msg ); | 429 | QStringList copy( msg ); |
441 | // FIXME: for Qt3 | 430 | // FIXME: for Qt3 |
442 | // copy.pop_front() | 431 | // copy.pop_front() |
443 | copy.remove( copy.begin() ); | 432 | copy.remove( copy.begin() ); |
444 | args = copy.join( " " ); | 433 | args = copy.join( " " ); |
445 | } | 434 | } |
446 | 435 | ||
447 | //qDebug( "args: %s", args.latin1() ); | 436 | //odebug << "args: " << args << "" << oendl; |
448 | 437 | ||
449 | // we always respond to QUIT, regardless of state | 438 | // we always respond to QUIT, regardless of state |
450 | if ( cmd == "QUIT" ) { | 439 | if ( cmd == "QUIT" ) { |
451 | send( "211 Good bye!" ); // No tr | 440 | send( "211 Good bye!" ); // No tr |
452 | close(); | 441 | close(); |
453 | return; | 442 | return; |
454 | } | 443 | } |
455 | 444 | ||
456 | // connected to client | 445 | // connected to client |
457 | if ( Connected == state ) | 446 | if ( Connected == state ) |
458 | return; | 447 | return; |
459 | 448 | ||
460 | // waiting for user name | 449 | // waiting for user name |
461 | if ( Wait_USER == state ) { | 450 | if ( Wait_USER == state ) { |
462 | 451 | ||
463 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { | 452 | if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { |
464 | send( "530 Please login with USER and PASS" ); // No tr | 453 | send( "530 Please login with USER and PASS" ); // No tr |
465 | return; | 454 | return; |
466 | } | 455 | } |
467 | send( "331 User name ok, need password" ); // No tr | 456 | send( "331 User name ok, need password" ); // No tr |
468 | state = Wait_PASS; | 457 | state = Wait_PASS; |
469 | return; | 458 | return; |
470 | } | 459 | } |
471 | 460 | ||
472 | // waiting for password | 461 | // waiting for password |
473 | if ( Wait_PASS == state ) { | 462 | if ( Wait_PASS == state ) { |
474 | 463 | ||
475 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { | 464 | if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { |
476 | send( "530 Please login with USER and PASS" ); // No tr | 465 | send( "530 Please login with USER and PASS" ); // No tr |
477 | return; | 466 | return; |
478 | } | 467 | } |
479 | send( "230 User logged in, proceed" ); // No tr | 468 | send( "230 User logged in, proceed" ); // No tr |
480 | state = Ready; | 469 | state = Ready; |
481 | return; | 470 | return; |
482 | } | 471 | } |
483 | 472 | ||
484 | // ACCESS CONTROL COMMANDS | 473 | // ACCESS CONTROL COMMANDS |
485 | 474 | ||
486 | // Only an ALLO sent immediately before STOR is valid. | 475 | // Only an ALLO sent immediately before STOR is valid. |
487 | if ( cmd != "STOR" ) | 476 | if ( cmd != "STOR" ) |
488 | storFileSize = -1; | 477 | storFileSize = -1; |
489 | 478 | ||
490 | // account (ACCT) | 479 | // account (ACCT) |
491 | if ( cmd == "ACCT" ) { | 480 | if ( cmd == "ACCT" ) { |
492 | // even wu-ftp does not support it | 481 | // even wu-ftp does not support it |
493 | send( "502 Command not implemented" ); // No tr | 482 | send( "502 Command not implemented" ); // No tr |
494 | } | 483 | } |
495 | 484 | ||
496 | // change working directory (CWD) | 485 | // change working directory (CWD) |
497 | else if ( cmd == "CWD" ) { | 486 | else if ( cmd == "CWD" ) { |
498 | 487 | ||
499 | if ( !args.isEmpty() ) { | 488 | if ( !args.isEmpty() ) { |
500 | if ( directory.cd( args, TRUE ) ) | 489 | if ( directory.cd( args, TRUE ) ) |
501 | send( "250 Requested file action okay, completed" ); // No tr | 490 | send( "250 Requested file action okay, completed" ); // No tr |
502 | else | 491 | else |
503 | send( "550 Requested action not taken" ); // No tr | 492 | send( "550 Requested action not taken" ); // No tr |
504 | } | 493 | } |
505 | else | 494 | else |
506 | send( "500 Syntax error, command unrecognized" ); // No tr | 495 | send( "500 Syntax error, command unrecognized" ); // No tr |
507 | } | 496 | } |
508 | 497 | ||
509 | // change to parent directory (CDUP) | 498 | // change to parent directory (CDUP) |
510 | else if ( cmd == "CDUP" ) { | 499 | else if ( cmd == "CDUP" ) { |
511 | if ( directory.cdUp() ) | 500 | if ( directory.cdUp() ) |
512 | send( "250 Requested file action okay, completed" ); // No tr | 501 | send( "250 Requested file action okay, completed" ); // No tr |
513 | else | 502 | else |
514 | send( "550 Requested action not taken" ); // No tr | 503 | send( "550 Requested action not taken" ); // No tr |
515 | } | 504 | } |
516 | 505 | ||
517 | // structure mount (SMNT) | 506 | // structure mount (SMNT) |
518 | else if ( cmd == "SMNT" ) { | 507 | else if ( cmd == "SMNT" ) { |
519 | // even wu-ftp does not support it | 508 | // even wu-ftp does not support it |
520 | send( "502 Command not implemented" ); // No tr | 509 | send( "502 Command not implemented" ); // No tr |
521 | } | 510 | } |
522 | 511 | ||
523 | // reinitialize (REIN) | 512 | // reinitialize (REIN) |
524 | else if ( cmd == "REIN" ) { | 513 | else if ( cmd == "REIN" ) { |
525 | // even wu-ftp does not support it | 514 | // even wu-ftp does not support it |
526 | send( "502 Command not implemented" ); // No tr | 515 | send( "502 Command not implemented" ); // No tr |
527 | } | 516 | } |
528 | 517 | ||
529 | 518 | ||
530 | // TRANSFER PARAMETER COMMANDS | 519 | // TRANSFER PARAMETER COMMANDS |
531 | 520 | ||
532 | 521 | ||
533 | // data port (PORT) | 522 | // data port (PORT) |
534 | else if ( cmd == "PORT" ) { | 523 | else if ( cmd == "PORT" ) { |
535 | if ( parsePort( arg ) ) | 524 | if ( parsePort( arg ) ) |
536 | send( "200 Command okay" ); // No tr | 525 | send( "200 Command okay" ); // No tr |
537 | else | 526 | else |
538 | send( "500 Syntax error, command unrecognized" ); // No tr | 527 | send( "500 Syntax error, command unrecognized" ); // No tr |
539 | } | 528 | } |
540 | 529 | ||
541 | // passive (PASV) | 530 | // passive (PASV) |
542 | else if ( cmd == "PASV" ) { | 531 | else if ( cmd == "PASV" ) { |
543 | passiv = TRUE; | 532 | passiv = TRUE; |
544 | send( "227 Entering Passive Mode (" // No tr | 533 | send( "227 Entering Passive Mode (" // No tr |
545 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," | 534 | + address().toString().replace( QRegExp( "\\." ), "," ) + "," |
546 | + QString::number( ( serversocket->port() ) >> 8 ) + "," | 535 | + QString::number( ( serversocket->port() ) >> 8 ) + "," |
547 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); | 536 | + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); |
548 | } | 537 | } |
549 | 538 | ||
550 | // representation type (TYPE) | 539 | // representation type (TYPE) |
551 | else if ( cmd == "TYPE" ) { | 540 | else if ( cmd == "TYPE" ) { |
552 | if ( arg.upper() == "A" || arg.upper() == "I" ) | 541 | if ( arg.upper() == "A" || arg.upper() == "I" ) |
553 | send( "200 Command okay" ); // No tr | 542 | send( "200 Command okay" ); // No tr |
554 | else | 543 | else |
555 | send( "504 Command not implemented for that parameter" ); // No tr | 544 | send( "504 Command not implemented for that parameter" ); // No tr |
556 | } | 545 | } |
557 | 546 | ||
558 | // file structure (STRU) | 547 | // file structure (STRU) |
559 | else if ( cmd == "STRU" ) { | 548 | else if ( cmd == "STRU" ) { |
560 | if ( arg.upper() == "F" ) | 549 | if ( arg.upper() == "F" ) |
561 | send( "200 Command okay" ); // No tr | 550 | send( "200 Command okay" ); // No tr |
562 | else | 551 | else |
563 | send( "504 Command not implemented for that parameter" ); // No tr | 552 | send( "504 Command not implemented for that parameter" ); // No tr |
564 | } | 553 | } |
565 | 554 | ||
566 | // transfer mode (MODE) | 555 | // transfer mode (MODE) |
567 | else if ( cmd == "MODE" ) { | 556 | else if ( cmd == "MODE" ) { |
568 | if ( arg.upper() == "S" ) | 557 | if ( arg.upper() == "S" ) |
569 | send( "200 Command okay" ); // No tr | 558 | send( "200 Command okay" ); // No tr |
570 | else | 559 | else |
571 | send( "504 Command not implemented for that parameter" ); // No tr | 560 | send( "504 Command not implemented for that parameter" ); // No tr |
572 | } | 561 | } |
573 | 562 | ||
574 | 563 | ||
575 | // FTP SERVICE COMMANDS | 564 | // FTP SERVICE COMMANDS |
576 | 565 | ||
577 | 566 | ||
578 | // retrieve (RETR) | 567 | // retrieve (RETR) |
579 | else if ( cmd == "RETR" ) | 568 | else if ( cmd == "RETR" ) |
580 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) | 569 | if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) |
581 | || backupRestoreGzip( absFilePath( args ) ) ) { | 570 | || backupRestoreGzip( absFilePath( args ) ) ) { |
582 | send( "150 File status okay" ); // No tr | 571 | send( "150 File status okay" ); // No tr |
583 | sendFile( absFilePath( args ) ); | 572 | sendFile( absFilePath( args ) ); |
584 | } | 573 | } |
585 | else { | 574 | else { |
586 | qDebug("550 Requested action not taken"); | 575 | odebug << "550 Requested action not taken" << oendl; |
587 | send( "550 Requested action not taken" ); // No tr | 576 | send( "550 Requested action not taken" ); // No tr |
588 | } | 577 | } |
589 | 578 | ||
590 | // store (STOR) | 579 | // store (STOR) |
591 | else if ( cmd == "STOR" ) | 580 | else if ( cmd == "STOR" ) |
592 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { | 581 | if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { |
593 | send( "150 File status okay" ); // No tr | 582 | send( "150 File status okay" ); // No tr |
594 | retrieveFile( absFilePath( args ) ); | 583 | retrieveFile( absFilePath( args ) ); |
595 | } | 584 | } |
596 | else | 585 | else |
597 | send( "550 Requested action not taken" ); // No tr | 586 | send( "550 Requested action not taken" ); // No tr |
598 | 587 | ||
599 | // store unique (STOU) | 588 | // store unique (STOU) |
600 | else if ( cmd == "STOU" ) { | 589 | else if ( cmd == "STOU" ) { |
601 | send( "502 Command not implemented" ); // No tr | 590 | send( "502 Command not implemented" ); // No tr |
602 | } | 591 | } |
603 | 592 | ||
604 | // append (APPE) | 593 | // append (APPE) |
605 | else if ( cmd == "APPE" ) { | 594 | else if ( cmd == "APPE" ) { |
606 | send( "502 Command not implemented" ); // No tr | 595 | send( "502 Command not implemented" ); // No tr |
607 | } | 596 | } |
608 | 597 | ||
609 | // allocate (ALLO) | 598 | // allocate (ALLO) |
610 | else if ( cmd == "ALLO" ) { | 599 | else if ( cmd == "ALLO" ) { |
611 | storFileSize = args.toInt(); | 600 | storFileSize = args.toInt(); |
612 | send( "200 Command okay" ); // No tr | 601 | send( "200 Command okay" ); // No tr |
613 | } | 602 | } |
614 | 603 | ||
615 | // restart (REST) | 604 | // restart (REST) |
616 | else if ( cmd == "REST" ) { | 605 | else if ( cmd == "REST" ) { |
617 | send( "502 Command not implemented" ); // No tr | 606 | send( "502 Command not implemented" ); // No tr |
618 | } | 607 | } |
619 | 608 | ||
620 | // rename from (RNFR) | 609 | // rename from (RNFR) |
621 | else if ( cmd == "RNFR" ) { | 610 | else if ( cmd == "RNFR" ) { |
622 | renameFrom = QString::null; | 611 | renameFrom = QString::null; |
623 | if ( args.isEmpty() ) | 612 | if ( args.isEmpty() ) |
624 | send( "500 Syntax error, command unrecognized" ); // No tr | 613 | send( "500 Syntax error, command unrecognized" ); // No tr |
625 | else { | 614 | else { |
626 | QFile file( absFilePath( args ) ); | 615 | QFile file( absFilePath( args ) ); |
627 | if ( file.exists() ) { | 616 | if ( file.exists() ) { |
628 | send( "350 File exists, ready for destination name" ); // No tr | 617 | send( "350 File exists, ready for destination name" ); // No tr |
629 | renameFrom = absFilePath( args ); | 618 | renameFrom = absFilePath( args ); |
630 | } | 619 | } |
631 | else | 620 | else |
632 | send( "550 Requested action not taken" ); // No tr | 621 | send( "550 Requested action not taken" ); // No tr |
633 | } | 622 | } |
634 | } | 623 | } |
635 | 624 | ||
636 | // rename to (RNTO) | 625 | // rename to (RNTO) |
637 | else if ( cmd == "RNTO" ) { | 626 | else if ( cmd == "RNTO" ) { |
638 | if ( lastCommand != "RNFR" ) | 627 | if ( lastCommand != "RNFR" ) |
639 | send( "503 Bad sequence of commands" ); // No tr | 628 | send( "503 Bad sequence of commands" ); // No tr |
640 | else if ( args.isEmpty() ) | 629 | else if ( args.isEmpty() ) |
641 | send( "500 Syntax error, command unrecognized" ); // No tr | 630 | send( "500 Syntax error, command unrecognized" ); // No tr |
642 | else { | 631 | else { |
643 | QDir dir( absFilePath( args ) ); | 632 | QDir dir( absFilePath( args ) ); |
644 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) | 633 | if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) |
645 | send( "250 Requested file action okay, completed." ); // No tr | 634 | send( "250 Requested file action okay, completed." ); // No tr |
646 | else | 635 | else |
647 | send( "550 Requested action not taken" ); // No tr | 636 | send( "550 Requested action not taken" ); // No tr |
648 | } | 637 | } |
649 | } | 638 | } |
650 | 639 | ||
651 | // abort (ABOR) | 640 | // abort (ABOR) |
652 | else if ( cmd.contains( "ABOR" ) ) { | 641 | else if ( cmd.contains( "ABOR" ) ) { |
653 | dtp->close(); | 642 | dtp->close(); |
654 | if ( dtp->dtpMode() != ServerDTP::Idle ) | 643 | if ( dtp->dtpMode() != ServerDTP::Idle ) |
655 | send( "426 Connection closed; transfer aborted" ); // No tr | 644 | send( "426 Connection closed; transfer aborted" ); // No tr |
656 | else | 645 | else |
657 | send( "226 Closing data connection" ); // No tr | 646 | send( "226 Closing data connection" ); // No tr |
658 | } | 647 | } |
659 | 648 | ||
660 | // delete (DELE) | 649 | // delete (DELE) |
661 | else if ( cmd == "DELE" ) { | 650 | else if ( cmd == "DELE" ) { |
662 | if ( args.isEmpty() ) | 651 | if ( args.isEmpty() ) |
663 | send( "500 Syntax error, command unrecognized" ); // No tr | 652 | send( "500 Syntax error, command unrecognized" ); // No tr |
664 | else { | 653 | else { |
665 | QFile file( absFilePath( args ) ) ; | 654 | QFile file( absFilePath( args ) ) ; |
666 | if ( file.remove() ) { | 655 | if ( file.remove() ) { |
667 | send( "250 Requested file action okay, completed" ); // No tr | 656 | send( "250 Requested file action okay, completed" ); // No tr |
668 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 657 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
669 | e << file.name(); | 658 | e << file.name(); |
670 | } else { | 659 | } else { |
671 | send( "550 Requested action not taken" ); // No tr | 660 | send( "550 Requested action not taken" ); // No tr |
672 | } | 661 | } |
673 | } | 662 | } |
674 | } | 663 | } |
675 | 664 | ||
676 | // remove directory (RMD) | 665 | // remove directory (RMD) |
677 | else if ( cmd == "RMD" ) { | 666 | else if ( cmd == "RMD" ) { |
678 | if ( args.isEmpty() ) | 667 | if ( args.isEmpty() ) |
679 | send( "500 Syntax error, command unrecognized" ); // No tr | 668 | send( "500 Syntax error, command unrecognized" ); // No tr |
680 | else { | 669 | else { |
681 | QDir dir; | 670 | QDir dir; |
682 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) | 671 | if ( dir.rmdir( absFilePath( args ), TRUE ) ) |
683 | send( "250 Requested file action okay, completed" ); // No tr | 672 | send( "250 Requested file action okay, completed" ); // No tr |
684 | else | 673 | else |
685 | send( "550 Requested action not taken" ); // No tr | 674 | send( "550 Requested action not taken" ); // No tr |
686 | } | 675 | } |
687 | } | 676 | } |
688 | 677 | ||
689 | // make directory (MKD) | 678 | // make directory (MKD) |
690 | else if ( cmd == "MKD" ) { | 679 | else if ( cmd == "MKD" ) { |
691 | if ( args.isEmpty() ) { | 680 | if ( args.isEmpty() ) { |
692 | qDebug(" Error: no arg"); | 681 | odebug << " Error: no arg" << oendl; |
693 | send( "500 Syntax error, command unrecognized" ); // No tr | 682 | send( "500 Syntax error, command unrecognized" ); // No tr |
694 | } | 683 | } |
695 | else { | 684 | else { |
696 | QDir dir; | 685 | QDir dir; |
697 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) | 686 | if ( dir.mkdir( absFilePath( args ), TRUE ) ) |
698 | send( "250 Requested file action okay, completed." ); // No tr | 687 | send( "250 Requested file action okay, completed." ); // No tr |
699 | else | 688 | else |
700 | send( "550 Requested action not taken" ); // No tr | 689 | send( "550 Requested action not taken" ); // No tr |
701 | } | 690 | } |
702 | } | 691 | } |
703 | 692 | ||
704 | // print working directory (PWD) | 693 | // print working directory (PWD) |
705 | else if ( cmd == "PWD" ) { | 694 | else if ( cmd == "PWD" ) { |
706 | send( "257 \"" + directory.path() +"\"" ); | 695 | send( "257 \"" + directory.path() +"\"" ); |
707 | } | 696 | } |
708 | 697 | ||
709 | // list (LIST) | 698 | // list (LIST) |
710 | else if ( cmd == "LIST" ) { | 699 | else if ( cmd == "LIST" ) { |
711 | if ( sendList( absFilePath( args ) ) ) | 700 | if ( sendList( absFilePath( args ) ) ) |
712 | send( "150 File status okay" ); // No tr | 701 | send( "150 File status okay" ); // No tr |
713 | else | 702 | else |
714 | send( "500 Syntax error, command unrecognized" ); // No tr | 703 | send( "500 Syntax error, command unrecognized" ); // No tr |
715 | } | 704 | } |
716 | 705 | ||
717 | // size (SIZE) | 706 | // size (SIZE) |
718 | else if ( cmd == "SIZE" ) { | 707 | else if ( cmd == "SIZE" ) { |
719 | QString filePath = absFilePath( args ); | 708 | QString filePath = absFilePath( args ); |
720 | QFileInfo fi( filePath ); | 709 | QFileInfo fi( filePath ); |
721 | bool gzipfile = backupRestoreGzip( filePath ); | 710 | bool gzipfile = backupRestoreGzip( filePath ); |
722 | if ( !fi.exists() && !gzipfile ) | 711 | if ( !fi.exists() && !gzipfile ) |
723 | send( "500 Syntax error, command unrecognized" ); // No tr | 712 | send( "500 Syntax error, command unrecognized" ); // No tr |
724 | else { | 713 | else { |
725 | if ( !gzipfile ) | 714 | if ( !gzipfile ) |
726 | send( "213 " + QString::number( fi.size() ) ); | 715 | send( "213 " + QString::number( fi.size() ) ); |
727 | else { | 716 | else { |
728 | Process duproc( QString("du") ); | 717 | Process duproc( QString("du") ); |
729 | duproc.addArgument("-s"); | 718 | duproc.addArgument("-s"); |
730 | QString in, out; | 719 | QString in, out; |
731 | if ( !duproc.exec(in, out) ) { | 720 | if ( !duproc.exec(in, out) ) { |
732 | qDebug("du process failed; just sending back 1K"); | 721 | odebug << "du process failed; just sending back 1K" << oendl; |
733 | send( "213 1024"); | 722 | send( "213 1024"); |
734 | } | 723 | } |
735 | else { | 724 | else { |
736 | QString size = out.left( out.find("\t") ); | 725 | QString size = out.left( out.find("\t") ); |
737 | int guess = size.toInt()/5; | 726 | int guess = size.toInt()/5; |
738 | if ( filePath.contains("doc") ) // No tr | 727 | if ( filePath.contains("doc") ) // No tr |
739 | guess *= 1000; | 728 | guess *= 1000; |
740 | qDebug("sending back gzip guess of %d", guess); | 729 | odebug << "sending back gzip guess of " << guess << "" << oendl; |
741 | send( "213 " + QString::number(guess) ); | 730 | send( "213 " + QString::number(guess) ); |
742 | } | 731 | } |
743 | } | 732 | } |
744 | } | 733 | } |
745 | } | 734 | } |
746 | // name list (NLST) | 735 | // name list (NLST) |
747 | else if ( cmd == "NLST" ) { | 736 | else if ( cmd == "NLST" ) { |
748 | send( "502 Command not implemented" ); // No tr | 737 | send( "502 Command not implemented" ); // No tr |
749 | } | 738 | } |
750 | 739 | ||
751 | // site parameters (SITE) | 740 | // site parameters (SITE) |
752 | else if ( cmd == "SITE" ) { | 741 | else if ( cmd == "SITE" ) { |
753 | send( "502 Command not implemented" ); // No tr | 742 | send( "502 Command not implemented" ); // No tr |
754 | } | 743 | } |
755 | 744 | ||
756 | // system (SYST) | 745 | // system (SYST) |
757 | else if ( cmd == "SYST" ) { | 746 | else if ( cmd == "SYST" ) { |
758 | send( "215 UNIX Type: L8" ); // No tr | 747 | send( "215 UNIX Type: L8" ); // No tr |
759 | } | 748 | } |
760 | 749 | ||
761 | // status (STAT) | 750 | // status (STAT) |
762 | else if ( cmd == "STAT" ) { | 751 | else if ( cmd == "STAT" ) { |
763 | send( "502 Command not implemented" ); // No tr | 752 | send( "502 Command not implemented" ); // No tr |
764 | } | 753 | } |
765 | 754 | ||
766 | // help (HELP ) | 755 | // help (HELP ) |
767 | else if ( cmd == "HELP" ) { | 756 | else if ( cmd == "HELP" ) { |
768 | send( "502 Command not implemented" ); // No tr | 757 | send( "502 Command not implemented" ); // No tr |
769 | } | 758 | } |
770 | 759 | ||
771 | // noop (NOOP) | 760 | // noop (NOOP) |
772 | else if ( cmd == "NOOP" ) { | 761 | else if ( cmd == "NOOP" ) { |
773 | send( "200 Command okay" ); // No tr | 762 | send( "200 Command okay" ); // No tr |
774 | } | 763 | } |
775 | 764 | ||
776 | // not implemented | 765 | // not implemented |
777 | else | 766 | else |
778 | send( "502 Command not implemented" ); // No tr | 767 | send( "502 Command not implemented" ); // No tr |
779 | 768 | ||
780 | lastCommand = cmd; | 769 | lastCommand = cmd; |
781 | } | 770 | } |
782 | 771 | ||
783 | bool ServerPI::backupRestoreGzip( const QString &file ) | 772 | bool ServerPI::backupRestoreGzip( const QString &file ) |
784 | { | 773 | { |
785 | return (file.find( "backup" ) != -1 && // No tr | 774 | return (file.find( "backup" ) != -1 && // No tr |
786 | file.findRev( ".tgz" ) == (int)file.length()-4 ); | 775 | file.findRev( ".tgz" ) == (int)file.length()-4 ); |
787 | } | 776 | } |
788 | 777 | ||
789 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) | 778 | bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) |
790 | { | 779 | { |
791 | if ( file.find( "backup" ) != -1 && // No tr | 780 | if ( file.find( "backup" ) != -1 && // No tr |
792 | file.findRev( ".tgz" ) == (int)file.length()-4 ) { | 781 | file.findRev( ".tgz" ) == (int)file.length()-4 ) { |
793 | QFileInfo info( file ); | 782 | QFileInfo info( file ); |
794 | targets = info.dirPath( TRUE ); | 783 | targets = info.dirPath( TRUE ); |
795 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), | 784 | qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), |
796 | targets.join(" ").latin1() ); | 785 | targets.join(" ").latin1() ); |
797 | return true; | 786 | return true; |
798 | } | 787 | } |
799 | return false; | 788 | return false; |
800 | } | 789 | } |
801 | 790 | ||
802 | void ServerPI::sendFile( const QString& file ) | 791 | void ServerPI::sendFile( const QString& file ) |
803 | { | 792 | { |
804 | if ( passiv ) { | 793 | if ( passiv ) { |
805 | wait[SendFile] = TRUE; | 794 | wait[SendFile] = TRUE; |
806 | waitfile = file; | 795 | waitfile = file; |
807 | if ( waitsocket ) | 796 | if ( waitsocket ) |
808 | newConnection( waitsocket ); | 797 | newConnection( waitsocket ); |
809 | } | 798 | } |
810 | else { | 799 | else { |
811 | QStringList targets; | 800 | QStringList targets; |
812 | if ( backupRestoreGzip( file, targets ) ) | 801 | if ( backupRestoreGzip( file, targets ) ) |
813 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); | 802 | dtp->sendGzipFile( file, targets, peeraddress, peerport ); |
814 | else dtp->sendFile( file, peeraddress, peerport ); | 803 | else dtp->sendFile( file, peeraddress, peerport ); |
815 | } | 804 | } |
816 | } | 805 | } |
817 | 806 | ||
818 | void ServerPI::retrieveFile( const QString& file ) | 807 | void ServerPI::retrieveFile( const QString& file ) |
819 | { | 808 | { |
820 | if ( passiv ) { | 809 | if ( passiv ) { |
821 | wait[RetrieveFile] = TRUE; | 810 | wait[RetrieveFile] = TRUE; |
822 | waitfile = file; | 811 | waitfile = file; |
823 | if ( waitsocket ) | 812 | if ( waitsocket ) |
824 | newConnection( waitsocket ); | 813 | newConnection( waitsocket ); |
825 | } | 814 | } |
826 | else { | 815 | else { |
827 | QStringList targets; | 816 | QStringList targets; |
828 | if ( backupRestoreGzip( file, targets ) ) | 817 | if ( backupRestoreGzip( file, targets ) ) |
829 | dtp->retrieveGzipFile( file, peeraddress, peerport ); | 818 | dtp->retrieveGzipFile( file, peeraddress, peerport ); |
830 | else | 819 | else |
831 | dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); | 820 | dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); |
832 | } | 821 | } |
833 | } | 822 | } |
834 | 823 | ||
835 | bool ServerPI::parsePort( const QString& pp ) | 824 | bool ServerPI::parsePort( const QString& pp ) |
836 | { | 825 | { |
837 | QStringList p = QStringList::split( ",", pp ); | 826 | QStringList p = QStringList::split( ",", pp ); |
838 | if ( p.count() != 6 ) return FALSE; | 827 | if ( p.count() != 6 ) return FALSE; |
839 | 828 | ||
840 | // h1,h2,h3,h4,p1,p2 | 829 | // h1,h2,h3,h4,p1,p2 |
841 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + | 830 | peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + |
842 | ( p[2].toInt() << 8 ) + p[3].toInt() ); | 831 | ( p[2].toInt() << 8 ) + p[3].toInt() ); |
843 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); | 832 | peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); |
844 | return TRUE; | 833 | return TRUE; |
845 | } | 834 | } |
846 | 835 | ||
847 | void ServerPI::dtpCompleted() | 836 | void ServerPI::dtpCompleted() |
848 | { | 837 | { |
849 | send( "226 Closing data connection, file transfer successful" ); // No tr | 838 | send( "226 Closing data connection, file transfer successful" ); // No tr |
850 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { | 839 | if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { |
851 | QString fn = dtp->fileName(); | 840 | QString fn = dtp->fileName(); |
852 | if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { | 841 | if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { |
853 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); | 842 | QCopEnvelope e("QPE/System", "linkChanged(QString)" ); |
854 | e << fn; | 843 | e << fn; |
855 | } | 844 | } |
856 | } | 845 | } |
857 | waitsocket = 0; | 846 | waitsocket = 0; |
858 | dtp->close(); | 847 | dtp->close(); |
859 | storFileSize = -1; | 848 | storFileSize = -1; |
860 | } | 849 | } |
861 | 850 | ||
862 | void ServerPI::dtpFailed() | 851 | void ServerPI::dtpFailed() |
863 | { | 852 | { |
864 | dtp->close(); | 853 | dtp->close(); |
865 | waitsocket = 0; | 854 | waitsocket = 0; |
866 | send( "451 Requested action aborted: local error in processing" ); // No tr | 855 | send( "451 Requested action aborted: local error in processing" ); // No tr |
867 | storFileSize = -1; | 856 | storFileSize = -1; |
868 | } | 857 | } |
869 | 858 | ||
870 | void ServerPI::dtpError( int ) | 859 | void ServerPI::dtpError( int ) |
871 | { | 860 | { |
872 | dtp->close(); | 861 | dtp->close(); |
873 | waitsocket = 0; | 862 | waitsocket = 0; |
874 | send( "451 Requested action aborted: local error in processing" ); // No tr | 863 | send( "451 Requested action aborted: local error in processing" ); // No tr |
875 | storFileSize = -1; | 864 | storFileSize = -1; |
876 | } | 865 | } |
877 | 866 | ||
878 | bool ServerPI::sendList( const QString& arg ) | 867 | bool ServerPI::sendList( const QString& arg ) |
879 | { | 868 | { |
880 | QByteArray listing; | 869 | QByteArray listing; |
881 | QBuffer buffer( listing ); | 870 | QBuffer buffer( listing ); |
882 | 871 | ||
883 | if ( !buffer.open( IO_WriteOnly ) ) | 872 | if ( !buffer.open( IO_WriteOnly ) ) |
884 | return FALSE; | 873 | return FALSE; |
885 | 874 | ||
886 | QTextStream ts( &buffer ); | 875 | QTextStream ts( &buffer ); |
887 | QString fn = arg; | 876 | QString fn = arg; |
888 | 877 | ||
889 | if ( fn.isEmpty() ) | 878 | if ( fn.isEmpty() ) |
890 | fn = directory.path(); | 879 | fn = directory.path(); |
891 | 880 | ||
892 | QFileInfo fi( fn ); | 881 | QFileInfo fi( fn ); |
893 | if ( !fi.exists() ) return FALSE; | 882 | if ( !fi.exists() ) return FALSE; |
894 | 883 | ||
895 | // return file listing | 884 | // return file listing |
896 | if ( fi.isFile() ) { | 885 | if ( fi.isFile() ) { |
897 | ts << fileListing( &fi ) << endl; | 886 | ts << fileListing( &fi ) << endl; |
898 | } | 887 | } |
899 | 888 | ||
900 | // return directory listing | 889 | // return directory listing |
901 | else if ( fi.isDir() ) { | 890 | else if ( fi.isDir() ) { |
902 | QDir dir( fn ); | 891 | QDir dir( fn ); |
903 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); | 892 | const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); |
904 | 893 | ||
905 | QFileInfoListIterator it( *list ); | 894 | QFileInfoListIterator it( *list ); |
906 | QFileInfo *info; | 895 | QFileInfo *info; |
907 | 896 | ||
908 | unsigned long total = 0; | 897 | unsigned long total = 0; |
909 | while ( ( info = it.current() ) ) { | 898 | while ( ( info = it.current() ) ) { |
910 | if ( info->fileName() != "." && info->fileName() != ".." ) | 899 | if ( info->fileName() != "." && info->fileName() != ".." ) |
911 | total += info->size(); | 900 | total += info->size(); |
912 | ++it; | 901 | ++it; |
913 | } | 902 | } |
914 | 903 | ||
915 | ts << "total " << QString::number( total / 1024 ) << endl; // No tr | 904 | ts << "total " << QString::number( total / 1024 ) << endl; // No tr |
916 | 905 | ||
917 | it.toFirst(); | 906 | it.toFirst(); |
918 | while ( ( info = it.current() ) ) { | 907 | while ( ( info = it.current() ) ) { |
919 | if ( info->fileName() == "." || info->fileName() == ".." ) { | 908 | if ( info->fileName() == "." || info->fileName() == ".." ) { |
920 | ++it; | 909 | ++it; |
921 | continue; | 910 | continue; |
922 | } | 911 | } |
923 | ts << fileListing( info ) << endl; | 912 | ts << fileListing( info ) << endl; |
924 | ++it; | 913 | ++it; |
925 | } | 914 | } |
926 | } | 915 | } |
927 | 916 | ||
928 | if ( passiv ) { | 917 | if ( passiv ) { |
929 | waitarray = buffer.buffer(); | 918 | waitarray = buffer.buffer(); |
930 | wait[SendByteArray] = TRUE; | 919 | wait[SendByteArray] = TRUE; |
931 | if ( waitsocket ) | 920 | if ( waitsocket ) |
932 | newConnection( waitsocket ); | 921 | newConnection( waitsocket ); |
933 | } | 922 | } |
934 | else | 923 | else |
935 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); | 924 | dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); |
936 | return TRUE; | 925 | return TRUE; |
937 | } | 926 | } |
938 | 927 | ||
939 | QString ServerPI::fileListing( QFileInfo *info ) | 928 | QString ServerPI::fileListing( QFileInfo *info ) |
940 | { | 929 | { |
941 | if ( !info ) return QString::null; | 930 | if ( !info ) return QString::null; |
942 | QString s; | 931 | QString s; |
943 | 932 | ||
944 | // type char | 933 | // type char |
945 | if ( info->isDir() ) | 934 | if ( info->isDir() ) |
946 | s += "d"; | 935 | s += "d"; |
947 | else if ( info->isSymLink() ) | 936 | else if ( info->isSymLink() ) |
948 | s += "l"; | 937 | s += "l"; |
949 | else | 938 | else |
950 | s += "-"; | 939 | s += "-"; |
951 | 940 | ||
952 | // permisson string | 941 | // permisson string |
953 | s += permissionString( info ) + " "; | 942 | s += permissionString( info ) + " "; |
954 | 943 | ||
955 | // number of hardlinks | 944 | // number of hardlinks |
956 | int subdirs = 1; | 945 | int subdirs = 1; |
957 | 946 | ||
958 | if ( info->isDir() ) | 947 | if ( info->isDir() ) |
959 | subdirs = 2; | 948 | subdirs = 2; |
960 | // FIXME : this is to slow | 949 | // FIXME : this is to slow |
961 | //if ( info->isDir() ) | 950 | //if ( info->isDir() ) |
962 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); | 951 | //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); |
963 | 952 | ||
964 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; | 953 | s += QString::number( subdirs ).rightJustify( 3, ' ', TRUE ) + " "; |
965 | 954 | ||
966 | // owner | 955 | // owner |
967 | QString o = info->owner(); | 956 | QString o = info->owner(); |
968 | if ( o.isEmpty() ) | 957 | if ( o.isEmpty() ) |
969 | o = QString::number(info->ownerId()); | 958 | o = QString::number(info->ownerId()); |
970 | s += o.leftJustify( 8, ' ', TRUE ) + " "; | 959 | s += o.leftJustify( 8, ' ', TRUE ) + " "; |
971 | 960 | ||
972 | // group | 961 | // group |
973 | QString g = info->group(); | 962 | QString g = info->group(); |
974 | if ( g.isEmpty() ) | 963 | if ( g.isEmpty() ) |
975 | g = QString::number(info->groupId()); | 964 | g = QString::number(info->groupId()); |
976 | s += g.leftJustify( 8, ' ', TRUE ) + " "; | 965 | s += g.leftJustify( 8, ' ', TRUE ) + " "; |
977 | 966 | ||
978 | // file size in bytes | 967 | // file size in bytes |
979 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; | 968 | s += QString::number( info->size() ).rightJustify( 9, ' ', TRUE ) + " "; |
980 | 969 | ||
981 | // last modified date | 970 | // last modified date |
982 | QDate date = info->lastModified().date(); | 971 | QDate date = info->lastModified().date(); |
983 | QTime time = info->lastModified().time(); | 972 | QTime time = info->lastModified().time(); |
984 | s += date.monthName( date.month() ) + " " | 973 | s += date.monthName( date.month() ) + " " |
985 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " | 974 | + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " |
986 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" | 975 | + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" |
987 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; | 976 | + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; |
988 | 977 | ||
989 | // file name | 978 | // file name |
990 | s += info->fileName(); | 979 | s += info->fileName(); |
991 | 980 | ||
992 | return s; | 981 | return s; |
993 | } | 982 | } |
994 | 983 | ||
995 | QString ServerPI::permissionString( QFileInfo *info ) | 984 | QString ServerPI::permissionString( QFileInfo *info ) |
996 | { | 985 | { |
997 | if ( !info ) return QString( "---------" ); | 986 | if ( !info ) return QString( "---------" ); |
998 | QString s; | 987 | QString s; |
999 | 988 | ||
1000 | // user | 989 | // user |
1001 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; | 990 | if ( info->permission( QFileInfo::ReadUser ) ) s += "r"; |
1002 | else s += "-"; | 991 | else s += "-"; |
1003 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; | 992 | if ( info->permission( QFileInfo::WriteUser ) ) s += "w"; |
1004 | else s += "-"; | 993 | else s += "-"; |
1005 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; | 994 | if ( info->permission( QFileInfo::ExeUser ) ) s += "x"; |
1006 | else s += "-"; | 995 | else s += "-"; |
1007 | 996 | ||
1008 | // group | 997 | // group |
1009 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; | 998 | if ( info->permission( QFileInfo::ReadGroup ) ) s += "r"; |
1010 | else s += "-"; | 999 | else s += "-"; |
1011 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; | 1000 | if ( info->permission( QFileInfo::WriteGroup ) )s += "w"; |
1012 | else s += "-"; | 1001 | else s += "-"; |
1013 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; | 1002 | if ( info->permission( QFileInfo::ExeGroup ) ) s += "x"; |
1014 | else s += "-"; | 1003 | else s += "-"; |
1015 | 1004 | ||
1016 | // exec | 1005 | // exec |
1017 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; | 1006 | if ( info->permission( QFileInfo::ReadOther ) ) s += "r"; |
1018 | else s += "-"; | 1007 | else s += "-"; |
1019 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; | 1008 | if ( info->permission( QFileInfo::WriteOther ) ) s += "w"; |
1020 | else s += "-"; | 1009 | else s += "-"; |
1021 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; | 1010 | if ( info->permission( QFileInfo::ExeOther ) ) s += "x"; |
1022 | else s += "-"; | 1011 | else s += "-"; |
1023 | 1012 | ||
1024 | return s; | 1013 | return s; |
1025 | } | 1014 | } |
1026 | 1015 | ||
1027 | void ServerPI::newConnection( int socket ) | 1016 | void ServerPI::newConnection( int socket ) |
1028 | { | 1017 | { |
1029 | //qDebug( "New incomming connection" ); | 1018 | //odebug << "New incomming connection" << oendl; |
1030 | 1019 | ||
1031 | if ( !passiv ) return; | 1020 | if ( !passiv ) return; |
1032 | 1021 | ||
1033 | if ( wait[SendFile] ) { | 1022 | if ( wait[SendFile] ) { |
1034 | QStringList targets; | 1023 | QStringList targets; |
1035 | if ( backupRestoreGzip( waitfile, targets ) ) | 1024 | if ( backupRestoreGzip( waitfile, targets ) ) |
1036 | dtp->sendGzipFile( waitfile, targets ); | 1025 | dtp->sendGzipFile( waitfile, targets ); |
1037 | else | 1026 | else |
1038 | dtp->sendFile( waitfile ); | 1027 | dtp->sendFile( waitfile ); |
1039 | dtp->setSocket( socket ); | 1028 | dtp->setSocket( socket ); |
1040 | } | 1029 | } |
1041 | else if ( wait[RetrieveFile] ) { | 1030 | else if ( wait[RetrieveFile] ) { |
1042 | qDebug("check retrieve file"); | 1031 | odebug << "check retrieve file" << oendl; |
1043 | if ( backupRestoreGzip( waitfile ) ) | 1032 | if ( backupRestoreGzip( waitfile ) ) |
1044 | dtp->retrieveGzipFile( waitfile ); | 1033 | dtp->retrieveGzipFile( waitfile ); |
1045 | else | 1034 | else |
1046 | dtp->retrieveFile( waitfile, storFileSize ); | 1035 | dtp->retrieveFile( waitfile, storFileSize ); |
1047 | dtp->setSocket( socket ); | 1036 | dtp->setSocket( socket ); |
1048 | } | 1037 | } |
1049 | else if ( wait[SendByteArray] ) { | 1038 | else if ( wait[SendByteArray] ) { |
1050 | dtp->sendByteArray( waitarray ); | 1039 | dtp->sendByteArray( waitarray ); |
1051 | dtp->setSocket( socket ); | 1040 | dtp->setSocket( socket ); |
1052 | } | 1041 | } |
1053 | else if ( wait[RetrieveByteArray] ) { | 1042 | else if ( wait[RetrieveByteArray] ) { |
1054 | qDebug("retrieve byte array"); | 1043 | odebug << "retrieve byte array" << oendl; |
1055 | dtp->retrieveByteArray(); | 1044 | dtp->retrieveByteArray(); |
1056 | dtp->setSocket( socket ); | 1045 | dtp->setSocket( socket ); |
1057 | } | 1046 | } |
1058 | else | 1047 | else |
1059 | waitsocket = socket; | 1048 | waitsocket = socket; |
1060 | 1049 | ||
1061 | for( int i = 0; i < 4; i++ ) | 1050 | for( int i = 0; i < 4; i++ ) |
1062 | wait[i] = FALSE; | 1051 | wait[i] = FALSE; |
1063 | } | 1052 | } |
1064 | 1053 | ||
1065 | QString ServerPI::absFilePath( const QString& file ) | 1054 | QString ServerPI::absFilePath( const QString& file ) |
1066 | { | 1055 | { |
1067 | if ( file.isEmpty() ) return file; | 1056 | if ( file.isEmpty() ) return file; |
1068 | 1057 | ||
1069 | QString filepath( file ); | 1058 | QString filepath( file ); |
1070 | if ( file[0] != "/" ) | 1059 | if ( file[0] != "/" ) |
1071 | filepath = directory.path() + "/" + file; | 1060 | filepath = directory.path() + "/" + file; |
1072 | 1061 | ||
1073 | return filepath; | 1062 | return filepath; |
1074 | } | 1063 | } |
1075 | 1064 | ||
1076 | 1065 | ||
1077 | void ServerPI::timerEvent( QTimerEvent * ) | 1066 | void ServerPI::timerEvent( QTimerEvent * ) |
1078 | { | 1067 | { |
1079 | connectionClosed(); | 1068 | connectionClosed(); |
1080 | } | 1069 | } |
1081 | 1070 | ||
1082 | 1071 | ||
1083 | ServerDTP::ServerDTP( QObject *parent, const char* name) | 1072 | ServerDTP::ServerDTP( QObject *parent, const char* name) |
1084 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), | 1073 | : QSocket( parent, name ), mode( Idle ), createTargzProc( 0 ), |
1085 | retrieveTargzProc( 0 ) | 1074 | retrieveTargzProc( 0 ) |
1086 | { | 1075 | { |
1087 | 1076 | ||
1088 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); | 1077 | connect( this, SIGNAL( connected() ), SLOT( connected() ) ); |
1089 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); | 1078 | connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); |
1090 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); | 1079 | connect( this, SIGNAL( bytesWritten(int) ), SLOT( bytesWritten(int) ) ); |
1091 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); | 1080 | connect( this, SIGNAL( readyRead() ), SLOT( readyRead() ) ); |
1092 | 1081 | ||
1093 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr | 1082 | createTargzProc = new QProcess( QString("tar"), this, "createTargzProc"); // No tr |
1094 | createTargzProc->setCommunication( QProcess::Stdout ); | 1083 | createTargzProc->setCommunication( QProcess::Stdout ); |
1095 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1084 | createTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1096 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); | 1085 | connect( createTargzProc, SIGNAL( processExited() ), SLOT( targzDone() ) ); |
1097 | 1086 | ||
1098 | retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); | 1087 | retrieveTargzProc = new QProcess( this, "retrieveTargzProc" ); |
1099 | retrieveTargzProc->setCommunication( QProcess::Stdin ); | 1088 | retrieveTargzProc->setCommunication( QProcess::Stdin ); |
1100 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); | 1089 | retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); |
1101 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1090 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1102 | SIGNAL( completed() ) ); | 1091 | SIGNAL( completed() ) ); |
1103 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1092 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1104 | SLOT( extractTarDone() ) ); | 1093 | SLOT( extractTarDone() ) ); |
1105 | } | 1094 | } |
1106 | 1095 | ||
1107 | ServerDTP::~ServerDTP() | 1096 | ServerDTP::~ServerDTP() |
1108 | { | 1097 | { |
1109 | buf.close(); | 1098 | buf.close(); |
1110 | if ( RetrieveFile == mode && file.isOpen() ) { | 1099 | if ( RetrieveFile == mode && file.isOpen() ) { |
1111 | // We're being shutdown before the client closed. | 1100 | // We're being shutdown before the client closed. |
1112 | file.close(); | 1101 | file.close(); |
1113 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { | 1102 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { |
1114 | qDebug( "STOR incomplete" ); | 1103 | odebug << "STOR incomplete" << oendl; |
1115 | file.remove(); | 1104 | file.remove(); |
1116 | } | 1105 | } |
1117 | } else { | 1106 | } else { |
1118 | file.close(); | 1107 | file.close(); |
1119 | } | 1108 | } |
1120 | createTargzProc->kill(); | 1109 | createTargzProc->kill(); |
1121 | } | 1110 | } |
1122 | 1111 | ||
1123 | void ServerDTP::extractTarDone() | 1112 | void ServerDTP::extractTarDone() |
1124 | { | 1113 | { |
1125 | qDebug("extract done"); | 1114 | odebug << "extract done" << oendl; |
1126 | #ifndef QT_NO_COP | 1115 | #ifndef QT_NO_COP |
1127 | QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); | 1116 | QCopEnvelope e( "QPE/System", "restoreDone(QString)" ); |
1128 | e << file.name(); | 1117 | e << file.name(); |
1129 | #endif | 1118 | #endif |
1130 | } | 1119 | } |
1131 | 1120 | ||
1132 | void ServerDTP::connected() | 1121 | void ServerDTP::connected() |
1133 | { | 1122 | { |
1134 | // send file mode | 1123 | // send file mode |
1135 | switch ( mode ) { | 1124 | switch ( mode ) { |
1136 | case SendFile : | 1125 | case SendFile : |
1137 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { | 1126 | if ( !file.exists() || !file.open( IO_ReadOnly) ) { |
1138 | emit failed(); | 1127 | emit failed(); |
1139 | mode = Idle; | 1128 | mode = Idle; |
1140 | return; | 1129 | return; |
1141 | } | 1130 | } |
1142 | 1131 | ||
1143 | //qDebug( "Debug: Sending file '%s'", file.name().latin1() ); | 1132 | //odebug << "Debug: Sending file '" << file.name() << "'" << oendl; |
1144 | 1133 | ||
1145 | bytes_written = 0; | 1134 | bytes_written = 0; |
1146 | if ( file.size() == 0 ) { | 1135 | if ( file.size() == 0 ) { |
1147 | //make sure it doesn't hang on empty files | 1136 | //make sure it doesn't hang on empty files |
1148 | file.close(); | 1137 | file.close(); |
1149 | emit completed(); | 1138 | emit completed(); |
1150 | mode = Idle; | 1139 | mode = Idle; |
1151 | } else { | 1140 | } else { |
1152 | // Don't write more if there is plenty buffered already. | 1141 | // Don't write more if there is plenty buffered already. |
1153 | if ( bytesToWrite() <= block_size && !file.atEnd() ) { | 1142 | if ( bytesToWrite() <= block_size && !file.atEnd() ) { |
1154 | QCString s; | 1143 | QCString s; |
1155 | s.resize( block_size ); | 1144 | s.resize( block_size ); |
1156 | int bytes = file.readBlock( s.data(), block_size ); | 1145 | int bytes = file.readBlock( s.data(), block_size ); |
1157 | writeBlock( s.data(), bytes ); | 1146 | writeBlock( s.data(), bytes ); |
1158 | } | 1147 | } |
1159 | } | 1148 | } |
1160 | break; | 1149 | break; |
1161 | case SendGzipFile: | 1150 | case SendGzipFile: |
1162 | if ( createTargzProc->isRunning() ) { | 1151 | if ( createTargzProc->isRunning() ) { |
1163 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY | 1152 | // SHOULDN'T GET HERE, BUT DOING A SAFETY CHECK ANYWAY |
1164 | qWarning("Previous tar --gzip process is still running; killing it..."); | 1153 | owarn << "Previous tar --gzip process is still running; killing it..." << oendl; |
1165 | createTargzProc->kill(); | 1154 | createTargzProc->kill(); |
1166 | } | 1155 | } |
1167 | 1156 | ||
1168 | bytes_written = 0; | 1157 | bytes_written = 0; |
1169 | qDebug("==>start send tar process"); | 1158 | odebug << "==>start send tar process" << oendl; |
1170 | if ( !createTargzProc->start() ) | 1159 | if ( !createTargzProc->start() ) |
1171 | qWarning("Error starting %s", | 1160 | qWarning("Error starting %s", |
1172 | createTargzProc->arguments().join(" ").latin1()); | 1161 | createTargzProc->arguments().join(" ").latin1()); |
1173 | break; | 1162 | break; |
1174 | case SendBuffer: | 1163 | case SendBuffer: |
1175 | if ( !buf.open( IO_ReadOnly) ) { | 1164 | if ( !buf.open( IO_ReadOnly) ) { |
1176 | emit failed(); | 1165 | emit failed(); |
1177 | mode = Idle; | 1166 | mode = Idle; |
1178 | return; | 1167 | return; |
1179 | } | 1168 | } |
1180 | 1169 | ||
1181 | // qDebug( "Debug: Sending byte array" ); | 1170 | // odebug << "Debug: Sending byte array" << oendl; |
1182 | bytes_written = 0; | 1171 | bytes_written = 0; |
1183 | while( !buf.atEnd() ) | 1172 | while( !buf.atEnd() ) |
1184 | putch( buf.getch() ); | 1173 | putch( buf.getch() ); |
1185 | buf.close(); | 1174 | buf.close(); |
1186 | break; | 1175 | break; |
1187 | case RetrieveFile: | 1176 | case RetrieveFile: |
1188 | // retrieve file mode | 1177 | // retrieve file mode |
1189 | if ( file.exists() && !file.remove() ) { | 1178 | if ( file.exists() && !file.remove() ) { |
1190 | emit failed(); | 1179 | emit failed(); |
1191 | mode = Idle; | 1180 | mode = Idle; |
1192 | return; | 1181 | return; |
1193 | } | 1182 | } |
1194 | 1183 | ||
1195 | if ( !file.open( IO_WriteOnly) ) { | 1184 | if ( !file.open( IO_WriteOnly) ) { |
1196 | emit failed(); | 1185 | emit failed(); |
1197 | mode = Idle; | 1186 | mode = Idle; |
1198 | return; | 1187 | return; |
1199 | } | 1188 | } |
1200 | // qDebug( "Debug: Retrieving file %s", file.name().latin1() ); | 1189 | // odebug << "Debug: Retrieving file " << file.name() << "" << oendl; |
1201 | break; | 1190 | break; |
1202 | case RetrieveGzipFile: | 1191 | case RetrieveGzipFile: |
1203 | qDebug("=-> starting tar process to receive .tgz file"); | 1192 | odebug << "=-> starting tar process to receive .tgz file" << oendl; |
1204 | break; | 1193 | break; |
1205 | case RetrieveBuffer: | 1194 | case RetrieveBuffer: |
1206 | // retrieve buffer mode | 1195 | // retrieve buffer mode |
1207 | if ( !buf.open( IO_WriteOnly) ) { | 1196 | if ( !buf.open( IO_WriteOnly) ) { |
1208 | emit failed(); | 1197 | emit failed(); |
1209 | mode = Idle; | 1198 | mode = Idle; |
1210 | return; | 1199 | return; |
1211 | } | 1200 | } |
1212 | // qDebug( "Debug: Retrieving byte array" ); | 1201 | // odebug << "Debug: Retrieving byte array" << oendl; |
1213 | break; | 1202 | break; |
1214 | case Idle: | 1203 | case Idle: |
1215 | qDebug("connection established but mode set to Idle; BUG!"); | 1204 | odebug << "connection established but mode set to Idle; BUG!" << oendl; |
1216 | break; | 1205 | break; |
1217 | } | 1206 | } |
1218 | } | 1207 | } |
1219 | 1208 | ||
1220 | void ServerDTP::connectionClosed() | 1209 | void ServerDTP::connectionClosed() |
1221 | { | 1210 | { |
1222 | //qDebug( "Debug: Data connection closed %ld bytes written", bytes_written ); | 1211 | //odebug << "Debug: Data connection closed " << bytes_written << " bytes written" << oendl; |
1223 | 1212 | ||
1224 | // send file mode | 1213 | // send file mode |
1225 | if ( SendFile == mode ) { | 1214 | if ( SendFile == mode ) { |
1226 | if ( bytes_written == file.size() ) | 1215 | if ( bytes_written == file.size() ) |
1227 | emit completed(); | 1216 | emit completed(); |
1228 | else | 1217 | else |
1229 | emit failed(); | 1218 | emit failed(); |
1230 | } | 1219 | } |
1231 | 1220 | ||
1232 | // send buffer mode | 1221 | // send buffer mode |
1233 | else if ( SendBuffer == mode ) { | 1222 | else if ( SendBuffer == mode ) { |
1234 | if ( bytes_written == buf.size() ) | 1223 | if ( bytes_written == buf.size() ) |
1235 | emit completed(); | 1224 | emit completed(); |
1236 | else | 1225 | else |
1237 | emit failed(); | 1226 | emit failed(); |
1238 | } | 1227 | } |
1239 | 1228 | ||
1240 | // retrieve file mode | 1229 | // retrieve file mode |
1241 | else if ( RetrieveFile == mode ) { | 1230 | else if ( RetrieveFile == mode ) { |
1242 | file.close(); | 1231 | file.close(); |
1243 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { | 1232 | if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { |
1244 | qDebug( "STOR incomplete" ); | 1233 | odebug << "STOR incomplete" << oendl; |
1245 | file.remove(); | 1234 | file.remove(); |
1246 | emit failed(); | 1235 | emit failed(); |
1247 | } else { | 1236 | } else { |
1248 | emit completed(); | 1237 | emit completed(); |
1249 | } | 1238 | } |
1250 | } | 1239 | } |
1251 | 1240 | ||
1252 | else if ( RetrieveGzipFile == mode ) { | 1241 | else if ( RetrieveGzipFile == mode ) { |
1253 | qDebug("Done writing ungzip file; closing input"); | 1242 | odebug << "Done writing ungzip file; closing input" << oendl; |
1254 | retrieveTargzProc->flushStdin(); | 1243 | retrieveTargzProc->flushStdin(); |
1255 | retrieveTargzProc->closeStdin(); | 1244 | retrieveTargzProc->closeStdin(); |
1256 | } | 1245 | } |
1257 | 1246 | ||
1258 | // retrieve buffer mode | 1247 | // retrieve buffer mode |
1259 | else if ( RetrieveBuffer == mode ) { | 1248 | else if ( RetrieveBuffer == mode ) { |
1260 | buf.close(); | 1249 | buf.close(); |
1261 | emit completed(); | 1250 | emit completed(); |
1262 | } | 1251 | } |
1263 | 1252 | ||
1264 | mode = Idle; | 1253 | mode = Idle; |
1265 | } | 1254 | } |
1266 | 1255 | ||
1267 | void ServerDTP::bytesWritten( int bytes ) | 1256 | void ServerDTP::bytesWritten( int bytes ) |
1268 | { | 1257 | { |
1269 | bytes_written += bytes; | 1258 | bytes_written += bytes; |
1270 | 1259 | ||
1271 | // send file mode | 1260 | // send file mode |
1272 | if ( SendFile == mode ) { | 1261 | if ( SendFile == mode ) { |
1273 | 1262 | ||
1274 | if ( bytes_written == file.size() ) { | 1263 | if ( bytes_written == file.size() ) { |
1275 | // qDebug( "Debug: Sending complete: %d bytes", file.size() ); | 1264 | // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; |
1276 | file.close(); | 1265 | file.close(); |
1277 | emit completed(); | 1266 | emit completed(); |
1278 | mode = Idle; | 1267 | mode = Idle; |
1279 | } | 1268 | } |
1280 | else if( !file.atEnd() ) { | 1269 | else if( !file.atEnd() ) { |
1281 | QCString s; | 1270 | QCString s; |
1282 | s.resize( block_size ); | 1271 | s.resize( block_size ); |
1283 | int bytes = file.readBlock( s.data(), block_size ); | 1272 | int bytes = file.readBlock( s.data(), block_size ); |
1284 | writeBlock( s.data(), bytes ); | 1273 | writeBlock( s.data(), bytes ); |
1285 | } | 1274 | } |
1286 | } | 1275 | } |
1287 | 1276 | ||
1288 | // send buffer mode | 1277 | // send buffer mode |
1289 | if ( SendBuffer == mode ) { | 1278 | if ( SendBuffer == mode ) { |
1290 | 1279 | ||
1291 | if ( bytes_written == buf.size() ) { | 1280 | if ( bytes_written == buf.size() ) { |
1292 | // qDebug( "Debug: Sending complete: %d bytes", buf.size() ); | 1281 | // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; |
1293 | emit completed(); | 1282 | emit completed(); |
1294 | mode = Idle; | 1283 | mode = Idle; |
1295 | } | 1284 | } |
1296 | } | 1285 | } |
1297 | } | 1286 | } |
1298 | 1287 | ||
1299 | void ServerDTP::readyRead() | 1288 | void ServerDTP::readyRead() |
1300 | { | 1289 | { |
1301 | // retrieve file mode | 1290 | // retrieve file mode |
1302 | if ( RetrieveFile == mode ) { | 1291 | if ( RetrieveFile == mode ) { |
1303 | QCString s; | 1292 | QCString s; |
1304 | s.resize( bytesAvailable() ); | 1293 | s.resize( bytesAvailable() ); |
1305 | readBlock( s.data(), bytesAvailable() ); | 1294 | readBlock( s.data(), bytesAvailable() ); |
1306 | file.writeBlock( s.data(), s.size() ); | 1295 | file.writeBlock( s.data(), s.size() ); |
1307 | } | 1296 | } |
1308 | else if ( RetrieveGzipFile == mode ) { | 1297 | else if ( RetrieveGzipFile == mode ) { |
1309 | if ( !retrieveTargzProc->isRunning() ) | 1298 | if ( !retrieveTargzProc->isRunning() ) |
1310 | retrieveTargzProc->start(); | 1299 | retrieveTargzProc->start(); |
1311 | 1300 | ||
1312 | QByteArray s; | 1301 | QByteArray s; |
1313 | s.resize( bytesAvailable() ); | 1302 | s.resize( bytesAvailable() ); |
1314 | readBlock( s.data(), bytesAvailable() ); | 1303 | readBlock( s.data(), bytesAvailable() ); |
1315 | retrieveTargzProc->writeToStdin( s ); | 1304 | retrieveTargzProc->writeToStdin( s ); |
1316 | qDebug("wrote %d bytes to ungzip ", s.size() ); | 1305 | odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; |
1317 | } | 1306 | } |
1318 | // retrieve buffer mode | 1307 | // retrieve buffer mode |
1319 | else if ( RetrieveBuffer == mode ) { | 1308 | else if ( RetrieveBuffer == mode ) { |
1320 | QCString s; | 1309 | QCString s; |
1321 | s.resize( bytesAvailable() ); | 1310 | s.resize( bytesAvailable() ); |
1322 | readBlock( s.data(), bytesAvailable() ); | 1311 | readBlock( s.data(), bytesAvailable() ); |
1323 | buf.writeBlock( s.data(), s.size() ); | 1312 | buf.writeBlock( s.data(), s.size() ); |
1324 | } | 1313 | } |
1325 | } | 1314 | } |
1326 | 1315 | ||
1327 | void ServerDTP::writeTargzBlock() | 1316 | void ServerDTP::writeTargzBlock() |
1328 | { | 1317 | { |
1329 | QByteArray block = createTargzProc->readStdout(); | 1318 | QByteArray block = createTargzProc->readStdout(); |
1330 | writeBlock( block.data(), block.size() ); | 1319 | writeBlock( block.data(), block.size() ); |
1331 | qDebug("writeTargzBlock %d", block.size()); | 1320 | odebug << "writeTargzBlock " << block.size() << "" << oendl; |
1332 | } | 1321 | } |
1333 | 1322 | ||
1334 | void ServerDTP::targzDone() | 1323 | void ServerDTP::targzDone() |
1335 | { | 1324 | { |
1336 | qDebug("tar and gzip done"); | 1325 | odebug << "tar and gzip done" << oendl; |
1337 | emit completed(); | 1326 | emit completed(); |
1338 | mode = Idle; | 1327 | mode = Idle; |
1339 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), | 1328 | disconnect( createTargzProc, SIGNAL( readyReadStdout() ), |
1340 | this, SLOT( writeTargzBlock() ) ); | 1329 | this, SLOT( writeTargzBlock() ) ); |
1341 | } | 1330 | } |
1342 | 1331 | ||
1343 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) | 1332 | void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) |
1344 | { | 1333 | { |
1345 | file.setName( fn ); | 1334 | file.setName( fn ); |
1346 | mode = SendFile; | 1335 | mode = SendFile; |
1347 | connectToHost( host.toString(), port ); | 1336 | connectToHost( host.toString(), port ); |
1348 | } | 1337 | } |
1349 | 1338 | ||
1350 | void ServerDTP::sendFile( const QString fn ) | 1339 | void ServerDTP::sendFile( const QString fn ) |
1351 | { | 1340 | { |
1352 | file.setName( fn ); | 1341 | file.setName( fn ); |
1353 | mode = SendFile; | 1342 | mode = SendFile; |
1354 | } | 1343 | } |
1355 | 1344 | ||
1356 | void ServerDTP::sendGzipFile( const QString &fn, | 1345 | void ServerDTP::sendGzipFile( const QString &fn, |
1357 | const QStringList &archiveTargets, | 1346 | const QStringList &archiveTargets, |
1358 | const QHostAddress& host, Q_UINT16 port ) | 1347 | const QHostAddress& host, Q_UINT16 port ) |
1359 | { | 1348 | { |
1360 | sendGzipFile( fn, archiveTargets ); | 1349 | sendGzipFile( fn, archiveTargets ); |
1361 | connectToHost( host.toString(), port ); | 1350 | connectToHost( host.toString(), port ); |
1362 | } | 1351 | } |
1363 | 1352 | ||
1364 | void ServerDTP::sendGzipFile( const QString &fn, | 1353 | void ServerDTP::sendGzipFile( const QString &fn, |
1365 | const QStringList &archiveTargets ) | 1354 | const QStringList &archiveTargets ) |
1366 | { | 1355 | { |
1367 | mode = SendGzipFile; | 1356 | mode = SendGzipFile; |
1368 | file.setName( fn ); | 1357 | file.setName( fn ); |
1369 | 1358 | ||
1370 | QStringList args = "targzip"; | 1359 | QStringList args = "targzip"; |
1371 | //args += "-cv"; | 1360 | //args += "-cv"; |
1372 | args += archiveTargets; | 1361 | args += archiveTargets; |
1373 | qDebug("sendGzipFile %s", args.join(" ").latin1() ); | 1362 | odebug << "sendGzipFile " << args.join(" ") << "" << oendl; |
1374 | createTargzProc->setArguments( args ); | 1363 | createTargzProc->setArguments( args ); |
1375 | connect( createTargzProc, | 1364 | connect( createTargzProc, |
1376 | SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); | 1365 | SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); |
1377 | } | 1366 | } |
1378 | 1367 | ||
1379 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) | 1368 | void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) |
1380 | { | 1369 | { |
1381 | recvFileSize = fileSize; | 1370 | recvFileSize = fileSize; |
1382 | file.setName( fn ); | 1371 | file.setName( fn ); |
1383 | mode = RetrieveFile; | 1372 | mode = RetrieveFile; |
1384 | connectToHost( host.toString(), port ); | 1373 | connectToHost( host.toString(), port ); |
1385 | } | 1374 | } |
1386 | 1375 | ||
1387 | void ServerDTP::retrieveFile( const QString fn, int fileSize ) | 1376 | void ServerDTP::retrieveFile( const QString fn, int fileSize ) |
1388 | { | 1377 | { |
1389 | recvFileSize = fileSize; | 1378 | recvFileSize = fileSize; |
1390 | file.setName( fn ); | 1379 | file.setName( fn ); |
1391 | mode = RetrieveFile; | 1380 | mode = RetrieveFile; |
1392 | } | 1381 | } |
1393 | 1382 | ||
1394 | void ServerDTP::retrieveGzipFile( const QString &fn ) | 1383 | void ServerDTP::retrieveGzipFile( const QString &fn ) |
1395 | { | 1384 | { |
1396 | qDebug("retrieveGzipFile %s", fn.latin1()); | 1385 | odebug << "retrieveGzipFile " << fn << "" << oendl; |
1397 | file.setName( fn ); | 1386 | file.setName( fn ); |
1398 | mode = RetrieveGzipFile; | 1387 | mode = RetrieveGzipFile; |
1399 | 1388 | ||
1400 | retrieveTargzProc->setArguments( "targunzip" ); | 1389 | retrieveTargzProc->setArguments( "targunzip" ); |
1401 | connect( retrieveTargzProc, SIGNAL( processExited() ), | 1390 | connect( retrieveTargzProc, SIGNAL( processExited() ), |
1402 | SLOT( extractTarDone() ) ); | 1391 | SLOT( extractTarDone() ) ); |
1403 | } | 1392 | } |
1404 | 1393 | ||
1405 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) | 1394 | void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) |
1406 | { | 1395 | { |
1407 | retrieveGzipFile( fn ); | 1396 | retrieveGzipFile( fn ); |
1408 | connectToHost( host.toString(), port ); | 1397 | connectToHost( host.toString(), port ); |
1409 | } | 1398 | } |
1410 | 1399 | ||
1411 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) | 1400 | void ServerDTP::sendByteArray( const QByteArray& array, const QHostAddress& host, Q_UINT16 port ) |
1412 | { | 1401 | { |
1413 | buf.setBuffer( array ); | 1402 | buf.setBuffer( array ); |
1414 | mode = SendBuffer; | 1403 | mode = SendBuffer; |
1415 | connectToHost( host.toString(), port ); | 1404 | connectToHost( host.toString(), port ); |
1416 | } | 1405 | } |
1417 | 1406 | ||
1418 | void ServerDTP::sendByteArray( const QByteArray& array ) | 1407 | void ServerDTP::sendByteArray( const QByteArray& array ) |
1419 | { | 1408 | { |
1420 | buf.setBuffer( array ); | 1409 | buf.setBuffer( array ); |
1421 | mode = SendBuffer; | 1410 | mode = SendBuffer; |
1422 | } | 1411 | } |
1423 | 1412 | ||
1424 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) | 1413 | void ServerDTP::retrieveByteArray( const QHostAddress& host, Q_UINT16 port ) |
1425 | { | 1414 | { |
1426 | buf.setBuffer( QByteArray() ); | 1415 | buf.setBuffer( QByteArray() ); |
1427 | mode = RetrieveBuffer; | 1416 | mode = RetrieveBuffer; |
1428 | connectToHost( host.toString(), port ); | 1417 | connectToHost( host.toString(), port ); |
1429 | } | 1418 | } |
1430 | 1419 | ||
1431 | void ServerDTP::retrieveByteArray() | 1420 | void ServerDTP::retrieveByteArray() |
1432 | { | 1421 | { |
1433 | buf.setBuffer( QByteArray() ); | 1422 | buf.setBuffer( QByteArray() ); |
1434 | mode = RetrieveBuffer; | 1423 | mode = RetrieveBuffer; |
1435 | } | 1424 | } |
1436 | 1425 | ||
1437 | void ServerDTP::setSocket( int socket ) | 1426 | void ServerDTP::setSocket( int socket ) |
1438 | { | 1427 | { |
1439 | QSocket::setSocket( socket ); | 1428 | QSocket::setSocket( socket ); |
1440 | connected(); | 1429 | connected(); |
1441 | } | 1430 | } |
1442 | 1431 | ||