From f8add41b2e0b0371754521b44d95f87fa70a6ff2 Mon Sep 17 00:00:00 2001 From: ar Date: Sun, 02 May 2004 16:35:53 +0000 Subject: - convert qDebug to odebug --- (limited to 'core') 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 @@ -387,7 +387,7 @@ void DocumentList::DiffAppLnks() ++it1; } 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 ); } ++it2; @@ -403,7 +403,7 @@ void DocumentList::DiffAppLnks() ++it2; } 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 ); } @@ -422,10 +422,10 @@ void DocumentList::storageChanged() t.start(); DiffAppLnks(); // 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 // Could be a bit more intelligent and somehow work out which // mtab entry has changed and then only scan that and add and remove 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 @@ -133,32 +133,32 @@ public: #if defined(QT_QPROCESS_DEBUG) odebug << "QProc: Constructor for pid " << pid << " and QProcess " << process << "" << oendl; #endif - socketStdin = 0; - socketStdout = 0; - socketStderr = 0; + socketStdin = 0; + socketStdout = 0; + socketStderr = 0; } ~QProc() { #if defined(QT_QPROCESS_DEBUG) odebug << "QProc: Destructor for pid " << pid << " and QProcess " << process << "" << oendl; #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 ); } pid_t pid; @@ -208,17 +208,17 @@ QProcessManager::QProcessManager() // something happened. This is done to get the processing in sync with the // event reporting. if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, sigchldFd ) ) { - sigchldFd[0] = 0; - sigchldFd[1] = 0; + sigchldFd[0] = 0; + sigchldFd[1] = 0; } else { #if defined(QT_QPROCESS_DEBUG) odebug << "QProcessManager: install socket notifier (" << sigchldFd[1] << ")" << oendl; #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 ); } // install a SIGCHLD handler and ignore SIGPIPE @@ -241,10 +241,10 @@ QProcessManager::QProcessManager() odebug << "QProcessManager: install a SIGPIPE handler (SIG_IGN)" << oendl; #endif /* - 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. */ act.sa_handler = qt_C_sigpipeHnd; sigemptyset( &(act.sa_mask) ); @@ -259,9 +259,9 @@ QProcessManager::~QProcessManager() delete procList; if ( sigchldFd[0] != 0 ) - ::close( sigchldFd[0] ); + ::close( sigchldFd[0] ); if ( sigchldFd[1] != 0 ) - ::close( sigchldFd[1] ); + ::close( sigchldFd[1] ); // restore SIGCHLD handler #if defined(QT_QPROCESS_DEBUG) @@ -297,16 +297,16 @@ void QProcessManager::remove( QProc *p ) void QProcessManager::cleanup() { if ( procList->count() == 0 ) { - QTimer::singleShot( 0, this, SLOT(removeMe()) ); + QTimer::singleShot( 0, this, SLOT(removeMe()) ); } } 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; } } @@ -322,53 +322,53 @@ void QProcessManager::sigchldHnd( int fd ) bool removeProc; proc = procList->first(); 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) odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess available)" << oendl; #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) odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stdout" << oendl; #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) odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): reading " << nbytes << " bytes of pending data on stderr" << oendl; #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) odebug << "QProcessManager::sigchldHnd() (PID: " << proc->pid << "): process exited (QProcess not available)" << oendl; #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(); } } @@ -406,15 +406,15 @@ QProcessPrivate::~QProcessPrivate() #endif 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; } while ( !stdinBuf.isEmpty() ) { - delete stdinBuf.dequeue(); + delete stdinBuf.dequeue(); } delete notifierStdin; delete notifierStdout; @@ -429,18 +429,18 @@ QProcessPrivate::~QProcessPrivate() 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 ); + } } } @@ -448,8 +448,8 @@ void QProcessPrivate::newProc( pid_t pid, QProcess *process ) { proc = new QProc( pid, process ); if ( procManager == 0 ) { - procManager = new QProcessManager; - qprocess_cleanup_procmanager.add( &procManager ); + procManager = new QProcessManager; + qprocess_cleanup_procmanager.add( &procManager ); } // the QProcessManager takes care of deleting the QProc instances procManager->append( proc ); @@ -463,9 +463,9 @@ void QProcessPrivate::newProc( pid_t pid, QProcess *process ) QT_SIGNAL_RETTYPE qt_C_sigchldHnd( QT_SIGNAL_ARGS ) { if ( QProcessPrivate::procManager == 0 ) - return; + return; if ( QProcessPrivate::procManager->sigchldFd[0] == 0 ) - return; + return; char a = 1; ::write( QProcessPrivate::procManager->sigchldFd[0], &a, sizeof(a) ); @@ -508,9 +508,9 @@ void QProcess::reset() 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 ); } return &d->bufStdout; } @@ -518,9 +518,9 @@ QByteArray* QProcess::bufStdout() 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 ); } return &d->bufStderr; } @@ -529,11 +529,11 @@ void QProcess::consumeBufStdout( int consume ) { uint n = d->bufStdout.size(); 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; } } @@ -541,11 +541,11 @@ void QProcess::consumeBufStderr( int consume ) { uint n = d->bufStderr.size(); 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; } } @@ -608,22 +608,22 @@ bool QProcess::start( QStringList *env ) // open sockets for piping 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; } // the following pipe is only used to determine if the process could be // started int fd[2]; 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; } // construct the arguments for exec @@ -631,164 +631,164 @@ bool QProcess::start( QStringList *env ) const char** arglist = new const char*[ _arguments.count() + 1 ]; int i = 0; 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) odebug << "QProcess::start(): arg " << i << " = " << arglist[i] << "" << oendl; #endif - i++; + i++; } arglist[i] = 0; // Must make sure signal handlers are installed before exec'ing // in case the process exits quickly. if ( d->procManager == 0 ) { - d->procManager = new QProcessManager; - qprocess_cleanup_procmanager.add( &d->procManager ); + d->procManager = new QProcessManager; + qprocess_cleanup_procmanager.add( &d->procManager ); } // fork and exec QApplication::flushX(); pid_t pid = fork(); 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; } // test if exec was successful 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] ); } d->newProc( pid, this ); 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 ); } // cleanup and return @@ -801,18 +801,18 @@ error: odebug << "QProcess::start(): error starting process" << oendl; #endif 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] ); } ::close( fd[0] ); ::close( fd[1] ); @@ -835,7 +835,7 @@ error: void QProcess::tryTerminate() const { if ( d->proc != 0 ) - ::kill( d->proc->pid, SIGTERM ); + ::kill( d->proc->pid, SIGTERM ); } /*! @@ -865,7 +865,7 @@ void QProcess::tryTerminate() const void QProcess::kill() const { if ( d->proc != 0 ) - ::kill( d->proc->pid, SIGKILL ); + ::kill( d->proc->pid, SIGKILL ); } /*! @@ -879,24 +879,24 @@ bool QProcess::isRunning() const #if defined(QT_QPROCESS_DEBUG) odebug << "QProcess::isRunning(): FALSE (already computed)" << oendl; #endif - return FALSE; + return FALSE; } if ( d->proc == 0 ) - return FALSE; + return FALSE; int status; if ( ::waitpid( d->proc->pid, &status, WNOHANG ) == d->proc->pid ) { - // 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) odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): FALSE" << oendl; #endif - return FALSE; + return FALSE; } #if defined(QT_QPROCESS_DEBUG) odebug << "QProcess::isRunning() (PID: " << d->proc->pid << "): TRUE" << oendl; @@ -923,7 +923,7 @@ void QProcess::writeToStdin( const QByteArray& buf ) #endif d->stdinBuf.enqueue( new QByteArray(buf) ); if ( d->notifierStdin != 0 ) - d->notifierStdin->setEnabled( TRUE ); + d->notifierStdin->setEnabled( TRUE ); } @@ -938,20 +938,20 @@ void QProcess::writeToStdin( const QByteArray& buf ) 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) odebug << "QProcess::closeStdin(): stdin (" << d->proc->socketStdin << ") closed" << oendl; #endif - d->proc->socketStdin = 0; + d->proc->socketStdin = 0; } } @@ -963,27 +963,27 @@ void QProcess::closeStdin() 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; } #if defined(QT_QPROCESS_DEBUG) odebug << "QProcess::socketRead(): " << fd << "" << oendl; #endif if ( fd == 0 ) - return; + return; const int bufsize = 4096; QByteArray *buffer = 0; uint oldSize; int n; 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; } // read data @@ -991,57 +991,57 @@ void QProcess::socketRead( int fd ) buffer->resize( oldSize + bufsize ); n = ::read( fd, buffer->data()+oldSize, bufsize ); 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) odebug << "QProcess::socketRead(): stdout (" << fd << ") closed" << oendl; #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) odebug << "QProcess::socketRead(): stderr (" << fd << ") closed" << oendl; #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; + } } // read all data that is available 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 ); } d->socketReadCalled = TRUE; if ( fd == d->proc->socketStdout ) { #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(); } d->socketReadCalled = FALSE; } @@ -1054,25 +1054,25 @@ void QProcess::socketRead( int fd ) 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; } #if defined(QT_QPROCESS_DEBUG) odebug << "QProcess::socketWrite(): write to stdin (" << fd << ")" << oendl; #endif 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 ); } } @@ -1105,15 +1105,15 @@ void QProcess::setIoRedirection( bool value ) { ioRedirection = 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 ); } } @@ -1152,21 +1152,21 @@ void QProcess::setWroteStdinConnected( bool value ) QProcess::PID QProcess::processIdentifier() { if ( d->proc == 0 ) - return -1; + return -1; return d->proc->pid; } int QProcess::priority() const { if ( d->proc ) - return getpriority(PRIO_PROCESS,d->proc->pid); + return getpriority(PRIO_PROCESS,d->proc->pid); return 0; } 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 @@ -5,6 +5,7 @@ #include #include +#include using namespace Opie::Core; @@ -12,36 +13,36 @@ 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 ); } @@ -50,14 +51,14 @@ OpieScreenSaver::OpieScreenSaver ( ) */ 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 ); } @@ -70,52 +71,52 @@ void OpieScreenSaver::restore() */ 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; } @@ -134,41 +135,41 @@ bool OpieScreenSaver::save( int level ) */ 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 ); } @@ -180,15 +181,15 @@ void OpieScreenSaver::setIntervals ( int dim, int lightoff, int suspend ) */ void OpieScreenSaver::setInterval ( int interval ) { - setIntervals ( -1, -1, interval ); + setIntervals ( -1, -1, interval ); } 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; } @@ -203,39 +204,40 @@ void OpieScreenSaver::setMode ( int mode ) */ 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); } @@ -250,25 +252,25 @@ void OpieScreenSaver::setBacklight ( int bright ) */ 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; + } } @@ -278,25 +280,27 @@ void OpieScreenSaver::setBacklightInternal ( int bright ) */ 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 ); } @@ -305,10 +309,10 @@ void OpieScreenSaver::timerEvent ( QTimerEvent * ) */ 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; + } } @@ -317,12 +321,12 @@ void OpieScreenSaver::setDisplayState ( bool on ) */ 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 @@ -78,16 +78,16 @@ static QWidget *calibrate(bool) #define FACTORY(T) \ 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; \ } @@ -107,14 +107,14 @@ static Global::Command builtins[] = { /* FIXME defines need to be defined*/ #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 }, }; @@ -166,11 +166,11 @@ Server::Server() : QCopChannel *channel = new QCopChannel("QPE/System", this); connect(channel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); + this, SLOT(systemMsg(const QCString&,const QByteArray&)) ); QCopChannel *tbChannel = new QCopChannel( "QPE/TaskBar", this ); connect( tbChannel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); + this, SLOT(receiveTaskBar(const QCString&,const QByteArray&)) ); connect( qApp, SIGNAL(prepareForRestart()), this, SLOT(terminateServers()) ); connect( qApp, SIGNAL(timeChanged()), this, SLOT(pokeTimeMonitors()) ); @@ -202,20 +202,20 @@ static bool hasVisibleWindow(const QString& clientname, bool partial) const QList &list = qwsServer->clientWindows(); QWSWindow* w; for (QListIterator 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; + } + } } #endif return FALSE; @@ -226,9 +226,9 @@ void Server::activate(const ODeviceButton* button, bool held) Global::terminateBuiltin("calibrate"); // No tr OQCopMessage om; if ( held ) { - om = button->heldAction(); + om = button->heldAction(); } else { - om = button->pressedAction(); + om = button->pressedAction(); } if ( om.channel() != "ignore" ) @@ -239,16 +239,16 @@ void Server::activate(const ODeviceButton* button, bool held) /* ### FIXME */ #if 0 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(); } #endif } @@ -292,14 +292,14 @@ bool Server::setKeyboardLayout( const QString &kb ) QIntDict *om = 0; if ( kb == "us101" ) { // No tr - om = 0; + om = 0; } else if ( kb == "jp109" ) { - om = new QIntDict(37); - const KeyOverride *k = jp109keys; - while ( k->scan_code ) { - om->insert( k->scan_code, &k->map ); - k++; - } + om = new QIntDict(37); + const KeyOverride *k = jp109keys; + while ( k->scan_code ) { + om->insert( k->scan_code, &k->map ); + k++; + } } QWSServer::setOverrideKeys( om ); @@ -313,66 +313,66 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) QDataStream stream( data, IO_ReadOnly ); if ( msg == "securityChanged()" ) { - if ( transferServer ) - transferServer->authorizeConnections(); - if ( qcopBridge ) - qcopBridge->authorizeConnections(); + if ( transferServer ) + transferServer->authorizeConnections(); + if ( qcopBridge ) + qcopBridge->authorizeConnections(); } /* ### FIXME support TempScreenSaverMode */ #if 0 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); } #endif 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 } @@ -383,100 +383,100 @@ void Server::systemMsg(const QCString &msg, const QByteArray &data) * to sync with QtopiaDesktop1.6 */ 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 &fs = storage->fileSystems(); - QListIterator 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 &fs = storage->fileSystems(); + QListIterator 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(); } #ifdef Q_WS_QWS 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)" ) { QString appName; stream >> appName; @@ -529,16 +529,16 @@ void Server::receiveTaskBar(const QCString &msg, const QByteArray &data) QDataStream stream( data, IO_ReadOnly ); 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 ll = ODevice::inst ( )-> ledList ( ); - if ( ll. count ( )) { + if ( ll. count ( )) { OLed l = ll. contains ( Led_Mail ) ? Led_Mail : ll [0]; bool canblink = ODevice::inst ( )-> ledStateList ( l ). contains ( Led_BlinkSlow ); @@ -560,7 +560,7 @@ bool Server::mkdir(const QString &localPath) { QDir fullDir(localPath); if (fullDir.exists()) - return true; + return true; // at this point the directory doesn't exist // go through the directory tree and start creating the direcotories @@ -573,29 +573,29 @@ bool Server::mkdir(const QString &localPath) // didn't find any seps; weird, use the cur dir instead if (dirIndex == -1) { //odebug << "No seperators found in path " << localPath << "" << oendl; - checkedPath = QDir::currentDirPath(); + checkedPath = QDir::currentDirPath(); } 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; + } + } } return TRUE; @@ -609,53 +609,53 @@ void Server::styleChange( QStyle &s ) 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 ); } void Server::timerEvent( QTimerEvent *e ) { if ( e->timerId() == tid_xfer ) { - killTimer( tid_xfer ); - tid_xfer = 0; - startTransferServer(); + killTimer( tid_xfer ); + tid_xfer = 0; + startTransferServer(); } /* ### FIXME today startin */ #if 0 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 #define QPE_DEFAULT_TODAY_MODE "Never" #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()"); + } + } } #endif } @@ -681,9 +681,9 @@ void Server::pokeTimeMonitors() // inform all TimeMonitors QStrList tms = Service::channels("TimeMonitor"); 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; } #endif } @@ -722,7 +722,7 @@ void Server::preloadApps() QStringList apps = cfg.readListEntry("Apps",','); for (QStringList::ConstIterator it=apps.begin(); it!=apps.end(); ++it) { #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 @@ -62,11 +62,11 @@ void TransferServer::authorizeConnections() { QListIterator it(connections); 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; } } @@ -104,9 +104,9 @@ QString SyncAuthentication::ownerName() QString vfilename = Global::applicationFileName("addressbook", "businesscard.vcf"); if (QFile::exists(vfilename)) { - Contact c; - c = Contact::readVCard( vfilename )[0]; - return c.fullName(); + Contact c; + c = Contact::readVCard( vfilename )[0]; + return c.fullName(); } return QString::null; @@ -127,18 +127,18 @@ QString SyncAuthentication::loginName() 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; } bool SyncAuthentication::checkUser( const QString& user ) @@ -161,12 +161,12 @@ bool SyncAuthentication::checkPassword( const QString& password ) QString cpwd = QString::fromLocal8Bit( pw->pw_passwd ); if ( cpwd == "x" && spw ) - cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); + cpwd = QString::fromLocal8Bit( spw->sp_pwdp ); // Note: some systems use more than crypt for passwords. QString cpassword = QString::fromLocal8Bit( crypt( password.local8Bit(), cpwd.local8Bit() ) ); if ( cpwd == cpassword ) - return TRUE; + return TRUE; #endif static int lastdenial=0; @@ -202,22 +202,22 @@ bool SyncAuthentication::checkPassword( const QString& password ) // Detect old Qtopia Desktop (no password) and fail if ( password.isEmpty() ) { - if ( denials < 3 || now > lastdenial+600 ) { - QMessageBox unauth( - tr("Sync Connection"), - tr("

