-rw-r--r-- | core/launcher/documentlist.cpp | 8 | ||||
-rw-r--r-- | core/launcher/qprocess_unix.cpp | 646 | ||||
-rw-r--r-- | core/launcher/screensaver.cpp | 386 | ||||
-rw-r--r-- | core/launcher/server.cpp | 434 | ||||
-rw-r--r-- | core/launcher/transferserver.cpp | 851 |
5 files changed, 1164 insertions, 1161 deletions
diff --git a/core/launcher/documentlist.cpp b/core/launcher/documentlist.cpp index 19ceb0f..44ceb0c 100644 --- a/core/launcher/documentlist.cpp +++ b/core/launcher/documentlist.cpp @@ -389,3 +389,3 @@ void DocumentList::DiffAppLnks() if (!found) { - qDebug("Item %s needs to be added",j->name().ascii() ); + odebug << "Item " << j->name().ascii() << " needs to be added" << oendl; d->serverGui->applicationAdded( j->type(), *j ); @@ -405,3 +405,3 @@ void DocumentList::DiffAppLnks() if (!found) { - qDebug("Item %s needs to be removed",i->name().ascii() ); + odebug << "Item " << i->name().ascii() << " needs to be removed" << oendl; d->serverGui->applicationRemoved( i->type(), *i ); @@ -424,6 +424,6 @@ void DocumentList::storageChanged() // reloadAppLnks(); - qDebug("Reload App links took %i ms",t.elapsed() ); + odebug << "Reload App links took " << t.elapsed() << " ms" << oendl; reloadDocLnks(); // odebug << "Reload links took " << t.elapsed() << " ms " << oendl; - qDebug("Reload All links took %i ms",t.elapsed() ); + odebug << "Reload All links took " << t.elapsed() << " ms" << oendl; // ### Optimization opportunity diff --git a/core/launcher/qprocess_unix.cpp b/core/launcher/qprocess_unix.cpp index 56e1b1d..97c0460 100644 --- a/core/launcher/qprocess_unix.cpp +++ b/core/launcher/qprocess_unix.cpp @@ -135,5 +135,5 @@ public: #endif - socketStdin = 0; - socketStdout = 0; - socketStderr = 0; + socketStdin = 0; + socketStdout = 0; + socketStderr = 0; } @@ -144,19 +144,19 @@ public: #endif - if ( process != 0 ) { - if ( process->d->notifierStdin ) - process->d->notifierStdin->setEnabled( FALSE ); - if ( process->d->notifierStdout ) - process->d->notifierStdout->setEnabled( FALSE ); - if ( process->d->notifierStderr ) - process->d->notifierStderr->setEnabled( FALSE ); - process->d->proc = 0; - } - if( socketStdin != 0 ) - ::close( socketStdin ); - // ### close these sockets even on parent exit or is it better only on - // sigchld (but what do I have to do with them on exit then)? - if( socketStdout != 0 ) - ::close( socketStdout ); - if( socketStderr != 0 ) - ::close( socketStderr ); + if ( process != 0 ) { + if ( process->d->notifierStdin ) + process->d->notifierStdin->setEnabled( FALSE ); + if ( process->d->notifierStdout ) + process->d->notifierStdout->setEnabled( FALSE ); + if ( process->d->notifierStderr ) + process->d->notifierStderr->setEnabled( FALSE ); + process->d->proc = 0; + } + if( socketStdin != 0 ) + ::close( socketStdin ); + // ### close these sockets even on parent exit or is it better only on + // sigchld (but what do I have to do with them on exit then)? + if( socketStdout != 0 ) + ::close( socketStdout ); + if( socketStderr != 0 ) + ::close( socketStderr ); } @@ -210,4 +210,4 @@ QProcessManager::QProcessManager() if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { - sigchldFd[0] = 0; - sigchldFd[1] = 0; + sigchldFd[0] = 0; + sigchldFd[1] = 0; } else { @@ -216,7 +216,7 @@ QProcessManager::QProcessManager() #endif - QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], - QSocketNotifier::Read, this ); - connect( sn, SIGNAL(activated(int)), - this, SLOT(sigchldHnd(int)) ); - sn->setEnabled( TRUE ); + QSocketNotifier *sn = new QSocketNotifier( sigchldFd[1], + QSocketNotifier::Read, this ); + connect( sn, SIGNAL(activated(int)), + this, SLOT(sigchldHnd(int)) ); + sn->setEnabled( TRUE ); } @@ -243,6 +243,6 @@ QProcessManager::QProcessManager() /* - Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround - for a strange problem where GNU tar (called by backuprestore) - would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd - is never even called, yet this avoids the hang. + Using qt_C_sigpipeHnd rather than SIG_IGN is a workaround + for a strange problem where GNU tar (called by backuprestore) + would hang on filesystem-full. Strangely, the qt_C_sigpipeHnd + is never even called, yet this avoids the hang. */ @@ -261,5 +261,5 @@ QProcessManager::~QProcessManager() if ( sigchldFd[0] != 0 ) - ::close( sigchldFd[0] ); + ::close( sigchldFd[0] ); if ( sigchldFd[1] != 0 ) - ::close( sigchldFd[1] ); + ::close( sigchldFd[1] ); @@ -299,3 +299,3 @@ void QProcessManager::cleanup() if ( procList->count() == 0 ) { - QTimer::singleShot( 0, this, SLOT(removeMe()) ); + QTimer::singleShot( 0, this, SLOT(removeMe()) ); } @@ -306,5 +306,5 @@ void QProcessManager::removeMe() if ( procList->count() == 0 ) { - qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); - QProcessPrivate::procManager = 0; - delete this; + qprocess_cleanup_procmanager.remove( &QProcessPrivate::procManager ); + QProcessPrivate::procManager = 0; + delete this; } @@ -324,7 +324,7 @@ void QProcessManager::sigchldHnd( int fd ) while ( proc != 0 ) { - removeProc = FALSE; - process = proc->process; - QProcess *process_exit_notify=0; - if ( process != 0 ) { - if ( !process->isRunning() ) { + removeProc = FALSE; + process = proc->process; + QProcess *process_exit_notify=0; + if ( process != 0 ) { + if ( !process->isRunning() ) { #if defined(QT_QPROCESS_DEBUG) @@ -332,5 +332,5 @@ void QProcessManager::sigchldHnd( int fd ) #endif - // read pending data - int nbytes = 0; - if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { + // read pending data + int nbytes = 0; + if ( ::ioctl(proc->socketStdout, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { #if defined(QT_QPROCESS_DEBUG) @@ -338,6 +338,6 @@ void QProcessManager::sigchldHnd( int fd ) #endif - process->socketRead( proc->socketStdout ); - } - nbytes = 0; - if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { + process->socketRead( proc->socketStdout ); + } + nbytes = 0; + if ( ::ioctl(proc->socketStderr, FIONREAD, (char*)&nbytes)==0 && nbytes>0 ) { #if defined(QT_QPROCESS_DEBUG) @@ -345,13 +345,13 @@ void QProcessManager::sigchldHnd( int fd ) #endif - process->socketRead( proc->socketStderr ); - } + process->socketRead( proc->socketStderr ); + } - if ( process->notifyOnExit ) - process_exit_notify = process; + if ( process->notifyOnExit ) + process_exit_notify = process; - removeProc = TRUE; - } - } else { - int status; - if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { + removeProc = TRUE; + } + } else { + int status; + if ( ::waitpid( proc->pid, &status, WNOHANG ) == proc->pid ) { #if defined(QT_QPROCESS_DEBUG) @@ -359,14 +359,14 @@ void QProcessManager::sigchldHnd( int fd ) #endif - removeProc = TRUE; - } - } - if ( removeProc ) { - QProc *oldproc = proc; - proc = procList->next(); - remove( oldproc ); - } else { - proc = procList->next(); - } - if ( process_exit_notify ) - emit process_exit_notify->processExited(); + removeProc = TRUE; + } + } + if ( removeProc ) { + QProc *oldproc = proc; + proc = procList->next(); + remove( oldproc ); + } else { + proc = procList->next(); + } + if ( process_exit_notify ) + emit process_exit_notify->processExited(); } @@ -408,7 +408,7 @@ QProcessPrivate::~QProcessPrivate() if ( proc != 0 ) { - if ( proc->socketStdin != 0 ) { - ::close( proc->socketStdin ); - proc->socketStdin = 0; - } - proc->process = 0; + if ( proc->socketStdin != 0 ) { + ::close( proc->socketStdin ); + proc->socketStdin = 0; + } + proc->process = 0; } @@ -416,3 +416,3 @@ QProcessPrivate::~QProcessPrivate() while ( !stdinBuf.isEmpty() ) { - delete stdinBuf.dequeue(); + delete stdinBuf.dequeue(); } @@ -431,14 +431,14 @@ void QProcessPrivate::closeOpenSocketsForChild() if ( procManager != 0 ) { - if ( procManager->sigchldFd[0] != 0 ) - ::close( procManager->sigchldFd[0] ); - if ( procManager->sigchldFd[1] != 0 ) - ::close( procManager->sigchldFd[1] ); - - // close also the sockets from other QProcess instances - QProc *proc; - for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { - ::close( proc->socketStdin ); - ::close( proc->socketStdout ); - ::close( proc->socketStderr ); - } + if ( procManager->sigchldFd[0] != 0 ) + ::close( procManager->sigchldFd[0] ); + if ( procManager->sigchldFd[1] != 0 ) + ::close( procManager->sigchldFd[1] ); + + // close also the sockets from other QProcess instances + QProc *proc; + for ( proc=procManager->procList->first(); proc!=0; proc=procManager->procList->next() ) { + ::close( proc->socketStdin ); + ::close( proc->socketStdout ); + ::close( proc->socketStderr ); + } } @@ -450,4 +450,4 @@ void QProcessPrivate::newProc( pid_t pid, QProcess *process ) if ( procManager == 0 ) { - procManager = new QProcessManager; - qprocess_cleanup_procmanager.add( &procManager ); + procManager = new QProcessManager; + qprocess_cleanup_procmanager.add( &procManager ); } @@ -465,5 +465,5 @@ QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) if ( QProcessPrivate::procManager == 0 ) - return; + return; if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) - return; + return; @@ -510,5 +510,5 @@ QByteArray* QProcess::bufStdout() if ( d->proc && d->proc->socketStdout ) { - // ### can this cause a blocking behaviour (maybe do a ioctl() to see - // if data is available)? - socketRead( d->proc->socketStdout ); + // ### can this cause a blocking behaviour (maybe do a ioctl() to see + // if data is available)? + socketRead( d->proc->socketStdout ); } @@ -520,5 +520,5 @@ QByteArray* QProcess::bufStderr() if ( d->proc && d->proc->socketStderr ) { - // ### can this cause a blocking behaviour (maybe do a ioctl() to see - // if data is available)? - socketRead( d->proc->socketStderr ); + // ### can this cause a blocking behaviour (maybe do a ioctl() to see + // if data is available)? + socketRead( d->proc->socketStderr ); } @@ -531,7 +531,7 @@ void QProcess::consumeBufStdout( int consume ) if ( consume==-1 || (uint)consume >= n ) { - d->bufStdout.resize( 0 ); + d->bufStdout.resize( 0 ); } else { - QByteArray tmp( n - consume ); - memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); - d->bufStdout = tmp; + QByteArray tmp( n - consume ); + memcpy( tmp.data(), d->bufStdout.data()+consume, n-consume ); + d->bufStdout = tmp; } @@ -543,7 +543,7 @@ void QProcess::consumeBufStderr( int consume ) if ( consume==-1 || (uint)consume >= n ) { - d->bufStderr.resize( 0 ); + d->bufStderr.resize( 0 ); } else { - QByteArray tmp( n - consume ); - memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); - d->bufStderr = tmp; + QByteArray tmp( n - consume ); + memcpy( tmp.data(), d->bufStderr.data()+consume, n-consume ); + d->bufStderr = tmp; } @@ -610,9 +610,9 @@ bool QProcess::start( QStringList *env ) if ( (comms & Stdin) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdin ) == -1 ) { - return FALSE; + return FALSE; } if ( (comms & Stderr) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStderr ) == -1 ) { - return FALSE; + return FALSE; } if ( (comms & Stdout) && ::socketpair( AF_UNIX, SOCK_STREAM, 0, sStdout ) == -1 ) { - return FALSE; + return FALSE; } @@ -623,5 +623,5 @@ bool QProcess::start( QStringList *env ) if ( pipe( fd ) < 0 ) { - // non critical error, go on - fd[0] = 0; - fd[1] = 0; + // non critical error, go on + fd[0] = 0; + fd[1] = 0; } @@ -633,4 +633,4 @@ bool QProcess::start( QStringList *env ) for ( QStringList::Iterator it = _arguments.begin(); it != _arguments.end(); ++it ) { - arglistQ[i] = (*it).local8Bit(); - arglist[i] = arglistQ[i]; + arglistQ[i] = (*it).local8Bit(); + arglist[i] = arglistQ[i]; #if defined(QT_QPROCESS_DEBUG) @@ -638,3 +638,3 @@ bool QProcess::start( QStringList *env ) #endif - i++; + i++; } @@ -645,4 +645,4 @@ bool QProcess::start( QStringList *env ) if ( d->procManager == 0 ) { - d->procManager = new QProcessManager; - qprocess_cleanup_procmanager.add( &d->procManager ); + d->procManager = new QProcessManager; + qprocess_cleanup_procmanager.add( &d->procManager ); } @@ -653,87 +653,87 @@ bool QProcess::start( QStringList *env ) if ( pid == 0 ) { - // child - d->closeOpenSocketsForChild(); - if ( comms & Stdin ) { - ::close( sStdin[1] ); - ::dup2( sStdin[0], STDIN_FILENO ); - } - if ( comms & Stdout ) { - ::close( sStdout[0] ); - ::dup2( sStdout[1], STDOUT_FILENO ); - } - if ( comms & Stderr ) { - ::close( sStderr[0] ); - ::dup2( sStderr[1], STDERR_FILENO ); - } - if ( comms & DupStderr ) { - ::dup2( STDOUT_FILENO, STDERR_FILENO ); - } + // child + d->closeOpenSocketsForChild(); + if ( comms & Stdin ) { + ::close( sStdin[1] ); + ::dup2( sStdin[0], STDIN_FILENO ); + } + if ( comms & Stdout ) { + ::close( sStdout[0] ); + ::dup2( sStdout[1], STDOUT_FILENO ); + } + if ( comms & Stderr ) { + ::close( sStderr[0] ); + ::dup2( sStderr[1], STDERR_FILENO ); + } + if ( comms & DupStderr ) { + ::dup2( STDOUT_FILENO, STDERR_FILENO ); + } #ifndef QT_NO_DIR - ::chdir( workingDir.absPath().latin1() ); + ::chdir( workingDir.absPath().latin1() ); #endif - if ( fd[0] ) - ::close( fd[0] ); - if ( fd[1] ) - ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess - - if ( env == 0 ) { // inherit environment and start process - ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice - } else { // start process with environment settins as specified in env - // construct the environment for exec - int numEntries = env->count(); - bool setLibraryPath = - env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && - getenv( "LD_LIBRARY_PATH" ) != 0; - if ( setLibraryPath ) - numEntries++; - QCString *envlistQ = new QCString[ numEntries + 1 ]; - const char** envlist = new const char*[ numEntries + 1 ]; - int i = 0; - if ( setLibraryPath ) { - envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); - envlist[i] = envlistQ[i]; - i++; - } - for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { - envlistQ[i] = (*it).local8Bit(); - envlist[i] = envlistQ[i]; - i++; - } - envlist[i] = 0; - - // look for the executable in the search path - if ( _arguments.count()>0 && getenv("PATH")!=0 ) { - QString command = _arguments[0]; - if ( !command.contains( '/' ) ) { - QStringList pathList = QStringList::split( ':', getenv( "PATH" ) ); - for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) { - QString dir = *it; + if ( fd[0] ) + ::close( fd[0] ); + if ( fd[1] ) + ::fcntl( fd[1], F_SETFD, FD_CLOEXEC ); // close on exec shows sucess + + if ( env == 0 ) { // inherit environment and start process + ::execvp( arglist[0], (char*const*)arglist ); // ### cast not nice + } else { // start process with environment settins as specified in env + // construct the environment for exec + int numEntries = env->count(); + bool setLibraryPath = + env->grep( QRegExp( "^LD_LIBRARY_PATH=" ) ).isEmpty() && + getenv( "LD_LIBRARY_PATH" ) != 0; + if ( setLibraryPath ) + numEntries++; + QCString *envlistQ = new QCString[ numEntries + 1 ]; + const char** envlist = new const char*[ numEntries + 1 ]; + int i = 0; + if ( setLibraryPath ) { + envlistQ[i] = QString( "LD_LIBRARY_PATH=%1" ).arg( getenv( "LD_LIBRARY_PATH" ) ).local8Bit(); + envlist[i] = envlistQ[i]; + i++; + } + for ( QStringList::Iterator it = env->begin(); it != env->end(); ++it ) { + envlistQ[i] = (*it).local8Bit(); + envlist[i] = envlistQ[i]; + i++; + } + envlist[i] = 0; + + // look for the executable in the search path + if ( _arguments.count()>0 && getenv("PATH")!=0 ) { + QString command = _arguments[0]; + if ( !command.contains( '/' ) ) { + QStringList pathList = QStringList::split( ':', getenv( "PATH" ) ); + for (QStringList::Iterator it = pathList.begin(); it != pathList.end(); ++it ) { + QString dir = *it; #ifdef Q_OS_MACX - if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle - dir += "/" + command + ".app/Contents/MacOS"; + if(QFile::exists(dir + "/" + command + ".app")) //look in a bundle + dir += "/" + command + ".app/Contents/MacOS"; #endif #ifndef QT_NO_DIR - QFileInfo fileInfo( dir, command ); + QFileInfo fileInfo( dir, command ); #else - QFileInfo fileInfo( dir + "/" + command ); + QFileInfo fileInfo( dir + "/" + command ); #endif - if ( fileInfo.isExecutable() ) { - arglistQ[0] = fileInfo.filePath().local8Bit(); - arglist[0] = arglistQ[0]; - break; - } - } - } - } - ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice - } - if ( fd[1] ) { - char buf = 0; - ::write( fd[1], &buf, 1 ); - ::close( fd[1] ); - } - ::exit( -1 ); + if ( fileInfo.isExecutable() ) { + arglistQ[0] = fileInfo.filePath().local8Bit(); + arglist[0] = arglistQ[0]; + break; + } + } + } + } + ::execve( arglist[0], (char*const*)arglist, (char*const*)envlist ); // ### casts not nice + } + if ( fd[1] ) { + char buf = 0; + ::write( fd[1], &buf, 1 ); + ::close( fd[1] ); + } + ::exit( -1 ); } else if ( pid == -1 ) { - // error forking - goto error; + // error forking + goto error; } @@ -742,19 +742,19 @@ bool QProcess::start( QStringList *env ) if ( fd[1] ) - ::close( fd[1] ); + ::close( fd[1] ); if ( fd[0] ) { - char buf; - for ( ;; ) { - int n = ::read( fd[0], &buf, 1 ); - if ( n==1 ) { - // socket was not closed => error - d->proc = 0; - goto error; - } else if ( n==-1 ) { - if ( errno==EAGAIN || errno==EINTR ) - // try it again - continue; - } - break; - } - ::close( fd[0] ); + char buf; + for ( ;; ) { + int n = ::read( fd[0], &buf, 1 ); + if ( n==1 ) { + // socket was not closed => error + d->proc = 0; + goto error; + } else if ( n==-1 ) { + if ( errno==EAGAIN || errno==EINTR ) + // try it again + continue; + } + break; + } + ::close( fd[0] ); } @@ -764,29 +764,29 @@ bool QProcess::start( QStringList *env ) if ( comms & Stdin ) { - ::close( sStdin[0] ); - d->proc->socketStdin = sStdin[1]; - d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write ); - connect( d->notifierStdin, SIGNAL(activated(int)), - this, SLOT(socketWrite(int)) ); - // setup notifiers for the sockets - if ( !d->stdinBuf.isEmpty() ) { - d->notifierStdin->setEnabled( TRUE ); - } + ::close( sStdin[0] ); + d->proc->socketStdin = sStdin[1]; + d->notifierStdin = new QSocketNotifier( sStdin[1], QSocketNotifier::Write ); + connect( d->notifierStdin, SIGNAL(activated(int)), + this, SLOT(socketWrite(int)) ); + // setup notifiers for the sockets + if ( !d->stdinBuf.isEmpty() ) { + d->notifierStdin->setEnabled( TRUE ); + } } if ( comms & Stdout ) { - ::close( sStdout[1] ); - d->proc->socketStdout = sStdout[0]; - d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read ); - connect( d->notifierStdout, SIGNAL(activated(int)), - this, SLOT(socketRead(int)) ); - if ( ioRedirection ) - d->notifierStdout->setEnabled( TRUE ); + ::close( sStdout[1] ); + d->proc->socketStdout = sStdout[0]; + d->notifierStdout = new QSocketNotifier( sStdout[0], QSocketNotifier::Read ); + connect( d->notifierStdout, SIGNAL(activated(int)), + this, SLOT(socketRead(int)) ); + if ( ioRedirection ) + d->notifierStdout->setEnabled( TRUE ); } if ( comms & Stderr ) { - ::close( sStderr[1] ); - d->proc->socketStderr = sStderr[0]; - d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read ); - connect( d->notifierStderr, SIGNAL(activated(int)), - this, SLOT(socketRead(int)) ); - if ( ioRedirection ) - d->notifierStderr->setEnabled( TRUE ); + ::close( sStderr[1] ); + d->proc->socketStderr = sStderr[0]; + d->notifierStderr = new QSocketNotifier( sStderr[0], QSocketNotifier::Read ); + connect( d->notifierStderr, SIGNAL(activated(int)), + this, SLOT(socketRead(int)) ); + if ( ioRedirection ) + d->notifierStderr->setEnabled( TRUE ); } @@ -803,14 +803,14 @@ error: if ( d->procManager ) - d->procManager->cleanup(); + d->procManager->cleanup(); if ( comms & Stdin ) { - ::close( sStdin[1] ); - ::close( sStdin[0] ); + ::close( sStdin[1] ); + ::close( sStdin[0] ); } if ( comms & Stdout ) { - ::close( sStdout[0] ); - ::close( sStdout[1] ); + ::close( sStdout[0] ); + ::close( sStdout[1] ); } if ( comms & Stderr ) { - ::close( sStderr[0] ); - ::close( sStderr[1] ); + ::close( sStderr[0] ); + ::close( sStderr[1] ); } @@ -837,3 +837,3 @@ void QProcess::tryTerminate() const if ( d->proc != 0 ) - ::kill( d->proc->pid, SIGTERM ); + ::kill( d->proc->pid, SIGTERM ); } @@ -867,3 +867,3 @@ void QProcess::kill() const if ( d->proc != 0 ) - ::kill( d->proc->pid, SIGKILL ); + ::kill( d->proc->pid, SIGKILL ); } @@ -881,6 +881,6 @@ bool QProcess::isRunning() const #endif - return FALSE; + return FALSE; } if ( d->proc == 0 ) - return FALSE; + return FALSE; int status; @@ -888,9 +888,9 @@ bool QProcess::isRunning() const { - // compute the exit values - QProcess *that = (QProcess*)this; // mutable - that->exitNormal = WIFEXITED( status ) != 0; - if ( exitNormal ) { - that->exitStat = (char)WEXITSTATUS( status ); - } - d->exitValuesCalculated = TRUE; + // compute the exit values + QProcess *that = (QProcess*)this; // mutable + that->exitNormal = WIFEXITED( status ) != 0; + if ( exitNormal ) { + that->exitStat = (char)WEXITSTATUS( status ); + } + d->exitValuesCalculated = TRUE; #if defined(QT_QPROCESS_DEBUG) @@ -898,3 +898,3 @@ bool QProcess::isRunning() const #endif - return FALSE; + return FALSE; } @@ -925,3 +925,3 @@ void QProcess::writeToStdin( const QByteArray& buf ) if ( d->notifierStdin != 0 ) - d->notifierStdin->setEnabled( TRUE ); + d->notifierStdin->setEnabled( TRUE ); } @@ -940,12 +940,12 @@ void QProcess::closeStdin() if ( d->proc == 0 ) - return; + return; if ( d->proc->socketStdin !=0 ) { - while ( !d->stdinBuf.isEmpty() ) { - delete d->stdinBuf.dequeue(); - } - delete d->notifierStdin; - d->notifierStdin = 0; - if ( ::close( d->proc->socketStdin ) != 0 ) { + while ( !d->stdinBuf.isEmpty() ) { + delete d->stdinBuf.dequeue(); + } + delete d->notifierStdin; + d->notifierStdin = 0; + if ( ::close( d->proc->socketStdin ) != 0 ) { owarn << "Could not close stdin of child process" << oendl; - } + } #if defined(QT_QPROCESS_DEBUG) @@ -953,3 +953,3 @@ void QProcess::closeStdin() #endif - d->proc->socketStdin = 0; + d->proc->socketStdin = 0; } @@ -965,6 +965,6 @@ void QProcess::socketRead( int fd ) if ( d->socketReadCalled ) { - // the slots that are connected to the readyRead...() signals might - // trigger a recursive call of socketRead(). Avoid this since you get a - // blocking read otherwise. - return; + // the slots that are connected to the readyRead...() signals might + // trigger a recursive call of socketRead(). Avoid this since you get a + // blocking read otherwise. + return; } @@ -974,3 +974,3 @@ void QProcess::socketRead( int fd ) if ( fd == 0 ) - return; + return; const int bufsize = 4096; @@ -980,8 +980,8 @@ void QProcess::socketRead( int fd ) if ( fd == d->proc->socketStdout ) { - buffer = &d->bufStdout; + buffer = &d->bufStdout; } else if ( fd == d->proc->socketStderr ) { - buffer = &d->bufStderr; + buffer = &d->bufStderr; } else { - // this case should never happen, but just to be safe - return; + // this case should never happen, but just to be safe + return; } @@ -993,8 +993,8 @@ void QProcess::socketRead( int fd ) if ( n > 0 ) - buffer->resize( oldSize + n ); + buffer->resize( oldSize + n ); else - buffer->resize( oldSize ); + buffer->resize( oldSize ); // eof or error? if ( n == 0 || n == -1 ) { - if ( fd == d->proc->socketStdout ) { + if ( fd == d->proc->socketStdout ) { #if defined(QT_QPROCESS_DEBUG) @@ -1002,9 +1002,9 @@ void QProcess::socketRead( int fd ) #endif - d->notifierStdout->setEnabled( FALSE ); - delete d->notifierStdout; - d->notifierStdout = 0; - ::close( d->proc->socketStdout ); - d->proc->socketStdout = 0; - return; - } else if ( fd == d->proc->socketStderr ) { + d->notifierStdout->setEnabled( FALSE ); + delete d->notifierStdout; + d->notifierStdout = 0; + ::close( d->proc->socketStdout ); + d->proc->socketStdout = 0; + return; + } else if ( fd == d->proc->socketStderr ) { #if defined(QT_QPROCESS_DEBUG) @@ -1012,9 +1012,9 @@ void QProcess::socketRead( int fd ) #endif - d->notifierStderr->setEnabled( FALSE ); - delete d->notifierStderr; - d->notifierStderr = 0; - ::close( d->proc->socketStderr ); - d->proc->socketStderr = 0; - return; - } + d->notifierStderr->setEnabled( FALSE ); + delete d->notifierStderr; + d->notifierStderr = 0; + ::close( d->proc->socketStderr ); + d->proc->socketStderr = 0; + return; + } } @@ -1022,9 +1022,9 @@ void QProcess::socketRead( int fd ) while ( n == bufsize ) { - oldSize = buffer->size(); - buffer->resize( oldSize + bufsize ); - n = ::read( fd, buffer->data()+oldSize, bufsize ); - if ( n > 0 ) - buffer->resize( oldSize + n ); - else - buffer->resize( oldSize ); + oldSize = buffer->size(); + buffer->resize( oldSize + bufsize ); + n = ::read( fd, buffer->data()+oldSize, bufsize ); + if ( n > 0 ) + buffer->resize( oldSize + n ); + else + buffer->resize( oldSize ); } @@ -1034,12 +1034,12 @@ void QProcess::socketRead( int fd ) #if defined(QT_QPROCESS_DEBUG) - qDebug( "QProcess::socketRead(): %d bytes read from stdout (%d)", - buffer->size()-oldSize, fd ); + odebug << "QProcess::socketRead(): " << buffer->size()-oldSize << "bytes read from stdout (" + << fd << ")" << oendl; #endif - emit readyReadStdout(); + emit readyReadStdout(); } else if ( fd == d->proc->socketStderr ) { #if defined(QT_QPROCESS_DEBUG) - qDebug( "QProcess::socketRead(): %d bytes read from stderr (%d)", - buffer->size()-oldSize, fd ); + odebug << "QProcess::socketRead(): " << buffer->size()-oldSize << " bytes read from stderr (" + << fd << ")" << oendl; #endif - emit readyReadStderr(); + emit readyReadStderr(); } @@ -1056,6 +1056,6 @@ void QProcess::socketWrite( int fd ) if ( fd != d->proc->socketStdin || d->proc->socketStdin == 0 ) - return; + return; if ( d->stdinBuf.isEmpty() ) { - d->notifierStdin->setEnabled( FALSE ); - return; + d->notifierStdin->setEnabled( FALSE ); + return; } @@ -1065,12 +1065,12 @@ void QProcess::socketWrite( int fd ) ssize_t ret = ::write( fd, - d->stdinBuf.head()->data() + d->stdinBufRead, - d->stdinBuf.head()->size() - d->stdinBufRead ); + d->stdinBuf.head()->data() + d->stdinBufRead, + d->stdinBuf.head()->size() - d->stdinBufRead ); if ( ret > 0 ) - d->stdinBufRead += ret; + d->stdinBufRead += ret; if ( d->stdinBufRead == (ssize_t)d->stdinBuf.head()->size() ) { - d->stdinBufRead = 0; - delete d->stdinBuf.dequeue(); - if ( wroteToStdinConnected && d->stdinBuf.isEmpty() ) - emit wroteToStdin(); - socketWrite( fd ); + d->stdinBufRead = 0; + delete d->stdinBuf.dequeue(); + if ( wroteToStdinConnected && d->stdinBuf.isEmpty() ) + emit wroteToStdin(); + socketWrite( fd ); } @@ -1107,11 +1107,11 @@ void QProcess::setIoRedirection( bool value ) if ( ioRedirection ) { - if ( d->notifierStdout ) - d->notifierStdout->setEnabled( TRUE ); - if ( d->notifierStderr ) - d->notifierStderr->setEnabled( TRUE ); + if ( d->notifierStdout ) + d->notifierStdout->setEnabled( TRUE ); + if ( d->notifierStderr ) + d->notifierStderr->setEnabled( TRUE ); } else { - if ( d->notifierStdout ) - d->notifierStdout->setEnabled( FALSE ); - if ( d->notifierStderr ) - d->notifierStderr->setEnabled( FALSE ); + if ( d->notifierStdout ) + d->notifierStdout->setEnabled( FALSE ); + if ( d->notifierStderr ) + d->notifierStderr->setEnabled( FALSE ); } @@ -1154,3 +1154,3 @@ QProcess::PID QProcess::processIdentifier() if ( d->proc == 0 ) - return -1; + return -1; return d->proc->pid; @@ -1161,3 +1161,3 @@ int QProcess::priority() const if ( d->proc ) - return getpriority(PRIO_PROCESS,d->proc->pid); + return getpriority(PRIO_PROCESS,d->proc->pid); return 0; @@ -1168,3 +1168,3 @@ void QProcess::setPriority(int p) if ( d->proc ) - setpriority(PRIO_PROCESS,d->proc->pid,p); + setpriority(PRIO_PROCESS,d->proc->pid,p); } diff --git a/core/launcher/screensaver.cpp b/core/launcher/screensaver.cpp index a7d23c4..f818d62 100644 --- a/core/launcher/screensaver.cpp +++ b/core/launcher/screensaver.cpp @@ -7,2 +7,3 @@ #include <opie2/odevice.h> +#include <opie2/odebug.h> @@ -14,32 +15,32 @@ using namespace Opie::Core; OpieScreenSaver::OpieScreenSaver ( ) - : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) + : QObject ( 0, "screensaver" ), QWSScreenSaver ( ) { - m_disable_suspend = 100; - m_enable_dim = false; - m_enable_lightoff = false; - m_enable_suspend = false; - m_onlylcdoff = false; + m_disable_suspend = 100; + m_enable_dim = false; + m_enable_lightoff = false; + m_enable_suspend = false; + m_onlylcdoff = false; - m_enable_dim_ac = false; - m_enable_lightoff_ac = false; - m_enable_suspend_ac = false; - m_onlylcdoff_ac = false; + m_enable_dim_ac = false; + m_enable_lightoff_ac = false; + m_enable_suspend_ac = false; + m_onlylcdoff_ac = false; - m_use_light_sensor = false; - m_backlight_sensor = -1; - ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); + m_use_light_sensor = false; + m_backlight_sensor = -1; + ::memset ( m_sensordata, 0xff, LS_Count * sizeof( m_sensordata [0] )); - m_lcd_status = true; + m_lcd_status = true; - m_backlight_normal = -1; - m_backlight_current = -1; - m_backlight_forcedoff = false; + m_backlight_normal = -1; + m_backlight_current = -1; + m_backlight_forcedoff = false; - m_on_ac = false; + m_on_ac = false; - m_level = -1; + m_level = -1; - // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) - ODevice::inst ( )-> setDisplayStatus ( true ); - setBacklight ( -1 ); + // Make sure the LCD is in fact on, (if opie was killed while the LCD is off it would still be off) + ODevice::inst ( )-> setDisplayStatus ( true ); + setBacklight ( -1 ); } @@ -52,10 +53,10 @@ void OpieScreenSaver::restore() { - m_level = -1; + m_level = -1; - if ( !m_lcd_status ) { // We must have turned it off - ODevice::inst ( ) -> setDisplayStatus ( true ); - m_lcd_status = true; - } + if ( !m_lcd_status ) { // We must have turned it off + ODevice::inst ( ) -> setDisplayStatus ( true ); + m_lcd_status = true; + } - setBacklightInternal ( -1 ); + setBacklightInternal ( -1 ); } @@ -72,48 +73,48 @@ bool OpieScreenSaver::save( int level ) { - m_level = level; - - switch ( level ) { - case 0: - if (( m_on_ac && m_enable_dim_ac ) || - ( !m_on_ac && m_enable_dim )) { - if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) - setBacklightInternal ( 1 ); // lowest non-off - } - return true; - break; - - case 1: - if (( m_on_ac && m_enable_lightoff_ac ) || - ( !m_on_ac && m_enable_lightoff )) { - if ( m_disable_suspend > 1 ) - setBacklightInternal ( 0 ); // off - } - return true; - break; - - case 2: - if (( m_on_ac && !m_enable_suspend_ac ) || - ( !m_on_ac && !m_enable_suspend )) { - return true; - } - - if (( m_on_ac && m_onlylcdoff_ac ) || - ( !m_on_ac && m_onlylcdoff )) { - ODevice::inst ( ) -> setDisplayStatus ( false ); - m_lcd_status = false; - return true; - } - - // We're going to suspend the whole machine - - if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { - // TODO: why is this key F34 hard coded? -- schurig - // Does this now only work an devices with a ODevice::filter? - QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); - return true; - } - - break; - } - return false; + m_level = level; + + switch ( level ) { + case 0: + if (( m_on_ac && m_enable_dim_ac ) || + ( !m_on_ac && m_enable_dim )) { + if (( m_disable_suspend > 0 ) && ( m_backlight_current > 1 ) && !m_use_light_sensor ) + setBacklightInternal ( 1 ); // lowest non-off + } + return true; + break; + + case 1: + if (( m_on_ac && m_enable_lightoff_ac ) || + ( !m_on_ac && m_enable_lightoff )) { + if ( m_disable_suspend > 1 ) + setBacklightInternal ( 0 ); // off + } + return true; + break; + + case 2: + if (( m_on_ac && !m_enable_suspend_ac ) || + ( !m_on_ac && !m_enable_suspend )) { + return true; + } + + if (( m_on_ac && m_onlylcdoff_ac ) || + ( !m_on_ac && m_onlylcdoff )) { + ODevice::inst ( ) -> setDisplayStatus ( false ); + m_lcd_status = false; + return true; + } + + // We're going to suspend the whole machine + + if (( m_disable_suspend > 2 ) && !Network::networkOnline ( )) { + // TODO: why is this key F34 hard coded? -- schurig + // Does this now only work an devices with a ODevice::filter? + QWSServer::sendKeyEvent( 0xffff, Qt::Key_F34, FALSE, TRUE, FALSE ); + return true; + } + + break; + } + return false; } @@ -136,37 +137,37 @@ void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) { - Config config ( "apm" ); - config. setGroup ( m_on_ac ? "AC" : "Battery" ); - - int v[ 4 ]; - if ( dim < 0 ) - dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); - if ( lightoff < 0 ) - lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); - if ( suspend < 0 ) - suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); - - if ( m_on_ac ) { - m_enable_dim_ac = ( dim > 0 ); - m_enable_lightoff_ac = ( lightoff > 0 ); - m_enable_suspend_ac = ( suspend > 0 ); - m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); - } - else { - m_enable_dim = ( dim > 0 ); - m_enable_lightoff = ( lightoff > 0 ); - m_enable_suspend = ( suspend > 0 ); - m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); - } - - //odebug << "screen saver intervals: " << dim << " " << lightoff << " " << suspend << "" << oendl; - - v [ 0 ] = QMAX( 1000 * dim, 100 ); - v [ 1 ] = QMAX( 1000 * lightoff, 100 ); - v [ 2 ] = QMAX( 1000 * suspend, 100 ); - v [ 3 ] = 0; - - if ( !dim && !lightoff && !suspend ) - QWSServer::setScreenSaverInterval( 0 ); - else - QWSServer::setScreenSaverIntervals( v ); + Config config ( "apm" ); + config. setGroup ( m_on_ac ? "AC" : "Battery" ); + + int v[ 4 ]; + if ( dim < 0 ) + dim = config. readNumEntry ( "Dim", m_on_ac ? 60 : 30 ); + if ( lightoff < 0 ) + lightoff = config. readNumEntry ( "LightOff", m_on_ac ? 120 : 20 ); + if ( suspend < 0 ) + suspend = config. readNumEntry ( "Suspend", m_on_ac ? 0 : 60 ); + + if ( m_on_ac ) { + m_enable_dim_ac = ( dim > 0 ); + m_enable_lightoff_ac = ( lightoff > 0 ); + m_enable_suspend_ac = ( suspend > 0 ); + m_onlylcdoff_ac = config.readBoolEntry ( "LcdOffOnly", false ); + } + else { + m_enable_dim = ( dim > 0 ); + m_enable_lightoff = ( lightoff > 0 ); + m_enable_suspend = ( suspend > 0 ); + m_onlylcdoff = config.readBoolEntry ( "LcdOffOnly", false ); + } + + //odebug << "screen saver intervals: " << dim << " " << lightoff << " " << suspend << "" << oendl; + + v [ 0 ] = QMAX( 1000 * dim, 100 ); + v [ 1 ] = QMAX( 1000 * lightoff, 100 ); + v [ 2 ] = QMAX( 1000 * suspend, 100 ); + v [ 3 ] = 0; + + if ( !dim && !lightoff && !suspend ) + QWSServer::setScreenSaverInterval( 0 ); + else + QWSServer::setScreenSaverIntervals( v ); } @@ -182,3 +183,3 @@ void OpieScreenSaver::setInterval ( int interval ) { - setIntervals ( -1, -1, interval ); + setIntervals ( -1, -1, interval ); } @@ -188,5 +189,5 @@ void OpieScreenSaver::setMode ( int mode ) { - if ( mode > m_disable_suspend ) - setInterval ( -1 ); - m_disable_suspend = mode; + if ( mode > m_disable_suspend ) + setInterval ( -1 ); + m_disable_suspend = mode; } @@ -205,35 +206,36 @@ void OpieScreenSaver::setBacklight ( int bright ) { - // Read from config - Config config ( "apm" ); - config. setGroup ( m_on_ac ? "AC" : "Battery" ); - m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); - int contrast = config. readNumEntry ( "Contrast", 127); - m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); - - //qDebug ( "setBacklight: %d (norm: %d) (ls: %d)", bright, m_backlight_normal, m_use_light_sensor ? 1 : 0 ); - - killTimers ( ); - if (( bright < 0 ) && m_use_light_sensor ) { - QStringList sl = config. readListEntry ( "LightSensorData", ';' ); - - m_sensordata [LS_SensorMin] = 40; - m_sensordata [LS_SensorMax] = 215; - m_sensordata [LS_LightMin] = 1; - m_sensordata [LS_LightMax] = 255; - m_sensordata [LS_Steps] = 12; - m_sensordata [LS_Interval] = 2000; - - for ( uint i = 0; i < LS_Count; i++ ) { - if ( i < sl. count ( )) - m_sensordata [i] = sl [i]. toInt ( ); - } - if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE - m_sensordata [LS_Steps] = 2; - - timerEvent ( 0 ); - startTimer ( m_sensordata [LS_Interval] ); - } - - setBacklightInternal ( bright ); - ODevice::inst ( )-> setDisplayContrast(contrast); + // Read from config + Config config ( "apm" ); + config. setGroup ( m_on_ac ? "AC" : "Battery" ); + m_backlight_normal = config. readNumEntry ( "Brightness", m_on_ac ? 255 : 127 ); + int contrast = config. readNumEntry ( "Contrast", 127); + m_use_light_sensor = config. readBoolEntry ( "LightSensor", false ); + + //odebug << "setBacklight: " << bright << " (norm: " << m_backlight_normal << ") (ls: " + // << ( m_use_light_sensor ? 1 : 0 ) << ")" << oendl; + + killTimers ( ); + if (( bright < 0 ) && m_use_light_sensor ) { + QStringList sl = config. readListEntry ( "LightSensorData", ';' ); + + m_sensordata [LS_SensorMin] = 40; + m_sensordata [LS_SensorMax] = 215; + m_sensordata [LS_LightMin] = 1; + m_sensordata [LS_LightMax] = 255; + m_sensordata [LS_Steps] = 12; + m_sensordata [LS_Interval] = 2000; + + for ( uint i = 0; i < LS_Count; i++ ) { + if ( i < sl. count ( )) + m_sensordata [i] = sl [i]. toInt ( ); + } + if ( m_sensordata [LS_Steps] < 2 ) // sanity check to avoid SIGFPE + m_sensordata [LS_Steps] = 2; + + timerEvent ( 0 ); + startTimer ( m_sensordata [LS_Interval] ); + } + + setBacklightInternal ( bright ); + ODevice::inst ( )-> setDisplayContrast(contrast); } @@ -252,21 +254,21 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) { - if ( bright == -3 ) { - // Forced on - m_backlight_forcedoff = false; - bright = -1; - } - if ( m_backlight_forcedoff && bright != -2 ) - return ; - if ( bright == -2 ) { - // Toggle between off and on - bright = m_backlight_current ? 0 : -1; - m_backlight_forcedoff = !bright; - } - if ( bright == -1 ) - bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; - - if ( bright != m_backlight_current ) { - ODevice::inst ( )-> setDisplayBrightness ( bright ); - m_backlight_current = bright; - } + if ( bright == -3 ) { + // Forced on + m_backlight_forcedoff = false; + bright = -1; + } + if ( m_backlight_forcedoff && bright != -2 ) + return ; + if ( bright == -2 ) { + // Toggle between off and on + bright = m_backlight_current ? 0 : -1; + m_backlight_forcedoff = !bright; + } + if ( bright == -1 ) + bright = m_use_light_sensor ? m_backlight_sensor : m_backlight_normal; + + if ( bright != m_backlight_current ) { + ODevice::inst ( )-> setDisplayBrightness ( bright ); + m_backlight_current = bright; + } } @@ -280,21 +282,23 @@ void OpieScreenSaver::timerEvent ( QTimerEvent * ) { - int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); + int s = ODevice::inst ( )-> readLightSensor ( ) * 256 / ODevice::inst ( )-> lightSensorResolution ( ); - if ( s < m_sensordata [LS_SensorMin] ) - m_backlight_sensor = m_sensordata [LS_LightMax]; - else if ( s >= m_sensordata [LS_SensorMax] ) - m_backlight_sensor = m_sensordata [LS_LightMin]; - else { - int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; - int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; + if ( s < m_sensordata [LS_SensorMin] ) + m_backlight_sensor = m_sensordata [LS_LightMax]; + else if ( s >= m_sensordata [LS_SensorMax] ) + m_backlight_sensor = m_sensordata [LS_LightMin]; + else { + int dx = m_sensordata [LS_SensorMax] - m_sensordata [LS_SensorMin]; + int dy = m_sensordata [LS_LightMax] - m_sensordata [LS_LightMin]; - int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 + int stepno = ( s - m_sensordata [LS_SensorMin] ) * m_sensordata [LS_Steps] / dx; // dx is never 0 - m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); - } + m_backlight_sensor = m_sensordata [LS_LightMax] - dy * stepno / ( m_sensordata [LS_Steps] - 1 ); + } - //qDebug ( "f(%d) = %d [%d - %d] -> [%d - %d] / %d", s, m_backlight_sensor, m_sensordata [LS_SensorMin], m_sensordata [LS_SensorMax], m_sensordata [LS_LightMin], m_sensordata [LS_LightMax], m_sensordata [LS_Steps] ); + odebug << "f(" << s << ") = " << m_backlight_sensor << " [" << m_sensordata [LS_SensorMin] + << " - " << m_sensordata [LS_SensorMax] << " ] -> [" << m_sensordata [LS_LightMin] + << " - " << m_sensordata [LS_LightMax] << "] / " << m_sensordata [LS_Steps] << oendl; - if ( m_level <= 0 ) - setBacklightInternal ( -1 ); + if ( m_level <= 0 ) + setBacklightInternal ( -1 ); } @@ -307,6 +311,6 @@ void OpieScreenSaver::setDisplayState ( bool on ) { - if ( m_lcd_status != on ) { - ODevice::inst ( ) -> setDisplayStatus ( on ); - m_lcd_status = on; - } + if ( m_lcd_status != on ) { + ODevice::inst ( ) -> setDisplayStatus ( on ); + m_lcd_status = on; + } } @@ -319,10 +323,10 @@ void OpieScreenSaver::powerStatusChanged ( PowerStatus ps ) { - bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); - - if ( newonac != m_on_ac ) { - m_on_ac = newonac; - setInterval ( -1 ); - setBacklight ( -1 ); - restore ( ); - } + bool newonac = ( ps. acStatus ( ) == PowerStatus::Online ); + + if ( newonac != m_on_ac ) { + m_on_ac = newonac; + setInterval ( -1 ); + setBacklight ( -1 ); + restore ( ); + } } diff --git a/core/launcher/server.cpp b/core/launcher/server.cpp index b9fa1e5..950032d 100644 --- a/core/launcher/server.cpp +++ b/core/launcher/server.cpp @@ -80,12 +80,12 @@ static QWidget *calibrate(bool) static QWidget *new##T( bool maximized ) { \ - QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ - if ( maximized ) { \ - if ( qApp->desktop()->width() <= 350 ) { \ - w->showMaximized(); \ - } else { \ - w->resize( QSize( 300, 300 ) ); \ - } \ - } \ - w->show(); \ - return w; \ + QWidget *w = new T( 0, 0, QWidget::WDestructiveClose | QWidget::WGroupLeader ); \ + if ( maximized ) { \ + if ( qApp->desktop()->width() <= 350 ) { \ + w->showMaximized(); \ + } else { \ + w->resize( QSize( 300, 300 ) ); \ + } \ + } \ + w->show(); \ + return w; \ } @@ -109,10 +109,10 @@ static Global::Command builtins[] = { #if !defined(OPIE_NO_BUILTIN_CALIBRATE) - { "calibrate", calibrate, 1, 0 }, // No tr + { "calibrate", calibrate, 1, 0 }, // No tr #endif #if !defined(OPIE_NO_BUILTIN_SHUTDOWN) - { "shutdown", Global::shutdown, 1, 0 }, // No tr -// { "run", run, 1, 0 }, // No tr + { "shutdown", Global::shutdown, 1, 0 }, // No tr +// { "run", run, 1, 0 }, // No tr #endif - { 0, calibrate, 0, 0 }, + { 0, calibrate, 0, 0 }, }; @@ -168,3 +168,3 @@ Server::Server() : connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); + this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); @@ -172,3 +172,3 @@ Server::Server() : connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); + this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); @@ -204,16 +204,16 @@ static bool hasVisibleWindow(const QString& clientname, bool partial) for (QListIterator<QWSWindow> it(list); (w=it.current()); ++it) { - if ( w->client()->identity() == clientname ) { - if ( partial && !w->isFullyObscured() ) - return TRUE; - if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { + if ( w->client()->identity() == clientname ) { + if ( partial && !w->isFullyObscured() ) + return TRUE; + if ( !partial && !w->isFullyObscured() && !w->isPartiallyObscured() ) { # if QT_VERSION < 0x030000 - QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, - QSize(qt_screen->width(),qt_screen->height()) ); + QRect mwr = qt_screen->mapToDevice(qt_maxWindowRect, + QSize(qt_screen->width(),qt_screen->height()) ); # else - QRect mwr = qt_maxWindowRect; + QRect mwr = qt_maxWindowRect; # endif - if ( mwr.contains(w->requested().boundingRect()) ) - return TRUE; - } - } + if ( mwr.contains(w->requested().boundingRect()) ) + return TRUE; + } + } } @@ -228,5 +228,5 @@ void Server::activate(const ODeviceButton* button, bool held) if ( held ) { - om = button->heldAction(); + om = button->heldAction(); } else { - om = button->pressedAction(); + om = button->pressedAction(); } @@ -241,12 +241,12 @@ void Server::activate(const ODeviceButton* button, bool held) if ( !sr.isNull() ) { - QString app = sr.app(); - bool vis = hasVisibleWindow(app, app != "qpe"); - if ( sr.message() == "raise()" && vis ) { - sr.setMessage("nextView()"); - } else { - // "back door" - sr << (int)vis; - } - - sr.send(); + QString app = sr.app(); + bool vis = hasVisibleWindow(app, app != "qpe"); + if ( sr.message() == "raise()" && vis ) { + sr.setMessage("nextView()"); + } else { + // "back door" + sr << (int)vis; + } + + sr.send(); } @@ -294,10 +294,10 @@ bool Server::setKeyboardLayout( const QString &kb ) if ( kb == "us101" ) { // No tr - om = 0; + om = 0; } else if ( kb == "jp109" ) { - om = new QIntDict<QWSServer::KeyMap>(37); - const KeyOverride *k = jp109keys; - while ( k->scan_code ) { - om->insert( k->scan_code, &k->map ); - k++; - } + om = new QIntDict<QWSServer::KeyMap>(37); + const KeyOverride *k = jp109keys; + while ( k->scan_code ) { + om->insert( k->scan_code, &k->map ); + k++; + } } @@ -315,6 +315,6 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) if ( msg == "securityChanged()" ) { - if ( transferServer ) - transferServer->authorizeConnections(); - if ( qcopBridge ) - qcopBridge->authorizeConnections(); + if ( transferServer ) + transferServer->authorizeConnections(); + if ( qcopBridge ) + qcopBridge->authorizeConnections(); } @@ -323,5 +323,5 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) else if ( msg == "setTempScreenSaverMode(int,int)" ) { - int mode, pid; - stream >> mode >> pid; - tsmMonitor->setTempMode(mode, pid); + int mode, pid; + stream >> mode >> pid; + tsmMonitor->setTempMode(mode, pid); } @@ -329,48 +329,48 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) else if ( msg == "linkChanged(QString)" ) { - QString link; - stream >> link; + QString link; + stream >> link; odebug << "desktop.cpp systemMsg -> linkchanged( " << link << " )" << oendl; - docList->linkChanged(link); + docList->linkChanged(link); } else if ( msg == "serviceChanged(QString)" ) { - MimeType::updateApplications(); + MimeType::updateApplications(); } else if ( msg == "mkdir(QString)" ) { - QString dir; - stream >> dir; - if ( !dir.isEmpty() ) - mkdir( dir ); + QString dir; + stream >> dir; + if ( !dir.isEmpty() ) + mkdir( dir ); } else if ( msg == "rdiffGenSig(QString,QString)" ) { - QString baseFile, sigFile; - stream >> baseFile >> sigFile; - QRsync::generateSignature( baseFile, sigFile ); + QString baseFile, sigFile; + stream >> baseFile >> sigFile; + QRsync::generateSignature( baseFile, sigFile ); } else if ( msg == "rdiffGenDiff(QString,QString,QString)" ) { - QString baseFile, sigFile, deltaFile; - stream >> baseFile >> sigFile >> deltaFile; - QRsync::generateDiff( baseFile, sigFile, deltaFile ); + QString baseFile, sigFile, deltaFile; + stream >> baseFile >> sigFile >> deltaFile; + QRsync::generateDiff( baseFile, sigFile, deltaFile ); } else if ( msg == "rdiffApplyPatch(QString,QString)" ) { - QString baseFile, deltaFile; - stream >> baseFile >> deltaFile; - if ( !QFile::exists( baseFile ) ) { - QFile f( baseFile ); - f.open( IO_WriteOnly ); - f.close(); - } - QRsync::applyDiff( baseFile, deltaFile ); + QString baseFile, deltaFile; + stream >> baseFile >> deltaFile; + if ( !QFile::exists( baseFile ) ) { + QFile f( baseFile ); + f.open( IO_WriteOnly ); + f.close(); + } + QRsync::applyDiff( baseFile, deltaFile ); #ifndef QT_NO_COP - QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); - e << baseFile; + QCopEnvelope e( "QPE/Desktop", "patchApplied(QString)" ); + e << baseFile; #endif } else if ( msg == "rdiffCleanup()" ) { - mkdir( "/tmp/rdiff" ); - QDir dir; - dir.setPath( "/tmp/rdiff" ); - QStringList entries = dir.entryList(); - for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) - dir.remove( *it ); + mkdir( "/tmp/rdiff" ); + QDir dir; + dir.setPath( "/tmp/rdiff" ); + QStringList entries = dir.entryList(); + for ( QStringList::Iterator it = entries.begin(); it != entries.end(); ++it ) + dir.remove( *it ); } else if ( msg == "sendHandshakeInfo()" ) { - QString home = getenv( "HOME" ); + QString home = getenv( "HOME" ); #ifndef QT_NO_COP - QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); - e << home; - int locked = (int) ServerApplication::screenLocked(); - e << locked; + QCopEnvelope e( "QPE/Desktop", "handshakeInfo(QString,bool)" ); + e << home; + int locked = (int) ServerApplication::screenLocked(); + e << locked; #endif @@ -385,68 +385,68 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) else if ( msg == "sendVersionInfo()" ) { - QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); + QCopEnvelope e( "QPE/Desktop", "versionInfo(QString,QString)" ); /* ### FIXME Architecture ### */ - e << QString::fromLatin1("1.7") << "Uncustomized Device"; + e << QString::fromLatin1("1.7") << "Uncustomized Device"; } else if ( msg == "sendCardInfo()" ) { #ifndef QT_NO_COP - QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); + QCopEnvelope e( "QPE/Desktop", "cardInfo(QString)" ); #endif - storage->update(); - const QList<FileSystem> &fs = storage->fileSystems(); - QListIterator<FileSystem> it ( fs ); - QString s; - QString homeDir = getenv("HOME"); - QString homeFs, homeFsPath; - for ( ; it.current(); ++it ) { - int k4 = (*it)->blockSize()/256; - if ( (*it)->isRemovable() ) { - s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr - + QString::number( (*it)->availBlocks() * k4/4 ) - + "K " + (*it)->options() + ";"; - } else if ( homeDir.contains( (*it)->path() ) && - (*it)->path().length() > homeFsPath.length() ) { - homeFsPath = (*it)->path(); - homeFs = - (*it)->name() + "=" + homeDir + "/Documents " // No tr - + QString::number( (*it)->availBlocks() * k4/4 ) - + "K " + (*it)->options() + ";"; - } - } - if ( !homeFs.isEmpty() ) - s += homeFs; + storage->update(); + const QList<FileSystem> &fs = storage->fileSystems(); + QListIterator<FileSystem> it ( fs ); + QString s; + QString homeDir = getenv("HOME"); + QString homeFs, homeFsPath; + for ( ; it.current(); ++it ) { + int k4 = (*it)->blockSize()/256; + if ( (*it)->isRemovable() ) { + s += (*it)->name() + "=" + (*it)->path() + "/Documents " // No tr + + QString::number( (*it)->availBlocks() * k4/4 ) + + "K " + (*it)->options() + ";"; + } else if ( homeDir.contains( (*it)->path() ) && + (*it)->path().length() > homeFsPath.length() ) { + homeFsPath = (*it)->path(); + homeFs = + (*it)->name() + "=" + homeDir + "/Documents " // No tr + + QString::number( (*it)->availBlocks() * k4/4 ) + + "K " + (*it)->options() + ";"; + } + } + if ( !homeFs.isEmpty() ) + s += homeFs; #ifndef QT_NO_COP - e << s; + e << s; #endif } else if ( msg == "sendSyncDate(QString)" ) { - QString app; - stream >> app; - Config cfg( "qpe" ); - cfg.setGroup("SyncDate"); + QString app; + stream >> app; + Config cfg( "qpe" ); + cfg.setGroup("SyncDate"); #ifndef QT_NO_COP - QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); - e << app << cfg.readEntry( app ); + QCopEnvelope e( "QPE/Desktop", "syncDate(QString,QString)" ); + e << app << cfg.readEntry( app ); #endif - //qDebug("QPE/System sendSyncDate for %s: response %s", app.latin1(), - //cfg.readEntry( app ).latin1() ); + //odebug << "QPE/System sendSyncDate for " << app.latin1() << ": response " + // << cfg.readEntry( app ).latin1() << oendl; } else if ( msg == "setSyncDate(QString,QString)" ) { - QString app, date; - stream >> app >> date; - Config cfg( "qpe" ); - cfg.setGroup("SyncDate"); - cfg.writeEntry( app, date ); + QString app, date; + stream >> app >> date; + Config cfg( "qpe" ); + cfg.setGroup("SyncDate"); + cfg.writeEntry( app, date ); //odebug << "setSyncDate(QString,QString) " << app << " " << date << "" << oendl; } else if ( msg == "startSync(QString)" ) { - QString what; - stream >> what; - delete syncDialog; - syncDialog = new SyncDialog( this, what ); - syncDialog->show(); - connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); + QString what; + stream >> what; + delete syncDialog; + syncDialog = new SyncDialog( this, what ); + syncDialog->show(); + connect( syncDialog, SIGNAL(cancel()), SLOT(cancelSync()) ); } else if ( msg == "stopSync()") { - delete syncDialog; - syncDialog = 0; + delete syncDialog; + syncDialog = 0; } else if (msg == "restoreDone(QString)") { - docList->restoreDone(); + docList->restoreDone(); } else if ( msg == "getAllDocLinks()" ) { - docList->sendAllDocLinks(); + docList->sendAllDocLinks(); } @@ -454,27 +454,27 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) else if ( msg == "setMouseProto(QString)" ) { - QString mice; - stream >> mice; - setenv("QWS_MOUSE_PROTO",mice.latin1(),1); - qwsServer->openMouse(); + QString mice; + stream >> mice; + setenv("QWS_MOUSE_PROTO",mice.latin1(),1); + qwsServer->openMouse(); } else if ( msg == "setKeyboard(QString)" ) { - QString kb; - stream >> kb; - setenv("QWS_KEYBOARD",kb.latin1(),1); - qwsServer->openKeyboard(); + QString kb; + stream >> kb; + setenv("QWS_KEYBOARD",kb.latin1(),1); + qwsServer->openKeyboard(); } else if ( msg == "setKeyboardAutoRepeat(int,int)" ) { - int delay, period; - stream >> delay >> period; - qwsSetKeyboardAutoRepeat( delay, period ); - Config cfg( "qpe" ); - cfg.setGroup("Keyboard"); - cfg.writeEntry( "RepeatDelay", delay ); - cfg.writeEntry( "RepeatPeriod", period ); + int delay, period; + stream >> delay >> period; + qwsSetKeyboardAutoRepeat( delay, period ); + Config cfg( "qpe" ); + cfg.setGroup("Keyboard"); + cfg.writeEntry( "RepeatDelay", delay ); + cfg.writeEntry( "RepeatPeriod", period ); } else if ( msg == "setKeyboardLayout(QString)" ) { - QString kb; - stream >> kb; - setKeyboardLayout( kb ); - Config cfg( "qpe" ); - cfg.setGroup("Keyboard"); - cfg.writeEntry( "Layout", kb ); + QString kb; + stream >> kb; + setKeyboardLayout( kb ); + Config cfg( "qpe" ); + cfg.setGroup("Keyboard"); + cfg.writeEntry( "Layout", kb ); } else if ( msg == "autoStart(QString)" ) { @@ -531,12 +531,12 @@ void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) if ( msg == "reloadApps()" ) { - docList->reloadAppLnks(); + docList->reloadAppLnks(); } else if ( msg == "soundAlarm()" ) { - ServerApplication::soundAlarm(); + ServerApplication::soundAlarm(); } else if ( msg == "setLed(int,bool)" ) { - int led, status; - stream >> led >> status; + int led, status; + stream >> led >> status; QValueList <OLed> ll = ODevice::inst ( )-> ledList ( ); - if ( ll. count ( )) { + if ( ll. count ( )) { OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; @@ -562,3 +562,3 @@ bool Server::mkdir(const QString &localPath) if (fullDir.exists()) - return true; + return true; @@ -575,3 +575,3 @@ bool Server::mkdir(const QString &localPath) //odebug << "No seperators found in path " << localPath << "" << oendl; - checkedPath = QDir::currentDirPath(); + checkedPath = QDir::currentDirPath(); } @@ -579,21 +579,21 @@ bool Server::mkdir(const QString &localPath) while (checkedPath != localPath) { - // no more seperators found, use the local path - if (dirIndex == -1) - checkedPath = localPath; - else { - // the next directory to check - checkedPath = localPath.left(dirIndex) + "/"; - // advance the iterator; the next dir seperator - dirIndex = localPath.find(dirSeps, dirIndex+1); - } - - QDir checkDir(checkedPath); - if (!checkDir.exists()) { + // no more seperators found, use the local path + if (dirIndex == -1) + checkedPath = localPath; + else { + // the next directory to check + checkedPath = localPath.left(dirIndex) + "/"; + // advance the iterator; the next dir seperator + dirIndex = localPath.find(dirSeps, dirIndex+1); + } + + QDir checkDir(checkedPath); + if (!checkDir.exists()) { //odebug << "mkdir making dir " << checkedPath << "" << oendl; - if (!checkDir.mkdir(checkedPath)) { + if (!checkDir.mkdir(checkedPath)) { odebug << "Unable to make directory " << checkedPath << "" << oendl; - return FALSE; - } - } + return FALSE; + } + } @@ -611,25 +611,25 @@ void Server::startTransferServer() if ( !qcopBridge ) { - // start qcop bridge server - qcopBridge = new QCopBridge( 4243 ); - if ( qcopBridge->ok() ) { - // ... OK - connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), - this, SLOT(syncConnectionClosed(const QHostAddress&)) ); - } else { - delete qcopBridge; - qcopBridge = 0; - } + // start qcop bridge server + qcopBridge = new QCopBridge( 4243 ); + if ( qcopBridge->ok() ) { + // ... OK + connect( qcopBridge, SIGNAL(connectionClosed(const QHostAddress&)), + this, SLOT(syncConnectionClosed(const QHostAddress&)) ); + } else { + delete qcopBridge; + qcopBridge = 0; + } } if ( !transferServer ) { - // start transfer server - transferServer = new TransferServer( 4242 ); - if ( transferServer->ok() ) { - // ... OK - } else { - delete transferServer; - transferServer = 0; - } + // start transfer server + transferServer = new TransferServer( 4242 ); + if ( transferServer->ok() ) { + // ... OK + } else { + delete transferServer; + transferServer = 0; + } } if ( !transferServer || !qcopBridge ) - tid_xfer = startTimer( 2000 ); + tid_xfer = startTimer( 2000 ); } @@ -639,5 +639,5 @@ void Server::timerEvent( QTimerEvent *e ) if ( e->timerId() == tid_xfer ) { - killTimer( tid_xfer ); - tid_xfer = 0; - startTransferServer(); + killTimer( tid_xfer ); + tid_xfer = 0; + startTransferServer(); } @@ -646,7 +646,7 @@ void Server::timerEvent( QTimerEvent *e ) else if ( e->timerId() == tid_today ) { - QDate today = QDate::currentDate(); - if ( today != last_today_show ) { - last_today_show = today; - Config cfg("today"); - cfg.setGroup("Start"); + QDate today = QDate::currentDate(); + if ( today != last_today_show ) { + last_today_show = today; + Config cfg("today"); + cfg.setGroup("Start"); #ifndef QPE_DEFAULT_TODAY_MODE @@ -654,6 +654,6 @@ void Server::timerEvent( QTimerEvent *e ) #endif - if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { - QCopEnvelope env(Service::channel("today"),"raise()"); - } - } + if ( cfg.readEntry("Mode",QPE_DEFAULT_TODAY_MODE) == "Daily" ) { + QCopEnvelope env(Service::channel("today"),"raise()"); + } + } } @@ -683,5 +683,5 @@ void Server::pokeTimeMonitors() for (const char* ch = tms.first(); ch; ch=tms.next()) { - QString t = getenv("TZ"); - QCopEnvelope e(ch, "timeChange(QString)"); - e << t; + QString t = getenv("TZ"); + QCopEnvelope e(ch, "timeChange(QString)"); + e << t; } @@ -724,3 +724,3 @@ void Server::preloadApps() #ifndef QT_NO_COP - QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); + QCopEnvelope e("QPE/Application/"+(*it).local8Bit(), "enablePreload()"); #endif diff --git a/core/launcher/transferserver.cpp b/core/launcher/transferserver.cpp index 4b764e3..c3f936e 100644 --- a/core/launcher/transferserver.cpp +++ b/core/launcher/transferserver.cpp @@ -64,7 +64,7 @@ void TransferServer::authorizeConnections() while ( it.current() ) { - if ( !it.current()->verifyAuthorised() ) { - disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); - connections.removeRef( it.current() ); - } else - ++it; + if ( !it.current()->verifyAuthorised() ) { + disconnect( it.current(), SIGNAL(connectionClosed(ServerPI*)), this, SLOT( closed(ServerPI*)) ); + connections.removeRef( it.current() ); + } else + ++it; } @@ -106,5 +106,5 @@ QString SyncAuthentication::ownerName() if (QFile::exists(vfilename)) { - Contact c; - c = Contact::readVCard( vfilename )[0]; - return c.fullName(); + Contact c; + c = Contact::readVCard( vfilename )[0]; + return c.fullName(); } @@ -129,14 +129,14 @@ int SyncAuthentication::isAuthorized(QHostAddress peeraddress) Config cfg("Security"); - cfg.setGroup("Sync"); - // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); - uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); - - // QHostAddress allowed; - // allowed.setAddress(allowedstr); - // uint auth_peer = allowed.ip4Addr(); - uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); - uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined - ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); - - return (peeraddress.ip4Addr() & mask) == auth_peer; + cfg.setGroup("Sync"); + // QString allowedstr = cfg.readEntry("auth_peer","192.168.1.0"); + uint auth_peer = cfg.readNumEntry("auth_peer", 0xc0a80100); + + // QHostAddress allowed; + // allowed.setAddress(allowedstr); + // uint auth_peer = allowed.ip4Addr(); + uint auth_peer_bits = cfg.readNumEntry("auth_peer_bits", 24); + uint mask = auth_peer_bits >= 32 // shifting by 32 is not defined + ? 0xffffffff : (((1 << auth_peer_bits) - 1) << (32 - auth_peer_bits)); + + return (peeraddress.ip4Addr() & mask) == auth_peer; } @@ -163,3 +163,3 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( cpwd == "x" && spw ) - cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); + cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); @@ -168,3 +168,3 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( cpwd == cpassword ) - return TRUE; + return TRUE; #endif @@ -204,18 +204,18 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( password.isEmpty() ) { - if ( denials < 3 || now > lastdenial+600 ) { - QMessageBox unauth( - tr("Sync Connection"), - tr("<p>An unauthorized system is requesting access to this device." - "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " - "please upgrade or change the security setting to use IntelliSync." ), - QMessageBox::Warning, - QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, - 0, QString::null, TRUE, WStyle_StaysOnTop); - unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); - unauth.exec(); + if ( denials < 3 || now > lastdenial+600 ) { + QMessageBox unauth( + tr("Sync Connection"), + tr("<p>An unauthorized system is requesting access to this device." + "<p>If you are using a version of Qtopia Desktop older than 1.5.1, " + "please upgrade or change the security setting to use IntelliSync." ), + QMessageBox::Warning, + QMessageBox::Cancel, QMessageBox::NoButton, QMessageBox::NoButton, + 0, QString::null, TRUE, WStyle_StaysOnTop); + unauth.setButtonText(QMessageBox::Cancel, tr("Deny")); + unauth.exec(); - denials++; - lastdenial=now; - } - return FALSE; + denials++; + lastdenial=now; + } + return FALSE; @@ -234,55 +234,55 @@ bool SyncAuthentication::checkPassword( const QString& password ) if ( password.left(6) == "Qtopia" || password.left(6) == "rootme" ) { - Config cfg( "Security" ); - cfg.setGroup("Sync"); - QStringList pwds = cfg.readListEntry("Passwords",' '); - for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { + Config cfg( "Security" ); + cfg.setGroup("Sync"); + QStringList pwds = cfg.readListEntry("Passwords",' '); + for (QStringList::ConstIterator it=pwds.begin(); it!=pwds.end(); ++it) { #ifndef Q_OS_WIN32 - QString cpassword = QString::fromLocal8Bit( - crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); + QString cpassword = QString::fromLocal8Bit( + crypt( password.mid(8).local8Bit(), (*it).left(2).latin1() ) ); #else - // ### revise - QString cpassword(""); + // ### revise + QString cpassword(""); #endif - if ( *it == cpassword ) { - lock--; - return TRUE; - } - } - - // Unrecognized system. Be careful... - QMessageBox unrecbox( - tr("Sync Connection"), - tr( "<p>An unrecognized system is requesting access to this device." - "<p>If you have just initiated a Sync for the first time, this is normal."), - QMessageBox::Warning, - QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, - 0, QString::null, TRUE, WStyle_StaysOnTop); - unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); - unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); - - if ( (denials > 2 && now < lastdenial+600) - || unrecbox.exec() != QMessageBox::Yes) - { - denials++; - lastdenial=now; - lock--; - return FALSE; - } else { - const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; - char salt[2]; - salt[0]= salty[rand() % (sizeof(salty)-1)]; - salt[1]= salty[rand() % (sizeof(salty)-1)]; + if ( *it == cpassword ) { + lock--; + return TRUE; + } + } + + // Unrecognized system. Be careful... + QMessageBox unrecbox( + tr("Sync Connection"), + tr( "<p>An unrecognized system is requesting access to this device." + "<p>If you have just initiated a Sync for the first time, this is normal."), + QMessageBox::Warning, + QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, + 0, QString::null, TRUE, WStyle_StaysOnTop); + unrecbox.setButtonText(QMessageBox::Cancel, tr("Deny")); + unrecbox.setButtonText(QMessageBox::Yes, tr("Allow")); + + if ( (denials > 2 && now < lastdenial+600) + || unrecbox.exec() != QMessageBox::Yes) + { + denials++; + lastdenial=now; + lock--; + return FALSE; + } else { + const char salty[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/."; + char salt[2]; + salt[0]= salty[rand() % (sizeof(salty)-1)]; + salt[1]= salty[rand() % (sizeof(salty)-1)]; #ifndef Q_OS_WIN32 - QString cpassword = QString::fromLocal8Bit( - crypt( password.mid(8).local8Bit(), salt ) ); + QString cpassword = QString::fromLocal8Bit( + crypt( password.mid(8).local8Bit(), salt ) ); #else - //### revise - QString cpassword(""); + //### revise + QString cpassword(""); #endif - denials=0; - pwds.prepend(cpassword); - cfg.writeEntry("Passwords",pwds,' '); - lock--; - return TRUE; - } + denials=0; + pwds.prepend(cpassword); + cfg.writeEntry("Passwords",pwds,' '); + lock--; + return TRUE; + } } @@ -307,4 +307,4 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) if ( !SyncAuthentication::isAuthorized(peeraddress) ) { - state = Forbidden; - startTimer( 0 ); + state = Forbidden; + startTimer( 0 ); } else @@ -312,28 +312,28 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) { - connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); - connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); + connect( this, SIGNAL( readyRead() ), SLOT( read() ) ); + connect( this, SIGNAL( connectionClosed() ), SLOT( connectionClosed() ) ); - passiv = FALSE; - for( int i = 0; i < 4; i++ ) - wait[i] = FALSE; + passiv = FALSE; + for( int i = 0; i < 4; i++ ) + wait[i] = FALSE; - send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr - state = Wait_USER; + send( "220 Qtopia " QPE_VERSION " FTP Server" ); // No tr + state = Wait_USER; - dtp = new ServerDTP( this ); - connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); - connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); - connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); + dtp = new ServerDTP( this ); + connect( dtp, SIGNAL( completed() ), SLOT( dtpCompleted() ) ); + connect( dtp, SIGNAL( failed() ), SLOT( dtpFailed() ) ); + connect( dtp, SIGNAL( error(int) ), SLOT( dtpError(int) ) ); - directory = QDir::currentDirPath(); + directory = QDir::currentDirPath(); - static int p = 1024; + static int p = 1024; - while ( !serversocket || !serversocket->ok() ) { - delete serversocket; - serversocket = new ServerSocket( ++p, this ); - } - connect( serversocket, SIGNAL( newIncomming(int) ), - SLOT( newConnection(int) ) ); + while ( !serversocket || !serversocket->ok() ) { + delete serversocket; + serversocket = new ServerSocket( ++p, this ); + } + connect( serversocket, SIGNAL( newIncomming(int) ), + SLOT( newConnection(int) ) ); } @@ -354,4 +354,4 @@ bool ServerPI::verifyAuthorised() if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { - state = Forbidden; - return FALSE; + state = Forbidden; + return FALSE; } @@ -376,3 +376,3 @@ void ServerPI::read() while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } @@ -384,5 +384,5 @@ bool ServerPI::checkReadFile( const QString& file ) if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; @@ -397,5 +397,5 @@ bool ServerPI::checkWriteFile( const QString& file ) if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; @@ -404,4 +404,4 @@ bool ServerPI::checkWriteFile( const QString& file ) if ( fi.exists() ) - if ( !QFile( filename ).remove() ) - return FALSE; + if ( !QFile( filename ).remove() ) + return FALSE; return TRUE; @@ -423,3 +423,3 @@ void ServerPI::process( const QString& message ) if ( msg.count() >= 2 ) - arg = msg[1]; + arg = msg[1]; @@ -439,5 +439,5 @@ void ServerPI::process( const QString& message ) if ( cmd == "QUIT" ) { - send( "211 Good bye!" ); // No tr - close(); - return; + send( "211 Good bye!" ); // No tr + close(); + return; } @@ -446,3 +446,3 @@ void ServerPI::process( const QString& message ) if ( Connected == state ) - return; + return; @@ -451,9 +451,9 @@ void ServerPI::process( const QString& message ) - if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { - send( "530 Please login with USER and PASS" ); // No tr - return; - } - send( "331 User name ok, need password" ); // No tr - state = Wait_PASS; - return; + if ( cmd != "USER" || msg.count() < 2 || !SyncAuthentication::checkUser( arg ) ) { + send( "530 Please login with USER and PASS" ); // No tr + return; + } + send( "331 User name ok, need password" ); // No tr + state = Wait_PASS; + return; } @@ -463,9 +463,9 @@ void ServerPI::process( const QString& message ) - if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { - send( "530 Please login with USER and PASS" ); // No tr - return; - } - send( "230 User logged in, proceed" ); // No tr - state = Ready; - return; + if ( cmd != "PASS" || !SyncAuthentication::checkPassword( arg ) ) { + send( "530 Please login with USER and PASS" ); // No tr + return; + } + send( "230 User logged in, proceed" ); // No tr + state = Ready; + return; } @@ -476,3 +476,3 @@ void ServerPI::process( const QString& message ) if ( cmd != "STOR" ) - storFileSize = -1; + storFileSize = -1; @@ -480,4 +480,4 @@ void ServerPI::process( const QString& message ) if ( cmd == "ACCT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -487,10 +487,10 @@ void ServerPI::process( const QString& message ) - if ( !args.isEmpty() ) { - if ( directory.cd( args, TRUE ) ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( !args.isEmpty() ) { + if ( directory.cd( args, TRUE ) ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -499,6 +499,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "CDUP" ) { - if ( directory.cdUp() ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr + if ( directory.cdUp() ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr } @@ -507,4 +507,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SMNT" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -513,4 +513,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "REIN" ) { - // even wu-ftp does not support it - send( "502 Command not implemented" ); // No tr + // even wu-ftp does not support it + send( "502 Command not implemented" ); // No tr } @@ -523,6 +523,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PORT" ) { - if ( parsePort( arg ) ) - send( "200 Command okay" ); // No tr - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( parsePort( arg ) ) + send( "200 Command okay" ); // No tr + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -531,7 +531,7 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PASV" ) { - passiv = TRUE; - send( "227 Entering Passive Mode (" // No tr - + address().toString().replace( QRegExp( "\\." ), "," ) + "," - + QString::number( ( serversocket->port() ) >> 8 ) + "," - + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); + passiv = TRUE; + send( "227 Entering Passive Mode (" // No tr + + address().toString().replace( QRegExp( "\\." ), "," ) + "," + + QString::number( ( serversocket->port() ) >> 8 ) + "," + + QString::number( ( serversocket->port() ) & 0xFF ) +")" ); } @@ -540,6 +540,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "TYPE" ) { - if ( arg.upper() == "A" || arg.upper() == "I" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "A" || arg.upper() == "I" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -548,6 +548,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STRU" ) { - if ( arg.upper() == "F" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "F" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -556,6 +556,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "MODE" ) { - if ( arg.upper() == "S" ) - send( "200 Command okay" ); // No tr - else - send( "504 Command not implemented for that parameter" ); // No tr + if ( arg.upper() == "S" ) + send( "200 Command okay" ); // No tr + else + send( "504 Command not implemented for that parameter" ); // No tr } @@ -568,11 +568,11 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RETR" ) - if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) - || backupRestoreGzip( absFilePath( args ) ) ) { - send( "150 File status okay" ); // No tr - sendFile( absFilePath( args ) ); - } - else { + if ( !args.isEmpty() && checkReadFile( absFilePath( args ) ) + || backupRestoreGzip( absFilePath( args ) ) ) { + send( "150 File status okay" ); // No tr + sendFile( absFilePath( args ) ); + } + else { odebug << "550 Requested action not taken" << oendl; - send( "550 Requested action not taken" ); // No tr - } + send( "550 Requested action not taken" ); // No tr + } @@ -580,8 +580,8 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STOR" ) - if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { - send( "150 File status okay" ); // No tr - retrieveFile( absFilePath( args ) ); - } - else - send( "550 Requested action not taken" ); // No tr + if ( !args.isEmpty() && checkWriteFile( absFilePath( args ) ) ) { + send( "150 File status okay" ); // No tr + retrieveFile( absFilePath( args ) ); + } + else + send( "550 Requested action not taken" ); // No tr @@ -589,3 +589,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STOU" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -594,3 +594,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "APPE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -599,4 +599,4 @@ void ServerPI::process( const QString& message ) else if ( cmd == "ALLO" ) { - storFileSize = args.toInt(); - send( "200 Command okay" ); // No tr + storFileSize = args.toInt(); + send( "200 Command okay" ); // No tr } @@ -605,3 +605,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "REST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -610,14 +610,14 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RNFR" ) { - renameFrom = QString::null; - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QFile file( absFilePath( args ) ); - if ( file.exists() ) { - send( "350 File exists, ready for destination name" ); // No tr - renameFrom = absFilePath( args ); - } - else - send( "550 Requested action not taken" ); // No tr - } + renameFrom = QString::null; + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QFile file( absFilePath( args ) ); + if ( file.exists() ) { + send( "350 File exists, ready for destination name" ); // No tr + renameFrom = absFilePath( args ); + } + else + send( "550 Requested action not taken" ); // No tr + } } @@ -626,13 +626,13 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RNTO" ) { - if ( lastCommand != "RNFR" ) - send( "503 Bad sequence of commands" ); // No tr - else if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QDir dir( absFilePath( args ) ); - if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + if ( lastCommand != "RNFR" ) + send( "503 Bad sequence of commands" ); // No tr + else if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QDir dir( absFilePath( args ) ); + if ( dir.rename( renameFrom, absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -641,7 +641,7 @@ void ServerPI::process( const QString& message ) else if ( cmd.contains( "ABOR" ) ) { - dtp->close(); - if ( dtp->dtpMode() != ServerDTP::Idle ) - send( "426 Connection closed; transfer aborted" ); // No tr - else - send( "226 Closing data connection" ); // No tr + dtp->close(); + if ( dtp->dtpMode() != ServerDTP::Idle ) + send( "426 Connection closed; transfer aborted" ); // No tr + else + send( "226 Closing data connection" ); // No tr } @@ -650,14 +650,14 @@ void ServerPI::process( const QString& message ) else if ( cmd == "DELE" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QFile file( absFilePath( args ) ) ; - if ( file.remove() ) { - send( "250 Requested file action okay, completed" ); // No tr - QCopEnvelope e("QPE/System", "linkChanged(QString)" ); - e << file.name(); - } else { - send( "550 Requested action not taken" ); // No tr - } - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QFile file( absFilePath( args ) ) ; + if ( file.remove() ) { + send( "250 Requested file action okay, completed" ); // No tr + QCopEnvelope e("QPE/System", "linkChanged(QString)" ); + e << file.name(); + } else { + send( "550 Requested action not taken" ); // No tr + } + } } @@ -666,11 +666,11 @@ void ServerPI::process( const QString& message ) else if ( cmd == "RMD" ) { - if ( args.isEmpty() ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - QDir dir; - if ( dir.rmdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed" ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + if ( args.isEmpty() ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + QDir dir; + if ( dir.rmdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed" ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -679,13 +679,13 @@ void ServerPI::process( const QString& message ) else if ( cmd == "MKD" ) { - if ( args.isEmpty() ) { + if ( args.isEmpty() ) { odebug << " Error: no arg" << oendl; - send( "500 Syntax error, command unrecognized" ); // No tr - } - else { - QDir dir; - if ( dir.mkdir( absFilePath( args ), TRUE ) ) - send( "250 Requested file action okay, completed." ); // No tr - else - send( "550 Requested action not taken" ); // No tr - } + send( "500 Syntax error, command unrecognized" ); // No tr + } + else { + QDir dir; + if ( dir.mkdir( absFilePath( args ), TRUE ) ) + send( "250 Requested file action okay, completed." ); // No tr + else + send( "550 Requested action not taken" ); // No tr + } } @@ -694,3 +694,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "PWD" ) { - send( "257 \"" + directory.path() +"\"" ); + send( "257 \"" + directory.path() +"\"" ); } @@ -699,6 +699,6 @@ void ServerPI::process( const QString& message ) else if ( cmd == "LIST" ) { - if ( sendList( absFilePath( args ) ) ) - send( "150 File status okay" ); // No tr - else - send( "500 Syntax error, command unrecognized" ); // No tr + if ( sendList( absFilePath( args ) ) ) + send( "150 File status okay" ); // No tr + else + send( "500 Syntax error, command unrecognized" ); // No tr } @@ -707,28 +707,28 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SIZE" ) { - QString filePath = absFilePath( args ); - QFileInfo fi( filePath ); - bool gzipfile = backupRestoreGzip( filePath ); - if ( !fi.exists() && !gzipfile ) - send( "500 Syntax error, command unrecognized" ); // No tr - else { - if ( !gzipfile ) - send( "213 " + QString::number( fi.size() ) ); - else { - Process duproc( QString("du") ); - duproc.addArgument("-s"); - QString in, out; - if ( !duproc.exec(in, out) ) { + QString filePath = absFilePath( args ); + QFileInfo fi( filePath ); + bool gzipfile = backupRestoreGzip( filePath ); + if ( !fi.exists() && !gzipfile ) + send( "500 Syntax error, command unrecognized" ); // No tr + else { + if ( !gzipfile ) + send( "213 " + QString::number( fi.size() ) ); + else { + Process duproc( QString("du") ); + duproc.addArgument("-s"); + QString in, out; + if ( !duproc.exec(in, out) ) { odebug << "du process failed; just sending back 1K" << oendl; - send( "213 1024"); - } - else { - QString size = out.left( out.find("\t") ); - int guess = size.toInt()/5; - if ( filePath.contains("doc") ) // No tr - guess *= 1000; + send( "213 1024"); + } + else { + QString size = out.left( out.find("\t") ); + int guess = size.toInt()/5; + if ( filePath.contains("doc") ) // No tr + guess *= 1000; odebug << "sending back gzip guess of " << guess << "" << oendl; - send( "213 " + QString::number(guess) ); - } - } - } + send( "213 " + QString::number(guess) ); + } + } + } } @@ -736,3 +736,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "NLST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -741,3 +741,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SITE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -746,3 +746,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "SYST" ) { - send( "215 UNIX Type: L8" ); // No tr + send( "215 UNIX Type: L8" ); // No tr } @@ -751,3 +751,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "STAT" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -756,3 +756,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "HELP" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } @@ -761,3 +761,3 @@ void ServerPI::process( const QString& message ) else if ( cmd == "NOOP" ) { - send( "200 Command okay" ); // No tr + send( "200 Command okay" ); // No tr } @@ -766,3 +766,3 @@ void ServerPI::process( const QString& message ) else - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr @@ -774,3 +774,3 @@ bool ServerPI::backupRestoreGzip( const QString &file ) return (file.find( "backup" ) != -1 && // No tr - file.findRev( ".tgz" ) == (int)file.length()-4 ); + file.findRev( ".tgz" ) == (int)file.length()-4 ); } @@ -783,4 +783,3 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) targets = info.dirPath( TRUE ); - qDebug("ServerPI::backupRestoreGzip for %s = %s", file.latin1(), - targets.join(" ").latin1() ); + odebug << "ServerPI::backupRestoreGzip for " << file.latin1() << " = " << targets.join(" ").latin1() << oendl; return true; @@ -793,6 +792,6 @@ void ServerPI::sendFile( const QString& file ) if ( passiv ) { - wait[SendFile] = TRUE; - waitfile = file; - if ( waitsocket ) - newConnection( waitsocket ); + wait[SendFile] = TRUE; + waitfile = file; + if ( waitsocket ) + newConnection( waitsocket ); } @@ -801,3 +800,3 @@ void ServerPI::sendFile( const QString& file ) if ( backupRestoreGzip( file, targets ) ) - dtp->sendGzipFile( file, targets, peeraddress, peerport ); + dtp->sendGzipFile( file, targets, peeraddress, peerport ); else dtp->sendFile( file, peeraddress, peerport ); @@ -809,6 +808,6 @@ void ServerPI::retrieveFile( const QString& file ) if ( passiv ) { - wait[RetrieveFile] = TRUE; - waitfile = file; - if ( waitsocket ) - newConnection( waitsocket ); + wait[RetrieveFile] = TRUE; + waitfile = file; + if ( waitsocket ) + newConnection( waitsocket ); } @@ -817,5 +816,5 @@ void ServerPI::retrieveFile( const QString& file ) if ( backupRestoreGzip( file, targets ) ) - dtp->retrieveGzipFile( file, peeraddress, peerport ); + dtp->retrieveGzipFile( file, peeraddress, peerport ); else - dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); + dtp->retrieveFile( file, peeraddress, peerport, storFileSize ); } @@ -830,3 +829,3 @@ bool ServerPI::parsePort( const QString& pp ) peeraddress = QHostAddress( ( p[0].toInt() << 24 ) + ( p[1].toInt() << 16 ) + - ( p[2].toInt() << 8 ) + p[3].toInt() ); + ( p[2].toInt() << 8 ) + p[3].toInt() ); peerport = ( p[4].toInt() << 8 ) + p[5].toInt(); @@ -839,7 +838,7 @@ void ServerPI::dtpCompleted() if ( dtp->dtpMode() == ServerDTP::RetrieveFile ) { - QString fn = dtp->fileName(); - if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { - QCopEnvelope e("QPE/System", "linkChanged(QString)" ); - e << fn; - } + QString fn = dtp->fileName(); + if ( fn.right(8)==".desktop" && fn.find("/Documents/")>=0 ) { + QCopEnvelope e("QPE/System", "linkChanged(QString)" ); + e << fn; + } } @@ -872,3 +871,3 @@ bool ServerPI::sendList( const QString& arg ) if ( !buffer.open( IO_WriteOnly ) ) - return FALSE; + return FALSE; @@ -878,3 +877,3 @@ bool ServerPI::sendList( const QString& arg ) if ( fn.isEmpty() ) - fn = directory.path(); + fn = directory.path(); @@ -885,3 +884,3 @@ bool ServerPI::sendList( const QString& arg ) if ( fi.isFile() ) { - ts << fileListing( &fi ) << endl; + ts << fileListing( &fi ) << endl; } @@ -890,26 +889,26 @@ bool ServerPI::sendList( const QString& arg ) else if ( fi.isDir() ) { - QDir dir( fn ); - const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); + QDir dir( fn ); + const QFileInfoList *list = dir.entryInfoList( QDir::All | QDir::Hidden ); - QFileInfoListIterator it( *list ); - QFileInfo *info; + QFileInfoListIterator it( *list ); + QFileInfo *info; - unsigned long total = 0; - while ( ( info = it.current() ) ) { - if ( info->fileName() != "." && info->fileName() != ".." ) - total += info->size(); - ++it; - } + unsigned long total = 0; + while ( ( info = it.current() ) ) { + if ( info->fileName() != "." && info->fileName() != ".." ) + total += info->size(); + ++it; + } - ts << "total " << QString::number( total / 1024 ) << endl; // No tr + ts << "total " << QString::number( total / 1024 ) << endl; // No tr - it.toFirst(); - while ( ( info = it.current() ) ) { - if ( info->fileName() == "." || info->fileName() == ".." ) { - ++it; - continue; - } - ts << fileListing( info ) << endl; - ++it; - } + it.toFirst(); + while ( ( info = it.current() ) ) { + if ( info->fileName() == "." || info->fileName() == ".." ) { + ++it; + continue; + } + ts << fileListing( info ) << endl; + ++it; + } } @@ -917,9 +916,9 @@ bool ServerPI::sendList( const QString& arg ) if ( passiv ) { - waitarray = buffer.buffer(); - wait[SendByteArray] = TRUE; - if ( waitsocket ) - newConnection( waitsocket ); + waitarray = buffer.buffer(); + wait[SendByteArray] = TRUE; + if ( waitsocket ) + newConnection( waitsocket ); } else - dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); + dtp->sendByteArray( buffer.buffer(), peeraddress, peerport ); return TRUE; @@ -934,7 +933,7 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( info->isDir() ) - s += "d"; + s += "d"; else if ( info->isSymLink() ) - s += "l"; + s += "l"; else - s += "-"; + s += "-"; @@ -947,3 +946,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( info->isDir() ) - subdirs = 2; + subdirs = 2; // FIXME : this is to slow @@ -957,3 +956,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( o.isEmpty() ) - o = QString::number(info->ownerId()); + o = QString::number(info->ownerId()); s += o.leftJustify( 8, ' ', TRUE ) + " "; @@ -963,3 +962,3 @@ QString ServerPI::fileListing( QFileInfo *info ) if ( g.isEmpty() ) - g = QString::number(info->groupId()); + g = QString::number(info->groupId()); s += g.leftJustify( 8, ' ', TRUE ) + " "; @@ -973,5 +972,5 @@ QString ServerPI::fileListing( QFileInfo *info ) s += date.monthName( date.month() ) + " " - + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " - + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" - + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; + + QString::number( date.day() ).rightJustify( 2, ' ', TRUE ) + " " + + QString::number( time.hour() ).rightJustify( 2, '0', TRUE ) + ":" + + QString::number( time.minute() ).rightJustify( 2,'0', TRUE ) + " "; @@ -1022,8 +1021,8 @@ void ServerPI::newConnection( int socket ) if ( wait[SendFile] ) { - QStringList targets; - if ( backupRestoreGzip( waitfile, targets ) ) - dtp->sendGzipFile( waitfile, targets ); - else - dtp->sendFile( waitfile ); - dtp->setSocket( socket ); + QStringList targets; + if ( backupRestoreGzip( waitfile, targets ) ) + dtp->sendGzipFile( waitfile, targets ); + else + dtp->sendFile( waitfile ); + dtp->setSocket( socket ); } @@ -1032,5 +1031,5 @@ void ServerPI::newConnection( int socket ) if ( backupRestoreGzip( waitfile ) ) - dtp->retrieveGzipFile( waitfile ); + dtp->retrieveGzipFile( waitfile ); else - dtp->retrieveFile( waitfile, storFileSize ); + dtp->retrieveFile( waitfile, storFileSize ); dtp->setSocket( socket ); @@ -1038,4 +1037,4 @@ void ServerPI::newConnection( int socket ) else if ( wait[SendByteArray] ) { - dtp->sendByteArray( waitarray ); - dtp->setSocket( socket ); + dtp->sendByteArray( waitarray ); + dtp->setSocket( socket ); } @@ -1043,10 +1042,10 @@ void ServerPI::newConnection( int socket ) odebug << "retrieve byte array" << oendl; - dtp->retrieveByteArray(); - dtp->setSocket( socket ); + dtp->retrieveByteArray(); + dtp->setSocket( socket ); } else - waitsocket = socket; + waitsocket = socket; for( int i = 0; i < 4; i++ ) - wait[i] = FALSE; + wait[i] = FALSE; } @@ -1059,3 +1058,3 @@ QString ServerPI::absFilePath( const QString& file ) if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; @@ -1090,5 +1089,5 @@ ServerDTP::ServerDTP( QObject *parent, const char* name) connect( retrieveTargzProc, SIGNAL( processExited() ), - SIGNAL( completed() ) ); + SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } @@ -1099,10 +1098,10 @@ ServerDTP::~ServerDTP() if ( RetrieveFile == mode && file.isOpen() ) { - // We're being shutdown before the client closed. - file.close(); - if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { + // We're being shutdown before the client closed. + file.close(); + if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { odebug << "STOR incomplete" << oendl; - file.remove(); - } + file.remove(); + } } else { - file.close(); + file.close(); } @@ -1142,6 +1141,6 @@ void ServerDTP::connected() if ( bytesToWrite() <= block_size && !file.atEnd() ) { - QCString s; - s.resize( block_size ); - int bytes = file.readBlock( s.data(), block_size ); - writeBlock( s.data(), bytes ); + QCString s; + s.resize( block_size ); + int bytes = file.readBlock( s.data(), block_size ); + writeBlock( s.data(), bytes ); } @@ -1160,3 +1159,3 @@ void ServerDTP::connected() qWarning("Error starting %s", - createTargzProc->arguments().join(" ").latin1()); + createTargzProc->arguments().join(" ").latin1()); break; @@ -1214,6 +1213,6 @@ void ServerDTP::connectionClosed() if ( SendFile == mode ) { - if ( bytes_written == file.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == file.size() ) + emit completed(); + else + emit failed(); } @@ -1222,6 +1221,6 @@ void ServerDTP::connectionClosed() else if ( SendBuffer == mode ) { - if ( bytes_written == buf.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == buf.size() ) + emit completed(); + else + emit failed(); } @@ -1230,10 +1229,10 @@ void ServerDTP::connectionClosed() else if ( RetrieveFile == mode ) { - file.close(); - if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { + file.close(); + if ( recvFileSize >= 0 && (int)file.size() != recvFileSize ) { odebug << "STOR incomplete" << oendl; - file.remove(); - emit failed(); - } else { - emit completed(); - } + file.remove(); + emit failed(); + } else { + emit completed(); + } } @@ -1242,4 +1241,4 @@ void ServerDTP::connectionClosed() odebug << "Done writing ungzip file; closing input" << oendl; - retrieveTargzProc->flushStdin(); - retrieveTargzProc->closeStdin(); + retrieveTargzProc->flushStdin(); + retrieveTargzProc->closeStdin(); } @@ -1248,4 +1247,4 @@ void ServerDTP::connectionClosed() else if ( RetrieveBuffer == mode ) { - buf.close(); - emit completed(); + buf.close(); + emit completed(); } @@ -1262,14 +1261,14 @@ void ServerDTP::bytesWritten( int bytes ) - if ( bytes_written == file.size() ) { + if ( bytes_written == file.size() ) { // odebug << "Debug: Sending complete: " << file.size() << " bytes" << oendl; - file.close(); - emit completed(); - mode = Idle; - } - else if( !file.atEnd() ) { - QCString s; - s.resize( block_size ); - int bytes = file.readBlock( s.data(), block_size ); - writeBlock( s.data(), bytes ); - } + file.close(); + emit completed(); + mode = Idle; + } + else if( !file.atEnd() ) { + QCString s; + s.resize( block_size ); + int bytes = file.readBlock( s.data(), block_size ); + writeBlock( s.data(), bytes ); + } } @@ -1279,7 +1278,7 @@ void ServerDTP::bytesWritten( int bytes ) - if ( bytes_written == buf.size() ) { + if ( bytes_written == buf.size() ) { // odebug << "Debug: Sending complete: " << buf.size() << " bytes" << oendl; - emit completed(); - mode = Idle; - } + emit completed(); + mode = Idle; + } } @@ -1291,15 +1290,15 @@ void ServerDTP::readyRead() if ( RetrieveFile == mode ) { - QCString s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - file.writeBlock( s.data(), s.size() ); + QCString s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + file.writeBlock( s.data(), s.size() ); } else if ( RetrieveGzipFile == mode ) { - if ( !retrieveTargzProc->isRunning() ) - retrieveTargzProc->start(); + if ( !retrieveTargzProc->isRunning() ) + retrieveTargzProc->start(); - QByteArray s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - retrieveTargzProc->writeToStdin( s ); + QByteArray s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + retrieveTargzProc->writeToStdin( s ); odebug << "wrote " << s.size() << " bytes to ungzip " << oendl; @@ -1308,6 +1307,6 @@ void ServerDTP::readyRead() else if ( RetrieveBuffer == mode ) { - QCString s; - s.resize( bytesAvailable() ); - readBlock( s.data(), bytesAvailable() ); - buf.writeBlock( s.data(), s.size() ); + QCString s; + s.resize( bytesAvailable() ); + readBlock( s.data(), bytesAvailable() ); + buf.writeBlock( s.data(), s.size() ); } @@ -1328,3 +1327,3 @@ void ServerDTP::targzDone() disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + this, SLOT( writeTargzBlock() ) ); } @@ -1345,4 +1344,4 @@ void ServerDTP::sendFile( const QString fn ) void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets, - const QHostAddress& host, Q_UINT16 port ) + const QStringList &archiveTargets, + const QHostAddress& host, Q_UINT16 port ) { @@ -1353,3 +1352,3 @@ void ServerDTP::sendGzipFile( const QString &fn, void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets ) + const QStringList &archiveTargets ) { @@ -1364,3 +1363,3 @@ void ServerDTP::sendGzipFile( const QString &fn, connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); + SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); } @@ -1390,3 +1389,3 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } |