summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/applauncher.cpp11
-rw-r--r--core/launcher/config.in6
-rw-r--r--core/launcher/documentlist.cpp11
-rw-r--r--core/launcher/main.cpp9
-rw-r--r--core/launcher/qcopbridge.cpp7
-rw-r--r--core/launcher/screensaver.cpp2
-rw-r--r--core/launcher/server.cpp4
-rw-r--r--core/launcher/server.pro7
-rw-r--r--core/launcher/startmenu.cpp2
-rw-r--r--core/launcher/transferserver.cpp27
-rw-r--r--core/launcher/wait.cpp2
11 files changed, 45 insertions, 43 deletions
diff --git a/core/launcher/applauncher.cpp b/core/launcher/applauncher.cpp
index 0db99dd..f161e98 100644
--- a/core/launcher/applauncher.cpp
+++ b/core/launcher/applauncher.cpp
@@ -1,692 +1,691 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#ifndef QTOPIA_INTERNAL_PRELOADACCESS 21#ifndef QTOPIA_INTERNAL_PRELOADACCESS
22#define QTOPIA_INTERNAL_PRELOADACCESS 22#define QTOPIA_INTERNAL_PRELOADACCESS
23#endif 23#endif
24#ifndef QTOPIA_INTERNAL_FILEOPERATIONS 24#ifndef QTOPIA_INTERNAL_FILEOPERATIONS
25#define QTOPIA_INTERNAL_FILEOPERATIONS 25#define QTOPIA_INTERNAL_FILEOPERATIONS
26#endif 26#endif
27#ifndef QTOPIA_PROGRAM_MONITOR 27#ifndef QTOPIA_PROGRAM_MONITOR
28#define QTOPIA_PROGRAM_MONITOR 28#define QTOPIA_PROGRAM_MONITOR
29#endif 29#endif
30#include <qtopia/global.h> 30#include <opie2/oglobal.h>
31 31
32#ifndef Q_OS_WIN32 32#ifndef Q_OS_WIN32
33#include <sys/stat.h> 33#include <sys/stat.h>
34#include <sys/wait.h> 34#include <sys/wait.h>
35#include <sys/file.h> 35#include <sys/file.h>
36#include <unistd.h> 36#include <unistd.h>
37#include <sys/time.h> 37#include <sys/time.h>
38#include <sys/resource.h> 38#include <sys/resource.h>
39#include <errno.h> 39#include <errno.h>
40#else 40#else
41#include <process.h> 41#include <process.h>
42#include <windows.h> 42#include <windows.h>
43#include <winbase.h> 43#include <winbase.h>
44#endif 44#endif
45 45
46#include <signal.h> 46#include <signal.h>
47#include <sys/types.h> 47#include <sys/types.h>
48#include <stdlib.h> 48#include <stdlib.h>
49 49
50#include <qtimer.h> 50#include <qtimer.h>
51#include <qwindowsystem_qws.h> 51#include <qwindowsystem_qws.h>
52#include <qmessagebox.h> 52#include <qmessagebox.h>
53#include <qfile.h> 53#include <qfile.h>
54#include <qfileinfo.h> 54#include <qfileinfo.h>
55 55
56#include <qtopia/qcopenvelope_qws.h> 56#include <qtopia/qcopenvelope_qws.h>
57#include <qtopia/applnk.h> 57#include <qtopia/applnk.h>
58#include <qtopia/qpeapplication.h> 58#include <qtopia/qpeapplication.h>
59#include <qtopia/config.h> 59#include <qtopia/config.h>
60#include <qtopia/global.h> 60#include <qtopia/global.h>
61 61
62#include "applauncher.h" 62#include "applauncher.h"
63#include "documentlist.h" 63#include "documentlist.h"
64#include "launcherglobal.h"
65 64
66const int AppLauncher::RAISE_TIMEOUT_MS = 5000; 65const int AppLauncher::RAISE_TIMEOUT_MS = 5000;
67 66
68//--------------------------------------------------------------------------- 67//---------------------------------------------------------------------------
69 68
70static AppLauncher* appLauncherPtr; 69static AppLauncher* appLauncherPtr;
71 70
72const int appStopEventID = 1290; 71const int appStopEventID = 1290;
73 72
74class AppStoppedEvent : public QCustomEvent 73class AppStoppedEvent : public QCustomEvent
75{ 74{
76public: 75public:
77 AppStoppedEvent(int pid, int status) 76 AppStoppedEvent(int pid, int status)
78 : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { } 77 : QCustomEvent( appStopEventID ), mPid(pid), mStatus(status) { }
79 78
80 int pid() { return mPid; } 79 int pid() { return mPid; }
81 int status() { return mStatus; } 80 int status() { return mStatus; }
82 81
83private: 82private:
84 int mPid, mStatus; 83 int mPid, mStatus;
85}; 84};
86 85
87AppLauncher::AppLauncher(QObject *parent, const char *name) 86AppLauncher::AppLauncher(QObject *parent, const char *name)
88 : QObject(parent, name), qlPid(0), qlReady(FALSE), 87 : QObject(parent, name), qlPid(0), qlReady(FALSE),
89 appKillerBox(0) 88 appKillerBox(0)
90{ 89{
91 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&))); 90 connect(qwsServer, SIGNAL(newChannel(const QString&)), this, SLOT(newQcopChannel(const QString&)));
92 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&))); 91 connect(qwsServer, SIGNAL(removedChannel(const QString&)), this, SLOT(removedQcopChannel(const QString&)));
93 QCopChannel* channel = new QCopChannel( "QPE/System", this ); 92 QCopChannel* channel = new QCopChannel( "QPE/System", this );
94 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 93 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
95 this, SLOT(received(const QCString&, const QByteArray&)) ); 94 this, SLOT(received(const QCString&, const QByteArray&)) );
96 95
97 channel = new QCopChannel( "QPE/Server", this ); 96 channel = new QCopChannel( "QPE/Server", this );
98 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 97 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
99 this, SLOT(received(const QCString&, const QByteArray&)) ); 98 this, SLOT(received(const QCString&, const QByteArray&)) );
100 99
101#ifndef Q_OS_WIN32 100#ifndef Q_OS_WIN32
102 signal(SIGCHLD, signalHandler); 101 signal(SIGCHLD, signalHandler);
103#else 102#else
104 runningAppsProc.setAutoDelete( TRUE ); 103 runningAppsProc.setAutoDelete( TRUE );
105#endif 104#endif
106 QString tmp = qApp->argv()[0]; 105 QString tmp = qApp->argv()[0];
107 int pos = tmp.findRev('/'); 106 int pos = tmp.findRev('/');
108 if ( pos > -1 ) 107 if ( pos > -1 )
109 tmp = tmp.mid(++pos); 108 tmp = tmp.mid(++pos);
110 runningApps[::getpid()] = tmp; 109 runningApps[::getpid()] = tmp;
111 110
112 appLauncherPtr = this; 111 appLauncherPtr = this;
113 112
114 QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) ); 113 QTimer::singleShot( 1000, this, SLOT(createQuickLauncher()) );
115} 114}
116 115
117AppLauncher::~AppLauncher() 116AppLauncher::~AppLauncher()
118{ 117{
119 appLauncherPtr = 0; 118 appLauncherPtr = 0;
120#ifndef Q_OS_WIN32 119#ifndef Q_OS_WIN32
121 signal(SIGCHLD, SIG_DFL); 120 signal(SIGCHLD, SIG_DFL);
122#endif 121#endif
123 if ( qlPid ) { 122 if ( qlPid ) {
124 int status; 123 int status;
125 ::kill( qlPid, SIGTERM ); 124 ::kill( qlPid, SIGTERM );
126 waitpid( qlPid, &status, 0 ); 125 waitpid( qlPid, &status, 0 );
127 } 126 }
128} 127}
129 128
130/* We use the QCopChannel of the app as an indicator of when it has been launched 129/* We use the QCopChannel of the app as an indicator of when it has been launched
131 so that we can disable the busy indicators */ 130 so that we can disable the busy indicators */
132void AppLauncher::newQcopChannel(const QString& channelName) 131void AppLauncher::newQcopChannel(const QString& channelName)
133{ 132{
134// qDebug("channel %s added", channelName.data() ); 133// qDebug("channel %s added", channelName.data() );
135 QString prefix("QPE/Application/"); 134 QString prefix("QPE/Application/");
136 if (channelName.startsWith(prefix)) { 135 if (channelName.startsWith(prefix)) {
137 { 136 {
138 QCopEnvelope e("QPE/System", "newChannel(QString)"); 137 QCopEnvelope e("QPE/System", "newChannel(QString)");
139 e << channelName; 138 e << channelName;
140 } 139 }
141 QString appName = channelName.mid(prefix.length()); 140 QString appName = channelName.mid(prefix.length());
142 if ( appName != "quicklauncher" ) { 141 if ( appName != "quicklauncher" ) {
143 emit connected( appName ); 142 emit connected( appName );
144 QCopEnvelope e("QPE/System", "notBusy(QString)"); 143 QCopEnvelope e("QPE/System", "notBusy(QString)");
145 e << appName; 144 e << appName;
146 } 145 }
147 } else if (channelName.startsWith("QPE/QuickLauncher-")) { 146 } else if (channelName.startsWith("QPE/QuickLauncher-")) {
148 qDebug("Registered %s", channelName.latin1()); 147 qDebug("Registered %s", channelName.latin1());
149 int pid = channelName.mid(18).toInt(); 148 int pid = channelName.mid(18).toInt();
150 if (pid == qlPid) 149 if (pid == qlPid)
151 qlReady = TRUE; 150 qlReady = TRUE;
152 } 151 }
153} 152}
154 153
155void AppLauncher::removedQcopChannel(const QString& channelName) 154void AppLauncher::removedQcopChannel(const QString& channelName)
156{ 155{
157 if (channelName.startsWith("QPE/Application/")) { 156 if (channelName.startsWith("QPE/Application/")) {
158 QCopEnvelope e("QPE/System", "removedChannel(QString)"); 157 QCopEnvelope e("QPE/System", "removedChannel(QString)");
159 e << channelName; 158 e << channelName;
160 } 159 }
161} 160}
162 161
163void AppLauncher::received(const QCString& msg, const QByteArray& data) 162void AppLauncher::received(const QCString& msg, const QByteArray& data)
164{ 163{
165 QDataStream stream( data, IO_ReadOnly ); 164 QDataStream stream( data, IO_ReadOnly );
166 if ( msg == "execute(QString)" ) { 165 if ( msg == "execute(QString)" ) {
167 QString t; 166 QString t;
168 stream >> t; 167 stream >> t;
169 if ( !executeBuiltin( t, QString::null ) ) 168 if ( !executeBuiltin( t, QString::null ) )
170 execute(t, QString::null); 169 execute(t, QString::null);
171 } else if ( msg == "execute(QString,QString)" ) { 170 } else if ( msg == "execute(QString,QString)" ) {
172 QString t,d; 171 QString t,d;
173 stream >> t >> d; 172 stream >> t >> d;
174 if ( !executeBuiltin( t, d ) ) 173 if ( !executeBuiltin( t, d ) )
175 execute( t, d ); 174 execute( t, d );
176 } else if ( msg == "processQCop(QString)" ) { // from QPE/Server 175 } else if ( msg == "processQCop(QString)" ) { // from QPE/Server
177 QString t; 176 QString t;
178 stream >> t; 177 stream >> t;
179 if ( !executeBuiltin( t, QString::null ) ) 178 if ( !executeBuiltin( t, QString::null ) )
180 execute( t, QString::null, TRUE); 179 execute( t, QString::null, TRUE);
181 } else if ( msg == "raise(QString)" ) { 180 } else if ( msg == "raise(QString)" ) {
182 QString appName; 181 QString appName;
183 stream >> appName; 182 stream >> appName;
184 183
185 if ( !executeBuiltin( appName, QString::null ) ) { 184 if ( !executeBuiltin( appName, QString::null ) ) {
186 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { 185 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) {
187 //qDebug( "Raising: %s", appName.latin1() ); 186 //qDebug( "Raising: %s", appName.latin1() );
188 QCString channel = "QPE/Application/"; 187 QCString channel = "QPE/Application/";
189 channel += appName.latin1(); 188 channel += appName.latin1();
190 189
191 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile 190 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile
192 QFile f("/tmp/qcop-msg-" + appName); 191 QFile f("/tmp/qcop-msg-" + appName);
193 if ( f.open(IO_WriteOnly | IO_Append) ) { 192 if ( f.open(IO_WriteOnly | IO_Append) ) {
194#ifndef Q_OS_WIN32 193#ifndef Q_OS_WIN32
195 flock(f.handle(), LOCK_EX); 194 flock(f.handle(), LOCK_EX);
196#endif 195#endif
197 QDataStream ds(&f); 196 QDataStream ds(&f);
198 QByteArray b; 197 QByteArray b;
199 QDataStream bstream(b, IO_WriteOnly); 198 QDataStream bstream(b, IO_WriteOnly);
200 ds << channel << QCString("raise()") << b; 199 ds << channel << QCString("raise()") << b;
201 f.flush(); 200 f.flush();
202#ifndef Q_OS_WIN32 201#ifndef Q_OS_WIN32
203 flock(f.handle(), LOCK_UN); 202 flock(f.handle(), LOCK_UN);
204#endif 203#endif
205 f.close(); 204 f.close();
206 } 205 }
207 bool alreadyRunning = isRunning( appName ); 206 bool alreadyRunning = isRunning( appName );
208 if ( execute(appName, QString::null) ) { 207 if ( execute(appName, QString::null) ) {
209 int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0); 208 int id = startTimer(RAISE_TIMEOUT_MS + alreadyRunning?2000:0);
210 waitingHeartbeat.insert( appName, id ); 209 waitingHeartbeat.insert( appName, id );
211 } 210 }
212 } 211 }
213 } 212 }
214 } else if ( msg == "sendRunningApps()" ) { 213 } else if ( msg == "sendRunningApps()" ) {
215 QStringList apps; 214 QStringList apps;
216 QMap<int,QString>::Iterator it; 215 QMap<int,QString>::Iterator it;
217 for( it = runningApps.begin(); it != runningApps.end(); ++it ) 216 for( it = runningApps.begin(); it != runningApps.end(); ++it )
218 apps.append( *it ); 217 apps.append( *it );
219 QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" ); 218 QCopEnvelope e( "QPE/Desktop", "runningApps(QStringList)" );
220 e << apps; 219 e << apps;
221 } else if ( msg == "appRaised(QString)" ) { 220 } else if ( msg == "appRaised(QString)" ) {
222 QString appName; 221 QString appName;
223 stream >> appName; 222 stream >> appName;
224 qDebug("Got a heartbeat from %s", appName.latin1()); 223 qDebug("Got a heartbeat from %s", appName.latin1());
225 QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName); 224 QMap<QString,int>::Iterator it = waitingHeartbeat.find(appName);
226 if ( it != waitingHeartbeat.end() ) { 225 if ( it != waitingHeartbeat.end() ) {
227 killTimer( *it ); 226 killTimer( *it );
228 waitingHeartbeat.remove(it); 227 waitingHeartbeat.remove(it);
229 } 228 }
230 // Check to make sure we're not waiting on user input... 229 // Check to make sure we're not waiting on user input...
231 if ( appKillerBox && appName == appKillerName ) { 230 if ( appKillerBox && appName == appKillerName ) {
232 // If we are, we kill the dialog box, and the code waiting on the result 231 // If we are, we kill the dialog box, and the code waiting on the result
233 // will clean us up (basically the user said "no"). 232 // will clean us up (basically the user said "no").
234 delete appKillerBox; 233 delete appKillerBox;
235 appKillerBox = 0; 234 appKillerBox = 0;
236 appKillerName = QString::null; 235 appKillerName = QString::null;
237 } 236 }
238 } 237 }
239} 238}
240 239
241void AppLauncher::signalHandler(int) 240void AppLauncher::signalHandler(int)
242{ 241{
243#ifndef Q_OS_WIN32 242#ifndef Q_OS_WIN32
244 int status; 243 int status;
245 pid_t pid = waitpid(-1, &status, WNOHANG); 244 pid_t pid = waitpid(-1, &status, WNOHANG);
246/* if (pid == 0 || &status == 0 ) { 245/* if (pid == 0 || &status == 0 ) {
247 qDebug("hmm, could not get return value from signal"); 246 qDebug("hmm, could not get return value from signal");
248 } 247 }
249*/ 248*/
250 QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) ); 249 QApplication::postEvent(appLauncherPtr, new AppStoppedEvent(pid, status) );
251#else 250#else
252 qDebug("Unhandled signal see by AppLauncher::signalHandler(int)"); 251 qDebug("Unhandled signal see by AppLauncher::signalHandler(int)");
253#endif 252#endif
254} 253}
255 254
256bool AppLauncher::event(QEvent *e) 255bool AppLauncher::event(QEvent *e)
257{ 256{
258 if ( e->type() == appStopEventID ) { 257 if ( e->type() == appStopEventID ) {
259 AppStoppedEvent *ae = (AppStoppedEvent *) e; 258 AppStoppedEvent *ae = (AppStoppedEvent *) e;
260 sigStopped(ae->pid(), ae->status() ); 259 sigStopped(ae->pid(), ae->status() );
261 return TRUE; 260 return TRUE;
262 } 261 }
263 262
264 return QObject::event(e); 263 return QObject::event(e);
265} 264}
266 265
267void AppLauncher::timerEvent( QTimerEvent *e ) 266void AppLauncher::timerEvent( QTimerEvent *e )
268{ 267{
269 int id = e->timerId(); 268 int id = e->timerId();
270 QMap<QString,int>::Iterator it; 269 QMap<QString,int>::Iterator it;
271 for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) { 270 for ( it = waitingHeartbeat.begin(); it != waitingHeartbeat.end(); ++it ) {
272 if ( *it == id ) { 271 if ( *it == id ) {
273 if ( appKillerBox ) // we're already dealing with one 272 if ( appKillerBox ) // we're already dealing with one
274 return; 273 return;
275 274
276 appKillerName = it.key(); 275 appKillerName = it.key();
277 killTimer( id ); 276 killTimer( id );
278 waitingHeartbeat.remove( it ); 277 waitingHeartbeat.remove( it );
279 278
280 // qDebug("Checking in on %s", appKillerName.latin1()); 279 // qDebug("Checking in on %s", appKillerName.latin1());
281 280
282 // We store this incase the application responds while we're 281 // We store this incase the application responds while we're
283 // waiting for user input so we know not to delete ourselves. 282 // waiting for user input so we know not to delete ourselves.
284 appKillerBox = new QMessageBox(tr("Application Problem"), 283 appKillerBox = new QMessageBox(tr("Application Problem"),
285 tr("<p>%1 is not responding.</p>").arg(appKillerName) + 284 tr("<p>%1 is not responding.</p>").arg(appKillerName) +
286 tr("<p>Would you like to force the application to exit?</p>"), 285 tr("<p>Would you like to force the application to exit?</p>"),
287 QMessageBox::Warning, QMessageBox::Yes, 286 QMessageBox::Warning, QMessageBox::Yes,
288 QMessageBox::No | QMessageBox::Default, 287 QMessageBox::No | QMessageBox::Default,
289 QMessageBox::NoButton); 288 QMessageBox::NoButton);
290 if (appKillerBox->exec() == QMessageBox::Yes) { 289 if (appKillerBox->exec() == QMessageBox::Yes) {
291 // qDebug("Killing the app!!! Bwuhahahaha!"); 290 // qDebug("Killing the app!!! Bwuhahahaha!");
292 int pid = pidForName(appKillerName); 291 int pid = pidForName(appKillerName);
293 if ( pid > 0 ) 292 if ( pid > 0 )
294 kill( pid ); 293 kill( pid );
295 } 294 }
296 appKillerName = QString::null; 295 appKillerName = QString::null;
297 delete appKillerBox; 296 delete appKillerBox;
298 appKillerBox = 0; 297 appKillerBox = 0;
299 return; 298 return;
300 } 299 }
301 } 300 }
302 301
303 QObject::timerEvent( e ); 302 QObject::timerEvent( e );
304} 303}
305 304
306#ifndef Q_OS_WIN32 305#ifndef Q_OS_WIN32
307void AppLauncher::sigStopped(int sigPid, int sigStatus) 306void AppLauncher::sigStopped(int sigPid, int sigStatus)
308{ 307{
309 int exitStatus = 0; 308 int exitStatus = 0;
310 309
311 bool crashed = WIFSIGNALED(sigStatus); 310 bool crashed = WIFSIGNALED(sigStatus);
312 if ( !crashed ) { 311 if ( !crashed ) {
313 if ( WIFEXITED(sigStatus) ) 312 if ( WIFEXITED(sigStatus) )
314 exitStatus = WEXITSTATUS(sigStatus); 313 exitStatus = WEXITSTATUS(sigStatus);
315 } else { 314 } else {
316 exitStatus = WTERMSIG(sigStatus); 315 exitStatus = WTERMSIG(sigStatus);
317 } 316 }
318 317
319 QMap<int,QString>::Iterator it = runningApps.find( sigPid ); 318 QMap<int,QString>::Iterator it = runningApps.find( sigPid );
320 if ( it == runningApps.end() ) { 319 if ( it == runningApps.end() ) {
321 if ( sigPid == qlPid ) { 320 if ( sigPid == qlPid ) {
322 qDebug( "quicklauncher stopped" ); 321 qDebug( "quicklauncher stopped" );
323 qlPid = 0; 322 qlPid = 0;
324 qlReady = FALSE; 323 qlReady = FALSE;
325 QFile::remove("/tmp/qcop-msg-quicklauncher" ); 324 QFile::remove("/tmp/qcop-msg-quicklauncher" );
326 QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) ); 325 QTimer::singleShot( 2000, this, SLOT(createQuickLauncher()) );
327 } 326 }
328/* 327/*
329 if ( sigPid == -1 ) 328 if ( sigPid == -1 )
330 qDebug("non-qtopia application exited (disregarded)"); 329 qDebug("non-qtopia application exited (disregarded)");
331 else 330 else
332 qDebug("==== no pid matching %d in list, definite bug", sigPid); 331 qDebug("==== no pid matching %d in list, definite bug", sigPid);
333*/ 332*/
334 return; 333 return;
335 } 334 }
336 QString appName = *it; 335 QString appName = *it;
337 runningApps.remove(it); 336 runningApps.remove(it);
338 337
339 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName); 338 QMap<QString,int>::Iterator hbit = waitingHeartbeat.find(appName);
340 if ( hbit != waitingHeartbeat.end() ) { 339 if ( hbit != waitingHeartbeat.end() ) {
341 killTimer( *hbit ); 340 killTimer( *hbit );
342 waitingHeartbeat.remove( hbit ); 341 waitingHeartbeat.remove( hbit );
343 } 342 }
344 if ( appName == appKillerName ) { 343 if ( appName == appKillerName ) {
345 appKillerName = QString::null; 344 appKillerName = QString::null;
346 delete appKillerBox; 345 delete appKillerBox;
347 appKillerBox = 0; 346 appKillerBox = 0;
348 } 347 }
349 348
350 /* we must disable preload for an app that crashes as the system logic relies on preloaded apps 349 /* we must disable preload for an app that crashes as the system logic relies on preloaded apps
351 actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload 350 actually being loaded. If eg. the crash happened in the constructor, we can't automatically reload
352 the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution) 351 the app (withouth some timeout value for eg. 3 tries (which I think is a bad solution)
353 */ 352 */
354 bool preloadDisabled = FALSE; 353 bool preloadDisabled = FALSE;
355 if ( !DocumentList::appLnkSet ) return; 354 if ( !DocumentList::appLnkSet ) return;
356 const AppLnk* app = DocumentList::appLnkSet->findExec( appName ); 355 const AppLnk* app = DocumentList::appLnkSet->findExec( appName );
357 if ( !app ) return; // QCop messages processed to slow? 356 if ( !app ) return; // QCop messages processed to slow?
358 if ( crashed && app->isPreloaded() ) { 357 if ( crashed && app->isPreloaded() ) {
359 Config cfg("Launcher"); 358 Config cfg("Launcher");
360 cfg.setGroup("Preload"); 359 cfg.setGroup("Preload");
361 QStringList apps = cfg.readListEntry("Apps",','); 360 QStringList apps = cfg.readListEntry("Apps",',');
362 QString exe = app->exec(); 361 QString exe = app->exec();
363 apps.remove(exe); 362 apps.remove(exe);
364 cfg.writeEntry("Apps",apps,','); 363 cfg.writeEntry("Apps",apps,',');
365 preloadDisabled = TRUE; 364 preloadDisabled = TRUE;
366 } 365 }
367 366
368 // clean up 367 // clean up
369 if ( exitStatus ) { 368 if ( exitStatus ) {
370 QCopEnvelope e("QPE/System", "notBusy(QString)"); 369 QCopEnvelope e("QPE/System", "notBusy(QString)");
371 e << app->exec(); 370 e << app->exec();
372 } 371 }
373/* 372/*
374 // debug info 373 // debug info
375 for (it = runningApps.begin(); it != runningApps.end(); ++it) { 374 for (it = runningApps.begin(); it != runningApps.end(); ++it) {
376 qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() ); 375 qDebug("running according to internal list: %s, with pid %d", (*it).data(), it.key() );
377 } 376 }
378*/ 377*/
379 378
380#ifdef QTOPIA_PROGRAM_MONITOR 379#ifdef QTOPIA_PROGRAM_MONITOR
381 if ( crashed ) { 380 if ( crashed ) {
382 QString sig; 381 QString sig;
383 switch( exitStatus ) { 382 switch( exitStatus ) {
384 case SIGABRT: sig = "SIGABRT"; break; 383 case SIGABRT: sig = "SIGABRT"; break;
385 case SIGALRM: sig = "SIGALRM"; break; 384 case SIGALRM: sig = "SIGALRM"; break;
386 case SIGBUS: sig = "SIGBUS"; break; 385 case SIGBUS: sig = "SIGBUS"; break;
387 case SIGFPE: sig = "SIGFPE"; break; 386 case SIGFPE: sig = "SIGFPE"; break;
388 case SIGHUP: sig = "SIGHUP"; break; 387 case SIGHUP: sig = "SIGHUP"; break;
389 case SIGILL: sig = "SIGILL"; break; 388 case SIGILL: sig = "SIGILL"; break;
390 case SIGKILL: sig = "SIGKILL"; break; 389 case SIGKILL: sig = "SIGKILL"; break;
391 case SIGPIPE: sig = "SIGPIPE"; break; 390 case SIGPIPE: sig = "SIGPIPE"; break;
392 case SIGQUIT: sig = "SIGQUIT"; break; 391 case SIGQUIT: sig = "SIGQUIT"; break;
393 case SIGSEGV: sig = "SIGSEGV"; break; 392 case SIGSEGV: sig = "SIGSEGV"; break;
394 case SIGTERM: sig = "SIGTERM"; break; 393 case SIGTERM: sig = "SIGTERM"; break;
395 case SIGTRAP: sig = "SIGTRAP"; break; 394 case SIGTRAP: sig = "SIGTRAP"; break;
396 default: sig = QString("Unkown %1").arg(exitStatus); 395 default: sig = QString("Unkown %1").arg(exitStatus);
397 } 396 }
398 if ( preloadDisabled ) 397 if ( preloadDisabled )
399 sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>"); 398 sig += tr("<qt><p>Fast loading has been disabled for this application. Tap and hold the application icon to reenable it.</qt>");
400 399
401 QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig ); 400 QString str = tr("<qt><b>%1</b> was terminated due to signal code %2</qt>").arg( app->name() ).arg( sig );
402 QMessageBox::information(0, tr("Application terminated"), str ); 401 QMessageBox::information(0, tr("Application terminated"), str );
403 } else { 402 } else {
404 if ( exitStatus == 255 ) { //could not find app (because global returns -1) 403 if ( exitStatus == 255 ) { //could not find app (because global returns -1)
405 QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) ); 404 QMessageBox::information(0, tr("Application not found"), tr("<qt>Could not locate application <b>%1</b></qt>").arg( app->exec() ) );
406 } else { 405 } else {
407 QFileInfo fi(Opie::Global::tempDir() + "qcop-msg-" + appName); 406 QFileInfo fi(OGlobal::tempDirPath() + "qcop-msg-" + appName);
408 if ( fi.exists() && fi.size() ) { 407 if ( fi.exists() && fi.size() ) {
409 emit terminated(sigPid, appName); 408 emit terminated(sigPid, appName);
410 qWarning("Re executing obmitted for %s", appName.latin1() ); 409 qWarning("Re executing obmitted for %s", appName.latin1() );
411 // execute( appName, QString::null ); 410 // execute( appName, QString::null );
412 return; 411 return;
413 } 412 }
414 } 413 }
415 } 414 }
416 415
417#endif 416#endif
418 417
419 emit terminated(sigPid, appName); 418 emit terminated(sigPid, appName);
420} 419}
421#else 420#else
422void AppLauncher::sigStopped(int sigPid, int sigStatus) 421void AppLauncher::sigStopped(int sigPid, int sigStatus)
423{ 422{
424 qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)"); 423 qDebug("Unhandled signal : AppLauncher::sigStopped(int sigPid, int sigStatus)");
425} 424}
426#endif // Q_OS_WIN32 425#endif // Q_OS_WIN32
427 426
428bool AppLauncher::isRunning(const QString &app) 427bool AppLauncher::isRunning(const QString &app)
429{ 428{
430 for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) { 429 for (QMap<int,QString>::ConstIterator it = runningApps.begin(); it != runningApps.end(); ++it) {
431 if ( *it == app ) { 430 if ( *it == app ) {
432#ifdef Q_OS_UNIX 431#ifdef Q_OS_UNIX
433 pid_t t = ::__getpgid( it.key() ); 432 pid_t t = ::__getpgid( it.key() );
434 if ( t == -1 ) { 433 if ( t == -1 ) {
435 qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() ); 434 qDebug("appLauncher bug, %s believed running, but pid %d is not existing", app.data(), it.key() );
436 runningApps.remove( it.key() ); 435 runningApps.remove( it.key() );
437 return FALSE; 436 return FALSE;
438 } 437 }
439#endif 438#endif
440 return TRUE; 439 return TRUE;
441 } 440 }
442 } 441 }
443 442
444 return FALSE; 443 return FALSE;
445} 444}
446 445
447bool AppLauncher::executeBuiltin(const QString &c, const QString &document) 446bool AppLauncher::executeBuiltin(const QString &c, const QString &document)
448{ 447{
449 Global::Command* builtin = Opie::Global::builtinCommands(); 448 Global::Command* builtin = OGlobal::builtinCommands();
450 QGuardedPtr<QWidget> *running = Opie::Global::builtinRunning(); 449 QGuardedPtr<QWidget> *running = OGlobal::builtinRunning();
451 450
452 // Attempt to execute the app using a builtin class for the app 451 // Attempt to execute the app using a builtin class for the app
453 if (builtin) { 452 if (builtin) {
454 for (int i = 0; builtin[i].file; i++) { 453 for (int i = 0; builtin[i].file; i++) {
455 if ( builtin[i].file == c ) { 454 if ( builtin[i].file == c ) {
456 if ( running[i] ) { 455 if ( running[i] ) {
457 if ( !document.isNull() && builtin[i].documentary ) 456 if ( !document.isNull() && builtin[i].documentary )
458 Global::setDocument(running[i], document); 457 Global::setDocument(running[i], document);
459 running[i]->raise(); 458 running[i]->raise();
460 running[i]->show(); 459 running[i]->show();
461 running[i]->setActiveWindow(); 460 running[i]->setActiveWindow();
462 } else { 461 } else {
463 running[i] = builtin[i].func( builtin[i].maximized ); 462 running[i] = builtin[i].func( builtin[i].maximized );
464 } 463 }
465#ifndef QT_NO_COP 464#ifndef QT_NO_COP
466 QCopEnvelope e("QPE/System", "notBusy(QString)" ); 465 QCopEnvelope e("QPE/System", "notBusy(QString)" );
467 e << c; // that was quick ;-) 466 e << c; // that was quick ;-)
468#endif 467#endif
469 return TRUE; 468 return TRUE;
470 } 469 }
471 } 470 }
472 } 471 }
473 472
474 // Convert the command line in to a list of arguments 473 // Convert the command line in to a list of arguments
475 QStringList list = QStringList::split(QRegExp(" *"),c); 474 QStringList list = QStringList::split(QRegExp(" *"),c);
476 QString ap=list[0]; 475 QString ap=list[0];
477 476
478 if ( ap == "suspend" ) { // No tr 477 if ( ap == "suspend" ) { // No tr
479 QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 478 QWSServer::processKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
480 return TRUE; 479 return TRUE;
481 } 480 }
482 481
483 return FALSE; 482 return FALSE;
484} 483}
485 484
486bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise) 485bool AppLauncher::execute(const QString &c, const QString &docParam, bool noRaise)
487{ 486{
488 qWarning("AppLauncher::execute"); 487 qWarning("AppLauncher::execute");
489 // Convert the command line in to a list of arguments 488 // Convert the command line in to a list of arguments
490 QStringList list = QStringList::split(QRegExp(" *"),c); 489 QStringList list = QStringList::split(QRegExp(" *"),c);
491 if ( !docParam.isEmpty() ) 490 if ( !docParam.isEmpty() )
492 list.append( docParam ); 491 list.append( docParam );
493 492
494 QString appName = list[0]; 493 QString appName = list[0];
495 if ( isRunning(appName) ) { 494 if ( isRunning(appName) ) {
496 QCString channel = "QPE/Application/"; 495 QCString channel = "QPE/Application/";
497 channel += appName.latin1(); 496 channel += appName.latin1();
498 497
499 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile 498 // Need to lock it to avoid race conditions with QPEApplication::processQCopFile
500 QFile f(Opie::Global::tempDir() + "qcop-msg-" + appName); 499 QFile f(OGlobal::tempDirPath() + "qcop-msg-" + appName);
501 if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) { 500 if ( !noRaise && f.open(IO_WriteOnly | IO_Append) ) {
502#ifndef Q_OS_WIN32 501#ifndef Q_OS_WIN32
503 flock(f.handle(), LOCK_EX); 502 flock(f.handle(), LOCK_EX);
504#endif 503#endif
505 504
506 QDataStream ds(&f); 505 QDataStream ds(&f);
507 QByteArray b; 506 QByteArray b;
508 QDataStream bstream(b, IO_WriteOnly); 507 QDataStream bstream(b, IO_WriteOnly);
509 if ( !f.size() ) { 508 if ( !f.size() ) {
510 ds << channel << QCString("raise()") << b; 509 ds << channel << QCString("raise()") << b;
511 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) { 510 if ( !waitingHeartbeat.contains( appName ) && appKillerName != appName ) {
512 int id = startTimer(RAISE_TIMEOUT_MS); 511 int id = startTimer(RAISE_TIMEOUT_MS);
513 waitingHeartbeat.insert( appName, id ); 512 waitingHeartbeat.insert( appName, id );
514 } 513 }
515 } 514 }
516 if ( !docParam.isEmpty() ) { 515 if ( !docParam.isEmpty() ) {
517 bstream << docParam; 516 bstream << docParam;
518 ds << channel << QCString("setDocument(QString)") << b; 517 ds << channel << QCString("setDocument(QString)") << b;
519 } 518 }
520 519
521 f.flush(); 520 f.flush();
522#ifndef Q_OS_WIN32 521#ifndef Q_OS_WIN32
523 flock(f.handle(), LOCK_UN); 522 flock(f.handle(), LOCK_UN);
524#endif 523#endif
525 f.close(); 524 f.close();
526 } 525 }
527 if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings 526 if ( QCopChannel::isRegistered(channel) ) // avoid unnecessary warnings
528 QCopChannel::send(channel,"QPEProcessQCop()"); 527 QCopChannel::send(channel,"QPEProcessQCop()");
529 528
530 return TRUE; 529 return TRUE;
531 } 530 }
532 531
533#ifdef QT_NO_QWS_MULTIPROCESS 532#ifdef QT_NO_QWS_MULTIPROCESS
534 QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c), 533 QMessageBox::warning( 0, tr("Error"), tr("<qt>Could not find the application %1</qt>").arg(c),
535 tr("OK"), 0, 0, 0, 1 ); 534 tr("OK"), 0, 0, 0, 1 );
536#else 535#else
537 536
538 QStrList slist; 537 QStrList slist;
539 unsigned j; 538 unsigned j;
540 for ( j = 0; j < list.count(); j++ ) 539 for ( j = 0; j < list.count(); j++ )
541 slist.append( list[j].utf8() ); 540 slist.append( list[j].utf8() );
542 541
543 const char **args = new const char *[slist.count() + 1]; 542 const char **args = new const char *[slist.count() + 1];
544 for ( j = 0; j < slist.count(); j++ ) 543 for ( j = 0; j < slist.count(); j++ )
545 args[j] = slist.at(j); 544 args[j] = slist.at(j);
546 args[j] = NULL; 545 args[j] = NULL;
547 546
548#ifndef Q_OS_WIN32 547#ifndef Q_OS_WIN32
549#ifdef Q_OS_MACX 548#ifdef Q_OS_MACX
550 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) { 549 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".dylib" ) ) {
551#else 550#else
552 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) { 551 if ( qlPid && qlReady && QFile::exists( QPEApplication::qpeDir()+"plugins/application/lib"+args[0] + ".so" ) ) {
553#endif /* Q_OS_MACX */ 552#endif /* Q_OS_MACX */
554 qDebug( "Quick launching: %s", args[0] ); 553 qDebug( "Quick launching: %s", args[0] );
555 if ( getuid() == 0 ) 554 if ( getuid() == 0 )
556 setpriority( PRIO_PROCESS, qlPid, 0 ); 555 setpriority( PRIO_PROCESS, qlPid, 0 );
557 QCString qlch("QPE/QuickLauncher-"); 556 QCString qlch("QPE/QuickLauncher-");
558 qlch += QString::number(qlPid); 557 qlch += QString::number(qlPid);
559 QCopEnvelope env( qlch, "execute(QStrList)" ); 558 QCopEnvelope env( qlch, "execute(QStrList)" );
560 env << slist; 559 env << slist;
561 runningApps[qlPid] = QString(args[0]); 560 runningApps[qlPid] = QString(args[0]);
562 emit launched(qlPid, QString(args[0])); 561 emit launched(qlPid, QString(args[0]));
563 QCopEnvelope e("QPE/System", "busy()"); 562 QCopEnvelope e("QPE/System", "busy()");
564 qlPid = 0; 563 qlPid = 0;
565 qlReady = FALSE; 564 qlReady = FALSE;
566 QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) ); 565 QTimer::singleShot( getuid() == 0 ? 800 : 1500, this, SLOT(createQuickLauncher()) );
567 } else { 566 } else {
568 int pid = ::vfork(); 567 int pid = ::vfork();
569 if ( !pid ) { 568 if ( !pid ) {
570 for ( int fd = 3; fd < 100; fd++ ) 569 for ( int fd = 3; fd < 100; fd++ )
571 ::close( fd ); 570 ::close( fd );
572 ::setpgid( ::getpid(), ::getppid() ); 571 ::setpgid( ::getpid(), ::getppid() );
573 // Try bindir first, so that foo/bar works too 572 // Try bindir first, so that foo/bar works too
574 ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args ); 573 ::execv( QPEApplication::qpeDir()+"bin/"+args[0], (char * const *)args );
575 ::execvp( args[0], (char * const *)args ); 574 ::execvp( args[0], (char * const *)args );
576 _exit( -1 ); 575 _exit( -1 );
577 } 576 }
578 577
579 runningApps[pid] = QString(args[0]); 578 runningApps[pid] = QString(args[0]);
580 emit launched(pid, QString(args[0])); 579 emit launched(pid, QString(args[0]));
581 QCopEnvelope e("QPE/System", "busy()"); 580 QCopEnvelope e("QPE/System", "busy()");
582 } 581 }
583#else 582#else
584 QProcess *proc = new QProcess(this); 583 QProcess *proc = new QProcess(this);
585 if (proc){ 584 if (proc){
586 for (int i=0; i < slist.count(); i++) 585 for (int i=0; i < slist.count(); i++)
587 proc->addArgument(args[i]); 586 proc->addArgument(args[i]);
588 connect(proc, SIGNAL(processExited()), this, SLOT(processExited())); 587 connect(proc, SIGNAL(processExited()), this, SLOT(processExited()));
589 if (!proc->start()){ 588 if (!proc->start()){
590 qDebug("Unable to start application %s", args[0]); 589 qDebug("Unable to start application %s", args[0]);
591 }else{ 590 }else{
592 PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier(); 591 PROCESS_INFORMATION *procInfo = (PROCESS_INFORMATION *)proc->processIdentifier();
593 if (procInfo){ 592 if (procInfo){
594 DWORD pid = procInfo->dwProcessId; 593 DWORD pid = procInfo->dwProcessId;
595 runningApps[pid] = QString(args[0]); 594 runningApps[pid] = QString(args[0]);
596 runningAppsProc.append(proc); 595 runningAppsProc.append(proc);
597 emit launched(pid, QString(args[0])); 596 emit launched(pid, QString(args[0]));
598 QCopEnvelope e("QPE/System", "busy()"); 597 QCopEnvelope e("QPE/System", "busy()");
599 }else{ 598 }else{
600 qDebug("Unable to read process inforation #1 for %s", args[0]); 599 qDebug("Unable to read process inforation #1 for %s", args[0]);
601 } 600 }
602 } 601 }
603 }else{ 602 }else{
604 qDebug("Unable to create process for application %s", args[0]); 603 qDebug("Unable to create process for application %s", args[0]);
605 return FALSE; 604 return FALSE;
606 } 605 }
607#endif 606#endif
608#endif //QT_NO_QWS_MULTIPROCESS 607#endif //QT_NO_QWS_MULTIPROCESS
609 608
610 delete [] args; 609 delete [] args;
611 return TRUE; 610 return TRUE;
612} 611}
613 612
614void AppLauncher::kill( int pid ) 613void AppLauncher::kill( int pid )
615{ 614{
616#ifndef Q_OS_WIN32 615#ifndef Q_OS_WIN32
617 ::kill( pid, SIGTERM ); 616 ::kill( pid, SIGTERM );
618#else 617#else
619 for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) { 618 for ( QProcess *proc = runningAppsProc.first(); proc; proc = runningAppsProc.next() ) {
620 if ( proc->processIdentifier() == pid ) { 619 if ( proc->processIdentifier() == pid ) {
621 proc->kill(); 620 proc->kill();
622 break; 621 break;
623 } 622 }
624 } 623 }
625#endif 624#endif
626} 625}
627 626
628int AppLauncher::pidForName( const QString &appName ) 627int AppLauncher::pidForName( const QString &appName )
629{ 628{
630 int pid = -1; 629 int pid = -1;
631 630
632 QMap<int, QString>::Iterator it; 631 QMap<int, QString>::Iterator it;
633 for (it = runningApps.begin(); it!= runningApps.end(); ++it) { 632 for (it = runningApps.begin(); it!= runningApps.end(); ++it) {
634 if (*it == appName) { 633 if (*it == appName) {
635 pid = it.key(); 634 pid = it.key();
636 break; 635 break;
637 } 636 }
638 } 637 }
639 638
640 return pid; 639 return pid;
641} 640}
642 641
643void AppLauncher::createQuickLauncher() 642void AppLauncher::createQuickLauncher()
644{ 643{
645 static bool disabled = FALSE; 644 static bool disabled = FALSE;
646 if (disabled) 645 if (disabled)
647 return; 646 return;
648 647
649 qlReady = FALSE; 648 qlReady = FALSE;
650 qlPid = ::vfork(); 649 qlPid = ::vfork();
651 if ( !qlPid ) { 650 if ( !qlPid ) {
652 char **args = new char *[2]; 651 char **args = new char *[2];
653 args[0] = "quicklauncher"; 652 args[0] = "quicklauncher";
654 args[1] = 0; 653 args[1] = 0;
655 for ( int fd = 3; fd < 100; fd++ ) 654 for ( int fd = 3; fd < 100; fd++ )
656 ::close( fd ); 655 ::close( fd );
657 ::setpgid( ::getpid(), ::getppid() ); 656 ::setpgid( ::getpid(), ::getppid() );
658 // Try bindir first, so that foo/bar works too 657 // Try bindir first, so that foo/bar works too
659 /* 658 /*
660 * LD_BIND_NOW will change the behaviour of ld.so and dlopen 659 * LD_BIND_NOW will change the behaviour of ld.so and dlopen
661 * RTLD_LAZY will be made RTLD_NOW which leads to problem 660 * RTLD_LAZY will be made RTLD_NOW which leads to problem
662 * with miscompiled libraries... if LD_BIND_NOW is set.. there 661 * with miscompiled libraries... if LD_BIND_NOW is set.. there
663 * is no way back.. We will wait for numbers from TT to see 662 * is no way back.. We will wait for numbers from TT to see
664 * if using LD_BIND_NOW is worth it - zecke 663 * if using LD_BIND_NOW is worth it - zecke
665 */ 664 */
666 //setenv( "LD_BIND_NOW", "1", 1 ); 665 //setenv( "LD_BIND_NOW", "1", 1 );
667 ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args ); 666 ::execv( QPEApplication::qpeDir()+"bin/quicklauncher", args );
668 ::execvp( "quicklauncher", args ); 667 ::execvp( "quicklauncher", args );
669 delete []args; 668 delete []args;
670 disabled = TRUE; 669 disabled = TRUE;
671 _exit( -1 ); 670 _exit( -1 );
672 } else if ( qlPid == -1 ) { 671 } else if ( qlPid == -1 ) {
673 qlPid = 0; 672 qlPid = 0;
674 } else { 673 } else {
675 if ( getuid() == 0 ) 674 if ( getuid() == 0 )
676 setpriority( PRIO_PROCESS, qlPid, 19 ); 675 setpriority( PRIO_PROCESS, qlPid, 19 );
677 } 676 }
678} 677}
679 678
680// Used only by Win32 679// Used only by Win32
681void AppLauncher::processExited() 680void AppLauncher::processExited()
682{ 681{
683#ifdef Q_OS_WIN32 682#ifdef Q_OS_WIN32
684 qDebug("AppLauncher::processExited()"); 683 qDebug("AppLauncher::processExited()");
685 bool found = FALSE; 684 bool found = FALSE;
686 QProcess *proc = (QProcess *) sender(); 685 QProcess *proc = (QProcess *) sender();
687 if (!proc){ 686 if (!proc){
688 qDebug("Interanl error NULL proc"); 687 qDebug("Interanl error NULL proc");
689 return; 688 return;
690 } 689 }
691 690
692 QString appName = proc->arguments()[0]; 691 QString appName = proc->arguments()[0];
diff --git a/core/launcher/config.in b/core/launcher/config.in
index 2d9c1c2..db39210 100644
--- a/core/launcher/config.in
+++ b/core/launcher/config.in
@@ -1,16 +1,16 @@
1 config LAUNCHER 1 config LAUNCHER
2 boolean "opie-taskbar (program launcher qpe for Opie)" 2 boolean "opie-taskbar (program launcher qpe for Opie)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI
5 5
6if LAUNCHER 6if LAUNCHER
7 config PRELOAD 7 config PRELOAD
8 boolean 8 boolean
9 default "y" 9 default "y"
10 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && LAUNCHER 10 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI && LAUNCHER
11 11
12 config LAUNCHER_CORE 12 config LAUNCHER_CORE
13 boolean 13 boolean
14 default "y" 14 default "y"
15 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && LAUNCHER && PRELOAD 15 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2UI && LAUNCHER && PRELOAD
16endif 16endif
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp
index ece6931..440bf1e 100644
--- a/core/launcher/documentlist.cpp
+++ b/core/launcher/documentlist.cpp
@@ -1,464 +1,467 @@
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 "launcherglobal.h" 22
23#include <opie2/oglobal.h>
23 24
24#include <qtopia/config.h> 25#include <qtopia/config.h>
25#include <qtopia/mimetype.h> 26#include <qtopia/mimetype.h>
26#include <qtopia/resource.h> 27#include <qtopia/resource.h>
27#include <qtopia/global.h>
28#include <qtopia/private/categories.h> 28#include <qtopia/private/categories.h>
29#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
30#include <qtopia/applnk.h> 30#include <qtopia/applnk.h>
31#include <qtopia/storage.h> 31#include <qtopia/storage.h>
32#ifdef Q_WS_QWS 32#ifdef Q_WS_QWS
33#include <qtopia/qcopenvelope_qws.h> 33#include <qtopia/qcopenvelope_qws.h>
34#endif 34#endif
35 35
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qfileinfo.h> 37#include <qfileinfo.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qdir.h> 40#include <qdir.h>
41#include <qpainter.h> 41#include <qpainter.h>
42#include <qimage.h> 42#include <qimage.h>
43#include <qcopchannel_qws.h> 43#include <qcopchannel_qws.h>
44#include <qlistview.h> 44#include <qlistview.h>
45#include <qlist.h> 45#include <qlist.h>
46#include <qpixmap.h> 46#include <qpixmap.h>
47 47
48 48
49AppLnkSet *DocumentList::appLnkSet = 0; 49AppLnkSet *DocumentList::appLnkSet = 0;
50 50
51static const int MAX_SEARCH_DEPTH = 10; 51static const int MAX_SEARCH_DEPTH = 10;
52 52
53 53
54class DocumentListPrivate : public QObject { 54class DocumentListPrivate : public QObject {
55 Q_OBJECT 55 Q_OBJECT
56public: 56public:
57 DocumentListPrivate( ServerInterface *gui ); 57 DocumentListPrivate( ServerInterface *gui );
58 ~DocumentListPrivate(); 58 ~DocumentListPrivate();
59 59
60 void initialize(); 60 void initialize();
61 61
62 const QString nextFile(); 62 const QString nextFile();
63 const DocLnk *iterate(); 63 const DocLnk *iterate();
64 bool store( DocLnk* dl ); 64 bool store( DocLnk* dl );
65 void estimatedPercentScanned(); 65 void estimatedPercentScanned();
66 66
67 DocLnkSet dls; 67 DocLnkSet dls;
68 QDict<void> reference; 68 QDict<void> reference;
69 QDictIterator<void> *dit; 69 QDictIterator<void> *dit;
70 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state; 70 enum { Find, RemoveKnownFiles, MakeUnknownFiles, Done } state;
71 71
72 QStringList docPaths; 72 QStringList docPaths;
73 unsigned int docPathsSearched; 73 unsigned int docPathsSearched;
74 74
75 int searchDepth; 75 int searchDepth;
76 QDir *listDirs[MAX_SEARCH_DEPTH]; 76 QDir *listDirs[MAX_SEARCH_DEPTH];
77 const QFileInfoList *lists[MAX_SEARCH_DEPTH]; 77 const QFileInfoList *lists[MAX_SEARCH_DEPTH];
78 unsigned int listPositions[MAX_SEARCH_DEPTH]; 78 unsigned int listPositions[MAX_SEARCH_DEPTH];
79 79
80 StorageInfo *storage; 80 StorageInfo *storage;
81 81
82 int tid; 82 int tid;
83 83
84 ServerInterface *serverGui; 84 ServerInterface *serverGui;
85 85
86 bool needToSendAllDocLinks; 86 bool needToSendAllDocLinks;
87 bool sendAppLnks; 87 bool sendAppLnks;
88 bool sendDocLnks; 88 bool sendDocLnks;
89 bool scanDocs; 89 bool scanDocs;
90}; 90};
91 91
92 92
93DocumentList::DocumentList( ServerInterface *serverGui, bool scanDocs, 93/*
94 * scandocs will be read from Config
95 */
96DocumentList::DocumentList( ServerInterface *serverGui, bool /*scanDocs*/,
94 QObject *parent, const char *name ) 97 QObject *parent, const char *name )
95 : QObject( parent, name ) 98 : QObject( parent, name )
96{ 99{
97 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 100 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
98 d = new DocumentListPrivate( serverGui ); 101 d = new DocumentListPrivate( serverGui );
99 d->needToSendAllDocLinks = false; 102 d->needToSendAllDocLinks = false;
100 103
101 Config cfg( "Launcher" ); 104 Config cfg( "Launcher" );
102 cfg.setGroup( "DocTab" ); 105 cfg.setGroup( "DocTab" );
103 d->scanDocs = cfg.readBoolEntry( "Enable", true ); 106 d->scanDocs = cfg.readBoolEntry( "Enable", true );
104 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs ); 107 qDebug( "DocumentList::DocumentList() : scanDocs = %d", d->scanDocs );
105 108
106 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) ); 109 QTimer::singleShot( 10, this, SLOT( startInitialScan() ) );
107} 110}
108 111
109void DocumentList::startInitialScan() 112void DocumentList::startInitialScan()
110{ 113{
111 reloadAppLnks(); 114 reloadAppLnks();
112 reloadDocLnks(); 115 reloadDocLnks();
113} 116}
114 117
115DocumentList::~DocumentList() 118DocumentList::~DocumentList()
116{ 119{
117 delete appLnkSet; 120 delete appLnkSet;
118 delete d; 121 delete d;
119} 122}
120 123
121 124
122void DocumentList::add( const DocLnk& doc ) 125void DocumentList::add( const DocLnk& doc )
123{ 126{
124 if ( d->serverGui && QFile::exists( doc.file() ) ) 127 if ( d->serverGui && QFile::exists( doc.file() ) )
125 d->serverGui->documentAdded( doc ); 128 d->serverGui->documentAdded( doc );
126} 129}
127 130
128 131
129void DocumentList::start() 132void DocumentList::start()
130{ 133{
131 resume(); 134 resume();
132} 135}
133 136
134 137
135void DocumentList::pause() 138void DocumentList::pause()
136{ 139{
137 //qDebug("pause %i", d->tid); 140 //qDebug("pause %i", d->tid);
138 killTimer( d->tid ); 141 killTimer( d->tid );
139 d->tid = 0; 142 d->tid = 0;
140} 143}
141 144
142 145
143void DocumentList::resume() 146void DocumentList::resume()
144{ 147{
145 if ( d->tid == 0 ) { 148 if ( d->tid == 0 ) {
146 d->tid = startTimer( 20 ); 149 d->tid = startTimer( 20 );
147 //qDebug("resumed %i", d->tid); 150 //qDebug("resumed %i", d->tid);
148 } 151 }
149} 152}
150 153
151/* 154/*
152void DocumentList::resend() 155void DocumentList::resend()
153{ 156{
154 // Re-emits all the added items to the list (firstly letting everyone know to 157 // Re-emits all the added items to the list (firstly letting everyone know to
155 // clear what they have as it is being sent again) 158 // clear what they have as it is being sent again)
156 pause(); 159 pause();
157 emit allRemoved(); 160 emit allRemoved();
158 QTimer::singleShot( 5, this, SLOT( resendWorker() ) ); 161 QTimer::singleShot( 5, this, SLOT( resendWorker() ) );
159} 162}
160 163
161 164
162void DocumentList::resendWorker() 165void DocumentList::resendWorker()
163{ 166{
164 const QList<DocLnk> &list = d->dls.children(); 167 const QList<DocLnk> &list = d->dls.children();
165 for ( QListIterator<DocLnk> it( list ); it.current(); ++it ) 168 for ( QListIterator<DocLnk> it( list ); it.current(); ++it )
166 add( *(*it) ); 169 add( *(*it) );
167 resume(); 170 resume();
168} 171}
169*/ 172*/
170 173
171void DocumentList::rescan() 174void DocumentList::rescan()
172{ 175{
173 //qDebug("rescan"); 176 //qDebug("rescan");
174 pause(); 177 pause();
175 d->initialize(); 178 d->initialize();
176 resume(); 179 resume();
177} 180}
178 181
179 182
180void DocumentList::timerEvent( QTimerEvent *te ) 183void DocumentList::timerEvent( QTimerEvent *te )
181{ 184{
182 if ( te->timerId() == d->tid ) { 185 if ( te->timerId() == d->tid ) {
183 // Do 3 at a time 186 // Do 3 at a time
184 for (int i = 0; i < 3; i++ ) { 187 for (int i = 0; i < 3; i++ ) {
185 const DocLnk *lnk = d->iterate(); 188 const DocLnk *lnk = d->iterate();
186 if ( lnk ) { 189 if ( lnk ) {
187 add( *lnk ); 190 add( *lnk );
188 } else { 191 } else {
189 // stop when done 192 // stop when done
190 pause(); 193 pause();
191 if ( d->serverGui ) 194 if ( d->serverGui )
192 d->serverGui->documentScanningProgress( 100 ); 195 d->serverGui->documentScanningProgress( 100 );
193 if ( d->needToSendAllDocLinks ) 196 if ( d->needToSendAllDocLinks )
194 sendAllDocLinks(); 197 sendAllDocLinks();
195 break; 198 break;
196 } 199 }
197 } 200 }
198 } 201 }
199} 202}
200 203
201 204
202void DocumentList::reloadAppLnks() 205void DocumentList::reloadAppLnks()
203{ 206{
204 if ( d->sendAppLnks && d->serverGui ) { 207 if ( d->sendAppLnks && d->serverGui ) {
205 d->serverGui->applicationScanningProgress( 0 ); 208 d->serverGui->applicationScanningProgress( 0 );
206 d->serverGui->allApplicationsRemoved(); 209 d->serverGui->allApplicationsRemoved();
207 } 210 }
208 211
209 delete appLnkSet; 212 delete appLnkSet;
210 appLnkSet = new AppLnkSet( MimeType::appsFolderName() ); 213 appLnkSet = new AppLnkSet( MimeType::appsFolderName() );
211 214
212 if ( d->sendAppLnks && d->serverGui ) { 215 if ( d->sendAppLnks && d->serverGui ) {
213 static QStringList prevTypeList; 216 static QStringList prevTypeList;
214 QStringList types = appLnkSet->types(); 217 QStringList types = appLnkSet->types();
215 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) { 218 for ( QStringList::Iterator ittypes=types.begin(); ittypes!=types.end(); ++ittypes) {
216 if ( !(*ittypes).isEmpty() ) { 219 if ( !(*ittypes).isEmpty() ) {
217 if ( !prevTypeList.contains(*ittypes) ) { 220 if ( !prevTypeList.contains(*ittypes) ) {
218 QString name = appLnkSet->typeName(*ittypes); 221 QString name = appLnkSet->typeName(*ittypes);
219 QPixmap pm = appLnkSet->typePixmap(*ittypes); 222 QPixmap pm = appLnkSet->typePixmap(*ittypes);
220 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes); 223 QPixmap bgPm = appLnkSet->typeBigPixmap(*ittypes);
221 224
222 if (pm.isNull()) { 225 if (pm.isNull()) {
223 QImage img( Resource::loadImage( "UnknownDocument" ) ); 226 QImage img( Resource::loadImage( "UnknownDocument" ) );
224 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); 227 pm = img.smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() );
225 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() ); 228 bgPm = img.smoothScale( AppLnk::bigIconSize(), AppLnk::bigIconSize() );
226 } 229 }
227 230
228 //qDebug("adding type %s", (*ittypes).latin1()); 231 //qDebug("adding type %s", (*ittypes).latin1());
229 232
230 // ### our current launcher expects docs tab to be last 233 // ### our current launcher expects docs tab to be last
231 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm ); 234 d->serverGui->typeAdded( *ittypes, name.isNull() ? (*ittypes) : name, pm, bgPm );
232 } 235 }
233 prevTypeList.remove(*ittypes); 236 prevTypeList.remove(*ittypes);
234 } 237 }
235 } 238 }
236 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) { 239 for ( QStringList::Iterator ittypes=prevTypeList.begin(); ittypes!=prevTypeList.end(); ++ittypes) {
237 //qDebug("removing type %s", (*ittypes).latin1()); 240 //qDebug("removing type %s", (*ittypes).latin1());
238 d->serverGui->typeRemoved(*ittypes); 241 d->serverGui->typeRemoved(*ittypes);
239 } 242 }
240 prevTypeList = types; 243 prevTypeList = types;
241 } 244 }
242 245
243 QListIterator<AppLnk> itapp( appLnkSet->children() ); 246 QListIterator<AppLnk> itapp( appLnkSet->children() );
244 AppLnk* l; 247 AppLnk* l;
245 while ( (l=itapp.current()) ) { 248 while ( (l=itapp.current()) ) {
246 ++itapp; 249 ++itapp;
247 if ( d->sendAppLnks && d->serverGui ) 250 if ( d->sendAppLnks && d->serverGui )
248 d->serverGui->applicationAdded( l->type(), *l ); 251 d->serverGui->applicationAdded( l->type(), *l );
249 } 252 }
250 253
251 if ( d->sendAppLnks && d->serverGui ) 254 if ( d->sendAppLnks && d->serverGui )
252 d->serverGui->applicationScanningProgress( 100 ); 255 d->serverGui->applicationScanningProgress( 100 );
253} 256}
254 257
255void DocumentList::reloadDocLnks() 258void DocumentList::reloadDocLnks()
256{ 259{
257 if ( !d->scanDocs ) 260 if ( !d->scanDocs )
258 return; 261 return;
259 262
260 if ( d->sendDocLnks && d->serverGui ) { 263 if ( d->sendDocLnks && d->serverGui ) {
261 d->serverGui->documentScanningProgress( 0 ); 264 d->serverGui->documentScanningProgress( 0 );
262 d->serverGui->allDocumentsRemoved(); 265 d->serverGui->allDocumentsRemoved();
263 } 266 }
264 267
265 rescan(); 268 rescan();
266} 269}
267 270
268void DocumentList::linkChanged( QString arg ) 271void DocumentList::linkChanged( QString arg )
269{ 272{
270 //qDebug( "linkchanged( %s )", arg.latin1() ); 273 //qDebug( "linkchanged( %s )", arg.latin1() );
271 274
272 if ( arg.isNull() || Opie::Global::isAppLnkFileName( arg ) ) { 275 if ( arg.isNull() || OGlobal::isAppLnkFileName( arg ) ) {
273 reloadAppLnks(); 276 reloadAppLnks();
274 } else { 277 } else {
275 278
276 const QList<DocLnk> &list = d->dls.children(); 279 const QList<DocLnk> &list = d->dls.children();
277 QListIterator<DocLnk> it( list ); 280 QListIterator<DocLnk> it( list );
278 while ( it.current() ) { 281 while ( it.current() ) {
279 DocLnk *doc = it.current(); 282 DocLnk *doc = it.current();
280 ++it; 283 ++it;
281 if ( ( doc->linkFileKnown() && doc->linkFile() == arg ) 284 if ( ( doc->linkFileKnown() && doc->linkFile() == arg )
282 || ( doc->fileKnown() && doc->file() == arg ) ) { 285 || ( doc->fileKnown() && doc->file() == arg ) ) {
283 //qDebug( "found old link" ); 286 //qDebug( "found old link" );
284 DocLnk* dl = new DocLnk( arg ); 287 DocLnk* dl = new DocLnk( arg );
285 // add new one if it exists and matches the mimetype 288 // add new one if it exists and matches the mimetype
286 if ( d->store( dl ) ) { 289 if ( d->store( dl ) ) {
287 // Existing link has been changed, send old link ref and a ref 290 // Existing link has been changed, send old link ref and a ref
288 // to the new link 291 // to the new link
289 //qDebug( "change case" ); 292 //qDebug( "change case" );
290 if ( d->serverGui ) 293 if ( d->serverGui )
291 d->serverGui->documentChanged( *doc, *dl ); 294 d->serverGui->documentChanged( *doc, *dl );
292 295
293 } else { 296 } else {
294 // Link has been removed or doesn't match the mimetypes any more 297 // Link has been removed or doesn't match the mimetypes any more
295 // so we aren't interested in it, so take it away from the list 298 // so we aren't interested in it, so take it away from the list
296 //qDebug( "removal case" ); 299 //qDebug( "removal case" );
297 if ( d->serverGui ) 300 if ( d->serverGui )
298 d->serverGui->documentRemoved( *doc ); 301 d->serverGui->documentRemoved( *doc );
299 302
300 } 303 }
301 d->dls.remove( doc ); // remove old link from docLnkSet 304 d->dls.remove( doc ); // remove old link from docLnkSet
302 delete doc; 305 delete doc;
303 return; 306 return;
304 } 307 }
305 } 308 }
306 // Didn't find existing link, must be new 309 // Didn't find existing link, must be new
307 DocLnk* dl = new DocLnk( arg ); 310 DocLnk* dl = new DocLnk( arg );
308 if ( d->store( dl ) ) { 311 if ( d->store( dl ) ) {
309 // Add if it's a link we are interested in 312 // Add if it's a link we are interested in
310 //qDebug( "add case" ); 313 //qDebug( "add case" );
311 add( *dl ); 314 add( *dl );
312 } 315 }
313 316
314 } 317 }
315} 318}
316 319
317void DocumentList::restoreDone() 320void DocumentList::restoreDone()
318{ 321{
319 reloadAppLnks(); 322 reloadAppLnks();
320 reloadDocLnks(); 323 reloadDocLnks();
321} 324}
322 325
323void DocumentList::storageChanged() 326void DocumentList::storageChanged()
324{ 327{
325 // ### can implement better 328 // ### can implement better
326 reloadAppLnks(); 329 reloadAppLnks();
327 reloadDocLnks(); 330 reloadDocLnks();
328 // ### Optimization opportunity 331 // ### Optimization opportunity
329 // Could be a bit more intelligent and somehow work out which 332 // Could be a bit more intelligent and somehow work out which
330 // mtab entry has changed and then only scan that and add and remove 333 // mtab entry has changed and then only scan that and add and remove
331 // links appropriately. 334 // links appropriately.
332// rescan(); 335// rescan();
333} 336}
334 337
335void DocumentList::sendAllDocLinks() 338void DocumentList::sendAllDocLinks()
336{ 339{
337 if ( d->tid != 0 ) { 340 if ( d->tid != 0 ) {
338 // We are in the middle of scanning, set a flag so 341 // We are in the middle of scanning, set a flag so
339 // we do this when we finish our scanning 342 // we do this when we finish our scanning
340 d->needToSendAllDocLinks = true; 343 d->needToSendAllDocLinks = true;
341 return; 344 return;
342 } 345 }
343 346
344 QString contents; 347 QString contents;
345 Categories cats; 348 Categories cats;
346 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) { 349 for ( QListIterator<DocLnk> it( d->dls.children() ); it.current(); ++it ) {
347 DocLnk *doc = it.current(); 350 DocLnk *doc = it.current();
348 QFileInfo fi( doc->file() ); 351 QFileInfo fi( doc->file() );
349 if ( !fi.exists() ) 352 if ( !fi.exists() )
350 continue; 353 continue;
351 354
352 bool fake = !doc->linkFileKnown(); 355 bool fake = !doc->linkFileKnown();
353 if ( !fake ) { 356 if ( !fake ) {
354 QFile f( doc->linkFile() ); 357 QFile f( doc->linkFile() );
355 if ( f.open( IO_ReadOnly ) ) { 358 if ( f.open( IO_ReadOnly ) ) {
356 QTextStream ts( &f ); 359 QTextStream ts( &f );
357 ts.setEncoding( QTextStream::UnicodeUTF8 ); 360 ts.setEncoding( QTextStream::UnicodeUTF8 );
358 contents += ts.read(); 361 contents += ts.read();
359 f.close(); 362 f.close();
360 } else 363 } else
361 fake = TRUE; 364 fake = TRUE;
362 } 365 }
363 if (fake) { 366 if (fake) {
364 contents += "[Desktop Entry]\n"; // No tr 367 contents += "[Desktop Entry]\n"; // No tr
365 contents += "Categories = " + // No tr 368 contents += "Categories = " + // No tr
366 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr 369 cats.labels("Document View",doc->categories()).join(";") + "\n"; // No tr
367 contents += "Name = "+doc->name()+"\n"; // No tr 370 contents += "Name = "+doc->name()+"\n"; // No tr
368 contents += "Type = "+doc->type()+"\n"; // No tr 371 contents += "Type = "+doc->type()+"\n"; // No tr
369 } 372 }
370 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path) 373 contents += "File = "+doc->file()+"\n"; // No tr // (resolves path)
371 contents += QString("Size = %1\n").arg( fi.size() ); // No tr 374 contents += QString("Size = %1\n").arg( fi.size() ); // No tr
372 } 375 }
373 376
374 //qDebug( "sending length %d", contents.length() ); 377 //qDebug( "sending length %d", contents.length() );
375#ifndef QT_NO_COP 378#ifndef QT_NO_COP
376 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" ); 379 QCopEnvelope e( "QPE/Desktop", "docLinks(QString)" );
377 e << contents; 380 e << contents;
378#endif 381#endif
379 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() ); 382 //qDebug( "================ \n\n%s\n\n===============", contents.latin1() );
380 383
381 d->needToSendAllDocLinks = false; 384 d->needToSendAllDocLinks = false;
382} 385}
383 386
384 387
385 388
386 389
387 390
388 391
389 392
390 393
391 394
392 395
393 396
394 397
395 398
396 399
397 400
398 401
399 402
400 403
401 404
402 405
403 406
404 407
405 408
406 409
407DocumentListPrivate::DocumentListPrivate( ServerInterface *gui ) 410DocumentListPrivate::DocumentListPrivate( ServerInterface *gui )
408{ 411{
409 storage = new StorageInfo( this ); 412 storage = new StorageInfo( this );
410 serverGui = gui; 413 serverGui = gui;
411 if ( serverGui ) { 414 if ( serverGui ) {
412 sendAppLnks = serverGui->requiresApplications(); 415 sendAppLnks = serverGui->requiresApplications();
413 sendDocLnks = serverGui->requiresDocuments(); 416 sendDocLnks = serverGui->requiresDocuments();
414 } else { 417 } else {
415 sendAppLnks = false; 418 sendAppLnks = false;
416 sendDocLnks = false; 419 sendDocLnks = false;
417 } 420 }
418 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 421 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
419 listDirs[i] = 0; 422 listDirs[i] = 0;
420 lists[i] = 0; 423 lists[i] = 0;
421 listPositions[i] = 0; 424 listPositions[i] = 0;
422 } 425 }
423 initialize(); 426 initialize();
424 tid = 0; 427 tid = 0;
425} 428}
426 429
427 430
428void DocumentListPrivate::initialize() 431void DocumentListPrivate::initialize()
429{ 432{
430 // Reset 433 // Reset
431 dls.clear(); 434 dls.clear();
432 docPaths.clear(); 435 docPaths.clear();
433 reference.clear(); 436 reference.clear();
434 437
435 QDir docDir( QPEApplication::documentDir() ); 438 QDir docDir( QPEApplication::documentDir() );
436 if ( docDir.exists() ) 439 if ( docDir.exists() )
437 docPaths += QPEApplication::documentDir(); 440 docPaths += QPEApplication::documentDir();
438 int i = 1; 441 int i = 1;
439 const QList<FileSystem> &fs = storage->fileSystems(); 442 const QList<FileSystem> &fs = storage->fileSystems();
440 QListIterator<FileSystem> it( fs ); 443 QListIterator<FileSystem> it( fs );
441 for ( ; it.current(); ++it ) 444 for ( ; it.current(); ++it )
442 if ( (*it)->isRemovable() ) { 445 if ( (*it)->isRemovable() ) {
443 docPaths += (*it)->path(); 446 docPaths += (*it)->path();
444 i++; 447 i++;
445 } 448 }
446 449
447 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) { 450 for ( int i = 0; i < MAX_SEARCH_DEPTH; i++ ) {
448 if ( listDirs[i] ) { 451 if ( listDirs[i] ) {
449 delete listDirs[i]; 452 delete listDirs[i];
450 listDirs[i] = 0; 453 listDirs[i] = 0;
451 } 454 }
452 lists[i] = 0; 455 lists[i] = 0;
453 listPositions[i] = 0; 456 listPositions[i] = 0;
454 } 457 }
455 458
456 docPathsSearched = 0; 459 docPathsSearched = 0;
457 searchDepth = -1; 460 searchDepth = -1;
458 state = Find; 461 state = Find;
459 dit = 0; 462 dit = 0;
460} 463}
461 464
462 465
463DocumentListPrivate::~DocumentListPrivate() 466DocumentListPrivate::~DocumentListPrivate()
464{ 467{
diff --git a/core/launcher/main.cpp b/core/launcher/main.cpp
index 988e432..bf06e75 100644
--- a/core/launcher/main.cpp
+++ b/core/launcher/main.cpp
@@ -1,266 +1,267 @@
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#include "server.h" 24#include "server.h"
25#include "serverapp.h" 25#include "serverapp.h"
26#include "taskbar.h" 26#include "taskbar.h"
27#include "stabmon.h" 27#include "stabmon.h"
28#include "launcher.h" 28#include "launcher.h"
29#include "firstuse.h" 29#include "firstuse.h"
30#include "launcherglobal.h" 30
31#include <opie2/oglobal.h>
31 32
32#include <qtopia/qpeapplication.h> 33#include <qtopia/qpeapplication.h>
33#include <qtopia/network.h> 34#include <qtopia/network.h>
34#include <qtopia/config.h> 35#include <qtopia/config.h>
35//#include <qtopia/custom.h> 36//#include <qtopia/custom.h>
36#include <qtopia/global.h> 37
37 38
38#include <qfile.h> 39#include <qfile.h>
39#include <qdir.h> 40#include <qdir.h>
40#ifdef QWS 41#ifdef QWS
41#include <qwindowsystem_qws.h> 42#include <qwindowsystem_qws.h>
42#include <qtopia/qcopenvelope_qws.h> 43#include <qtopia/qcopenvelope_qws.h>
43#endif 44#endif
44#include <qtopia/alarmserver.h> 45#include <qtopia/alarmserver.h>
45 46
46#include <stdlib.h> 47#include <stdlib.h>
47#include <stdio.h> 48#include <stdio.h>
48#include <signal.h> 49#include <signal.h>
49#ifndef Q_OS_WIN32 50#ifndef Q_OS_WIN32
50#include <unistd.h> 51#include <unistd.h>
51#else 52#else
52#include <process.h> 53#include <process.h>
53#endif 54#endif
54 55
55#include "calibrate.h" 56#include "calibrate.h"
56 57
57 58
58#ifdef QT_QWS_LOGIN 59#ifdef QT_QWS_LOGIN
59#include "../login/qdmdialogimpl.h" 60#include "../login/qdmdialogimpl.h"
60#endif 61#endif
61 62
62#ifdef Q_WS_QWS 63#ifdef Q_WS_QWS
63#include <qkeyboard_qws.h> 64#include <qkeyboard_qws.h>
64#endif 65#endif
65 66
66#include <qmessagebox.h> 67#include <qmessagebox.h>
67#include <opie/odevice.h> 68#include <opie2/odevice.h>
68 69
69using namespace Opie; 70using namespace Opie;
70 71
71 72
72static void cleanup() 73static void cleanup()
73{ 74{
74 QDir dir( Opie::Global::tempDir(), "qcop-msg-*" ); 75 QDir dir( OGlobal::tempDirPath(), "qcop-msg-*" );
75 76
76 QStringList stale = dir.entryList(); 77 QStringList stale = dir.entryList();
77 QStringList::Iterator it; 78 QStringList::Iterator it;
78 for ( it = stale.begin(); it != stale.end(); ++it ) { 79 for ( it = stale.begin(); it != stale.end(); ++it ) {
79 dir.remove( *it ); 80 dir.remove( *it );
80 } 81 }
81} 82}
82 83
83static void refreshTimeZoneConfig() 84static void refreshTimeZoneConfig()
84{ 85{
85 /* ### FIXME timezone handling */ 86 /* ### FIXME timezone handling */
86#if 0 87#if 0
87 // We need to help WorldTime in setting up its configuration for 88 // We need to help WorldTime in setting up its configuration for
88 // the current translation 89 // the current translation
89 // BEGIN no tr 90 // BEGIN no tr
90 const char *defaultTz[] = { 91 const char *defaultTz[] = {
91 "America/New_York", 92 "America/New_York",
92 "America/Los_Angeles", 93 "America/Los_Angeles",
93 "Europe/Oslo", 94 "Europe/Oslo",
94 "Asia/Tokyo", 95 "Asia/Tokyo",
95 "Asia/Hong_Kong", 96 "Asia/Hong_Kong",
96 "Australia/Brisbane", 97 "Australia/Brisbane",
97 0 98 0
98 }; 99 };
99 // END no tr 100 // END no tr
100 101
101 TimeZone curZone; 102 TimeZone curZone;
102 QString zoneID; 103 QString zoneID;
103 int zoneIndex; 104 int zoneIndex;
104 Config cfg = Config( "WorldTime" ); 105 Config cfg = Config( "WorldTime" );
105 cfg.setGroup( "TimeZones" ); 106 cfg.setGroup( "TimeZones" );
106 if (!cfg.hasKey( "Zone0" )){ 107 if (!cfg.hasKey( "Zone0" )){
107 // We have no existing timezones use the defaults which are untranslated strings 108 // We have no existing timezones use the defaults which are untranslated strings
108 QString currTz = TimeZone::current().id(); 109 QString currTz = TimeZone::current().id();
109 QStringList zoneDefaults; 110 QStringList zoneDefaults;
110 zoneDefaults.append( currTz ); 111 zoneDefaults.append( currTz );
111 for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) { 112 for ( int i = 0; defaultTz[i] && zoneDefaults.count() < 6; i++ ) {
112 if ( defaultTz[i] != currTz ) 113 if ( defaultTz[i] != currTz )
113 zoneDefaults.append( defaultTz[i] ); 114 zoneDefaults.append( defaultTz[i] );
114 } 115 }
115 zoneIndex = 0; 116 zoneIndex = 0;
116 for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){ 117 for (QStringList::Iterator it = zoneDefaults.begin(); it != zoneDefaults.end() ; ++it){
117 cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it); 118 cfg.writeEntry( "Zone" + QString::number( zoneIndex ) , *it);
118 zoneIndex++; 119 zoneIndex++;
119 } 120 }
120 } 121 }
121 // We have an existing list of timezones refresh the 122 // We have an existing list of timezones refresh the
122 // translations of TimeZone name 123 // translations of TimeZone name
123 zoneIndex = 0; 124 zoneIndex = 0;
124 while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){ 125 while (cfg.hasKey( "Zone"+ QString::number( zoneIndex ))){
125 zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex )); 126 zoneID = cfg.readEntry( "Zone" + QString::number( zoneIndex ));
126 curZone = TimeZone( zoneID ); 127 curZone = TimeZone( zoneID );
127 if ( !curZone.isValid() ){ 128 if ( !curZone.isValid() ){
128 qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() ); 129 qDebug( "initEnvironment() Invalid TimeZone %s", zoneID.latin1() );
129 break; 130 break;
130 } 131 }
131 cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() ); 132 cfg.writeEntry( "ZoneName" + QString::number( zoneIndex ), curZone.city() );
132 zoneIndex++; 133 zoneIndex++;
133 } 134 }
134#endif 135#endif
135} 136}
136 137
137void initEnvironment() 138void initEnvironment()
138{ 139{
139#ifdef Q_OS_WIN32 140#ifdef Q_OS_WIN32
140 // Config file requires HOME dir which uses QDir which needs the winver 141 // Config file requires HOME dir which uses QDir which needs the winver
141 qt_init_winver(); 142 qt_init_winver();
142#endif 143#endif
143 Config config("locale"); 144 Config config("locale");
144 config.setGroup( "Location" ); 145 config.setGroup( "Location" );
145 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace(); 146 QString tz = config.readEntry( "Timezone", getenv("TZ") ).stripWhiteSpace();
146 147
147 // if not timezone set, pick New York 148 // if not timezone set, pick New York
148 if (tz.isNull() || tz.isEmpty()) 149 if (tz.isNull() || tz.isEmpty())
149 tz = "America/New_York"; 150 tz = "America/New_York";
150 151
151 setenv( "TZ", tz, 1 ); 152 setenv( "TZ", tz, 1 );
152 config.writeEntry( "Timezone", tz); 153 config.writeEntry( "Timezone", tz);
153 154
154 config.setGroup( "Language" ); 155 config.setGroup( "Language" );
155 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace(); 156 QString lang = config.readEntry( "Language", getenv("LANG") ).stripWhiteSpace();
156 if( lang.isNull() || lang.isEmpty()) 157 if( lang.isNull() || lang.isEmpty())
157 lang = "en_US"; 158 lang = "en_US";
158 159
159 setenv( "LANG", lang, 1 ); 160 setenv( "LANG", lang, 1 );
160 config.writeEntry("Language", lang); 161 config.writeEntry("Language", lang);
161 config.write(); 162 config.write();
162 163
163#if 0 164#if 0
164 setenv( "QWS_SIZE", "240x320", 0 ); 165 setenv( "QWS_SIZE", "240x320", 0 );
165#endif 166#endif
166 167
167 168
168 169
169 QString env(getenv("QWS_DISPLAY")); 170 QString env(getenv("QWS_DISPLAY"));
170 if (env.contains("Transformed")) { 171 if (env.contains("Transformed")) {
171 int rot; 172 int rot;
172 // transformed driver default rotation is controlled by the hardware. 173 // transformed driver default rotation is controlled by the hardware.
173 Config config("qpe"); 174 Config config("qpe");
174 config.setGroup( "Rotation" ); 175 config.setGroup( "Rotation" );
175 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 ) 176 if ( ( rot = config.readNumEntry( "Rot", -1 ) ) == -1 )
176 rot = ODevice::inst ( )-> rotation ( ) * 90; 177 rot = ODevice::inst ( )-> rotation ( ) * 90;
177 178
178 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1); 179 setenv("QWS_DISPLAY", QString("Transformed:Rot%1:0").arg(rot), 1);
179 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */ 180 QPEApplication::defaultRotation ( ); /* to ensure deforient matches reality */
180 } 181 }
181} 182}
182 183
183static void initKeyboard() 184static void initKeyboard()
184{ 185{
185 Config config("qpe"); 186 Config config("qpe");
186 187
187 config.setGroup( "Keyboard" ); 188 config.setGroup( "Keyboard" );
188 189
189 int ard = config.readNumEntry( "RepeatDelay" ); 190 int ard = config.readNumEntry( "RepeatDelay" );
190 int arp = config.readNumEntry( "RepeatPeriod" ); 191 int arp = config.readNumEntry( "RepeatPeriod" );
191 if ( ard > 0 && arp > 0 ) 192 if ( ard > 0 && arp > 0 )
192 qwsSetKeyboardAutoRepeat( ard, arp ); 193 qwsSetKeyboardAutoRepeat( ard, arp );
193 194
194 QString layout = config.readEntry( "Layout", "us101" ); 195 QString layout = config.readEntry( "Layout", "us101" );
195 Server::setKeyboardLayout( layout ); 196 Server::setKeyboardLayout( layout );
196} 197}
197 198
198static bool firstUse() 199static bool firstUse()
199{ 200{
200 bool needFirstUse = FALSE; 201 bool needFirstUse = FALSE;
201 if ( QWSServer::mouseHandler() && 202 if ( QWSServer::mouseHandler() &&
202 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) { 203 QWSServer::mouseHandler() ->inherits("QCalibratedMouseHandler") ) {
203 if ( !QFile::exists( "/etc/pointercal" ) ) 204 if ( !QFile::exists( "/etc/pointercal" ) )
204 needFirstUse = TRUE; 205 needFirstUse = TRUE;
205 } 206 }
206 207
207 { 208 {
208 Config config( "qpe" ); 209 Config config( "qpe" );
209 config.setGroup( "Startup" ); 210 config.setGroup( "Startup" );
210 needFirstUse |= config.readBoolEntry( "FirstUse", TRUE ); 211 needFirstUse |= config.readBoolEntry( "FirstUse", TRUE );
211 } 212 }
212 213
213 if ( !needFirstUse ) 214 if ( !needFirstUse )
214 return FALSE; 215 return FALSE;
215 216
216 FirstUse *fu = new FirstUse(); 217 FirstUse *fu = new FirstUse();
217 fu->exec(); 218 fu->exec();
218 bool rs = fu->restartNeeded(); 219 bool rs = fu->restartNeeded();
219 delete fu; 220 delete fu;
220 return rs; 221 return rs;
221} 222}
222 223
223int initApplication( int argc, char ** argv ) 224int initApplication( int argc, char ** argv )
224{ 225{
225 cleanup(); 226 cleanup();
226 227
227 228
228 initEnvironment(); 229 initEnvironment();
229 230
230 //Don't flicker at startup: 231 //Don't flicker at startup:
231#ifdef QWS 232#ifdef QWS
232 QWSServer::setDesktopBackground( QImage() ); 233 QWSServer::setDesktopBackground( QImage() );
233#endif 234#endif
234 ServerApplication a( argc, argv, QApplication::GuiServer ); 235 ServerApplication a( argc, argv, QApplication::GuiServer );
235 236
236 refreshTimeZoneConfig(); 237 refreshTimeZoneConfig();
237 238
238 initKeyboard(); 239 initKeyboard();
239 240
240 // Don't use first use under Windows 241 // Don't use first use under Windows
241 if ( firstUse() ) { 242 if ( firstUse() ) {
242 a.restart(); 243 a.restart();
243 return 0; 244 return 0;
244 } 245 }
245 246
246 ODevice::inst ( )-> setSoftSuspend ( true ); 247 ODevice::inst ( )-> setSoftSuspend ( true );
247 248
248 { 249 {
249 QCopEnvelope e("QPE/System", "setBacklight(int)" ); 250 QCopEnvelope e("QPE/System", "setBacklight(int)" );
250 e << -3; // Forced on 251 e << -3; // Forced on
251 } 252 }
252 253
253 AlarmServer::initialize(); 254 AlarmServer::initialize();
254 255
255 256
256 257
257 Server *s = new Server(); 258 Server *s = new Server();
258 259
259 (void)new SysFileMonitor(s); 260 (void)new SysFileMonitor(s);
260#ifdef QWS 261#ifdef QWS
261 Network::createServer(s); 262 Network::createServer(s);
262#endif 263#endif
263 264
264 s->show(); 265 s->show();
265 266
266 /* THE ARM rtc has problem holdings the time on reset */ 267 /* THE ARM rtc has problem holdings the time on reset */
diff --git a/core/launcher/qcopbridge.cpp b/core/launcher/qcopbridge.cpp
index 9cb56ce..b45f0cc 100644
--- a/core/launcher/qcopbridge.cpp
+++ b/core/launcher/qcopbridge.cpp
@@ -1,497 +1,498 @@
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#include <opie2/oglobal.h>
25
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
27#include <qtopia/qpeapplication.h> 29#include <qtopia/qpeapplication.h>
28#include <qtopia/global.h> 30
29#include <qtopia/version.h> 31#include <qtopia/version.h>
30#include <qtopia/config.h> 32#include <qtopia/config.h>
31 33
32#include <qdir.h> 34#include <qdir.h>
33#include <qfile.h> 35#include <qfile.h>
34#include <qtextstream.h> 36#include <qtextstream.h>
35#include <qdatastream.h> 37#include <qdatastream.h>
36#include <qcstring.h> 38#include <qcstring.h>
37#include <qstringlist.h> 39#include <qstringlist.h>
38#include <qfileinfo.h> 40#include <qfileinfo.h>
39#include <qregexp.h> 41#include <qregexp.h>
40#include <qtimer.h> 42#include <qtimer.h>
41#ifdef Q_WS_QWS 43#ifdef Q_WS_QWS
42#include <qcopchannel_qws.h> 44#include <qcopchannel_qws.h>
43#endif 45#endif
44 46
45#ifndef _XOPEN_SOURCE 47#ifndef _XOPEN_SOURCE
46#define _XOPEN_SOURCE 48#define _XOPEN_SOURCE
47#endif 49#endif
48#ifndef Q_OS_WIN32 50#ifndef Q_OS_WIN32
49#include <pwd.h> 51#include <pwd.h>
50#include <unistd.h> 52#include <unistd.h>
51#include <sys/types.h> 53#include <sys/types.h>
52#endif 54#endif
53 55
54#if defined(_OS_LINUX_) 56#if defined(_OS_LINUX_)
55#include <shadow.h> 57#include <shadow.h>
56#endif 58#endif
57 59
58#include "launcherglobal.h"
59 60
60//#define INSECURE 61//#define INSECURE
61 62
62const int block_size = 51200; 63const int block_size = 51200;
63 64
64QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent, 65QCopBridge::QCopBridge( Q_UINT16 port, QObject *parent,
65 const char* name ) 66 const char* name )
66 : QServerSocket( port, 1, parent, name ), 67 : QServerSocket( port, 1, parent, name ),
67 desktopChannel( 0 ), 68 desktopChannel( 0 ),
68 cardChannel( 0 ) 69 cardChannel( 0 )
69{ 70{
70 if ( !ok() ) 71 if ( !ok() )
71 qWarning( "Failed to bind to port %d", port ); 72 qWarning( "Failed to bind to port %d", port );
72 else { 73 else {
73#ifndef QT_NO_COP 74#ifndef QT_NO_COP
74 desktopChannel = new QCopChannel( "QPE/Desktop", this ); 75 desktopChannel = new QCopChannel( "QPE/Desktop", this );
75 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)), 76 connect( desktopChannel, SIGNAL(received(const QCString &, const QByteArray &)),
76 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 77 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
77 cardChannel = new QCopChannel( "QPE/Card", this ); 78 cardChannel = new QCopChannel( "QPE/Card", this );
78 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)), 79 connect( cardChannel, SIGNAL(received(const QCString &, const QByteArray &)),
79 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) ); 80 this, SLOT(desktopMessage( const QCString &, const QByteArray &)) );
80#endif 81#endif
81 } 82 }
82 sendSync = FALSE; 83 sendSync = FALSE;
83 openConnections.setAutoDelete( TRUE ); 84 openConnections.setAutoDelete( TRUE );
84 authorizeConnections(); 85 authorizeConnections();
85} 86}
86 87
87QCopBridge::~QCopBridge() 88QCopBridge::~QCopBridge()
88{ 89{
89#ifndef QT_NO_COP 90#ifndef QT_NO_COP
90 delete desktopChannel; 91 delete desktopChannel;
91#endif 92#endif
92} 93}
93 94
94void QCopBridge::authorizeConnections() 95void QCopBridge::authorizeConnections()
95{ 96{
96 Config cfg("Security"); 97 Config cfg("Security");
97 cfg.setGroup("SyncMode"); 98 cfg.setGroup("SyncMode");
98 m_mode = Mode(cfg.readNumEntry("Mode", Sharp )); 99 m_mode = Mode(cfg.readNumEntry("Mode", Sharp ));
99 QListIterator<QCopBridgePI> it(openConnections); 100 QListIterator<QCopBridgePI> it(openConnections);
100 while ( it.current() ) { 101 while ( it.current() ) {
101 if ( !it.current()->verifyAuthorised() ) { 102 if ( !it.current()->verifyAuthorised() ) {
102 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 103 disconnect ( it.current(), SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
103 openConnections.removeRef( it.current() ); 104 openConnections.removeRef( it.current() );
104 } else 105 } else
105 ++it; 106 ++it;
106 } 107 }
107} 108}
108 109
109void QCopBridge::newConnection( int socket ) 110void QCopBridge::newConnection( int socket )
110{ 111{
111 QCopBridgePI *pi = new QCopBridgePI( socket, this ); 112 QCopBridgePI *pi = new QCopBridgePI( socket, this );
112 openConnections.append( pi ); 113 openConnections.append( pi );
113 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) ); 114 connect ( pi, SIGNAL( connectionClosed( QCopBridgePI *) ), this, SLOT( closed( QCopBridgePI *) ) );
114 115
115 /* ### libqtopia merge FIXME */ 116 /* ### libqtopia merge FIXME */
116#if 0 117#if 0
117 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend ); 118 QPEApplication::setTempScreenSaverMode( QPEApplication::DisableSuspend );
118#endif 119#endif
119#ifndef QT_NO_COP 120#ifndef QT_NO_COP
120 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend; 121 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::DisableSuspend;
121#endif 122#endif
122 123
123 if ( sendSync ) { 124 if ( sendSync ) {
124 pi ->startSync(); 125 pi ->startSync();
125 sendSync = FALSE; 126 sendSync = FALSE;
126 } 127 }
127} 128}
128 129
129void QCopBridge::closed( QCopBridgePI *pi ) 130void QCopBridge::closed( QCopBridgePI *pi )
130{ 131{
131 emit connectionClosed( pi->peerAddress() ); 132 emit connectionClosed( pi->peerAddress() );
132 openConnections.removeRef( pi ); 133 openConnections.removeRef( pi );
133 if ( openConnections.count() == 0 ) { 134 if ( openConnections.count() == 0 ) {
134 /* ### FIXME libqtopia merge */ 135 /* ### FIXME libqtopia merge */
135#if 0 136#if 0
136 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable ); 137 QPEApplication::setTempScreenSaverMode( QPEApplication::Enable );
137#endif 138#endif
138#ifndef QT_NO_COP 139#ifndef QT_NO_COP
139 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 140 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
140#endif 141#endif
141 } 142 }
142} 143}
143 144
144void QCopBridge::closeOpenConnections() 145void QCopBridge::closeOpenConnections()
145{ 146{
146 QCopBridgePI *pi; 147 QCopBridgePI *pi;
147 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 148 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
148 pi->close(); 149 pi->close();
149} 150}
150 151
151 152
152void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data ) 153void QCopBridge::desktopMessage( const QCString &command, const QByteArray &data )
153{ 154{
154 if ( command == "startSync()" ) { 155 if ( command == "startSync()" ) {
155 // we need to buffer it a bit 156 // we need to buffer it a bit
156 sendSync = TRUE; 157 sendSync = TRUE;
157 startTimer( 20000 ); 158 startTimer( 20000 );
158 } 159 }
159 160
160 if ( m_mode & Qtopia1_7 ) { 161 if ( m_mode & Qtopia1_7 ) {
161 // send the command to all open connections 162 // send the command to all open connections
162 QCopBridgePI *pi; 163 QCopBridgePI *pi;
163 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) { 164 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) {
164 pi->sendDesktopMessage( command, data ); 165 pi->sendDesktopMessage( command, data );
165 } 166 }
166 } 167 }
167 if ( m_mode & Sharp ) 168 if ( m_mode & Sharp )
168 sendDesktopMessageOld( command, data ); 169 sendDesktopMessageOld( command, data );
169} 170}
170 171
171#ifndef OPIE_NO_OLD_SYNC_CODE 172#ifndef OPIE_NO_OLD_SYNC_CODE
172/* 173/*
173 * Old compat mode 174 * Old compat mode
174 */ 175 */
175void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) { 176void QCopBridge::sendDesktopMessageOld( const QCString& command, const QByteArray& args) {
176 command.stripWhiteSpace(); 177 command.stripWhiteSpace();
177 178
178 int paren = command.find( "(" ); 179 int paren = command.find( "(" );
179 if ( paren <= 0 ) { 180 if ( paren <= 0 ) {
180 qDebug("DesktopMessage: bad qcop syntax"); 181 qDebug("DesktopMessage: bad qcop syntax");
181 return; 182 return;
182 } 183 }
183 184
184 QString params = command.mid( paren + 1 ); 185 QString params = command.mid( paren + 1 );
185 if ( params[params.length()-1] != ')' ) { 186 if ( params[params.length()-1] != ')' ) {
186 qDebug("DesktopMessage: bad qcop syntax"); 187 qDebug("DesktopMessage: bad qcop syntax");
187 return; 188 return;
188 } 189 }
189 190
190 params.truncate( params.length()-1 ); 191 params.truncate( params.length()-1 );
191 192
192 QStringList paramList = QStringList::split( ",", params ); 193 QStringList paramList = QStringList::split( ",", params );
193 QString data; 194 QString data;
194 if ( paramList.count() ) { 195 if ( paramList.count() ) {
195 QDataStream stream( args, IO_ReadOnly ); 196 QDataStream stream( args, IO_ReadOnly );
196 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 197 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
197 QString str; 198 QString str;
198 if ( *it == "QString" ) { 199 if ( *it == "QString" ) {
199 stream >> str; 200 stream >> str;
200 } else if ( *it == "QCString" ) { 201 } else if ( *it == "QCString" ) {
201 QCString cstr; 202 QCString cstr;
202 stream >> cstr; 203 stream >> cstr;
203 str = QString::fromLocal8Bit( cstr ); 204 str = QString::fromLocal8Bit( cstr );
204 } else if ( *it == "int" ) { 205 } else if ( *it == "int" ) {
205 int i; 206 int i;
206 stream >> i; 207 stream >> i;
207 str = QString::number( i ); 208 str = QString::number( i );
208 } else if ( *it == "bool" ) { 209 } else if ( *it == "bool" ) {
209 int i; 210 int i;
210 stream >> i; 211 stream >> i;
211 str = QString::number( i ); 212 str = QString::number( i );
212 } else { 213 } else {
213 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() ); 214 qDebug(" cannot route the argument type %s throught the qcop bridge", (*it).latin1() );
214 return; 215 return;
215 } 216 }
216 QString estr; 217 QString estr;
217 for (int i=0; i<(int)str.length(); i++) { 218 for (int i=0; i<(int)str.length(); i++) {
218 QChar ch = str[i]; 219 QChar ch = str[i];
219 if ( ch.row() ) 220 if ( ch.row() )
220 goto quick; 221 goto quick;
221 switch (ch.cell()) { 222 switch (ch.cell()) {
222 case '&': 223 case '&':
223 estr.append( "&amp;" ); 224 estr.append( "&amp;" );
224 break; 225 break;
225 case ' ': 226 case ' ':
226 estr.append( "&0x20;" ); 227 estr.append( "&0x20;" );
227 break; 228 break;
228 case '\n': 229 case '\n':
229 estr.append( "&0x0d;" ); 230 estr.append( "&0x0d;" );
230 break; 231 break;
231 case '\r': 232 case '\r':
232 estr.append( "&0x0a;" ); 233 estr.append( "&0x0a;" );
233 break; 234 break;
234 default: quick: 235 default: quick:
235 estr.append(ch); 236 estr.append(ch);
236 } 237 }
237 } 238 }
238 data += " " + estr; 239 data += " " + estr;
239 } 240 }
240 } 241 }
241 QString sendCommand = QString(command.data()) + data; 242 QString sendCommand = QString(command.data()) + data;
242 243
243 244
244 // send the command to all open connections 245 // send the command to all open connections
245 QCopBridgePI *pi; 246 QCopBridgePI *pi;
246 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() ) 247 for ( pi = openConnections.first(); pi != 0; pi = openConnections.next() )
247 pi->sendDesktopMessage( sendCommand ); 248 pi->sendDesktopMessage( sendCommand );
248 249
249} 250}
250#endif 251#endif
251 252
252 253
253void QCopBridge::timerEvent( QTimerEvent * ) 254void QCopBridge::timerEvent( QTimerEvent * )
254{ 255{
255 sendSync = FALSE; 256 sendSync = FALSE;
256 killTimers(); 257 killTimers();
257} 258}
258 259
259 260
260QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name ) 261QCopBridgePI::QCopBridgePI( int socket, QObject *parent, const char* name )
261 : QSocket( parent, name ) 262 : QSocket( parent, name )
262{ 263{
263 setSocket( socket ); 264 setSocket( socket );
264 265
265 peerport = peerPort(); 266 peerport = peerPort();
266 peeraddress = peerAddress(); 267 peeraddress = peerAddress();
267 268
268#ifndef INSECURE 269#ifndef INSECURE
269 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 270 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
270 state = Forbidden; 271 state = Forbidden;
271 close(); 272 close();
272 } else 273 } else
273#endif 274#endif
274 { 275 {
275 state = Connected; 276 state = Connected;
276 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 277 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
277 QString intro="220 Qtopia "; 278 QString intro="220 Qtopia ";
278 intro += QPE_VERSION; intro += ";"; 279 intro += QPE_VERSION; intro += ";";
279 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr 280 intro += "challenge="; intro += SyncAuthentication::serverId(); intro += ";"; // No tr
280 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";"; 281 intro += "loginname="; intro += SyncAuthentication::loginName(); intro += ";";
281 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";"; 282 intro += "displayname="; intro += SyncAuthentication::ownerName(); intro += ";";
282 send( intro ); 283 send( intro );
283 state = Wait_USER; 284 state = Wait_USER;
284 } 285 }
285 sendSync = FALSE; 286 sendSync = FALSE;
286 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) ); 287 connect( this, SIGNAL( connectionClosed() ), SLOT( myConnectionClosed() ) );
287 288
288 // idle timer to close connections when not used anymore 289 // idle timer to close connections when not used anymore
289 timer = new QTimer(this); 290 timer = new QTimer(this);
290 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) ); 291 connect( timer, SIGNAL(timeout()), this, SLOT(myConnectionClosed()) );
291 timer->start( 300000, TRUE ); 292 timer->start( 300000, TRUE );
292} 293}
293 294
294 295
295QCopBridgePI::~QCopBridgePI() 296QCopBridgePI::~QCopBridgePI()
296{ 297{
297} 298}
298 299
299bool QCopBridgePI::verifyAuthorised() 300bool QCopBridgePI::verifyAuthorised()
300{ 301{
301 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 302 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
302 state = Forbidden; 303 state = Forbidden;
303 return FALSE; 304 return FALSE;
304 } 305 }
305 return TRUE; 306 return TRUE;
306} 307}
307 308
308void QCopBridgePI::myConnectionClosed() 309void QCopBridgePI::myConnectionClosed()
309{ 310{
310 emit connectionClosed( this ); 311 emit connectionClosed( this );
311} 312}
312 313
313void QCopBridgePI::sendDesktopMessage( const QString &msg ) 314void QCopBridgePI::sendDesktopMessage( const QString &msg )
314{ 315{
315 QString str = "CALL QPE/Desktop " + msg; // No tr 316 QString str = "CALL QPE/Desktop " + msg; // No tr
316 send ( str ); 317 send ( str );
317} 318}
318 319
319void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data ) 320void QCopBridgePI::sendDesktopMessage( const QCString &msg, const QByteArray& data )
320{ 321{
321 if ( !isOpen() ) // eg. Forbidden 322 if ( !isOpen() ) // eg. Forbidden
322 return; 323 return;
323 324
324 const char hdr[]="CALLB QPE/Desktop "; 325 const char hdr[]="CALLB QPE/Desktop ";
325 writeBlock(hdr,sizeof(hdr)-1); 326 writeBlock(hdr,sizeof(hdr)-1);
326 writeBlock(msg,msg.length()); 327 writeBlock(msg,msg.length());
327 writeBlock(" ",1); 328 writeBlock(" ",1);
328 QByteArray b64 = Opie::Global::encodeBase64(data); 329 QByteArray b64 = OGlobal::encodeBase64(data);
329 writeBlock(b64.data(),b64.size()); 330 writeBlock(b64.data(),b64.size());
330 writeBlock("\r\n",2); 331 writeBlock("\r\n",2);
331 332
332} 333}
333 334
334 335
335void QCopBridgePI::send( const QString& msg ) 336void QCopBridgePI::send( const QString& msg )
336{ 337{
337 if ( !isOpen() ) // eg. Forbidden 338 if ( !isOpen() ) // eg. Forbidden
338 return; 339 return;
339 QTextStream os( this ); 340 QTextStream os( this );
340 os << msg << endl; 341 os << msg << endl;
341 //qDebug( "sending qcop message: %s", msg.latin1() ); 342 //qDebug( "sending qcop message: %s", msg.latin1() );
342} 343}
343 344
344void QCopBridgePI::read() 345void QCopBridgePI::read()
345{ 346{
346 while ( canReadLine() ) { 347 while ( canReadLine() ) {
347 timer->start( 300000, TRUE ); 348 timer->start( 300000, TRUE );
348 process( readLine().stripWhiteSpace() ); 349 process( readLine().stripWhiteSpace() );
349 } 350 }
350} 351}
351 352
352void QCopBridgePI::process( const QString& message ) 353void QCopBridgePI::process( const QString& message )
353{ 354{
354 //qDebug( "Command: %s", message.latin1() ); 355 //qDebug( "Command: %s", message.latin1() );
355 356
356 // split message using "," as separator 357 // split message using "," as separator
357 QStringList msg = QStringList::split( " ", message ); 358 QStringList msg = QStringList::split( " ", message );
358 if ( msg.isEmpty() ) return; 359 if ( msg.isEmpty() ) return;
359 360
360 // command token 361 // command token
361 QString cmd = msg[0].upper(); 362 QString cmd = msg[0].upper();
362 363
363 // argument token 364 // argument token
364 QString arg; 365 QString arg;
365 if ( msg.count() >= 2 ) 366 if ( msg.count() >= 2 )
366 arg = msg[1]; 367 arg = msg[1];
367 368
368 // we always respond to QUIT, regardless of state 369 // we always respond to QUIT, regardless of state
369 if ( cmd == "QUIT" ) { 370 if ( cmd == "QUIT" ) {
370 send( "211 Have a nice day!" ); // No tr 371 send( "211 Have a nice day!" ); // No tr
371 close(); 372 close();
372 return; 373 return;
373 } 374 }
374 375
375 // connected to client 376 // connected to client
376 if ( Connected == state ) 377 if ( Connected == state )
377 return; 378 return;
378 379
379 // waiting for user name 380 // waiting for user name
380 if ( Wait_USER == state ) { 381 if ( Wait_USER == state ) {
381 382
382 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { 383 if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) {
383 send( "530 Please login with USER and PASS" ); // No tr 384 send( "530 Please login with USER and PASS" ); // No tr
384 return; 385 return;
385 } 386 }
386 send( "331 User name ok, need password" ); // No tr 387 send( "331 User name ok, need password" ); // No tr
387 state = Wait_PASS; 388 state = Wait_PASS;
388 return; 389 return;
389 } 390 }
390 391
391 // waiting for password 392 // waiting for password
392 if ( Wait_PASS == state ) { 393 if ( Wait_PASS == state ) {
393 394
394 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { 395 if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) {
395 send( "530 Please login with USER and PASS" ); // No tr 396 send( "530 Please login with USER and PASS" ); // No tr
396 return; 397 return;
397 } 398 }
398 send( "230 User logged in, proceed" ); // No tr 399 send( "230 User logged in, proceed" ); // No tr
399 state = Ready; 400 state = Ready;
400 if ( sendSync ) { 401 if ( sendSync ) {
401 sendDesktopMessage( "startSync()" ); 402 sendDesktopMessage( "startSync()" );
402 sendSync = FALSE; 403 sendSync = FALSE;
403 } 404 }
404 return; 405 return;
405 } 406 }
406 407
407 // noop (NOOP) 408 // noop (NOOP)
408 else if ( cmd == "NOOP" ) { 409 else if ( cmd == "NOOP" ) {
409 send( "200 Command okay" ); // No tr 410 send( "200 Command okay" ); // No tr
410 } 411 }
411 412
412 // call (CALL) 413 // call (CALL)
413 else if ( cmd == "CALL" ) { 414 else if ( cmd == "CALL" ) {
414 415
415 // example: call QPE/System execute(QString) addressbook 416 // example: call QPE/System execute(QString) addressbook
416 417
417 if ( msg.count() < 3 ) { 418 if ( msg.count() < 3 ) {
418 send( "500 Syntax error, command unrecognized" ); // No tr 419 send( "500 Syntax error, command unrecognized" ); // No tr
419 } 420 }
420 else { 421 else {
421 422
422 QString channel = msg[1]; 423 QString channel = msg[1];
423 QString command = msg[2]; 424 QString command = msg[2];
424 425
425 command.stripWhiteSpace(); 426 command.stripWhiteSpace();
426 427
427 int paren = command.find( "(" ); 428 int paren = command.find( "(" );
428 if ( paren <= 0 ) { 429 if ( paren <= 0 ) {
429 send( "500 Syntax error, command unrecognized" ); // No tr 430 send( "500 Syntax error, command unrecognized" ); // No tr
430 return; 431 return;
431 } 432 }
432 433
433 QString params = command.mid( paren + 1 ); 434 QString params = command.mid( paren + 1 );
434 if ( params[(int)params.length()-1] != ')' ) { 435 if ( params[(int)params.length()-1] != ')' ) {
435 send( "500 Syntax error, command unrecognized" ); // No tr 436 send( "500 Syntax error, command unrecognized" ); // No tr
436 return; 437 return;
437 } 438 }
438 439
439 params.truncate( params.length()-1 ); 440 params.truncate( params.length()-1 );
440 QByteArray buffer; 441 QByteArray buffer;
441 QDataStream ds( buffer, IO_WriteOnly ); 442 QDataStream ds( buffer, IO_WriteOnly );
442 443
443 int msgId = 3; 444 int msgId = 3;
444 445
445 QStringList paramList = QStringList::split( ",", params ); 446 QStringList paramList = QStringList::split( ",", params );
446 if ( paramList.count() > msg.count() - 3 ) { 447 if ( paramList.count() > msg.count() - 3 ) {
447 send( "500 Syntax error, command unrecognized" ); // No tr 448 send( "500 Syntax error, command unrecognized" ); // No tr
448 return; 449 return;
449 } 450 }
450 451
451 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) { 452 for ( QStringList::Iterator it = paramList.begin(); it != paramList.end(); ++it ) {
452 453
453 QString arg = msg[msgId]; 454 QString arg = msg[msgId];
454 arg.replace( QRegExp("&0x20;"), " " ); 455 arg.replace( QRegExp("&0x20;"), " " );
455 arg.replace( QRegExp("&amp;"), "&" ); 456 arg.replace( QRegExp("&amp;"), "&" );
456 arg.replace( QRegExp("&0x0d;"), "\n" ); 457 arg.replace( QRegExp("&0x0d;"), "\n" );
457 arg.replace( QRegExp("&0x0a;"), "\r" ); 458 arg.replace( QRegExp("&0x0a;"), "\r" );
458 if ( *it == "QString" ) 459 if ( *it == "QString" )
459 ds << arg; 460 ds << arg;
460 else if ( *it == "QCString" ) 461 else if ( *it == "QCString" )
461 ds << arg.local8Bit(); 462 ds << arg.local8Bit();
462 else if ( *it == "int" ) 463 else if ( *it == "int" )
463 ds << arg.toInt(); 464 ds << arg.toInt();
464 else if ( *it == "bool" ) 465 else if ( *it == "bool" )
465 ds << arg.toInt(); 466 ds << arg.toInt();
466 else { 467 else {
467 send( "500 Syntax error, command unrecognized" ); // No tr 468 send( "500 Syntax error, command unrecognized" ); // No tr
468 return; 469 return;
469 } 470 }
470 msgId++; 471 msgId++;
471 } 472 }
472 473
473#ifndef QT_NO_COP 474#ifndef QT_NO_COP
474 if ( !QCopChannel::isRegistered( channel.latin1() ) ) { 475 if ( !QCopChannel::isRegistered( channel.latin1() ) ) {
475 // send message back about it 476 // send message back about it
476 QString answer = "599 ChannelNotRegistered " + channel; 477 QString answer = "599 ChannelNotRegistered " + channel;
477 send( answer ); 478 send( answer );
478 return; 479 return;
479 } 480 }
480#endif 481#endif
481 482
482#ifndef QT_NO_COP 483#ifndef QT_NO_COP
483 if ( paramList.count() ) 484 if ( paramList.count() )
484 QCopChannel::send( channel.latin1(), command.latin1(), buffer ); 485 QCopChannel::send( channel.latin1(), command.latin1(), buffer );
485 else 486 else
486 QCopChannel::send( channel.latin1(), command.latin1() ); 487 QCopChannel::send( channel.latin1(), command.latin1() );
487 488
488 send( "200 Command okay" ); // No tr 489 send( "200 Command okay" ); // No tr
489#endif 490#endif
490 } 491 }
491 } 492 }
492 // not implemented 493 // not implemented
493 else 494 else
494 send( "502 Command not implemented" ); // No tr 495 send( "502 Command not implemented" ); // No tr
495} 496}
496 497
497 498
diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp
index 48770e8..1146dcd 100644
--- a/core/launcher/screensaver.cpp
+++ b/core/launcher/screensaver.cpp
@@ -1,200 +1,200 @@
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/power.h> 5#include <qpe/power.h>
6#include <qpe/network.h> 6#include <qpe/network.h>
7 7
8#include <opie/odevice.h> 8#include <opie2/odevice.h>
9 9
10 10
11using namespace Opie; 11using namespace Opie;
12 12
13 13
14 14
15OpieScreenSaver::OpieScreenSaver ( ) 15OpieScreenSaver::OpieScreenSaver ( )
16 : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) 16 : QObject ( 0, "screensaver" ), QWSScreenSaver ( )
17{ 17{
18 m_disable_suspend = 100; 18 m_disable_suspend = 100;
19 m_enable_dim = false; 19 m_enable_dim = false;
20 m_enable_lightoff = false; 20 m_enable_lightoff = false;
21 m_enable_suspend = false; 21 m_enable_suspend = false;
22 m_onlylcdoff = false; 22 m_onlylcdoff = false;
23 23
24 m_enable_dim_ac = false; 24 m_enable_dim_ac = false;
25 m_enable_lightoff_ac = false; 25 m_enable_lightoff_ac = false;
26 m_enable_suspend_ac = false; 26 m_enable_suspend_ac = false;
27 m_onlylcdoff_ac = false; 27 m_onlylcdoff_ac = false;
28 28
29 m_use_light_sensor = false; 29 m_use_light_sensor = false;
30 m_backlight_sensor = -1; 30 m_backlight_sensor = -1;
31 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); 31 ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] ));
32 32
33 m_lcd_status = true; 33 m_lcd_status = true;
34 34
35 m_backlight_normal = -1; 35 m_backlight_normal = -1;
36 m_backlight_current = -1; 36 m_backlight_current = -1;
37 m_backlight_forcedoff = false; 37 m_backlight_forcedoff = false;
38 38
39 m_on_ac = false; 39 m_on_ac = false;
40 40
41 m_level = -1; 41 m_level = -1;
42 42
43 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) 43 // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off)
44 ODevice::inst ( )-> setDisplayStatus ( true ); 44 ODevice::inst ( )-> setDisplayStatus ( true );
45 setBacklight ( -1 ); 45 setBacklight ( -1 );
46} 46}
47 47
48 48
49/** 49/**
50 * Stops the screen saver 50 * Stops the screen saver
51 */ 51 */
52void OpieScreenSaver::restore() 52void OpieScreenSaver::restore()
53{ 53{
54 m_level = -1; 54 m_level = -1;
55 55
56 if ( !m_lcd_status ) { // We must have turned it off 56 if ( !m_lcd_status ) { // We must have turned it off
57 ODevice::inst ( ) -> setDisplayStatus ( true ); 57 ODevice::inst ( ) -> setDisplayStatus ( true );
58 m_lcd_status = true; 58 m_lcd_status = true;
59 } 59 }
60 60
61 setBacklightInternal ( -1 ); 61 setBacklightInternal ( -1 );
62} 62}
63 63
64 64
65/** 65/**
66 * Starts the screen saver 66 * Starts the screen saver
67 * 67 *
68 * @param level what level of screen saving should happen (0=lowest non-off, 1=off, 68 * @param level what level of screen saving should happen (0=lowest non-off, 1=off,
69 * 2=suspend whole machine) 69 * 2=suspend whole machine)
70 * @returns true on success 70 * @returns true on success
71 */ 71 */
72bool OpieScreenSaver::save( int level ) 72bool OpieScreenSaver::save( int level )
73{ 73{
74 m_level = level; 74 m_level = level;
75 75
76 switch ( level ) { 76 switch ( level ) {
77 case 0: 77 case 0:
78 if (( m_on_ac && m_enable_dim_ac ) || 78 if (( m_on_ac && m_enable_dim_ac ) ||
79 ( !m_on_ac && m_enable_dim )) { 79 ( !m_on_ac && m_enable_dim )) {
80 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) 80 if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor )
81 setBacklightInternal ( 1 ); // lowest non-off 81 setBacklightInternal ( 1 ); // lowest non-off
82 } 82 }
83 return true; 83 return true;
84 break; 84 break;
85 85
86 case 1: 86 case 1:
87 if (( m_on_ac && m_enable_lightoff_ac ) || 87 if (( m_on_ac && m_enable_lightoff_ac ) ||
88 ( !m_on_ac && m_enable_lightoff )) { 88 ( !m_on_ac && m_enable_lightoff )) {
89 if ( m_disable_suspend > 1 ) 89 if ( m_disable_suspend > 1 )
90 setBacklightInternal ( 0 ); // off 90 setBacklightInternal ( 0 ); // off
91 } 91 }
92 return true; 92 return true;
93 break; 93 break;
94 94
95 case 2: 95 case 2:
96 if (( m_on_ac && !m_enable_suspend_ac ) || 96 if (( m_on_ac && !m_enable_suspend_ac ) ||
97 ( !m_on_ac && !m_enable_suspend )) { 97 ( !m_on_ac && !m_enable_suspend )) {
98 return true; 98 return true;
99 } 99 }
100 100
101 if (( m_on_ac && m_onlylcdoff_ac ) || 101 if (( m_on_ac && m_onlylcdoff_ac ) ||
102 ( !m_on_ac && m_onlylcdoff )) { 102 ( !m_on_ac && m_onlylcdoff )) {
103 ODevice::inst ( ) -> setDisplayStatus ( false ); 103 ODevice::inst ( ) -> setDisplayStatus ( false );
104 m_lcd_status = false; 104 m_lcd_status = false;
105 return true; 105 return true;
106 } 106 }
107 107
108 // We're going to suspend the whole machine 108 // We're going to suspend the whole machine
109 109
110 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { 110 if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) {
111 // TODO: why is this key F34 hard coded? -- schurig 111 // TODO: why is this key F34 hard coded? -- schurig
112 // Does this now only work an devices with a ODevice::filter? 112 // Does this now only work an devices with a ODevice::filter?
113 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); 113 QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE );
114 return true; 114 return true;
115 } 115 }
116 116
117 break; 117 break;
118 } 118 }
119 return false; 119 return false;
120} 120}
121 121
122 122
123/** 123/**
124 * Set intervals in seconds for automatic dimming, light off and suspend 124 * Set intervals in seconds for automatic dimming, light off and suspend
125 * 125 *
126 * This function also sets the member variables m_m_enable_dim[_ac], 126 * This function also sets the member variables m_m_enable_dim[_ac],
127 * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac] 127 * m_enable_lightoff[_ac], m_enable_suspend[_ac], m_onlylcdoff[_ac]
128 * 128 *
129 * @param dim time in seconds to dim, -1 to read value from config file, 129 * @param dim time in seconds to dim, -1 to read value from config file,
130 * 0 to disable 130 * 0 to disable
131 * @param lightoff time in seconds to turn LCD backlight off, -1 to 131 * @param lightoff time in seconds to turn LCD backlight off, -1 to
132 * read value from config file, 0 to disable 132 * read value from config file, 0 to disable
133 * @param suspend time in seconds to do an APM suspend, -1 to 133 * @param suspend time in seconds to do an APM suspend, -1 to
134 * read value from config file, 0 to disable 134 * read value from config file, 0 to disable
135 */ 135 */
136void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) 136void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend )
137{ 137{
138 Config config ( "apm" ); 138 Config config ( "apm" );
139 config. setGroup ( m_on_ac ? "AC" : "Battery" ); 139 config. setGroup ( m_on_ac ? "AC" : "Battery" );
140 140
141 int v[ 4 ]; 141 int v[ 4 ];
142 if ( dim < 0 ) 142 if ( dim < 0 )
143 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); 143 dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 );
144 if ( lightoff < 0 ) 144 if ( lightoff < 0 )
145 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); 145 lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 );
146 if ( suspend < 0 ) 146 if ( suspend < 0 )
147 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); 147 suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 );
148 148
149 if ( m_on_ac ) { 149 if ( m_on_ac ) {
150 m_enable_dim_ac = ( dim > 0 ); 150 m_enable_dim_ac = ( dim > 0 );
151 m_enable_lightoff_ac = ( lightoff > 0 ); 151 m_enable_lightoff_ac = ( lightoff > 0 );
152 m_enable_suspend_ac = ( suspend > 0 ); 152 m_enable_suspend_ac = ( suspend > 0 );
153 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); 153 m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false );
154 } 154 }
155 else { 155 else {
156 m_enable_dim = ( dim > 0 ); 156 m_enable_dim = ( dim > 0 );
157 m_enable_lightoff = ( lightoff > 0 ); 157 m_enable_lightoff = ( lightoff > 0 );
158 m_enable_suspend = ( suspend > 0 ); 158 m_enable_suspend = ( suspend > 0 );
159 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); 159 m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false );
160 } 160 }
161 161
162 //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend); 162 //qDebug("screen saver intervals: %d %d %d", dim, lightoff, suspend);
163 163
164 v [ 0 ] = QMAX( 1000 * dim, 100 ); 164 v [ 0 ] = QMAX( 1000 * dim, 100 );
165 v [ 1 ] = QMAX( 1000 * lightoff, 100 ); 165 v [ 1 ] = QMAX( 1000 * lightoff, 100 );
166 v [ 2 ] = QMAX( 1000 * suspend, 100 ); 166 v [ 2 ] = QMAX( 1000 * suspend, 100 );
167 v [ 3 ] = 0; 167 v [ 3 ] = 0;
168 168
169 if ( !dim && !lightoff && !suspend ) 169 if ( !dim && !lightoff && !suspend )
170 QWSServer::setScreenSaverInterval( 0 ); 170 QWSServer::setScreenSaverInterval( 0 );
171 else 171 else
172 QWSServer::setScreenSaverIntervals( v ); 172 QWSServer::setScreenSaverIntervals( v );
173} 173}
174 174
175 175
176/** 176/**
177 * Set suspend time. Will read the dim and lcd-off times from the config file. 177 * Set suspend time. Will read the dim and lcd-off times from the config file.
178 * 178 *
179 * @param suspend time in seconds to go into APM suspend, -1 to 179 * @param suspend time in seconds to go into APM suspend, -1 to
180 * read value from config file, 0 to disable 180 * read value from config file, 0 to disable
181 */ 181 */
182void OpieScreenSaver::setInterval ( int interval ) 182void OpieScreenSaver::setInterval ( int interval )
183{ 183{
184 setIntervals ( -1, -1, interval ); 184 setIntervals ( -1, -1, interval );
185} 185}
186 186
187 187
188void OpieScreenSaver::setMode ( int mode ) 188void OpieScreenSaver::setMode ( int mode )
189{ 189{
190 if ( mode > m_disable_suspend ) 190 if ( mode > m_disable_suspend )
191 setInterval ( -1 ); 191 setInterval ( -1 );
192 m_disable_suspend = mode; 192 m_disable_suspend = mode;
193} 193}
194 194
195 195
196/** 196/**
197 * Set display brightness 197 * Set display brightness
198 * 198 *
199 * Get's default values for backlight, contrast and light sensor from config file. 199 * Get's default values for backlight, contrast and light sensor from config file.
200 * 200 *
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp
index b9580c7..32fcdd0 100644
--- a/core/launcher/server.cpp
+++ b/core/launcher/server.cpp
@@ -1,247 +1,247 @@
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 "launcher.h" 23#include "launcher.h"
24#include "startmenu.h" 24#include "startmenu.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 "launcher.h" 32#include "launcher.h"
33#include "shutdownimpl.h" 33#include "shutdownimpl.h"
34#include "applauncher.h" 34#include "applauncher.h"
35#if 0 35#if 0
36#include "suspendmonitor.h" 36#include "suspendmonitor.h"
37#endif 37#endif
38#include "documentlist.h" 38#include "documentlist.h"
39 39
40#include <qtopia/applnk.h> 40#include <qtopia/applnk.h>
41#include <qtopia/private/categories.h> 41#include <qtopia/private/categories.h>
42#include <qtopia/mimetype.h> 42#include <qtopia/mimetype.h>
43#include <qtopia/config.h> 43#include <qtopia/config.h>
44#include <qtopia/resource.h> 44#include <qtopia/resource.h>
45#include <qtopia/version.h> 45#include <qtopia/version.h>
46#include <qtopia/storage.h> 46#include <qtopia/storage.h>
47 47
48#include <qtopia/qcopenvelope_qws.h> 48#include <qtopia/qcopenvelope_qws.h>
49#include <qwindowsystem_qws.h> 49#include <qwindowsystem_qws.h>
50#include <qgfx_qws.h> 50#include <qgfx_qws.h>
51#include <qtopia/global.h> 51#include <qtopia/global.h>
52//#include <qtopia/custom.h> 52//#include <qtopia/custom.h>
53 53
54#include <opie/odevicebutton.h> 54#include <opie2/odevicebutton.h>
55#include <opie/odevice.h> 55#include <opie2/odevice.h>
56 56
57#include <unistd.h> 57#include <unistd.h>
58#include <qmainwindow.h> 58#include <qmainwindow.h>
59#include <qmessagebox.h> 59#include <qmessagebox.h>
60#include <qtimer.h> 60#include <qtimer.h>
61#include <qtextstream.h> 61#include <qtextstream.h>
62 62
63#include <stdlib.h> 63#include <stdlib.h>
64 64
65extern QRect qt_maxWindowRect; 65extern QRect qt_maxWindowRect;
66 66
67using namespace Opie; 67using namespace Opie;
68 68
69static QWidget *calibrate(bool) 69static QWidget *calibrate(bool)
70{ 70{
71#ifdef Q_WS_QWS 71#ifdef Q_WS_QWS
72 Calibrate *c = new Calibrate; 72 Calibrate *c = new Calibrate;
73 c->show(); 73 c->show();
74 return c; 74 return c;
75#else 75#else
76 return 0; 76 return 0;
77#endif 77#endif
78} 78}
79 79
80#define FACTORY(T) \ 80#define FACTORY(T) \
81 static QWidget *new##T( bool maximized ) { \ 81 static QWidget *new##T( bool maximized ) { \
82 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ 82 QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \
83 if ( maximized ) { \ 83 if ( maximized ) { \
84 if ( qApp->desktop()->width() <= 350 ) { \ 84 if ( qApp->desktop()->width() <= 350 ) { \
85 w->showMaximized(); \ 85 w->showMaximized(); \
86 } else { \ 86 } else { \
87 w->resize( QSize( 300, 300 ) ); \ 87 w->resize( QSize( 300, 300 ) ); \
88 } \ 88 } \
89 } \ 89 } \
90 w->show(); \ 90 w->show(); \
91 return w; \ 91 return w; \
92 } 92 }
93 93
94 94
95#ifdef SINGLE_APP 95#ifdef SINGLE_APP
96#define APP(a,b,c,d) FACTORY(b) 96#define APP(a,b,c,d) FACTORY(b)
97#include "apps.h" 97#include "apps.h"
98#undef APP 98#undef APP
99#endif // SINGLE_APP 99#endif // SINGLE_APP
100 100
101static Global::Command builtins[] = { 101static Global::Command builtins[] = {
102 102
103#ifdef SINGLE_APP 103#ifdef SINGLE_APP
104#define APP(a,b,c,d) { a, new##b, c, d }, 104#define APP(a,b,c,d) { a, new##b, c, d },
105#include "apps.h" 105#include "apps.h"
106#undef APP 106#undef APP
107#endif 107#endif
108 108
109 /* FIXME defines need to be defined*/ 109 /* FIXME defines need to be defined*/
110#if !defined(OPIE_NO_BUILTIN_CALIBRATE) 110#if !defined(OPIE_NO_BUILTIN_CALIBRATE)
111 { "calibrate", calibrate, 1, 0 }, // No tr 111 { "calibrate", calibrate, 1, 0 }, // No tr
112#endif 112#endif
113#if !defined(OPIE_NO_BUILTIN_SHUTDOWN) 113#if !defined(OPIE_NO_BUILTIN_SHUTDOWN)
114 { "shutdown", Global::shutdown, 1, 0 }, // No tr 114 { "shutdown", Global::shutdown, 1, 0 }, // No tr
115 // { "run", run, 1, 0 }, // No tr 115 // { "run", run, 1, 0 }, // No tr
116#endif 116#endif
117 117
118 { 0, calibrate,0, 0 }, 118 { 0, calibrate,0, 0 },
119}; 119};
120 120
121 121
122//--------------------------------------------------------------------------- 122//---------------------------------------------------------------------------
123 123
124 124
125//=========================================================================== 125//===========================================================================
126 126
127Server::Server() : 127Server::Server() :
128 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ), 128 QWidget( 0, 0, WStyle_Tool | WStyle_Customize ),
129 qcopBridge( 0 ), 129 qcopBridge( 0 ),
130 transferServer( 0 ), 130 transferServer( 0 ),
131 packageHandler( 0 ), 131 packageHandler( 0 ),
132 syncDialog( 0 ) 132 syncDialog( 0 )
133{ 133{
134 Global::setBuiltinCommands(builtins); 134 Global::setBuiltinCommands(builtins);
135 135
136 tid_xfer = 0; 136 tid_xfer = 0;
137 /* ### FIXME ### */ 137 /* ### FIXME ### */
138/* tid_today = startTimer(3600*2*1000);*/ 138/* tid_today = startTimer(3600*2*1000);*/
139 last_today_show = QDate::currentDate(); 139 last_today_show = QDate::currentDate();
140 140
141#if 0 141#if 0
142 tsmMonitor = new TempScreenSaverMode(); 142 tsmMonitor = new TempScreenSaverMode();
143 connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) ); 143 connect( tsmMonitor, SIGNAL(forceSuspend()), qApp, SIGNAL(power()) );
144#endif 144#endif
145 145
146 serverGui = new Launcher; 146 serverGui = new Launcher;
147 serverGui->createGUI(); 147 serverGui->createGUI();
148 148
149 docList = new DocumentList( serverGui ); 149 docList = new DocumentList( serverGui );
150 appLauncher = new AppLauncher(this); 150 appLauncher = new AppLauncher(this);
151 connect(appLauncher, SIGNAL(launched(int, const QString &)), this, SLOT(applicationLaunched(int, const QString &)) ); 151 connect(appLauncher, SIGNAL(launched(int, const QString &)), this, SLOT(applicationLaunched(int, const QString &)) );
152 connect(appLauncher, SIGNAL(terminated(int, const QString &)), this, SLOT(applicationTerminated(int, const QString &)) ); 152 connect(appLauncher, SIGNAL(terminated(int, const QString &)), this, SLOT(applicationTerminated(int, const QString &)) );
153 connect(appLauncher, SIGNAL(connected(const QString &)), this, SLOT(applicationConnected(const QString &)) ); 153 connect(appLauncher, SIGNAL(connected(const QString &)), this, SLOT(applicationConnected(const QString &)) );
154 154
155 storage = new StorageInfo( this ); 155 storage = new StorageInfo( this );
156 connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) ); 156 connect( storage, SIGNAL(disksChanged()), this, SLOT(storageChanged()) );
157 157
158 // start services 158 // start services
159 startTransferServer(); 159 startTransferServer();
160 (void) new IrServer( this ); 160 (void) new IrServer( this );
161 161
162 packageHandler = new PackageHandler( this ); 162 packageHandler = new PackageHandler( this );
163 connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)), 163 connect(qApp, SIGNAL(activate(const Opie::ODeviceButton*,bool)),
164 this,SLOT(activate(const Opie::ODeviceButton*,bool))); 164 this,SLOT(activate(const Opie::ODeviceButton*,bool)));
165 165
166 setGeometry( -10, -10, 9, 9 ); 166 setGeometry( -10, -10, 9, 9 );
167 167
168 QCopChannel *channel = new QCopChannel("QPE/System", this); 168 QCopChannel *channel = new QCopChannel("QPE/System", this);
169 connect(channel, SIGNAL(received(const QCString &, const QByteArray &)), 169 connect(channel, SIGNAL(received(const QCString &, const QByteArray &)),
170 this, SLOT(systemMsg(const QCString &, const QByteArray &)) ); 170 this, SLOT(systemMsg(const QCString &, const QByteArray &)) );
171 171
172 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); 172 QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this );
173 connect( tbChannel, SIGNAL(received(const QCString&, const QByteArray&)), 173 connect( tbChannel, SIGNAL(received(const QCString&, const QByteArray&)),
174 this, SLOT(receiveTaskBar(const QCString&, const QByteArray&)) ); 174 this, SLOT(receiveTaskBar(const QCString&, const QByteArray&)) );
175 175
176 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); 176 connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) );
177 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); 177 connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) );
178 178
179 preloadApps(); 179 preloadApps();
180} 180}
181 181
182void Server::show() 182void Server::show()
183{ 183{
184 ServerApplication::login(TRUE); 184 ServerApplication::login(TRUE);
185 QWidget::show(); 185 QWidget::show();
186} 186}
187 187
188Server::~Server() 188Server::~Server()
189{ 189{
190 serverGui->destroyGUI(); 190 serverGui->destroyGUI();
191 delete docList; 191 delete docList;
192 delete qcopBridge; 192 delete qcopBridge;
193 delete transferServer; 193 delete transferServer;
194 delete serverGui; 194 delete serverGui;
195#if 0 195#if 0
196 delete tsmMonitor; 196 delete tsmMonitor;
197#endif 197#endif
198} 198}
199 199
200static bool hasVisibleWindow(const QString& clientname, bool partial) 200static bool hasVisibleWindow(const QString& clientname, bool partial)
201{ 201{
202#ifdef QWS 202#ifdef QWS
203 const QList<QWSWindow> &list = qwsServer->clientWindows(); 203 const QList<QWSWindow> &list = qwsServer->clientWindows();
204 QWSWindow* w; 204 QWSWindow* w;
205 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { 205 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
206 if ( w->client()->identity() == clientname ) { 206 if ( w->client()->identity() == clientname ) {
207 if ( partial && !w->isFullyObscured() ) 207 if ( partial && !w->isFullyObscured() )
208 return TRUE; 208 return TRUE;
209 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { 209 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) {
210# if QT_VERSION < 0x030000 210# if QT_VERSION < 0x030000
211 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, 211 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
212 QSize(qt_screen->width(),qt_screen->height()) ); 212 QSize(qt_screen->width(),qt_screen->height()) );
213# else 213# else
214 QRect mwr = qt_maxWindowRect; 214 QRect mwr = qt_maxWindowRect;
215# endif 215# endif
216 if ( mwr.contains(w->requested().boundingRect()) ) 216 if ( mwr.contains(w->requested().boundingRect()) )
217 return TRUE; 217 return TRUE;
218 } 218 }
219 } 219 }
220 } 220 }
221#endif 221#endif
222 return FALSE; 222 return FALSE;
223} 223}
224 224
225void Server::activate(const Opie::ODeviceButton* button, bool held) 225void Server::activate(const Opie::ODeviceButton* button, bool held)
226{ 226{
227 Global::terminateBuiltin("calibrate"); // No tr 227 Global::terminateBuiltin("calibrate"); // No tr
228 Opie::OQCopMessage om; 228 Opie::OQCopMessage om;
229 if ( held ) { 229 if ( held ) {
230 om = button->heldAction(); 230 om = button->heldAction();
231 } else { 231 } else {
232 om = button->pressedAction(); 232 om = button->pressedAction();
233 } 233 }
234 234
235 if ( om.channel() != "ignore" ) 235 if ( om.channel() != "ignore" )
236 om.send(); 236 om.send();
237 237
238 // A button with no action defined, will return a null ServiceRequest. Don't attempt 238 // A button with no action defined, will return a null ServiceRequest. Don't attempt
239 // to send/do anything with this as it will crash 239 // to send/do anything with this as it will crash
240 /* ### FIXME */ 240 /* ### FIXME */
241#if 0 241#if 0
242 if ( !sr.isNull() ) { 242 if ( !sr.isNull() ) {
243 QString app = sr.app(); 243 QString app = sr.app();
244 bool vis = hasVisibleWindow(app, app != "qpe"); 244 bool vis = hasVisibleWindow(app, app != "qpe");
245 if ( sr.message() == "raise()" && vis ) { 245 if ( sr.message() == "raise()" && vis ) {
246 sr.setMessage("nextView()"); 246 sr.setMessage("nextView()");
247 } else { 247 } else {
diff --git a/core/launcher/server.pro b/core/launcher/server.pro
index 0513536..f82c741 100644
--- a/core/launcher/server.pro
+++ b/core/launcher/server.pro
@@ -1,125 +1,124 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 2
3 CONFIG += qtopia warn_on release 3 CONFIG += qtopia warn_on release
4 4
5 DESTDIR = $$(OPIEDIR)/bin 5 DESTDIR = $$(OPIEDIR)/bin
6 6
7 HEADERS += server.h \ 7 HEADERS += server.h \
8 serverinterface.h \ 8 serverinterface.h \
9 launchertab.h \ 9 launchertab.h \
10 documentlist.h \ 10 documentlist.h \
11 appicons.h \ 11 appicons.h \
12 taskbar.h \ 12 taskbar.h \
13 runningappbar.h \ 13 runningappbar.h \
14 applauncher.h \ 14 applauncher.h \
15 stabmon.h \ 15 stabmon.h \
16 inputmethods.h \ 16 inputmethods.h \
17 systray.h \ 17 systray.h \
18 wait.h \ 18 wait.h \
19 shutdownimpl.h \ 19 shutdownimpl.h \
20 launcher.h \ 20 launcher.h \
21 launcherview.h \ 21 launcherview.h \
22 $$(OPIEDIR)/core/apps/calibrate/calibrate.h \ 22 $$(OPIEDIR)/core/apps/calibrate/calibrate.h \
23 startmenu.h \ 23 startmenu.h \
24 transferserver.h \ 24 transferserver.h \
25 qcopbridge.h \ 25 qcopbridge.h \
26 packageslave.h \ 26 packageslave.h \
27 irserver.h \ 27 irserver.h \
28 firstuse.h \ 28 firstuse.h \
29 $$(OPIEDIR)/rsync/buf.h \ 29 $$(OPIEDIR)/rsync/buf.h \
30 $$(OPIEDIR)/rsync/checksum.h \ 30 $$(OPIEDIR)/rsync/checksum.h \
31 $$(OPIEDIR)/rsync/command.h \ 31 $$(OPIEDIR)/rsync/command.h \
32 $$(OPIEDIR)/rsync/emit.h \ 32 $$(OPIEDIR)/rsync/emit.h \
33 $$(OPIEDIR)/rsync/job.h \ 33 $$(OPIEDIR)/rsync/job.h \
34 $$(OPIEDIR)/rsync/netint.h \ 34 $$(OPIEDIR)/rsync/netint.h \
35 $$(OPIEDIR)/rsync/protocol.h \ 35 $$(OPIEDIR)/rsync/protocol.h \
36 $$(OPIEDIR)/rsync/prototab.h \ 36 $$(OPIEDIR)/rsync/prototab.h \
37 $$(OPIEDIR)/rsync/rsync.h \ 37 $$(OPIEDIR)/rsync/rsync.h \
38 $$(OPIEDIR)/rsync/search.h \ 38 $$(OPIEDIR)/rsync/search.h \
39 $$(OPIEDIR)/rsync/stream.h \ 39 $$(OPIEDIR)/rsync/stream.h \
40 $$(OPIEDIR)/rsync/sumset.h \ 40 $$(OPIEDIR)/rsync/sumset.h \
41 $$(OPIEDIR)/rsync/trace.h \ 41 $$(OPIEDIR)/rsync/trace.h \
42 $$(OPIEDIR)/rsync/types.h \ 42 $$(OPIEDIR)/rsync/types.h \
43 $$(OPIEDIR)/rsync/util.h \ 43 $$(OPIEDIR)/rsync/util.h \
44 $$(OPIEDIR)/rsync/whole.h \ 44 $$(OPIEDIR)/rsync/whole.h \
45 $$(OPIEDIR)/rsync/config_rsync.h \ 45 $$(OPIEDIR)/rsync/config_rsync.h \
46 $$(OPIEDIR)/rsync/qrsync.h \ 46 $$(OPIEDIR)/rsync/qrsync.h \
47 syncdialog.h \ 47 syncdialog.h \
48 serverapp.h \ 48 serverapp.h \
49 launcherglobal.h \
50 qprocess.h \ 49 qprocess.h \
51 screensaver.h 50 screensaver.h
52 51
53 SOURCES += server.cpp \ 52 SOURCES += server.cpp \
54 serverinterface.cpp \ 53 serverinterface.cpp \
55 launchertab.cpp \ 54 launchertab.cpp \
56 documentlist.cpp \ 55 documentlist.cpp \
57 appicons.cpp \ 56 appicons.cpp \
58 taskbar.cpp \ 57 taskbar.cpp \
59 runningappbar.cpp \ 58 runningappbar.cpp \
60 applauncher.cpp \ 59 applauncher.cpp \
61 stabmon.cpp \ 60 stabmon.cpp \
62 inputmethods.cpp \ 61 inputmethods.cpp \
63 systray.cpp \ 62 systray.cpp \
64 wait.cpp \ 63 wait.cpp \
65 shutdownimpl.cpp \ 64 shutdownimpl.cpp \
66 launcher.cpp \ 65 launcher.cpp \
67 launcherview.cpp \ 66 launcherview.cpp \
68 $$(OPIEDIR)/core/apps/calibrate/calibrate.cpp \ 67 $$(OPIEDIR)/core/apps/calibrate/calibrate.cpp \
69 transferserver.cpp \ 68 transferserver.cpp \
70 packageslave.cpp \ 69 packageslave.cpp \
71 irserver.cpp \ 70 irserver.cpp \
72 qcopbridge.cpp \ 71 qcopbridge.cpp \
73 startmenu.cpp \ 72 startmenu.cpp \
74 main.cpp \ 73 main.cpp \
75 firstuse.cpp \ 74 firstuse.cpp \
76 $$(OPIEDIR)/rsync/base64.c \ 75 $$(OPIEDIR)/rsync/base64.c \
77 $$(OPIEDIR)/rsync/buf.c \ 76 $$(OPIEDIR)/rsync/buf.c \
78 $$(OPIEDIR)/rsync/checksum.c \ 77 $$(OPIEDIR)/rsync/checksum.c \
79 $$(OPIEDIR)/rsync/command.c \ 78 $$(OPIEDIR)/rsync/command.c \
80 $$(OPIEDIR)/rsync/delta.c \ 79 $$(OPIEDIR)/rsync/delta.c \
81 $$(OPIEDIR)/rsync/emit.c \ 80 $$(OPIEDIR)/rsync/emit.c \
82 $$(OPIEDIR)/rsync/hex.c \ 81 $$(OPIEDIR)/rsync/hex.c \
83 $$(OPIEDIR)/rsync/job.c \ 82 $$(OPIEDIR)/rsync/job.c \
84 $$(OPIEDIR)/rsync/mdfour.c \ 83 $$(OPIEDIR)/rsync/mdfour.c \
85 $$(OPIEDIR)/rsync/mksum.c \ 84 $$(OPIEDIR)/rsync/mksum.c \
86 $$(OPIEDIR)/rsync/msg.c \ 85 $$(OPIEDIR)/rsync/msg.c \
87 $$(OPIEDIR)/rsync/netint.c \ 86 $$(OPIEDIR)/rsync/netint.c \
88 $$(OPIEDIR)/rsync/patch.c \ 87 $$(OPIEDIR)/rsync/patch.c \
89 $$(OPIEDIR)/rsync/prototab.c \ 88 $$(OPIEDIR)/rsync/prototab.c \
90 $$(OPIEDIR)/rsync/readsums.c \ 89 $$(OPIEDIR)/rsync/readsums.c \
91 $$(OPIEDIR)/rsync/scoop.c \ 90 $$(OPIEDIR)/rsync/scoop.c \
92 $$(OPIEDIR)/rsync/search.c \ 91 $$(OPIEDIR)/rsync/search.c \
93 $$(OPIEDIR)/rsync/stats.c \ 92 $$(OPIEDIR)/rsync/stats.c \
94 $$(OPIEDIR)/rsync/stream.c \ 93 $$(OPIEDIR)/rsync/stream.c \
95 $$(OPIEDIR)/rsync/sumset.c \ 94 $$(OPIEDIR)/rsync/sumset.c \
96 $$(OPIEDIR)/rsync/trace.c \ 95 $$(OPIEDIR)/rsync/trace.c \
97 $$(OPIEDIR)/rsync/tube.c \ 96 $$(OPIEDIR)/rsync/tube.c \
98 $$(OPIEDIR)/rsync/util.c \ 97 $$(OPIEDIR)/rsync/util.c \
99 $$(OPIEDIR)/rsync/version.c \ 98 $$(OPIEDIR)/rsync/version.c \
100 $$(OPIEDIR)/rsync/whole.c \ 99 $$(OPIEDIR)/rsync/whole.c \
101 $$(OPIEDIR)/rsync/qrsync.cpp \ 100 $$(OPIEDIR)/rsync/qrsync.cpp \
102 syncdialog.cpp \ 101 syncdialog.cpp \
103 serverapp.cpp \ 102 serverapp.cpp \
104 launcherglobal.cpp \
105 qprocess.cpp \ 103 qprocess.cpp \
106 qprocess_unix.cpp \ 104 qprocess_unix.cpp \
107 screensaver.cpp 105 screensaver.cpp
108 106
109 107
110INCLUDEPATH += $(OPIEDIR)/core/apps/calibrate 108INCLUDEPATH += $(OPIEDIR)/core/apps/calibrate
111 DEPENDPATH+= $(OPIEDIR)/core/apps/calibrate 109 DEPENDPATH+= $(OPIEDIR)/core/apps/calibrate
112 110
113INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/rsync 111INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/rsync
114 DEPENDPATH+= $(OPIEDIR)/rsync 112 DEPENDPATH+= $(OPIEDIR)/rsync
115 113
116 TARGET = qpe 114 TARGET = qpe
117 115
116#needs OWait and ODevice
118CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 117CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
119contains( CONFTEST, y ){ 118contains( CONFTEST, y ){
120 LIBS += -lqpe -lopie 119 LIBS += -lqpe -lopiecore2 -lopieui2
121}else{ 120}else{
122 LIBS+= -lcrypt -lqpe -lopie 121 LIBS+= -lcrypt -lqpe -lopiecore2 -lopieui2
123} 122}
124 123
125include ( $(OPIEDIR)/include.pro ) 124include ( $(OPIEDIR)/include.pro )
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index b84eed8..c199063 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -165,230 +165,230 @@ void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
165} 165}
166 166
167void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot ) 167void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
168{ 168{
169 // do some sanity checks and collect information 169 // do some sanity checks and collect information
170 170
171 if ( file == "." || file == ".." ) return; 171 if ( file == "." || file == ".." ) return;
172 172
173 Config cfg( dir.path() + "/" + file + "/.directory", Config::File ); 173 Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
174 if ( !cfg.isValid() ) return; 174 if ( !cfg.isValid() ) return;
175 175
176 QString name = cfg.readEntry( "Name" ); 176 QString name = cfg.readEntry( "Name" );
177 QString icon = cfg.readEntry( "Icon" ); 177 QString icon = cfg.readEntry( "Icon" );
178 if ( !name || !icon ) return; 178 if ( !name || !icon ) return;
179 179
180 QDir subdir = QDir( dir ); 180 QDir subdir = QDir( dir );
181 subdir.cd( file ); 181 subdir.cd( file );
182 subdir.setFilter( QDir::Files ); 182 subdir.setFilter( QDir::Files );
183 subdir.setNameFilter( "*.desktop" ); 183 subdir.setNameFilter( "*.desktop" );
184 // we don' t show the menu if there are no entries 184 // we don' t show the menu if there are no entries
185 // perhaps one should check if there exist subsubdirs with entries... 185 // perhaps one should check if there exist subsubdirs with entries...
186 if ( subdir.entryList().isEmpty() ) return; 186 if ( subdir.entryList().isEmpty() ) return;
187 187
188 // checks were ok 188 // checks were ok
189 189
190 QPixmap test; 190 QPixmap test;
191 test.convertFromImage( Resource::loadImage( icon ).smoothScale( 191 test.convertFromImage( Resource::loadImage( icon ).smoothScale(
192 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 ); 192 AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
193 193
194 if ( useWidePopupMenu ) { 194 if ( useWidePopupMenu ) {
195 // generate submenu 195 // generate submenu
196 QPopupMenu *submenu = new QPopupMenu( menu ); 196 QPopupMenu *submenu = new QPopupMenu( menu );
197 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) ); 197 connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
198 menu->insertItem( test, name, submenu, NO_ID ); 198 menu->insertItem( test, name, submenu, NO_ID );
199 199
200 // ltabs is true cause else we wouldn't stuck around.. 200 // ltabs is true cause else we wouldn't stuck around..
201 createMenuEntries( submenu, subdir, true, lot ); 201 createMenuEntries( submenu, subdir, true, lot );
202 } else { 202 } else {
203 // no submenus - just bring corresponding tab to front 203 // no submenus - just bring corresponding tab to front
204 menu->insertItem( test, name, currentItem ); 204 menu->insertItem( test, name, currentItem );
205 tabNames.insert( currentItem, new QString( file ) ); 205 tabNames.insert( currentItem, new QString( file ) );
206 currentItem++; 206 currentItem++;
207 } 207 }
208} 208}
209 209
210void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot ) 210void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
211{ 211{
212 if ( lot ) { 212 if ( lot ) {
213 dir.setFilter( QDir::Files ); 213 dir.setFilter( QDir::Files );
214 dir.setNameFilter( "*.desktop" ); 214 dir.setNameFilter( "*.desktop" );
215 QStringList files = dir.entryList(); 215 QStringList files = dir.entryList();
216 files.sort(); 216 files.sort();
217 217
218 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) { 218 for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
219 createAppEntry( menu, dir, *it ); 219 createAppEntry( menu, dir, *it );
220 } 220 }
221 } 221 }
222 if ( ltabs ) { 222 if ( ltabs ) {
223 dir.setNameFilter( "*" ); 223 dir.setNameFilter( "*" );
224 dir.setFilter( QDir::Dirs ); 224 dir.setFilter( QDir::Dirs );
225 QStringList dirs = dir.entryList(); 225 QStringList dirs = dir.entryList();
226 dirs.sort(); 226 dirs.sort();
227 227
228 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) { 228 for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
229 createDirEntry( menu, dir, *it, lot ); 229 createDirEntry( menu, dir, *it, lot );
230 } 230 }
231 } 231 }
232} 232}
233 233
234bool StartMenu::loadMenu( QPopupMenu *menu ) 234bool StartMenu::loadMenu( QPopupMenu *menu )
235{ 235{
236 Config cfg("StartMenu"); 236 Config cfg("StartMenu");
237 cfg.setGroup("Menu"); 237 cfg.setGroup("Menu");
238 238
239 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE); 239 bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
240 bool lot = cfg.readBoolEntry("LauncherOther", TRUE); 240 bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
241 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE ); 241 useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
242 bool sepfirst = !ltabs && !lot; 242 bool sepfirst = !ltabs && !lot;
243 243
244 currentItem = 0; 244 currentItem = 0;
245 launchMenu->clear(); 245 launchMenu->clear();
246 246
247 appLnks.setAutoDelete( true ); 247 appLnks.setAutoDelete( true );
248 tabNames.setAutoDelete( true ); 248 tabNames.setAutoDelete( true );
249 appLnks.clear(); 249 appLnks.clear();
250 tabNames.clear(); 250 tabNames.clear();
251 appLnks.setAutoDelete( false ); 251 appLnks.setAutoDelete( false );
252 tabNames.setAutoDelete( false ); 252 tabNames.setAutoDelete( false );
253 253
254 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name ); 254 QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );
255 createMenuEntries( menu, dir, ltabs, lot ); 255 createMenuEntries( menu, dir, ltabs, lot );
256 256
257 if ( !menu->count() ) sepfirst = TRUE; 257 if ( !menu->count() ) sepfirst = TRUE;
258 258
259 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr 259 launchMenu->setName( sepfirst ? "accessories" : "accessories_need_sep" ); // No tr
260 260
261 return currentItem; 261 return currentItem;
262} 262}
263 263
264 264
265void StartMenu::launch() 265void StartMenu::launch()
266{ 266{
267 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height(); 267 int y = mapToGlobal( QPoint() ).y() - launchMenu->sizeHint().height();
268 268
269 if ( launchMenu->isVisible() ) 269 if ( launchMenu->isVisible() )
270 launchMenu->hide(); 270 launchMenu->hide();
271 else 271 else
272 launchMenu->popup( QPoint( 1, y ) ); 272 launchMenu->popup( QPoint( 1, y ) );
273} 273}
274 274
275 275
276 276
277 277
278static int compareAppletPositions(const void *b, const void *a) 278static int compareAppletPositions(const void *b, const void *a)
279{ 279{
280 const MenuApplet* aa = *(const MenuApplet**)a; 280 const MenuApplet* aa = *(const MenuApplet**)a;
281 const MenuApplet* ab = *(const MenuApplet**)b; 281 const MenuApplet* ab = *(const MenuApplet**)b;
282 int d = aa->iface->position() - ab->iface->position(); 282 int d = aa->iface->position() - ab->iface->position();
283 if ( d ) return d; 283 if ( d ) return d;
284 return QString::compare(aa->library->library(),ab->library->library()); 284 return QString::compare(aa->library->library(),ab->library->library());
285} 285}
286 286
287void StartMenu::clearApplets() 287void StartMenu::clearApplets()
288{ 288{
289 if ( launchMenu ) 289 if ( launchMenu )
290 launchMenu-> hide(); 290 launchMenu-> hide();
291 291
292 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 292 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
293 MenuApplet *applet = it.current(); 293 MenuApplet *applet = it.current();
294 if ( launchMenu ) { 294 if ( launchMenu ) {
295 launchMenu->removeItem( applet-> id ); 295 launchMenu->removeItem( applet-> id );
296 delete applet->popup; 296 delete applet->popup;
297 } 297 }
298 298
299 applet->iface->release(); 299 applet->iface->release();
300 applet->library->unload(); 300 applet->library->unload();
301 delete applet-> library; 301 delete applet-> library;
302 } 302 }
303 menuApplets.clear(); 303 menuApplets.clear();
304} 304}
305 305
306 306
307 307
308 308
309void StartMenu::loadApplets() 309void StartMenu::loadApplets()
310{ 310{
311 Config cfg( "StartMenu" ); 311 Config cfg( "StartMenu" );
312 cfg.setGroup( "Applets" ); 312 cfg.setGroup( "Applets" );
313 313
314 // SafeMode causes too much problems, so we disable it for now -- 314 // SafeMode causes too much problems, so we disable it for now --
315 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02 315 // maybe we should reenable it for OPIE 1.0 - sandman 26.09.02
316 // removed in the remerge PluginManager could handle it 316 // removed in the remerge PluginManager could handle it
317 // we don't currently use it -zecke 317 // we don't currently use it -zecke
318 318
319 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' ); 319 QStringList exclude = cfg.readListEntry( "ExcludeApplets", ',' );
320 320
321 QString lang = getenv( "LANG" ); 321 QString lang = getenv( "LANG" );
322 QString path = QPEApplication::qpeDir() + "/plugins/applets"; 322 QString path = QPEApplication::qpeDir() + "/plugins/applets";
323 QDir dir( path, "lib*.so" ); 323 QDir dir( path, "lib*.so" );
324 QStringList list = dir.entryList(); 324 QStringList list = dir.entryList();
325 QStringList::Iterator it; 325 QStringList::Iterator it;
326 int napplets = 0; 326 int napplets = 0;
327 MenuApplet* *xapplets = new MenuApplet*[list.count()]; 327 MenuApplet* *xapplets = new MenuApplet*[list.count()];
328 for ( it = list.begin(); it != list.end(); ++it ) { 328 for ( it = list.begin(); it != list.end(); ++it ) {
329 if ( exclude.find( *it ) != exclude.end() ) 329 if ( exclude.find( *it ) != exclude.end() )
330 continue; 330 continue;
331 MenuAppletInterface *iface = 0; 331 MenuAppletInterface *iface = 0;
332 QLibrary *lib = new QLibrary( path + "/" + *it ); 332 QLibrary *lib = new QLibrary( path + "/" + *it );
333 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) { 333 if (( lib->queryInterface( IID_MenuApplet, (QUnknownInterface**)&iface ) == QS_OK ) && iface ) {
334 MenuApplet *applet = new MenuApplet; 334 MenuApplet *applet = new MenuApplet;
335 xapplets[napplets++] = applet; 335 xapplets[napplets++] = applet;
336 applet->library = lib; 336 applet->library = lib;
337 applet->iface = iface; 337 applet->iface = iface;
338 338
339 QTranslator *trans = new QTranslator(qApp); 339 QTranslator *trans = new QTranslator(qApp);
340 QString type = (*it).left( (*it).find(".") ); 340 QString type = (*it).left( (*it).find(".") );
341 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm"; 341 QString tfn = QPEApplication::qpeDir()+"/i18n/"+lang+"/"+type+".qm";
342 if ( trans->load( tfn )) 342 if ( trans->load( tfn ))
343 qApp->installTranslator( trans ); 343 qApp->installTranslator( trans );
344 else 344 else
345 delete trans; 345 delete trans;
346 } else { 346 } else {
347 exclude += *it; 347 exclude += *it;
348 delete lib; 348 delete lib;
349 } 349 }
350 } 350 }
351 cfg.writeEntry( "ExcludeApplets", exclude, ',' ); 351 cfg.writeEntry( "ExcludeApplets", exclude, ',' );
352 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions); 352 qsort(xapplets, napplets, sizeof(menuApplets[0]), compareAppletPositions);
353 353
354 354
355 while ( napplets-- ) { 355 while ( napplets-- ) {
356 MenuApplet *applet = xapplets[napplets]; 356 MenuApplet *applet = xapplets[napplets];
357
358 applet->popup = applet->iface->popup( this ); 357 applet->popup = applet->iface->popup( this );
359 358
360 // menuApplets got an id < -1 359 // menuApplets got an id < -1
361 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) ); 360 menuApplets.insert( -( currentItem + 2 ), new MenuApplet( *applet ) );
362 currentItem++; 361 currentItem++;
363 } 362 }
364 delete [] xapplets; 363 delete [] xapplets;
365 364
366 addApplets( launchMenu ); 365 addApplets( launchMenu );
367} 366}
368 367
369 368
370/* 369/*
371 * Launcher calls loadMenu too often fix that 370 * Launcher calls loadMenu too often fix that
372 */ 371 */
373void StartMenu::addApplets(QPopupMenu* pop) { 372void StartMenu::addApplets(QPopupMenu* pop) {
374 QIntDict<MenuApplet> dict; 373 QIntDict<MenuApplet> dict;
375 if( pop-> count ( )) 374 if( pop-> count ( ))
376 pop-> insertSeparator ( ); 375 pop-> insertSeparator ( );
377 376
378 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) { 377 for ( QIntDictIterator<MenuApplet> it( menuApplets ); it.current(); ++it ) {
379 MenuApplet *applet = it.current(); 378 MenuApplet *applet = it.current();
380 if ( applet->popup ) 379 if ( applet->popup )
381 applet->id = pop->insertItem( applet->iface->icon(), 380 applet->id = pop->insertItem( applet->iface->icon(),
382 applet->iface->text(), applet->popup ); 381 applet->iface->text(), applet->popup );
383 else 382 else
384 applet->id = pop->insertItem( applet->iface->icon(), 383 applet->id = pop->insertItem( applet->iface->icon(),
385 applet->iface->text() ); 384 applet->iface->text() );
386 385
386
387 dict.insert( applet->id, new MenuApplet( *applet ) ); 387 dict.insert( applet->id, new MenuApplet( *applet ) );
388 } 388 }
389 /* need to update the key */ 389 /* need to update the key */
390 menuApplets.setAutoDelete( true ); 390 menuApplets.setAutoDelete( true );
391 menuApplets.clear(); 391 menuApplets.clear();
392 menuApplets.setAutoDelete( false ); 392 menuApplets.setAutoDelete( false );
393 menuApplets = dict; 393 menuApplets = dict;
394} 394}
diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp
index 9519d11..9cb9d7a 100644
--- a/core/launcher/transferserver.cpp
+++ b/core/launcher/transferserver.cpp
@@ -1,424 +1,423 @@
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//#define _XOPEN_SOURCE
21 21
22#include <qtopia/global.h> 22#include <opie2/oglobal.h>
23#include <qtopia/qpeapplication.h> 23#include <qtopia/qpeapplication.h>
24 24
25#ifndef Q_OS_WIN32 25#ifndef Q_OS_WIN32
26#include <pwd.h> 26#include <pwd.h>
27#include <sys/types.h> 27#include <sys/types.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <stdlib.h> 29#include <stdlib.h>
30#include <time.h> 30#include <time.h>
31 31
32#ifndef Q_OS_MACX 32#ifndef Q_OS_MACX
33#include <shadow.h> 33#include <shadow.h>
34#include <crypt.h> 34#include <crypt.h>
35#endif /* Q_OS_MACX */ 35#endif /* Q_OS_MACX */
36 36
37#else 37#else
38#include <stdlib.h> 38#include <stdlib.h>
39#include <time.h> 39#include <time.h>
40#endif 40#endif
41 41
42 42
43#if defined(_OS_LINUX_) 43#if defined(_OS_LINUX_)
44#include <shadow.h> 44#include <shadow.h>
45#endif 45#endif
46 46
47#include <qdir.h> 47#include <qdir.h>
48#include <qfile.h> 48#include <qfile.h>
49#include <qtextstream.h> 49#include <qtextstream.h>
50#include <qdatastream.h> 50#include <qdatastream.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qstringlist.h> 52#include <qstringlist.h>
53#include <qfileinfo.h> 53#include <qfileinfo.h>
54#include <qregexp.h> 54#include <qregexp.h>
55//#include <qtopia/qcopchannel_qws.h> 55//#include <qtopia/qcopchannel_qws.h>
56#include <qtopia/process.h> 56#include <qtopia/process.h>
57#include <qtopia/global.h> 57#include <qtopia/global.h>
58#include <qtopia/config.h> 58#include <qtopia/config.h>
59#include <qtopia/private/contact.h> 59#include <qtopia/private/contact.h>
60#include <qtopia/quuid.h> 60#include <qtopia/quuid.h>
61#include <qtopia/version.h> 61#include <qtopia/version.h>
62#ifdef Q_WS_QWS 62#ifdef Q_WS_QWS
63#include <qtopia/qcopenvelope_qws.h> 63#include <qtopia/qcopenvelope_qws.h>
64#endif 64#endif
65 65
66#include "launcherglobal.h"
67 66
68#include "transferserver.h" 67#include "transferserver.h"
69#include <qtopia/qprocess.h> 68#include <qtopia/qprocess.h>
70 69
71const int block_size = 51200; 70const int block_size = 51200;
72 71
73TransferServer::TransferServer( Q_UINT16 port, QObject *parent, 72TransferServer::TransferServer( Q_UINT16 port, QObject *parent,
74 const char* name) 73 const char* name)
75 : QServerSocket( port, 1, parent, name ) 74 : QServerSocket( port, 1, parent, name )
76{ 75{
77 connections.setAutoDelete( TRUE ); 76 connections.setAutoDelete( TRUE );
78 if ( !ok() ) 77 if ( !ok() )
79 qWarning( "Failed to bind to port %d", port ); 78 qWarning( "Failed to bind to port %d", port );
80} 79}
81 80
82void TransferServer::authorizeConnections() 81void TransferServer::authorizeConnections()
83{ 82{
84 QListIterator<ServerPI> it(connections); 83 QListIterator<ServerPI> it(connections);
85 while ( it.current() ) { 84 while ( it.current() ) {
86 if ( !it.current()->verifyAuthorised() ) { 85 if ( !it.current()->verifyAuthorised() ) {
87 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 86 disconnect( it.current(), SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
88 connections.removeRef( it.current() ); 87 connections.removeRef( it.current() );
89 } else 88 } else
90 ++it; 89 ++it;
91 } 90 }
92} 91}
93 92
94void TransferServer::closed(ServerPI *item) 93void TransferServer::closed(ServerPI *item)
95{ 94{
96 connections.removeRef(item); 95 connections.removeRef(item);
97} 96}
98 97
99TransferServer::~TransferServer() 98TransferServer::~TransferServer()
100{ 99{
101} 100}
102 101
103void TransferServer::newConnection( int socket ) 102void TransferServer::newConnection( int socket )
104{ 103{
105 ServerPI *ptr = new ServerPI( socket, this ); 104 ServerPI *ptr = new ServerPI( socket, this );
106 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) ); 105 connect( ptr, SIGNAL(connectionClosed(ServerPI *)), this, SLOT( closed(ServerPI *)) );
107 connections.append( ptr ); 106 connections.append( ptr );
108} 107}
109 108
110QString SyncAuthentication::serverId() 109QString SyncAuthentication::serverId()
111{ 110{
112 Config cfg("Security"); 111 Config cfg("Security");
113 cfg.setGroup("Sync"); 112 cfg.setGroup("Sync");
114 QString r = cfg.readEntry("serverid"); 113 QString r = cfg.readEntry("serverid");
115 114
116 if ( r.isEmpty() ) { 115 if ( r.isEmpty() ) {
117 r = Opie::Global::uuid(); 116 r = OGlobal::generateUuid();
118 cfg.writeEntry("serverid", r ); 117 cfg.writeEntry("serverid", r );
119 } 118 }
120 return r; 119 return r;
121} 120}
122 121
123QString SyncAuthentication::ownerName() 122QString SyncAuthentication::ownerName()
124{ 123{
125 QString vfilename = Global::applicationFileName("addressbook", 124 QString vfilename = Global::applicationFileName("addressbook",
126 "businesscard.vcf"); 125 "businesscard.vcf");
127 if (QFile::exists(vfilename)) { 126 if (QFile::exists(vfilename)) {
128 Contact c; 127 Contact c;
129 c = Contact::readVCard( vfilename )[0]; 128 c = Contact::readVCard( vfilename )[0];
130 return c.fullName(); 129 return c.fullName();
131 } 130 }
132 131
133 return QString::null; 132 return QString::null;
134} 133}
135 134
136QString SyncAuthentication::loginName() 135QString SyncAuthentication::loginName()
137{ 136{
138 struct passwd *pw = 0L; 137 struct passwd *pw = 0L;
139#ifndef Q_OS_WIN32 138#ifndef Q_OS_WIN32
140 pw = getpwuid( geteuid() ); 139 pw = getpwuid( geteuid() );
141 return QString::fromLocal8Bit( pw->pw_name ); 140 return QString::fromLocal8Bit( pw->pw_name );
142#else 141#else
143 //### revise 142 //### revise
144 return QString(); 143 return QString();
145#endif 144#endif
146} 145}
147 146
148int SyncAuthentication::isAuthorized(QHostAddress peeraddress) 147int SyncAuthentication::isAuthorized(QHostAddress peeraddress)
149{ 148{
150 Config cfg("Security"); 149 Config cfg("Security");
151 cfg.setGroup("Sync"); 150 cfg.setGroup("Sync");
152 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); 151 // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0");
153 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); 152 uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100);
154 153
155 // QHostAddress allowed; 154 // QHostAddress allowed;
156 // allowed.setAddress(allowedstr); 155 // allowed.setAddress(allowedstr);
157 // uint auth_peer = allowed.ip4Addr(); 156 // uint auth_peer = allowed.ip4Addr();
158 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); 157 uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24);
159 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined 158 uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined
160 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); 159 ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits));
161 160
162 return (peeraddress.ip4Addr() & mask) == auth_peer; 161 return (peeraddress.ip4Addr() & mask) == auth_peer;
163} 162}
164 163
165bool SyncAuthentication::checkUser( const QString& user ) 164bool SyncAuthentication::checkUser( const QString& user )
166{ 165{
167 if ( user.isEmpty() ) return FALSE; 166 if ( user.isEmpty() ) return FALSE;
168 QString euser = loginName(); 167 QString euser = loginName();
169 return user == euser; 168 return user == euser;
170} 169}
171 170
172bool SyncAuthentication::checkPassword( const QString& password ) 171bool SyncAuthentication::checkPassword( const QString& password )
173{ 172{
174#ifdef ALLOW_UNIX_USER_FTP 173#ifdef ALLOW_UNIX_USER_FTP
175 // First, check system password... 174 // First, check system password...
176 175
177 struct passwd *pw = 0; 176 struct passwd *pw = 0;
178 struct spwd *spw = 0; 177 struct spwd *spw = 0;
179 178
180 pw = getpwuid( geteuid() ); 179 pw = getpwuid( geteuid() );
181 spw = getspnam( pw->pw_name ); 180 spw = getspnam( pw->pw_name );
182 181
183 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); 182 QString cpwd = QString::fromLocal8Bit( pw->pw_passwd );
184 if ( cpwd == "x" && spw ) 183 if ( cpwd == "x" && spw )
185 cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); 184 cpwd = QString::fromLocal8Bit( spw->sp_pwdp );
186 185
187 // Note: some systems use more than crypt for passwords. 186 // Note: some systems use more than crypt for passwords.
188 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); 187 QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) );
189 if ( cpwd == cpassword ) 188 if ( cpwd == cpassword )
190 return TRUE; 189 return TRUE;
191#endif 190#endif
192 191
193 static int lastdenial=0; 192 static int lastdenial=0;
194 static int denials=0; 193 static int denials=0;
195 int now = time(0); 194 int now = time(0);
196 195
197 Config cfg("Security"); 196 Config cfg("Security");
198 cfg.setGroup("Sync"); 197 cfg.setGroup("Sync");
199 QString syncapp = cfg.readEntry("syncapp","Qtopia"); 198 QString syncapp = cfg.readEntry("syncapp","Qtopia");
200 199
201 //No password needed if the user really wants it 200 //No password needed if the user really wants it
202 if (syncapp == "IntelliSync") { 201 if (syncapp == "IntelliSync") {
203 return TRUE; 202 return TRUE;
204 } 203 }
205 204
206 // Detect old Qtopia Desktop (no password) 205 // Detect old Qtopia Desktop (no password)
207 if ( password.isEmpty() ) { 206 if ( password.isEmpty() ) {
208 if ( denials < 3 || now > lastdenial+600 ) { 207 if ( denials < 3 || now > lastdenial+600 ) {
209 QMessageBox unauth( 208 QMessageBox unauth(
210 tr("Sync Connection"), 209 tr("Sync Connection"),
211 tr("<p>An unauthorized system is requesting access to this device." 210 tr("<p>An unauthorized system is requesting access to this device."
212 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " 211 "<p>If you are using a version of Qtopia Desktop older than 1.5.1, "
213 "please upgrade or change the security setting to use IntelliSync." ), 212 "please upgrade or change the security setting to use IntelliSync." ),
214 QMessageBox::Warning, 213 QMessageBox::Warning,
215 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, 214 QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton,
216 0, QString::null, TRUE, WStyle_StaysOnTop); 215 0, QString::null, TRUE, WStyle_StaysOnTop);
217 unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); 216 unauth.setButtonText(QMessageBox::Cancel, tr("Deny"));
218 unauth.exec(); 217 unauth.exec();
219 218
220 denials++; 219 denials++;
221 lastdenial=now; 220 lastdenial=now;
222 } 221 }
223 return FALSE; 222 return FALSE;
224 223
225 } 224 }
226 225
227 // Second, check sync password... 226 // Second, check sync password...
228 227
229 static int lock=0; 228 static int lock=0;
230 if ( lock ) return FALSE; 229 if ( lock ) return FALSE;
231 230
232 ++lock; 231 ++lock;
233 232
234 /* 233 /*
235 * we need to support old Sync software and QtopiaDesktop 234 * we need to support old Sync software and QtopiaDesktop
236 */ 235 */
237 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { 236 if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) {
238 Config cfg( "Security" ); 237 Config cfg( "Security" );
239 cfg.setGroup("Sync"); 238 cfg.setGroup("Sync");
240 QStringList pwds = cfg.readListEntry("Passwords",' '); 239 QStringList pwds = cfg.readListEntry("Passwords",' ');
241 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { 240 for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) {
242#ifndef Q_OS_WIN32 241#ifndef Q_OS_WIN32
243 QString cpassword = QString::fromLocal8Bit( 242 QString cpassword = QString::fromLocal8Bit(
244 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); 243 crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) );
245#else 244#else
246 // ### revise 245 // ### revise
247 QString cpassword(""); 246 QString cpassword("");
248#endif 247#endif
249 if ( *it == cpassword ) { 248 if ( *it == cpassword ) {
250 lock--; 249 lock--;
251 return TRUE; 250 return TRUE;
252 } 251 }
253 } 252 }
254 253
255 // Unrecognized system. Be careful... 254 // Unrecognized system. Be careful...
256 QMessageBox unrecbox( 255 QMessageBox unrecbox(
257 tr("Sync Connection"), 256 tr("Sync Connection"),
258 tr("<p>An unrecognized system is requesting access to this device." 257 tr("<p>An unrecognized system is requesting access to this device."
259 "<p>If you have just initiated a Sync for the first time, this is normal."), 258 "<p>If you have just initiated a Sync for the first time, this is normal."),
260 QMessageBox::Warning, 259 QMessageBox::Warning,
261 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 260 QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton,
262 0, QString::null, TRUE, WStyle_StaysOnTop); 261 0, QString::null, TRUE, WStyle_StaysOnTop);
263 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); 262 unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny"));
264 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); 263 unrecbox.setButtonText(QMessageBox::Yes, tr("Allow"));
265 264
266 if ( (denials > 2 && now < lastdenial+600) 265 if ( (denials > 2 && now < lastdenial+600)
267 || unrecbox.exec() != QMessageBox::Yes) 266 || unrecbox.exec() != QMessageBox::Yes)
268 { 267 {
269 denials++; 268 denials++;
270 lastdenial=now; 269 lastdenial=now;
271 lock--; 270 lock--;
272 return FALSE; 271 return FALSE;
273 } else { 272 } else {
274 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; 273 const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.";
275 char salt[2]; 274 char salt[2];
276 salt[0]= salty[rand() % (sizeof(salty)-1)]; 275 salt[0]= salty[rand() % (sizeof(salty)-1)];
277 salt[1]= salty[rand() % (sizeof(salty)-1)]; 276 salt[1]= salty[rand() % (sizeof(salty)-1)];
278#ifndef Q_OS_WIN32 277#ifndef Q_OS_WIN32
279 QString cpassword = QString::fromLocal8Bit( 278 QString cpassword = QString::fromLocal8Bit(
280 crypt( password.mid(8).local8Bit(), salt ) ); 279 crypt( password.mid(8).local8Bit(), salt ) );
281#else 280#else
282 //### revise 281 //### revise
283 QString cpassword(""); 282 QString cpassword("");
284#endif 283#endif
285 denials=0; 284 denials=0;
286 pwds.prepend(cpassword); 285 pwds.prepend(cpassword);
287 cfg.writeEntry("Passwords",pwds,' '); 286 cfg.writeEntry("Passwords",pwds,' ');
288 lock--; 287 lock--;
289 return TRUE; 288 return TRUE;
290 } 289 }
291 } 290 }
292 lock--; 291 lock--;
293 292
294 return FALSE; 293 return FALSE;
295} 294}
296 295
297 296
298ServerPI::ServerPI( int socket, QObject *parent, const char* name ) 297ServerPI::ServerPI( int socket, QObject *parent, const char* name )
299 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ), 298 : QSocket( parent, name ) , dtp( 0 ), serversocket( 0 ), waitsocket( 0 ),
300 storFileSize(-1) 299 storFileSize(-1)
301{ 300{
302 state = Connected; 301 state = Connected;
303 302
304 setSocket( socket ); 303 setSocket( socket );
305 304
306 peerport = peerPort(); 305 peerport = peerPort();
307 peeraddress = peerAddress(); 306 peeraddress = peerAddress();
308 307
309#ifndef INSECURE 308#ifndef INSECURE
310 if ( !SyncAuthentication::isAuthorized(peeraddress) ) { 309 if ( !SyncAuthentication::isAuthorized(peeraddress) ) {
311 state = Forbidden; 310 state = Forbidden;
312 startTimer( 0 ); 311 startTimer( 0 );
313 } else 312 } else
314#endif 313#endif
315 { 314 {
316 connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); 315 connect( this, SIGNAL( readyRead() ), SLOT( read() ) );
317 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); 316 connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) );
318 317
319 passiv = FALSE; 318 passiv = FALSE;
320 for( int i = 0; i < 4; i++ ) 319 for( int i = 0; i < 4; i++ )
321 wait[i] = FALSE; 320 wait[i] = FALSE;
322 321
323 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr 322 send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr
324 state = Wait_USER; 323 state = Wait_USER;
325 324
326 dtp = new ServerDTP( this ); 325 dtp = new ServerDTP( this );
327 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); 326 connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) );
328 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); 327 connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) );
329 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) ); 328 connect( dtp, SIGNAL( error( int ) ), SLOT( dtpError( int ) ) );
330 329
331 330
332 directory = QDir::currentDirPath(); 331 directory = QDir::currentDirPath();
333 332
334 static int p = 1024; 333 static int p = 1024;
335 334
336 while ( !serversocket || !serversocket->ok() ) { 335 while ( !serversocket || !serversocket->ok() ) {
337 delete serversocket; 336 delete serversocket;
338 serversocket = new ServerSocket( ++p, this ); 337 serversocket = new ServerSocket( ++p, this );
339 } 338 }
340 connect( serversocket, SIGNAL( newIncomming( int ) ), 339 connect( serversocket, SIGNAL( newIncomming( int ) ),
341 SLOT( newConnection( int ) ) ); 340 SLOT( newConnection( int ) ) );
342 } 341 }
343} 342}
344 343
345ServerPI::~ServerPI() 344ServerPI::~ServerPI()
346{ 345{
347 close(); 346 close();
348 347
349 if ( dtp ) 348 if ( dtp )
350 dtp->close(); 349 dtp->close();
351 delete dtp; 350 delete dtp;
352 delete serversocket; 351 delete serversocket;
353} 352}
354 353
355bool ServerPI::verifyAuthorised() 354bool ServerPI::verifyAuthorised()
356{ 355{
357 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { 356 if ( !SyncAuthentication::isAuthorized(peerAddress()) ) {
358 state = Forbidden; 357 state = Forbidden;
359 return FALSE; 358 return FALSE;
360 } 359 }
361 return TRUE; 360 return TRUE;
362} 361}
363 362
364void ServerPI::connectionClosed() 363void ServerPI::connectionClosed()
365{ 364{
366 // qDebug( "Debug: Connection closed" ); 365 // qDebug( "Debug: Connection closed" );
367 emit connectionClosed(this); 366 emit connectionClosed(this);
368} 367}
369 368
370void ServerPI::send( const QString& msg ) 369void ServerPI::send( const QString& msg )
371{ 370{
372 QTextStream os( this ); 371 QTextStream os( this );
373 os << msg << endl; 372 os << msg << endl;
374 //qDebug( "Reply: %s", msg.latin1() ); 373 //qDebug( "Reply: %s", msg.latin1() );
375} 374}
376 375
377void ServerPI::read() 376void ServerPI::read()
378{ 377{
379 while ( canReadLine() ) 378 while ( canReadLine() )
380 process( readLine().stripWhiteSpace() ); 379 process( readLine().stripWhiteSpace() );
381} 380}
382 381
383bool ServerPI::checkReadFile( const QString& file ) 382bool ServerPI::checkReadFile( const QString& file )
384{ 383{
385 QString filename; 384 QString filename;
386 385
387 if ( file[0] != "/" ) 386 if ( file[0] != "/" )
388 filename = directory.path() + "/" + file; 387 filename = directory.path() + "/" + file;
389 else 388 else
390 filename = file; 389 filename = file;
391 390
392 QFileInfo fi( filename ); 391 QFileInfo fi( filename );
393 return ( fi.exists() && fi.isReadable() ); 392 return ( fi.exists() && fi.isReadable() );
394} 393}
395 394
396bool ServerPI::checkWriteFile( const QString& file ) 395bool ServerPI::checkWriteFile( const QString& file )
397{ 396{
398 QString filename; 397 QString filename;
399 398
400 if ( file[0] != "/" ) 399 if ( file[0] != "/" )
401 filename = directory.path() + "/" + file; 400 filename = directory.path() + "/" + file;
402 else 401 else
403 filename = file; 402 filename = file;
404 403
405 QFileInfo fi( filename ); 404 QFileInfo fi( filename );
406 405
407 if ( fi.exists() ) 406 if ( fi.exists() )
408 if ( !QFile( filename ).remove() ) 407 if ( !QFile( filename ).remove() )
409 return FALSE; 408 return FALSE;
410 return TRUE; 409 return TRUE;
411} 410}
412 411
413void ServerPI::process( const QString& message ) 412void ServerPI::process( const QString& message )
414{ 413{
415 //qDebug( "Command: %s", message.latin1() ); 414 //qDebug( "Command: %s", message.latin1() );
416 415
417 // split message using "," as separator 416 // split message using "," as separator
418 QStringList msg = QStringList::split( " ", message ); 417 QStringList msg = QStringList::split( " ", message );
419 if ( msg.isEmpty() ) return; 418 if ( msg.isEmpty() ) return;
420 419
421 // command token 420 // command token
422 QString cmd = msg[0].upper(); 421 QString cmd = msg[0].upper();
423 422
424 // argument token 423 // argument token
diff --git a/core/launcher/wait.cpp b/core/launcher/wait.cpp
index ab53a07..34ffd1a 100644
--- a/core/launcher/wait.cpp
+++ b/core/launcher/wait.cpp
@@ -1,78 +1,78 @@
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 "wait.h" 21#include "wait.h"
22 22
23#include <qtopia/resource.h> 23#include <qtopia/resource.h>
24#include <qtopia/config.h> 24#include <qtopia/config.h>
25 25
26#include <opie/owait.h> 26#include <opie2/owait.h>
27 27
28#include <qwidget.h> 28#include <qwidget.h>
29#include <qpixmap.h> 29#include <qpixmap.h>
30#include <qpainter.h> 30#include <qpainter.h>
31 31
32 32
33Wait *lastWaitObject = NULL; 33Wait *lastWaitObject = NULL;
34 34
35 35
36Wait::Wait( QWidget *parent ) : QWidget( parent ), 36Wait::Wait( QWidget *parent ) : QWidget( parent ),
37 pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE ) 37 pm( Resource::loadPixmap( "wait" ) ), waiting( FALSE )
38{ 38{
39 setFixedSize( pm.size() ); 39 setFixedSize( pm.size() );
40 lastWaitObject = this; 40 lastWaitObject = this;
41 m_centralWait = new OWait( 0l ); 41 m_centralWait = new OWait( 0l );
42 m_centralWait->hide(); 42 m_centralWait->hide();
43 hide(); 43 hide();
44} 44}
45 45
46 46
47Wait *Wait::getWaitObject() 47Wait *Wait::getWaitObject()
48{ 48{
49 return lastWaitObject; 49 return lastWaitObject;
50} 50}
51 51
52 52
53void Wait::setWaiting( bool w ) 53void Wait::setWaiting( bool w )
54{ 54{
55 Config cfg ( "Launcher" ); 55 Config cfg ( "Launcher" );
56 cfg.setGroup("GUI"); 56 cfg.setGroup("GUI");
57 57
58 58
59 waiting = w; 59 waiting = w;
60 if ( w ) { 60 if ( w ) {
61 if ( cfg. readBoolEntry( "BigBusy" ) ) 61 if ( cfg. readBoolEntry( "BigBusy" ) )
62 m_centralWait->show(); 62 m_centralWait->show();
63 else 63 else
64 show(); 64 show();
65 }else{ 65 }else{
66 m_centralWait->hide(); 66 m_centralWait->hide();
67 hide(); 67 hide();
68 } 68 }
69} 69}
70 70
71 71
72void Wait::paintEvent( QPaintEvent * ) 72void Wait::paintEvent( QPaintEvent * )
73{ 73{
74 QPainter p( this ); 74 QPainter p( this );
75 p.drawPixmap( 0, 0, pm ); 75 p.drawPixmap( 0, 0, pm );
76} 76}
77 77
78 78