summaryrefslogtreecommitdiff
path: root/noncore/apps/advancedfm/advancedfmMenu.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 80324eb..ed280aa 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -467,393 +467,407 @@ void AdvancedFm::move() {
QString curFile, destFile, item;
QDir *thisDir = CurrentDir();
QDir *thatDir = OtherDir();
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
item=(*it);
QString destFile = thatDir->canonicalPath();
if(destFile.right(1).find("/",0,TRUE) == -1)
destFile+="/";
destFile += item;
// odebug << "Destination file is "+destFile << oendl;
curFile = thisDir->canonicalPath();
if(curFile.right(1).find("/",0,TRUE) == -1)
curFile +="/";
curFile+= item;
// odebug << "CurrentFile file is " + curFile << oendl;
if(QFileInfo(curFile).isDir()) {
moveDirectory( curFile, destFile );
rePopulate();
return;
}
QFile f( destFile);
if( f.exists()) {
switch ( QMessageBox::warning(this,tr("File Exists!"),
tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile),
tr("Yes"),tr("No"),0,0,1)) {
case 0:
break;
case 1:
return;
break;
default:
return;
break;
};
}
if( !copyFile( curFile, destFile) ) {
QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile));
return;
} else
QFile::remove(curFile);
}
}
rePopulate();
// setOtherTabCurrent();
}
bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
int err = 0;
if( copyDirectory( src, dest ) ) {
QString cmd = "rm -rf " + src;
err = system((const char*)cmd);
} else
err = -1;
if(err!=0) {
QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src));
return false;
}
return true;
}
bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
QString cmd = "/bin/cp -fpR " + src + " " + dest;
owarn << cmd << oendl;
int err = system( (const char *) cmd );
if ( err != 0 ) {
QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) );
return false;
}
return true;
}
bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
if(QFileInfo(src).isDir()) {
if( copyDirectory( src, dest )) {
// setOtherTabCurrent();
rePopulate();
return true;
}
else
return false;
}
bool success = true;
struct stat status;
QFile srcFile(src);
QFile destFile(dest);
int err=0;
int read_fd=0;
int write_fd=0;
struct stat stat_buf;
off_t offset = 0;
if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
// owarn << "open failed" << oendl;
return success = false;
}
read_fd = srcFile.handle();
if(read_fd != -1) {
fstat (read_fd, &stat_buf);
if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
// owarn << "destfile open failed" << oendl;
return success = false;
}
write_fd = destFile.handle();
if(write_fd != -1) {
err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
if( err == -1) {
QString msg;
switch(err) {
case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
case EINVAL: msg = "Descriptor is not valid or locked. ";
case ENOMEM: msg = "Insufficient memory to read from in_fd.";
case EIO: msg = "Unspecified error while reading from in_fd.";
};
success = false;
// owarn << msg << oendl;
}
} else {
success = false;
}
} else {
success = false;
}
srcFile.close();
destFile.close();
// Set file permissions
if( stat( QFile::encodeName(src), &status ) == 0 ) {
chmod( QFile::encodeName(dest), status.st_mode );
}
return success;
}
void AdvancedFm::runCommand() {
if( !CurrentView()->currentItem()) return;
QDir *thisDir = CurrentDir();
QString curFile;
curFile = thisDir->canonicalPath() +"/"+ CurrentView()->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 ) {
// odebug << fileDlg->LineEdit1->text() << oendl;
QStringList command;
command << "/bin/sh";
command << "-c";
command << fileDlg->LineEdit1->text();
Output *outDlg;
outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
QPEApplication::execDialog( outDlg );
qApp->processEvents();
}
}
void AdvancedFm::runCommandStd() {
if( !CurrentView()->currentItem()) return;
QString curFile;
QDir *thisDir = CurrentDir();
QListView *thisView = CurrentView();
if( thisView->currentItem())
curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0);
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
fileDlg->setInputText(curFile);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
qApp->processEvents();
startProcess( (const QString)fileDlg->LineEdit1->text().latin1());
}
}
void AdvancedFm::fileStatus() {
if( !CurrentView()->currentItem()) return;
QString curFile;
curFile = CurrentView()->currentItem()->text(0);
-
+ if(QFileInfo("/usr/bin/stat").exists()) {
QStringList command;
command << "/bin/sh";
command << "-c";
command << "stat -l "+ curFile;
-
Output *outDlg;
outDlg = new Output( command, this, tr("AdvancedFm Output"), true);
QPEApplication::execDialog( outDlg );
+ } else {
+/* struct stat buf;
+ stat( curFile.local8bit(), &buf);
+
+ st_dev dev;
+ st_uid uid;
+ st_gid gid;
+ st_size size;
+ st_atime atime;
+ st_mtime mtime;
+ st_ctime ctime;
+ st_mode mode;
+*/
+ }
+
qApp->processEvents();
}
void AdvancedFm::mkDir() {
makeDir();
}
void AdvancedFm::rn() {
renameIt();
}
void AdvancedFm::del() {
doDelete();
}
void AdvancedFm::mkSym() {
QString cmd;
QStringList curFileList = getPath();
if( curFileList.count() > 0) {
QDir *thisDir = CurrentDir();
QDir * thatDir = OtherDir();
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
QString destName = thatDir->canonicalPath()+"/"+(*it);
if(destName.right(1) == "/") {
destName = destName.left( destName.length() -1);
}
QString curFile = thisDir->canonicalPath()+"/"+(*it);
if( curFile.right(1) == "/") {
curFile = curFile.left( curFile.length() -1);
}
cmd = "ln -s "+curFile+" "+destName;
// odebug << cmd << oendl;
startProcess( (const QString)cmd );
}
rePopulate();
setOtherTabCurrent();
}
}
void AdvancedFm::doBeam() {
Ir ir;
if(!ir.supported()) {
} else {
QStringList curFileList = getPath();
if( curFileList.count() > 0) {
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
QString curFile = (*it);
QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile;
if( curFilePath.right(1) == "/") {
curFilePath = curFilePath.left( curFilePath.length() -1);
}
Ir *file = new Ir(this, "IR");
connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*)));
file->send( curFilePath, curFile );
}
}
}
}
void AdvancedFm::fileBeamFinished( Ir *) {
QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") );
}
void AdvancedFm::selectAll() {
QListView *thisView = CurrentView();
thisView->selectAll(true);
thisView->setSelected( thisView->firstChild(),false);
}
void AdvancedFm::startProcess(const QString & cmd) {
QStringList command;
OProcess *process;
process = new OProcess();
connect(process,SIGNAL(processExited(Opie::Core::OProcess*)),this,SLOT(processEnded(Opie::Core::OProcess*)));
connect(process,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(oprocessStderr(Opie::Core::OProcess*,char*,int)));
command << "/bin/sh";
command << "-c";
command << cmd.latin1();
*process << command;
if(!process->start(OProcess::NotifyOnExit, OProcess::All) )
odebug << "could not start process" << oendl;
}
void AdvancedFm::processEnded(OProcess *) {
rePopulate();
}
void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) {
// owarn << "received stderrt " << buflen << " bytes" << oendl;
QString lineStr = buffer;
QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") );
}
bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) {
if ( o->inherits( "QLineEdit" ) ) {
if ( e->type() == QEvent::KeyPress ) {
QKeyEvent *ke = (QKeyEvent*)e;
if ( ke->key() == Key_Return ||
ke->key() == Key_Enter ) {
okRename();
return true;
}
else if ( ke->key() == Key_Escape ) {
cancelRename();
return true;
}
}
else if ( e->type() == QEvent::FocusOut ) {
cancelRename();
return true;
}
}
if ( o->inherits( "QListView" ) ) {
if ( e->type() == QEvent::FocusIn ) {
if( o == Local_View) { //keep track of which view
whichTab = 1;
viewMenu->setItemChecked(viewMenu->idAt(0), true);
viewMenu->setItemChecked(viewMenu->idAt(1), false);
} else {
whichTab = 2;
viewMenu->setItemChecked(viewMenu->idAt(0), false);
viewMenu->setItemChecked(viewMenu->idAt(1), true);
}
}
OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection
}
return QWidget::eventFilter( o, e );
}
void AdvancedFm::cancelRename() {
// odebug << "cancel rename" << oendl;
QListView * view;
view = CurrentView();
bool resetFocus = view->viewport()->focusProxy() == renameBox;
delete renameBox;
renameBox = 0;
if ( resetFocus ) {
view->viewport()->setFocusProxy( view);
view->setFocus();
}
}
void AdvancedFm::doRename(QListView * view) {
if( !CurrentView()->currentItem()) return;
QRect r = view->itemRect( view->currentItem( ));
r = QRect( view->viewportToContents( r.topLeft() ), r.size() );
r.setX( view->contentsX() );
if ( r.width() > view->visibleWidth() )
r.setWidth( view->visibleWidth() );
renameBox = new QLineEdit( view->viewport(), "qt_renamebox" );
renameBox->setFrame(true);
renameBox->setText( view->currentItem()->text(0) );
renameBox->selectAll();
renameBox->installEventFilter( this );
view->addChild( renameBox, r.x(), r.y() );
renameBox->resize( r.size() );
view->viewport()->setFocusProxy( renameBox );
renameBox->setFocus();
renameBox->show();
}
void AdvancedFm::renameIt() {
if( !CurrentView()->currentItem()) return;
QListView *thisView = CurrentView();
oldName = thisView->currentItem()->text(0);
doRename( thisView );
}
void AdvancedFm::okRename() {
qDebug("okrename");
if( !renameBox) return;
QString newName = renameBox->text();
cancelRename();
QListView * view = CurrentView();
QString path = CurrentDir()->canonicalPath() + "/";
oldName = path + oldName;