summaryrefslogtreecommitdiff
path: root/core/launcher/server.cpp
Unidiff
Diffstat (limited to 'core/launcher/server.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/server.cpp391
1 files changed, 310 insertions, 81 deletions
diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp
index 3bef36e..524e6dd 100644
--- a/core/launcher/server.cpp
+++ b/core/launcher/server.cpp
@@ -37,2 +37,3 @@
37#include "documentlist.h" 37#include "documentlist.h"
38#include "qrr.h"
38 39
@@ -119,2 +120,6 @@ static Global::Command builtins[] = {
119 120
121#ifdef QPE_HAVE_DIRECT_ACCESS
122extern void readyDirectAccess(QString cardInfo, QString installLocations);
123extern const char *directAccessQueueFile();
124#endif
120 125
@@ -139,2 +144,3 @@ Server::Server() :
139 144
145#warning FIXME support TempScreenSaverMode
140#if 0 146#if 0
@@ -156,2 +162,9 @@ Server::Server() :
156 162
163
164#ifdef QPE_HAVE_DIRECT_ACCESS
165 QCopChannel *desktopChannel = new QCopChannel( "QPE/Desktop", this );
166 connect( desktopChannel, SIGNAL(received( const QCString &, const QByteArray & )),
167 this, SLOT(desktopMessage( const QCString &, const QByteArray & )) );
168#endif
169
157 // start services 170 // start services
@@ -199,2 +212,27 @@ Server::~Server()
199 212
213static bool hasVisibleWindow(const QString& clientname, bool partial)
214{
215#ifdef QWS
216 const QList<QWSWindow> &list = qwsServer->clientWindows();
217 QWSWindow* w;
218 for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) {
219 if ( w->client()->identity() == clientname ) {
220 if ( partial && !w->isFullyObscured() )
221 return TRUE;
222 if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) {
223# if QT_VERSION < 0x030000
224 QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect,
225 QSize(qt_screen->width(),qt_screen->height()) );
226# else
227 QRect mwr = qt_maxWindowRect;
228# endif
229 if ( mwr.contains(w->requested().boundingRect()) )
230 return TRUE;
231 }
232 }
233 }
234#endif
235 return FALSE;
236}
237
200void Server::activate(const ODeviceButton* button, bool held) 238void Server::activate(const ODeviceButton* button, bool held)
@@ -294,7 +332,5 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
294 qcopBridge->authorizeConnections(); 332 qcopBridge->authorizeConnections();
295 } else 333#warning FIXME support TempScreenSaverMode
296
297#if 0 334#if 0
298 /* ### FIXME support TempScreenSaverMode */ 335 } else if ( msg == "setTempScreenSaverMode(int,int)" ) {
299 if ( msg == "setTempScreenSaverMode(int,int)" ) {
300 int mode, pid; 336 int mode, pid;
@@ -302,6 +338,4 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
302 tsmMonitor->setTempMode(mode, pid); 338 tsmMonitor->setTempMode(mode, pid);
303 } else
304#endif 339#endif
305 340 } else if ( msg == "linkChanged(QString)" ) {
306 if ( msg == "linkChanged(QString)" ) {
307 QString link; 341 QString link;
@@ -310,9 +344,5 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
310 docList->linkChanged(link); 344 docList->linkChanged(link);
311 } else 345 } else if ( msg == "serviceChanged(QString)" ) {
312
313 if ( msg == "serviceChanged(QString)" ) {
314 MimeType::updateApplications(); 346 MimeType::updateApplications();
315 } else 347 } else if ( msg == "mkdir(QString)" ) {
316
317 if ( msg == "mkdir(QString)" ) {
318 QString dir; 348 QString dir;
@@ -321,5 +351,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
321 mkdir( dir ); 351 mkdir( dir );
322 } else 352 } else if ( msg == "rdiffGenSig(QString,QString)" ) {
323
324 if ( msg == "rdiffGenSig(QString,QString)" ) {
325 QString baseFile, sigFile; 353 QString baseFile, sigFile;
@@ -327,5 +355,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
327 QRsync::generateSignature( baseFile, sigFile ); 355 QRsync::generateSignature( baseFile, sigFile );
328 } else 356 } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
329
330 if ( msg == "rdiffGenDiff(QString,QString,QString)" ) {
331 QString baseFile, sigFile, deltaFile; 357 QString baseFile, sigFile, deltaFile;
@@ -333,5 +359,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
333 QRsync::generateDiff( baseFile, sigFile, deltaFile ); 359 QRsync::generateDiff( baseFile, sigFile, deltaFile );
334 } else 360 } else if ( msg == "rdiffApplyPatch(QString,QString)" ) {
335
336 if ( msg == "rdiffApplyPatch(QString,QString)" ) {
337 QString baseFile, deltaFile; 361 QString baseFile, deltaFile;
@@ -348,5 +372,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
348#endif 372#endif
349 } else 373 } else if ( msg == "rdiffCleanup()" ) {
350
351 if ( msg == "rdiffCleanup()" ) {
352 mkdir( "/tmp/rdiff" ); 374 mkdir( "/tmp/rdiff" );
@@ -357,5 +379,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
357 dir.remove( *it ); 379 dir.remove( *it );
358 } else 380 } else if ( msg == "sendHandshakeInfo()" ) {
359
360 if ( msg == "sendHandshakeInfo()" ) {
361 QString home = getenv( "HOME" ); 381 QString home = getenv( "HOME" );
@@ -367,11 +387,9 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
367#endif 387#endif
368 } else 388 } else if ( msg == "sendVersionInfo()" ) {
369
370 /* 389 /*
371 * QtopiaDesktop relies on the major number 390 * QtopiaDesktop relies on the major number
372 * to start with 1. We're at 0.9 391 * to start with 1.
373 * so wee need to fake at least 1.4 to be able 392 * we need to fake at least 1.4 to be able
374 * to sync with QtopiaDesktop1.6 393 * to sync with QtopiaDesktop1.6
375 */ 394 */
376 if ( msg == "sendVersionInfo()" ) {
377 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); 395 QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" );
@@ -379,5 +397,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
379 e << QString::fromLatin1("1.7") << "Uncustomized Device"; 397 e << QString::fromLatin1("1.7") << "Uncustomized Device";
380 } else 398 } else if ( msg == "sendCardInfo()" ) {
381
382 if ( msg == "sendCardInfo()" ) {
383#ifndef QT_NO_COP 399#ifndef QT_NO_COP
@@ -411,5 +427,8 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
411#endif 427#endif
412 } else 428 } else if ( msg == "sendInstallLocations()" ) {
413 429#ifndef QT_NO_COP
414 if ( msg == "sendSyncDate(QString)" ) { 430 QCopEnvelope e( "QPE/Desktop", "installLocations(QString)" );
431 e << installLocationsString();
432#endif
433 } else if ( msg == "sendSyncDate(QString)" ) {
415 QString app; 434 QString app;
@@ -424,5 +443,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
424 // << cfg.readEntry( app ).latin1() << oendl; 443 // << cfg.readEntry( app ).latin1() << oendl;
425 } else 444 } else if ( msg == "setSyncDate(QString,QString)" ) {
426
427 if ( msg == "setSyncDate(QString,QString)" ) {
428 QString app, date; 445 QString app, date;
@@ -433,5 +450,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
433 //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; 450 //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl;
434 } else 451 } else if ( msg == "startSync(QString)" ) {
435
436 if ( msg == "startSync(QString)" ) {
437 QString what; 452 QString what;
@@ -442,19 +457,20 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
442 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); 457 connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) );
443 } else 458 } else if ( msg == "stopSync()") {
444
445 if ( msg == "stopSync()") {
446 delete syncDialog; 459 delete syncDialog;
447 syncDialog = 0; 460 syncDialog = 0;
448 } else 461 } else if (msg == "restoreDone(QString)") {
449
450 if (msg == "restoreDone(QString)") {
451 docList->restoreDone(); 462 docList->restoreDone();
452 } else 463 } else if ( msg == "getAllDocLinks()" ) {
453
454 if ( msg == "getAllDocLinks()" ) {
455 docList->sendAllDocLinks(); 464 docList->sendAllDocLinks();
456 } else 465 }
457 466#ifdef QPE_HAVE_DIRECT_ACCESS
467 else if ( msg == "prepareDirectAccess()" ) {
468 prepareDirectAccess();
469 } else if ( msg == "postDirectAccess()" ) {
470 postDirectAccess();
471 }
472#endif
458#ifdef Q_WS_QWS 473#ifdef Q_WS_QWS
459 if ( msg == "setMouseProto(QString)" ) { 474
475 else if ( msg == "setMouseProto(QString)" ) {
460 QString mice; 476 QString mice;
@@ -463,5 +479,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
463 qwsServer->openMouse(); 479 qwsServer->openMouse();
464 } else 480 } else if ( msg == "setKeyboard(QString)" ) {
465
466 if ( msg == "setKeyboard(QString)" ) {
467 QString kb; 481 QString kb;
@@ -470,5 +484,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
470 qwsServer->openKeyboard(); 484 qwsServer->openKeyboard();
471 } else 485 } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) {
472
473 if ( msg == "setKeyboardAutoRepeat(int,int)" ) {
474 int delay, period; 486 int delay, period;
@@ -480,5 +492,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
480 cfg.writeEntry( "RepeatPeriod", period ); 492 cfg.writeEntry( "RepeatPeriod", period );
481 } else 493 } else if ( msg == "setKeyboardLayout(QString)" ) {
482
483 if ( msg == "setKeyboardLayout(QString)" ) {
484 QString kb; 494 QString kb;
@@ -489,5 +499,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
489 cfg.writeEntry( "Layout", kb ); 499 cfg.writeEntry( "Layout", kb );
490 } else 500 } else if ( msg == "autoStart(QString)" ) {
491
492 if ( msg == "autoStart(QString)" ) {
493 QString appName; 501 QString appName;
@@ -499,5 +507,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
499 } 507 }
500 } else 508 } else if ( msg == "autoStart(QString,QString)" ) {
501
502 if ( msg == "autoStart(QString,QString)" ) {
503 QString modifier, appName; 509 QString modifier, appName;
@@ -522,5 +528,3 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
522 // case the autostart feature should be delayed 528 // case the autostart feature should be delayed
523 } else 529 } else if ( msg == "autoStart(QString,QString,QString)") {
524
525 if ( msg == "autoStart(QString,QString,QString)") {
526 QString modifier, appName, delay; 530 QString modifier, appName, delay;
@@ -541,2 +545,58 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data)
541 545
546QString Server::cardInfoString()
547{
548 storage->update();
549 const QList<FileSystem> &fs = storage->fileSystems();
550 QListIterator<FileSystem> it ( fs );
551 QString s;
552 QString homeDir = getenv("HOME");
553 QString homeFs, homeFsPath;
554 for ( ; it.current(); ++it ) {
555 int k4 = (*it)->blockSize()/256;
556 if ( (*it)->isRemovable() ) {
557 s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr
558 + QString::number( (*it)->availBlocks() * k4/4 )
559 + "K " + (*it)->options() + ";";
560 } else if ( homeDir.contains( (*it)->path() ) &&
561 (*it)->path().length() > homeFsPath.length() ) {
562 homeFsPath = (*it)->path();
563 homeFs =
564 (*it)->name() + "=" + homeDir + "/Documents " // No tr
565 + QString::number( (*it)->availBlocks() * k4/4 )
566 + "K " + (*it)->options() + ";";
567 }
568 }
569 if ( !homeFs.isEmpty() )
570 s += homeFs;
571 return s;
572}
573
574QString Server::installLocationsString()
575{
576 storage->update();
577 const QList<FileSystem> &fs = storage->fileSystems();
578 QListIterator<FileSystem> it ( fs );
579 QString s;
580 QString homeDir = getenv("HOME");
581 QString homeFs, homeFsPath;
582 for ( ; it.current(); ++it ) {
583 int k4 = (*it)->blockSize()/256;
584 if ( (*it)->isRemovable() ) {
585 s += (*it)->name() + "=" + (*it)->path() + " " // No tr
586 + QString::number( (*it)->availBlocks() * k4/4 )
587 + "K " + (*it)->options() + ";";
588 } else if ( homeDir.contains( (*it)->path() ) &&
589 (*it)->path().length() > homeFsPath.length() ) {
590 homeFsPath = (*it)->path();
591 homeFs =
592 (*it)->name() + "=" + homeDir + " " // No tr
593 + QString::number( (*it)->availBlocks() * k4/4 )
594 + "K " + (*it)->options() + ";";
595 }
596 }
597 if ( !homeFs.isEmpty() )
598 s = homeFs + s;
599 return s;
600}
601
542void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) 602void Server::receiveTaskBar(const QCString &msg, const QByteArray &data)
@@ -547,9 +607,5 @@ void Server::receiveTaskBar(const QCString &msg, const QByteArray &data)
547 docList->reloadAppLnks(); 607 docList->reloadAppLnks();
548 } else 608 } else if ( msg == "soundAlarm()" ) {
549
550 if ( msg == "soundAlarm()" ) {
551 ServerApplication::soundAlarm(); 609 ServerApplication::soundAlarm();
552 } else 610 } else if ( msg == "setLed(int,bool)" ) {
553
554 if ( msg == "setLed(int,bool)" ) {
555 int led, status; 611 int led, status;
@@ -750 +806,174 @@ void Server::preloadApps()
750} 806}
807
808// This is only called if QPE_HAVE_DIRECT_ACCESS is defined
809void Server::prepareDirectAccess()
810{
811 qDebug( "Server::prepareDirectAccess()" );
812 // Put up a pretty dialog
813 syncDialog = new SyncDialog( this, tr("USB Lock") );
814 syncDialog->show();
815
816 // Prevent the PDA from acting as a PDA
817 terminateServers();
818
819 // suspend the mtab monitor
820#ifndef QT_NO_COP
821 {
822 QCopEnvelope e( "QPE/Stabmon", "suspendMonitor()" );
823 }
824#endif
825
826 // send out a flush message
827 // once flushes are done call runDirectAccess()
828 // We just count the number of apps and set a timer.
829 // Either the timer expires or the correct number of apps responds.
830 // Note: quicklauncher isn't in the runningApps list but it responds
831 // to the flush so we start the counter at 1
832 pendingFlushes = 1;
833 directAccessRun = FALSE;
834 for ( QMap<int,QString>::ConstIterator it =
835 appLauncher->runningApplications().begin();
836 it != appLauncher->runningApplications().end();
837 ++it ) {
838 pendingFlushes++;
839 }
840#ifndef QT_NO_COP
841 QCopEnvelope e1( "QPE/System", "flush()" );
842#endif
843 QTimer::singleShot( 10000, this, SLOT(runDirectAccess()) );
844#warning FIXME support TempScreenSaverMode
845#if 0
846 QPEApplication::setTempScreenSaverMode(QPEApplication::DisableSuspend);
847#endif
848}
849
850// This is only connected if QPE_HAVE_DIRECT_ACCESS is defined
851// It fakes the presence of Qtopia Desktop
852void Server::desktopMessage( const QCString &message, const QByteArray &data )
853{
854 QDataStream stream( data, IO_ReadOnly );
855 if ( message == "flushDone(QString)" ) {
856 QString app;
857 stream >> app;
858 qDebug( "flushDone from %s", app.latin1() );
859 if ( --pendingFlushes == 0 ) {
860 qDebug( "pendingFlushes == 0, all the apps responded" );
861 runDirectAccess();
862 }
863 } else if ( message == "installStarted(QString)" ) {
864 QString package;
865 stream >> package;
866 qDebug( "\tInstall Started for package %s", package.latin1() );
867 } else if ( message == "installStep(QString)" ) {
868 QString step;
869 stream >> step;
870 qDebug( "\tInstall Step %s", step.latin1() );
871 } else if ( message == "installDone(QString)" ) {
872 QString package;
873 stream >> package;
874 qDebug( "\tInstall Finished for package %s", package.latin1() );
875 } else if ( message == "installFailed(QString,int,QString)" ) {
876 QString package, error;
877 int status;
878 stream >> package >> status >> error;
879 qDebug( "\tInstall Failed for package %s with error code %d and error message %s",
880 package.latin1(), status, error.latin1() );
881 } else if ( message == "removeStarted(QString)" ) {
882 QString package;
883 stream >> package;
884 qDebug( "\tRemove Started for package %s", package.latin1() );
885 } else if ( message == "removeDone(QString)" ) {
886 QString package;
887 stream >> package;
888 qDebug( "\tRemove Finished for package %s", package.latin1() );
889 } else if ( message == "removeFailed(QString)" ) {
890 QString package;
891 stream >> package;
892 qDebug( "\tRemove Failed for package %s", package.latin1() );
893 }
894
895 if ( qrr && qrr->waitingForMessages )
896 qrr->desktopMessage( message, data );
897}
898
899
900// This is only connected if QPE_HAVE_DIRECT_ACCESS is defined
901void Server::runDirectAccess()
902{
903#ifdef QPE_HAVE_DIRECT_ACCESS
904 // The timer must have fired after all the apps responded
905 // with flushDone(). Just ignore it.
906 if ( directAccessRun )
907 return;
908
909 directAccessRun = TRUE;
910 ::readyDirectAccess(cardInfoString(), installLocationsString());
911#endif
912}
913
914// This is only called if QPE_HAVE_DIRECT_ACCESS is defined
915void Server::postDirectAccess()
916{
917#ifdef QPE_HAVE_DIRECT_ACCESS
918 qDebug( "Server::postDirectAccess()" );
919
920 // Categories may have changed
921 QCopEnvelope e1( "QPE/System", "categoriesChanged()" );
922 // Apps need to reload their data
923 QCopEnvelope e2( "QPE/System", "reload()" );
924 // Reload DocLinks
925 docList->storageChanged();
926 // Restart the PDA server stuff
927 startTransferServer();
928
929 // restart the mtab monitor
930#ifndef QT_NO_COP
931 {
932 QCopEnvelope e( "QPE/Stabmon", "restartMonitor()" );
933 }
934#endif
935
936 // Process queued requests
937 const char *queueFile = ::directAccessQueueFile();
938 QFile *file = new QFile( queueFile );
939 if ( !file->exists() ) {
940 delete file;
941 // Get rid of the dialog
942 if ( syncDialog ) {
943 delete syncDialog;
944 syncDialog = 0;
945 }
946#warning FIXME support TempScreenSaverMode
947#if 0
948 QPEApplication::setTempScreenSaverMode(QPEApplication::Enable);
949#endif
950 } else {
951 qrr = new QueuedRequestRunner( file, syncDialog );
952 connect( qrr, SIGNAL(finished()),
953 this, SLOT(finishedQueuedRequests()) );
954 QTimer::singleShot( 100, qrr, SLOT(process()) );
955 // qrr will remove the sync dialog later
956 }
957#endif
958}
959
960void Server::finishedQueuedRequests()
961{
962 if ( qrr->readyToDelete ) {
963 delete qrr;
964 qrr = 0;
965 // Get rid of the dialog
966 if ( syncDialog ) {
967 delete syncDialog;
968 syncDialog = 0;
969 }
970#warning FIXME support TempScreenSaverMode
971#if 0
972 QPEApplication::setTempScreenSaverMode(QPEApplication::Enable);
973#endif
974 } else {
975 qrr->readyToDelete = TRUE;
976 QTimer::singleShot( 0, this, SLOT(finishedQueuedRequests()) );
977 }
978}
979