author | zecke <zecke> | 2004-03-14 18:51:10 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-14 18:51:10 (UTC) |
commit | ddfee0836adbd62be48888fbe05e7a79481e81c9 (patch) (side-by-side diff) | |
tree | c423c4f5cd9be39e892a6f3a346dde7c7c4400a9 | |
parent | 617e15d4cdbe7bc962388f9710bce834182bee24 (diff) | |
download | opie-ddfee0836adbd62be48888fbe05e7a79481e81c9.zip opie-ddfee0836adbd62be48888fbe05e7a79481e81c9.tar.gz opie-ddfee0836adbd62be48888fbe05e7a79481e81c9.tar.bz2 |
more ODP and right signal syntax
-rw-r--r-- | noncore/settings/aqpkg/ipkg.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.cpp | 4 | ||||
-rw-r--r-- | noncore/settings/sshkeys/sshkeys.cpp | 14 |
3 files changed, 11 insertions, 11 deletions
diff --git a/noncore/settings/aqpkg/ipkg.cpp b/noncore/settings/aqpkg/ipkg.cpp index 0091a3b..420863c 100644 --- a/noncore/settings/aqpkg/ipkg.cpp +++ b/noncore/settings/aqpkg/ipkg.cpp @@ -104,388 +104,388 @@ void Ipkg :: runIpkg() if ( destDir == "/" ) flags ^= MAKE_LINKS; } } #ifdef X86 commands << "-f"; commands << IPKG_CONF; #endif if ( option == "reinstall" ) commands << "install"; else commands << option; if ( package != "" ) commands << package; if ( package != "" ) emit outputText( tr( "Dealing with package %1" ).arg( package) ); qApp->processEvents(); // If we are removing, reinstalling or upgrading packages and make links option is selected // create the links if ( option == "remove" || option == "reinstall" || option == "upgrade" ) { createLinks = false; if ( flags & MAKE_LINKS ) { emit outputText( tr( "Removing symbolic links...\n" ) ); linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); emit outputText( QString( " " ) ); } } // Execute command dependantPackages = new QList<QString>; dependantPackages->setAutoDelete( true ); executeIpkgCommand( commands, option ); } void Ipkg :: createSymLinks() { if ( option == "install" || option == "reinstall" || option == "upgrade" ) { // If we are not removing packages and make links option is selected // create the links createLinks = true; if ( flags & MAKE_LINKS ) { emit outputText( " " ); emit outputText( tr( "Creating symbolic links for %1." ).arg( package) ); linkPackage( Utils::getPackageNameFromIpkFilename( package ), destination, destDir ); // link dependant packages that were installed with this release QString *pkg; for ( pkg = dependantPackages->first(); pkg != 0; pkg = dependantPackages->next() ) { if ( *pkg == package ) continue; emit outputText( " " ); emit outputText( tr( "Creating symbolic links for %1" ).arg( *pkg ) ); linkPackage( Utils::getPackageNameFromIpkFilename( *pkg ), destination, destDir ); } } } delete dependantPackages; emit outputText( tr("Finished") ); emit outputText( "" ); } void Ipkg :: removeStatusEntry() { QString statusFile = destDir; if ( statusFile.right( 1 ) != "/" ) statusFile.append( "/" ); statusFile.append( "usr/lib/ipkg/status" ); QString outStatusFile = statusFile; outStatusFile.append( ".tmp" ); emit outputText( "" ); emit outputText( tr("Removing status entry...") ); QString tempstr = tr("status file - "); tempstr.append( statusFile ); emit outputText( tempstr ); tempstr = tr("package - "); tempstr.append( package ); emit outputText( tempstr ); QFile readFile( statusFile ); QFile writeFile( outStatusFile ); if ( !readFile.open( IO_ReadOnly ) ) { tempstr = tr("Couldn't open status file - "); tempstr.append( statusFile ); emit outputText( tempstr ); return; } if ( !writeFile.open( IO_WriteOnly ) ) { tempstr = tr("Couldn't create tempory status file - "); tempstr.append( outStatusFile ); emit outputText( tempstr ); return; } int i = 0; QTextStream readStream( &readFile ); QTextStream writeStream( &writeFile ); QString line; char k[21]; char v[1001]; QString key; QString value; while ( !readStream.atEnd() ) { //read new line line = readStream.readLine(); if ( line.contains( ":", TRUE ) ) { //grep key and value from line k[0] = '\0'; v[0] = '\0'; sscanf( line, "%[^:]: %[^\n]", k, v ); key = k; value = v; key = key.stripWhiteSpace(); value = value.stripWhiteSpace(); } else { key = ""; value = ""; } if ( key == "Package" && value == package ) { //skip lines from the deleted package while ( ( !readStream.atEnd() ) && ( line.stripWhiteSpace() != "" ) ) { line = readStream.readLine(); } } else { //write other lines into the tempfile writeStream << line << "\n"; // Improve UI responsiveness i++; if ( ( i % 50 ) == 0 ) qApp->processEvents(); } } readFile.close(); writeFile.close(); // Remove old status file and put tmp stats file in its place remove( statusFile ); rename( outStatusFile, statusFile ); } int Ipkg :: executeIpkgCommand( QStringList &cmd, const QString /*option*/ ) { // If one is already running - should never be but just to be safe if ( proc ) { delete proc; proc = 0; } // OK we're gonna use OProcess to run this thing proc = new OProcess(); aborted = false; // Connect up our slots connect(proc, SIGNAL(processExited(Opie::Core::OProcess*)), this, SLOT( processFinished())); connect(proc, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), - this, SLOT(commandStdout(OProcess*,char*,int))); + this, SLOT(commandStdout(Opie::Core::OProcess*,char*,int))); connect(proc, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), - this, SLOT(commandStderr(OProcess*,char*,int))); + this, SLOT(commandStderr(Opie::Core::OProcess*,char*,int))); for ( QStringList::Iterator it = cmd.begin(); it != cmd.end(); ++it ) { *proc << (*it).latin1(); } // Start the process going finished = false; if(!proc->start(OProcess::NotifyOnExit, OProcess::All)) { emit outputText( tr("Couldn't start ipkg process" ) ); } } void Ipkg::commandStdout(OProcess*, char *buffer, int buflen) { QString lineStr = buffer; if ( lineStr[buflen-1] == '\n' ) buflen --; lineStr = lineStr.left( buflen ); emit outputText( lineStr ); // check if we are installing dependant packages if ( option == "install" || option == "reinstall" ) { // Need to keep track of any dependant packages that get installed // so that we can create links to them as necessary if ( lineStr.startsWith( "Installing " ) ) { int start = lineStr.find( " " ) + 1; int end = lineStr.find( " ", start ); QString *package = new QString( lineStr.mid( start, end-start ) ); dependantPackages->append( package ); } } else if ( option == "remove" && !( flags & FORCE_DEPENDS ) && lineStr.find( "is depended upon by packages:" ) != -1 ) { // Ipkg should send this to STDERR, but doesn't - so trap here error = true; } buffer[0] = '\0'; } void Ipkg::commandStderr(OProcess*, char *buffer, int buflen) { QString lineStr = buffer; if ( lineStr[buflen-1] == '\n' ) buflen --; lineStr=lineStr.left( buflen ); emit outputText( lineStr ); buffer[0] = '\0'; error = true; } void Ipkg::processFinished() { // Finally, if we are removing a package, remove its entry from the <destdir>/usr/lib/ipkg/status file // to workaround an ipkg bug which stops reinstall to a different location if ( !error && option == "remove" ) removeStatusEntry(); delete proc; proc = 0; finished = true; emit ipkgFinished(); } void Ipkg :: abort() { if ( proc ) { proc->kill(); aborted = true; } } void Ipkg :: linkPackage( const QString &packFileName, const QString &dest, const QString &destDir ) { if ( dest == "root" || dest == "/" ) return; qApp->processEvents(); QStringList *fileList = getList( packFileName, destDir ); qApp->processEvents(); processFileList( fileList, destDir ); delete fileList; } QStringList* Ipkg :: getList( const QString &packageFilename, const QString &destDir ) { QString packageFileDir = destDir; packageFileDir.append( "/usr/lib/ipkg/info/" ); packageFileDir.append( packageFilename ); packageFileDir.append( ".list" ); QFile f( packageFileDir ); if ( !f.open(IO_ReadOnly) ) { // Couldn't open from dest, try from / f.close(); packageFileDir = "/usr/lib/ipkg/info/"; packageFileDir.append( packageFilename ); packageFileDir.append( ".list" ); f.setName( packageFileDir ); if ( ! f.open(IO_ReadOnly) ) { QString tempstr = tr("Could not open :"); tempstr.append( packageFileDir ); emit outputText( tempstr ); return (QStringList*)0; } } QStringList *fileList = new QStringList(); QTextStream t( &f ); while ( !t.eof() ) *fileList += t.readLine(); f.close(); return fileList; } void Ipkg :: processFileList( const QStringList *fileList, const QString &destDir ) { if ( !fileList || fileList->isEmpty() ) return; QString baseDir = ROOT; if ( createLinks == true ) { for ( uint i=0; i < fileList->count(); i++ ) { processLinkDir( (*fileList)[i], baseDir, destDir ); qApp->processEvents(); } } else { for ( int i = fileList->count()-1; i >= 0 ; i-- ) { processLinkDir( (*fileList)[i], baseDir, destDir ); qApp->processEvents(); } } } void Ipkg :: processLinkDir( const QString &file, const QString &destDir, const QString &baseDir ) { QString sourceFile = baseDir; sourceFile.append( file ); QString linkFile = destDir; if ( file.startsWith( "/" ) && destDir.right( 1 ) == "/" ) { linkFile.append( file.mid( 1 ) ); } else { linkFile.append( file ); } QString text; if ( createLinks ) { // If this file is a directory (ends with a /) and it doesn't exist, // we need to create it if ( file.right(1) == "/" ) { QFileInfo f( linkFile ); if ( !f.exists() ) { QString tempstr = tr("Creating directory "); tempstr.append( linkFile ); emit outputText( tempstr ); QDir d; d.mkdir( linkFile, true ); } // else // emit outputText( QString( "Directory " ) + linkFile + " already exists" ); } else { int rc = symlink( sourceFile, linkFile ); text = ( rc == 0 ? tr( "Linked %1 to %2" ) : tr( "Failed to link %1 to %2" ) ). arg( sourceFile ). diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp index ba96f33..385d355 100644 --- a/noncore/settings/netsystemtime/mainwindow.cpp +++ b/noncore/settings/netsystemtime/mainwindow.cpp @@ -2,387 +2,387 @@ This file is part of the OPIE Project =. .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mainwindow.h" #include "timetabwidget.h" #include "formattabwidget.h" #include "settingstabwidget.h" #include "ntptabwidget.h" #include "predicttabwidget.h" #include <qpe/config.h> #include <qpe/datebookdb.h> #include <qpe/qpeapplication.h> #include <qpe/qpedialog.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #include <qlayout.h> #include <qmessagebox.h> #include <qsocket.h> #include <qstring.h> #include <qtimer.h> using namespace Opie::Ui; using namespace Opie::Core; MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) : QDialog( 0x0, 0x0, TRUE, 0 ) { setCaption( tr( "SystemTime" ) ); QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Create main tabbed control mainWidget = new OTabWidget( this ); // Default object pointers to null ntpProcess = 0x0; ntpTab = 0x0; // Add tab widgets mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); Config config( "ntp" ); config.setGroup( "settings" ); slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); mainWidget->setCurrentTab( tr( "Time" ) ); layout->addWidget( mainWidget ); connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) ); // Create NTP socket ntpSock = new QSocket( this ); connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); slotProbeNTPServer(); // Create timer for automatic time lookups ntpTimer = new QTimer( this ); // Connect everything together connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); connect( timeTab, SIGNAL(tzChanged(const QString&)), predictTab, SLOT(slotTZChanged(const QString&)) ); connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime(int)) ); connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat&)), timeTab, SLOT(slotDateFormatChanged(const DateFormat&)) ); connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); connect( predictTab, SIGNAL(setTime(const QDateTime&)), this, SLOT(slotSetTime(const QDateTime&)) ); // Do initial time server check slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); slotCheckNtp( -1 ); // Display app //showMaximized(); (void)new QPEDialogListener(this); } MainWindow::~MainWindow() { if ( ntpProcess ) delete ntpProcess; } void MainWindow::accept() { // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) { QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); disableScreenSaver << 0 << 0 << 0; } // Update the systemtime timeTab->saveSettings( TRUE ); // Save format options formatTab->saveSettings( TRUE ); // Save settings options settingsTab->saveSettings(); // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better // grip on itself (example re-trigger alarms for when we travel back in time). DateBookDB db; // Turn back on the screensaver QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); enableScreenSaver << -1 << -1 << -1; // Exit app qApp->quit(); } void MainWindow::reject() { // Reset time settings timeTab->saveSettings( FALSE ); // Send notifications but do not save settings formatTab->saveSettings( FALSE ); // Exit app qApp->quit(); } void MainWindow::runNTP() { if ( !ntpDelayElapsed() && ntpInteractive ) { QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); switch ( QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) ) { case QMessageBox::Yes: break; case QMessageBox::No: return; default: return; } } QString srv = settingsTab->ntpServer(); // Send information to time server tab if enabled if ( ntpTabEnabled ) { ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); QString output = tr( "Running:\nntpdate " ); output.append( srv ); ntpTab->addNtpOutput( output ); } if ( !ntpProcess ) { ntpProcess = new OProcess(); connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), - this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); + this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) ); connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), - this, SLOT(slotNtpFinished(OProcess*)) ); + this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) ); } else ntpProcess->clearArguments(); *ntpProcess << "ntpdate" << srv; bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); if ( !ret ) { QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); if ( ntpTabEnabled ) ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); } } bool MainWindow::ntpDelayElapsed() { // Determine if time elapsed is greater than time delay Config config( "ntp" ); config.setGroup( "lookups" ); _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); if ( _lookupDiff < 0 ) return true; return ( _lookupDiff - ( ntpDelay * 60) ) > 0; } void MainWindow::slotSetTime( const QDateTime &dt ) { timeTab->setDateTime( dt ); } void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) { if ( msg == "ntpLookup(QString)" ) { ntpInteractive = false; runNTP(); } if ( msg == "setPredictedTime(QString)" ) { //setPredictTime(); } } void MainWindow::slotDisplayNTPTab( bool display ) { ntpTabEnabled = display; // Create widget if it hasn't needed if ( display && !ntpTab ) { ntpTab = new NTPTabWidget( mainWidget ); connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); } // Display/hide tab display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) : mainWidget->removePage( ntpTab ); } void MainWindow::slotDisplayPredictTab( bool display ) { predictTabEnabled = display; // Create widget if it hasn't needed if ( display && !predictTab ) { } // Display/hide tab display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) : mainWidget->removePage( predictTab ); } void MainWindow::slotGetNTPTime() { ntpInteractive = TRUE; runNTP(); } void MainWindow::slotTimerGetNTPTime() { ntpInteractive = FALSE; runNTP(); } void MainWindow::slotProbeNTPServer() { ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); } void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) { QString output = QString( buffer ).left( buflen ); ntpOutput.append( output ); if ( ntpTabEnabled ) ntpTab->addNtpOutput( output ); } void MainWindow::slotNtpFinished( OProcess *p ) { QString output; QDateTime dt = QDateTime::currentDateTime(); // Verify run was successful if ( p->exitStatus() != 0 || !p->normalExit() ) { if ( isVisible() && ntpInteractive ) { output = tr( "Error while getting time from\n server: " ); output.append( settingsTab->ntpServer() ); QMessageBox::critical(this, tr( "Error" ), output ); } // slotCheckNtp(-1); return; } // Set controls on time tab to new time value timeTab->setDateTime( dt ); // Write out lookup information Config config( "ntp" ); config.setGroup( "lookups" ); int lastLookup = config.readNumEntry( "time", 0 ); int lookupCount = config.readNumEntry( "count", 0 ); bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); config.writeEntry( "time", time ); // Calculate new time/time shift QString _offset = "offset"; QString _sec = "sec"; QRegExp _reOffset = QRegExp( _offset ); QRegExp _reEndOffset = QRegExp( _sec ); int posOffset = _reOffset.match( ntpOutput ); int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); posOffset += _offset.length() + 1; QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); float timeShift = diff.toFloat(); if ( timeShift == 0.0 ) return; int secsSinceLast = time - lastLookup; output = tr( "%1 seconds").arg(QString::number( timeShift )); // Display information on time server tab if ( ntpTabEnabled ) { ntpTab->setTimeShift( output ); ntpTab->setNewTime( dt.toString() ); } if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) { QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); config.setGroup( grpname ); lookupCount++; predictTab->setShiftPerSec( timeShift / secsSinceLast ); config.writeEntry( "secsSinceLast", secsSinceLast ); config.writeEntry( "timeShift", QString::number( timeShift ) ); config.setGroup( "lookups" ); config.writeEntry( "count", lookupCount ); config.writeEntry( "lastNtp", TRUE ); } } void MainWindow::slotNTPDelayChanged( int delay ) { ntpTimer->changeInterval( delay * 1000 * 60 ); ntpDelay = delay; } void MainWindow::slotCheckNtp( int i ) { if ( i == 0 ) { if ( ntpDelayElapsed() ) { runNTP(); disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) ); connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) ); } else { disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) ); connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); } } else { predictTab->slotPredictTime(); if ( i > 0 ) diff --git a/noncore/settings/sshkeys/sshkeys.cpp b/noncore/settings/sshkeys/sshkeys.cpp index 31f6b85..cebc845 100644 --- a/noncore/settings/sshkeys/sshkeys.cpp +++ b/noncore/settings/sshkeys/sshkeys.cpp @@ -1,294 +1,294 @@ /* * ssh-agent key manipulation utility * * (C) 2002 David Woodhouse <dwmw2@infradead.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "sshkeys.h" #include <qpe/qpeapplication.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qlistview.h> #include <qcombobox.h> #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> #include <unistd.h> #include <stdio.h> #include <ctype.h> using namespace Opie::Core; static char *keynames[] = { "identity", "id_rsa", "id_dsa" }; SSHKeysApp::SSHKeysApp( QWidget* parent, const char* name, WFlags fl ) : SSHKeysBase( parent, name, fl ) { char *home = getenv("HOME"); unsigned i; connect(AddButton, SIGNAL(clicked()), this, SLOT(doAddButton())); connect(RefreshListButton, SIGNAL(clicked()), this, SLOT(doRefreshListButton())); connect(RemoveAllButton, SIGNAL(clicked()), this, SLOT(doRemoveAllButton())); connect(&addprocess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), - this, SLOT(log_sshadd_output(OProcess*,char*,int))); + this, SLOT(log_sshadd_output(Opie::Core::OProcess*,char*,int))); connect(&addprocess, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), - this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); connect(&addprocess, SIGNAL(processExited(Opie::Core::OProcess*)), - this, SLOT(ssh_add_exited(OProcess*))); + this, SLOT(ssh_add_exited(Opie::Core::OProcess*))); connect(KeyFileName, SIGNAL(textChanged(const QString&)), this, SLOT(add_text_changed(const QString&))); if (home) { for (i = 0; i < sizeof(keynames)/sizeof(keynames[0]); i++) { char thiskeyname[32]; thiskeyname[31] = 0; snprintf(thiskeyname, 31, "%s/.ssh/%s", home, keynames[i]); if (!access(thiskeyname, R_OK)) { KeyFileName->insertItem(thiskeyname); } } } doRefreshListButton(); } SSHKeysApp::~SSHKeysApp() { } void SSHKeysApp::doRefreshListButton() { OProcess sshadd_process; QListViewItem *t = KeyList->firstChild(); while(t) { QListViewItem *next = t->nextSibling(); KeyList->takeItem(t); delete(t); t = next; } connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), - this, SLOT(get_list_keys_output(OProcess*,char*,int))); + this, SLOT(get_list_keys_output(Opie::Core::OProcess*,char*,int))); connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), - this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); keystate = KeySize; incoming_keyname=""; incoming_keysize=""; incoming_keyfingerprint=""; // log_text("Running ssh-add -l"); sshadd_process << "ssh-add" << "-l"; bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); if (!ret) { log_text(tr("Error running ssh-add")); return; } flush_sshadd_output(); if (sshadd_process.exitStatus() == 2) { setEnabled(FALSE); } } void SSHKeysApp::get_list_keys_output(OProcess *proc, char *buffer, int buflen) { int i; (void) proc; for (i=0; i<buflen; i++) { switch(keystate) { case Noise: noise: if (buffer[i] == '\n') { log_text(incoming_noise.local8Bit()); incoming_noise = ""; keystate = KeySize; } else { incoming_noise += buffer[i]; } break; case KeySize: if (isdigit(buffer[i])) { incoming_keysize += buffer[i]; } else if (buffer[i] == ' ') { keystate = KeyFingerprint; } else { incoming_keysize = ""; incoming_noise = ""; keystate = Noise; goto noise; } break; case KeyFingerprint: if (isxdigit(buffer[i]) || buffer[i] == ':') { incoming_keyfingerprint += buffer[i]; } else if (buffer[i] == ' ') { keystate = KeyName; } else { incoming_keysize = ""; incoming_keyfingerprint = ""; incoming_noise = ""; keystate = Noise; goto noise; } break; case KeyName: if (buffer[i] == '\n') { /* Wheee. Got one. */ KeyList->insertItem(new QListViewItem(KeyList, incoming_keyname, incoming_keysize, incoming_keyfingerprint)); incoming_keysize = ""; incoming_keyfingerprint = ""; incoming_keyname = ""; keystate = KeySize; } else if (isprint(buffer[i])) { incoming_keyname += buffer[i]; } else { incoming_keysize = ""; incoming_keyfingerprint = ""; incoming_noise = ""; keystate = Noise; goto noise; } break; } } } void SSHKeysApp::flush_sshadd_output(void) { if (pending_stdout.length()) { log_text(pending_stdout.ascii()); } pending_stdout = ""; if (pending_stderr.length()) { log_text(pending_stderr.ascii()); } pending_stderr = ""; } void SSHKeysApp::log_sshadd_output(OProcess *proc, char *buffer, int buflen) { (void) proc; while (buflen) { if (*buffer == '\n') { log_text(pending_stdout); pending_stdout = ""; } else { pending_stdout += *buffer; } buffer++; buflen--; } } void SSHKeysApp::log_sshadd_stderr(OProcess *proc, char *buffer, int buflen) { (void) proc; while (buflen) { if (*buffer == '\n') { log_text(pending_stderr); pending_stderr = ""; } else { pending_stderr += *buffer; } buffer++; buflen--; } } void SSHKeysApp::ssh_add_exited(OProcess *proc) { (void)proc; doRefreshListButton(); setEnabled(TRUE); if (proc->exitStatus() == 2) { setEnabled(FALSE); } } void SSHKeysApp::add_text_changed(const QString &text) { struct stat sbuf; if (!text.length() || (!access(text.ascii(), R_OK) && !stat(text.ascii(), &sbuf) && S_ISREG(sbuf.st_mode))) AddButton->setEnabled(TRUE); else AddButton->setEnabled(FALSE); } void SSHKeysApp::doAddButton() { addprocess.clearArguments(); setEnabled(FALSE); if (KeyFileName->currentText().length()) { addprocess << "ssh-add" << "--" << KeyFileName->currentText(); // log_text(QString(tr("Running ssh-add -- ")) + KeyFileName->currentText()); } else { addprocess << "ssh-add"; // log_text(tr("Running ssh-add")); } bool ret = addprocess.start(OProcess::NotifyOnExit, OProcess::AllOutput); if (!ret) { log_text(tr("Error running ssh-add")); doRefreshListButton(); setEnabled(TRUE); } flush_sshadd_output(); } void SSHKeysApp::log_text(const char *text) { TextOutput->append(text); TextOutput->setCursorPosition(TextOutput->numLines()+1, 0, FALSE); } void SSHKeysApp::doRemoveAllButton() { OProcess sshadd_process; connect(&sshadd_process, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), - this, SLOT(log_sshadd_output(OProcess*,char*,int))); + this, SLOT(log_sshadd_output(Opie::Core::OProcess*,char*,int))); connect(&sshadd_process, SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)), - this, SLOT(log_sshadd_stderr(OProcess*,char*,int))); + this, SLOT(log_sshadd_stderr(Opie::Core::OProcess*,char*,int))); // log_text(tr("Running ssh-add -D")); sshadd_process << "ssh-add" << "-D"; bool ret = sshadd_process.start(OProcess::Block, OProcess::AllOutput); if (!ret) { log_text(tr("Error running ssh-add")); } flush_sshadd_output(); doRefreshListButton(); } |