author | llornkcor <llornkcor> | 2002-11-16 05:28:00 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-16 05:28:00 (UTC) |
commit | 9591a32654e5189841b9a6d60e7bf235b1b0fa4b (patch) (side-by-side diff) | |
tree | 8a8251b3af82ad830d5d7bc85cd39aea68e505d8 /noncore/apps/advancedfm/advancedfmMenu.cpp | |
parent | b17b2274c200403da25a994ed9d8ba4856d725c0 (diff) | |
download | opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.zip opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.tar.gz opie-9591a32654e5189841b9a6d60e7bf235b1b0fa4b.tar.bz2 |
moved input to output, switched all systems calls to OProcess. got rid of popen
Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 121 |
1 files changed, 69 insertions, 52 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index f89ad30..0a9f921 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -1,29 +1,29 @@ /*************************************************************************** AdvancedFm.cpp ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * 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. * ***************************************************************************/ #include "advancedfm.h" -#include "inputDialog.h" #include "output.h" #include "filePermissions.h" #include <opie/otabwidget.h> +#include <opie/oprocess.h> #include <qpe/lnkproperties.h> #include <qpe/qpeapplication.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/applnk.h> #include <qpe/ir.h> #include <qmessagebox.h> #include <qmultilineedit.h> @@ -224,47 +224,46 @@ void AdvancedFm::localDelete() { QString f = currentDir.canonicalPath(); if(f.right(1).find("/",0,TRUE) == -1) f+="/"; f+=myFile; if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) { switch ( QMessageBox::warning(this,tr("Delete Directory?"),tr("Really delete\n")+f+ "\nand all it's contents ?" ,tr("Yes"),tr("No"),0,0,1) ) { case 0: { f=f.left(f.length()-1); QString cmd="rm -rf "+f; - system( cmd.latin1()); + startProcess( (const QString)cmd.latin1() ); populateLocalView(); } break; case 1: // exit break; }; } else { if(doMsg) { switch ( QMessageBox::warning(this,tr("Delete"),tr("Really delete\n")+f +" ?",tr("Yes"),tr("No"),0,0,1) ) { case 1: return; break; }; } QString cmd="rm "+f; QFile file(f); if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) file.remove(); - // system( cmd.latin1()); } } } populateLocalView(); } void AdvancedFm::remoteDelete() { QStringList curFileList = getPath(); bool doMsg=true; int count=curFileList.count(); if( count > 0) { if(count > 1 ){ @@ -289,47 +288,46 @@ void AdvancedFm::remoteDelete() { myFile = myFile.left(myFile.find(" -> ",0,TRUE)); QString f = currentRemoteDir.canonicalPath(); if(f.right(1).find("/",0,TRUE) == -1) f+="/"; f+=myFile; if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) { switch ( QMessageBox::warning(this,tr("Delete Directory"),tr("Really delete\n")+f+ "\nand all it's contents ?", tr("Yes"),tr("No"),0,0,1) ) { case 0: { f=f.left(f.length()-1); QString cmd="rm -rf "+f; - system( cmd.latin1()); + startProcess( (const QString)cmd ); populateRemoteView(); } break; case 1: // exit break; }; } else { if(doMsg) { switch ( QMessageBox::warning(this,tr("Delete"),tr("Really delete\n")+f +" ?",tr("Yes"),tr("No"),0,0,1) ) { case 1: return; break; }; } QString cmd="rm "+f; QFile file(f); if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) file.remove(); - // system( cmd.latin1()); } } } populateRemoteView(); } void AdvancedFm::localRename() { QString curFile = Local_View->currentItem()->text(0); qDebug("currentItem "+curFile); if( curFile !="../") { InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); @@ -814,112 +812,111 @@ void AdvancedFm::runCommand() { if (TabWidget->getCurrentTab() == 0) { if( Local_View->currentItem()) curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); } else { if(Remote_View->currentItem()) curFile = currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0); } InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); - QString command; + //QString command; + if( fileDlg->result() == 1 ) { - command = fileDlg->LineEdit1->text(); + qDebug(fileDlg->LineEdit1->text()); + QStringList command; + command << "/bin/sh"; + command << "-c"; + command << fileDlg->LineEdit1->text(); Output *outDlg; - outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); + outDlg = new Output( command, this, tr("AdvancedFm Output"), true); outDlg->showMaximized(); - outDlg->show(); + outDlg->exec(); qApp->processEvents(); - FILE *fp; - char line[130]; - sleep(1); - command +=" 2>&1"; - fp = popen( (const char *) command, "r"); - if ( !fp ) { - qDebug("Could not execute '" + command + "'! err=%d", fp); - QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); - pclose(fp); - return; - } else { - while ( fgets( line, sizeof line, fp)) { - QString lineStr = line; - lineStr=lineStr.left(lineStr.length()-1); - outDlg->OutputEdit->append(lineStr); - outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); - } - } - pclose(fp); } } void AdvancedFm::runCommandStd() { QString curFile; if (TabWidget->getCurrentTab() == 0) { if( Local_View->currentItem()) curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0); } else { if(Remote_View->currentItem()) curFile = currentRemoteDir.canonicalPath() +"/" + Remote_View->currentItem()->text(0); } InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); - QString command; + if( fileDlg->result() == 1 ) { qApp->processEvents(); - command = fileDlg->LineEdit1->text() + " &"; - system(command.latin1()); + startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); } } void AdvancedFm::fileStatus() { QString curFile; if (TabWidget->getCurrentTab() == 0) { curFile = Local_View->currentItem()->text(0); } else { curFile = Remote_View->currentItem()->text(0); } - QString command = " stat -l "+ curFile +" 2>&1"; + + QStringList command; + command << "/bin/sh"; + command << "-c"; + command << "stat -l "+ curFile; + Output *outDlg; - outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); + outDlg = new Output( command, this, tr("AdvancedFm Output"), true); outDlg->showMaximized(); - outDlg->show(); + outDlg->exec(); qApp->processEvents(); - FILE *fp; - char line[130]; - sleep(1); - fp = popen( (const char *) command, "r"); - if ( !fp ) { - qDebug("Could not execute '" + command + "'! err=%d", fp); - QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); - pclose(fp); - return; - } else { - while ( fgets( line, sizeof line, fp)) { - outDlg->OutputEdit->append(line); - outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); - } - } - pclose(fp); +// Output *outDlg; +// outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); +// outDlg->showMaximized(); +// outDlg->show(); +// qApp->processEvents(); + +// FILE *fp; +// char line[130]; +// sleep(1); +// fp = popen( (const char *) command, "r"); +// if ( !fp ) { +// qDebug("Could not execute '" + command + "'! err=%d", fp); +// QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") ); +// pclose(fp); +// return; +// } else { +// while ( fgets( line, sizeof line, fp)) { +// outDlg->OutputEdit->append(line); +// outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE); + +// } + +// } +// pclose(fp); } + void AdvancedFm::mkDir() { if (TabWidget->getCurrentTab() == 0) localMakDir(); else remoteMakDir(); } void AdvancedFm::rn() { if (TabWidget->getCurrentTab() == 0) localRename(); else @@ -939,39 +936,39 @@ void AdvancedFm::mkSym() { QStringList curFileList = getPath(); if( curFileList.count() > 0) { if (TabWidget->getCurrentTab() == 0) { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destName = currentRemoteDir.canonicalPath()+"/"+(*it); if(destName.right(1) == "/") destName = destName.left( destName.length() -1); QString curFile = currentDir.canonicalPath()+"/"+(*it); if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); cmd = "ln -s "+curFile+" "+destName; qDebug(cmd); - system(cmd.latin1() ); + startProcess( (const QString)cmd ); } populateRemoteView(); TabWidget->setCurrentTab(1); } else { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destName = currentDir.canonicalPath()+"/"+(*it); if(destName.right(1) == "/") destName = destName.left( destName.length() -1); QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it); if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1); cmd = "ln -s "+curFile+" "+destName; qDebug(cmd); - system(cmd.latin1() ); + startProcess( (const QString)cmd ); } populateLocalView(); TabWidget->setCurrentTab(0); } } } void AdvancedFm::doBeam() { Ir ir; if(!ir.supported()){ } else { @@ -1009,12 +1006,32 @@ void AdvancedFm::fileBeamFinished( Ir *) { } void AdvancedFm::selectAll() { if (TabWidget->getCurrentTab() == 0) { Local_View->selectAll(true); Local_View->setSelected( Local_View->firstChild(),false); } else { Remote_View->selectAll(true); Remote_View->setSelected( Remote_View->firstChild(),false); } } + +void AdvancedFm::startProcess(const QString & cmd) { + QStringList command; + OProcess *process; + process = new OProcess(); + connect(process, SIGNAL(processExited(OProcess *)), + this, SLOT( processEnded())); + + command << "/bin/sh"; + command << "-c"; + command << cmd.latin1(); + *process << command; + if(!process->start(OProcess::NotifyOnExit) ) + qDebug("could not start process"); +} + +void AdvancedFm::processEnded() { + populateLocalView(); + populateRemoteView(); +} |