An unauthorized system is requesting access to this device." - "

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("

An unauthorized system is requesting access to this device." + "

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; } @@ -232,59 +232,59 @@ bool SyncAuthentication::checkPassword( const QString& password ) * we need to support old Sync software and QtopiaDesktop */ 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( "

An unrecognized system is requesting access to this device." - "

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( "

An unrecognized system is requesting access to this device." + "

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; + } } lock--; @@ -305,37 +305,37 @@ ServerPI::ServerPI( int socket, QObject *parent, const char* name ) #ifndef INSECURE if ( !SyncAuthentication::isAuthorized(peeraddress) ) { - state = Forbidden; - startTimer( 0 ); + state = Forbidden; + startTimer( 0 ); } else #endif { - 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) ) ); } } @@ -352,8 +352,8 @@ ServerPI::~ServerPI() bool ServerPI::verifyAuthorised() { if ( !SyncAuthentication::isAuthorized(peerAddress()) ) { - state = Forbidden; - return FALSE; + state = Forbidden; + return FALSE; } return TRUE; } @@ -374,7 +374,7 @@ void ServerPI::send( const QString& msg ) void ServerPI::read() { while ( canReadLine() ) - process( readLine().stripWhiteSpace() ); + process( readLine().stripWhiteSpace() ); } bool ServerPI::checkReadFile( const QString& file ) @@ -382,9 +382,9 @@ bool ServerPI::checkReadFile( const QString& file ) QString filename; if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; QFileInfo fi( filename ); return ( fi.exists() && fi.isReadable() ); @@ -395,15 +395,15 @@ bool ServerPI::checkWriteFile( const QString& file ) QString filename; if ( file[0] != "/" ) - filename = directory.path() + "/" + file; + filename = directory.path() + "/" + file; else - filename = file; + filename = file; QFileInfo fi( filename ); if ( fi.exists() ) - if ( !QFile( filename ).remove() ) - return FALSE; + if ( !QFile( filename ).remove() ) + return FALSE; return TRUE; } @@ -421,7 +421,7 @@ void ServerPI::process( const QString& message ) // argument token QString arg; if ( msg.count() >= 2 ) - arg = msg[1]; + arg = msg[1]; // full argument string QString args; @@ -437,82 +437,82 @@ void ServerPI::process( const QString& message ) // we always respond to QUIT, regardless of state if ( cmd == "QUIT" ) { - send( "211 Good bye!" ); // No tr - close(); - return; + send( "211 Good bye!" ); // No tr + close(); + return; } // connected to client if ( Connected == state ) - return; + return; // waiting for user name if ( Wait_USER == state ) { - 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; } // waiting for password if ( Wait_PASS == state ) { - 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; } // ACCESS CONTROL COMMANDS // Only an ALLO sent immediately before STOR is valid. if ( cmd != "STOR" ) - storFileSize = -1; + storFileSize = -1; // account (ACCT) 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 } // change working directory (CWD) else if ( cmd == "CWD" ) { - 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 } // change to parent directory (CDUP) 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 } // structure mount (SMNT) 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 } // reinitialize (REIN) 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 } @@ -521,43 +521,43 @@ void ServerPI::process( const QString& message ) // data port (PORT) 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 } // passive (PASV) 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 ) +")" ); } // representation type (TYPE) 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 } // file structure (STRU) 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 } // transfer mode (MODE) 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 } @@ -566,205 +566,205 @@ void ServerPI::process( const QString& message ) // retrieve (RETR) 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 + } // store (STOR) 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 // store unique (STOU) else if ( cmd == "STOU" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // append (APPE) else if ( cmd == "APPE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // allocate (ALLO) else if ( cmd == "ALLO" ) { - storFileSize = args.toInt(); - send( "200 Command okay" ); // No tr + storFileSize = args.toInt(); + send( "200 Command okay" ); // No tr } // restart (REST) else if ( cmd == "REST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // rename from (RNFR) 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 + } } // rename to (RNTO) 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 + } } // abort (ABOR) 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 } // delete (DELE) 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 + } + } } // remove directory (RMD) 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 + } } // make directory (MKD) 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 + } } // print working directory (PWD) else if ( cmd == "PWD" ) { - send( "257 \"" + directory.path() +"\"" ); + send( "257 \"" + directory.path() +"\"" ); } // list (LIST) 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 } // size (SIZE) 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) ); + } + } + } } // name list (NLST) else if ( cmd == "NLST" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // site parameters (SITE) else if ( cmd == "SITE" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // system (SYST) else if ( cmd == "SYST" ) { - send( "215 UNIX Type: L8" ); // No tr + send( "215 UNIX Type: L8" ); // No tr } // status (STAT) else if ( cmd == "STAT" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // help (HELP ) else if ( cmd == "HELP" ) { - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr } // noop (NOOP) else if ( cmd == "NOOP" ) { - send( "200 Command okay" ); // No tr + send( "200 Command okay" ); // No tr } // not implemented else - send( "502 Command not implemented" ); // No tr + send( "502 Command not implemented" ); // No tr lastCommand = cmd; } @@ -772,7 +772,7 @@ void ServerPI::process( const QString& message ) 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 ); } bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) @@ -781,8 +781,7 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) file.findRev( ".tgz" ) == (int)file.length()-4 ) { QFileInfo info( file ); 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; } return false; @@ -791,15 +790,15 @@ bool ServerPI::backupRestoreGzip( const QString &file, QStringList &targets ) 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 ); } else { QStringList targets; if ( backupRestoreGzip( file, targets ) ) - dtp->sendGzipFile( file, targets, peeraddress, peerport ); + dtp->sendGzipFile( file, targets, peeraddress, peerport ); else dtp->sendFile( file, peeraddress, peerport ); } } @@ -807,17 +806,17 @@ void ServerPI::sendFile( const QString& file ) 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 ); } else { QStringList targets; 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 ); } } @@ -828,7 +827,7 @@ bool ServerPI::parsePort( const QString& pp ) // h1,h2,h3,h4,p1,p2 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(); return TRUE; } @@ -837,11 +836,11 @@ void ServerPI::dtpCompleted() { send( "226 Closing data connection, file transfer successful" ); // No tr 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; + } } waitsocket = 0; dtp->close(); @@ -870,58 +869,58 @@ bool ServerPI::sendList( const QString& arg ) QBuffer buffer( listing ); if ( !buffer.open( IO_WriteOnly ) ) - return FALSE; + return FALSE; QTextStream ts( &buffer ); QString fn = arg; if ( fn.isEmpty() ) - fn = directory.path(); + fn = directory.path(); QFileInfo fi( fn ); if ( !fi.exists() ) return FALSE; // return file listing if ( fi.isFile() ) { - ts << fileListing( &fi ) << endl; + ts << fileListing( &fi ) << endl; } // return directory listing 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; + } } 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; } @@ -932,11 +931,11 @@ QString ServerPI::fileListing( QFileInfo *info ) // type char if ( info->isDir() ) - s += "d"; + s += "d"; else if ( info->isSymLink() ) - s += "l"; + s += "l"; else - s += "-"; + s += "-"; // permisson string s += permissionString( info ) + " "; @@ -945,7 +944,7 @@ QString ServerPI::fileListing( QFileInfo *info ) int subdirs = 1; if ( info->isDir() ) - subdirs = 2; + subdirs = 2; // FIXME : this is to slow //if ( info->isDir() ) //subdirs = QDir( info->absFilePath() ).entryList( QDir::Dirs ).count(); @@ -955,13 +954,13 @@ QString ServerPI::fileListing( QFileInfo *info ) // owner QString o = info->owner(); if ( o.isEmpty() ) - o = QString::number(info->ownerId()); + o = QString::number(info->ownerId()); s += o.leftJustify( 8, ' ', TRUE ) + " "; // group QString g = info->group(); if ( g.isEmpty() ) - g = QString::number(info->groupId()); + g = QString::number(info->groupId()); s += g.leftJustify( 8, ' ', TRUE ) + " "; // file size in bytes @@ -971,9 +970,9 @@ QString ServerPI::fileListing( QFileInfo *info ) QDate date = info->lastModified().date(); QTime time = info->lastModified().time(); 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 ) + " "; // file name s += info->fileName(); @@ -1020,35 +1019,35 @@ void ServerPI::newConnection( int socket ) if ( !passiv ) return; 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 ); } else if ( wait[RetrieveFile] ) { odebug << "check retrieve file" << oendl; if ( backupRestoreGzip( waitfile ) ) - dtp->retrieveGzipFile( waitfile ); + dtp->retrieveGzipFile( waitfile ); else - dtp->retrieveFile( waitfile, storFileSize ); + dtp->retrieveFile( waitfile, storFileSize ); dtp->setSocket( socket ); } else if ( wait[SendByteArray] ) { - dtp->sendByteArray( waitarray ); - dtp->setSocket( socket ); + dtp->sendByteArray( waitarray ); + dtp->setSocket( socket ); } else if ( wait[RetrieveByteArray] ) { 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; } QString ServerPI::absFilePath( const QString& file ) @@ -1057,7 +1056,7 @@ QString ServerPI::absFilePath( const QString& file ) QString filepath( file ); if ( file[0] != "/" ) - filepath = directory.path() + "/" + file; + filepath = directory.path() + "/" + file; return filepath; } @@ -1088,23 +1087,23 @@ ServerDTP::ServerDTP( QObject *parent, const char* name) retrieveTargzProc->setCommunication( QProcess::Stdin ); retrieveTargzProc->setWorkingDirectory( QDir::rootDirPath() ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SIGNAL( completed() ) ); + SIGNAL( completed() ) ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } ServerDTP::~ServerDTP() { buf.close(); 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(); } createTargzProc->kill(); } @@ -1140,10 +1139,10 @@ void ServerDTP::connected() } else { // Don't write more if there is plenty buffered already. 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 ); } } break; @@ -1158,7 +1157,7 @@ void ServerDTP::connected() odebug << "==>start send tar process" << oendl; if ( !createTargzProc->start() ) qWarning("Error starting %s", - createTargzProc->arguments().join(" ").latin1()); + createTargzProc->arguments().join(" ").latin1()); break; case SendBuffer: if ( !buf.open( IO_ReadOnly) ) { @@ -1212,42 +1211,42 @@ void ServerDTP::connectionClosed() // send file mode if ( SendFile == mode ) { - if ( bytes_written == file.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == file.size() ) + emit completed(); + else + emit failed(); } // send buffer mode else if ( SendBuffer == mode ) { - if ( bytes_written == buf.size() ) - emit completed(); - else - emit failed(); + if ( bytes_written == buf.size() ) + emit completed(); + else + emit failed(); } // retrieve file mode 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(); + } } else if ( RetrieveGzipFile == mode ) { odebug << "Done writing ungzip file; closing input" << oendl; - retrieveTargzProc->flushStdin(); - retrieveTargzProc->closeStdin(); + retrieveTargzProc->flushStdin(); + retrieveTargzProc->closeStdin(); } // retrieve buffer mode else if ( RetrieveBuffer == mode ) { - buf.close(); - emit completed(); + buf.close(); + emit completed(); } mode = Idle; @@ -1260,28 +1259,28 @@ void ServerDTP::bytesWritten( int bytes ) // send file mode if ( SendFile == mode ) { - 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 ); + } } // send buffer mode if ( SendBuffer == mode ) { - 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; + } } } @@ -1289,27 +1288,27 @@ void ServerDTP::readyRead() { // retrieve file mode 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; } // retrieve buffer mode 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() ); } } @@ -1326,7 +1325,7 @@ void ServerDTP::targzDone() emit completed(); mode = Idle; disconnect( createTargzProc, SIGNAL( readyReadStdout() ), - this, SLOT( writeTargzBlock() ) ); + this, SLOT( writeTargzBlock() ) ); } void ServerDTP::sendFile( const QString fn, const QHostAddress& host, Q_UINT16 port ) @@ -1343,15 +1342,15 @@ 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 ) { sendGzipFile( fn, archiveTargets ); connectToHost( host.toString(), port ); } void ServerDTP::sendGzipFile( const QString &fn, - const QStringList &archiveTargets ) + const QStringList &archiveTargets ) { mode = SendGzipFile; file.setName( fn ); @@ -1362,7 +1361,7 @@ void ServerDTP::sendGzipFile( const QString &fn, odebug << "sendGzipFile " << args.join(" ") << "" << oendl; createTargzProc->setArguments( args ); connect( createTargzProc, - SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); + SIGNAL( readyReadStdout() ), SLOT( writeTargzBlock() ) ); } void ServerDTP::retrieveFile( const QString fn, const QHostAddress& host, Q_UINT16 port, int fileSize ) @@ -1388,7 +1387,7 @@ void ServerDTP::retrieveGzipFile( const QString &fn ) retrieveTargzProc->setArguments( "targunzip" ); connect( retrieveTargzProc, SIGNAL( processExited() ), - SLOT( extractTarDone() ) ); + SLOT( extractTarDone() ) ); } void ServerDTP::retrieveGzipFile( const QString &fn, const QHostAddress& host, Q_UINT16 port ) -- cgit v0.9.0.2