summaryrefslogtreecommitdiff
path: root/noncore/apps/advancedfm/advancedfmMenu.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp161
1 files changed, 79 insertions, 82 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 78f9da2..18bbd43 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -4,27 +4,24 @@
** 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 "output.h"
#include "filePermissions.h"
-#include <opie/otabwidget.h>
-#include <opie/oprocess.h>
-
#include <qpe/lnkproperties.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/applnk.h>
#include <qpe/ir.h>
#include <qmessagebox.h>
#include <qmultilineedit.h>
#include <qstring.h>
@@ -60,36 +57,36 @@ void AdvancedFm::doDirChange() {
void AdvancedFm::showMenuHidden() {
if (b) {
CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
} else {
CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
}
b = !b;
- populateView();
+ populateView();
}
void AdvancedFm::showHidden() {
if (b) {
CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
} else {
CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
}
- populateView();
+ populateView();
}
QString AdvancedFm::dealWithSymName(const QString &fileName) {
QString strItem = fileName;
return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4);
}
void AdvancedFm::runThis() {
if( !CurrentView()->currentItem()) return;
QString fs;
QDir *thisDir = CurrentDir();
@@ -137,25 +134,25 @@ void AdvancedFm::runText() {
}
}
void AdvancedFm::makeDir() {
InputDialog *fileDlg;
fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
fileDlg->exec();
if( fileDlg->result() == 1 ) {
QDir *thisDir = CurrentDir();
QString filename = fileDlg->LineEdit1->text();
thisDir->mkdir( thisDir->canonicalPath()+"/"+filename);
}
- populateView();
+ populateView();
}
void AdvancedFm::doDelete() {
QStringList curFileList = getPath();
bool doMsg=true;
int count = curFileList.count();
if( count > 0) {
if(count > 1 ) {
QString msg;
msg=tr("Really delete\n%1 files?").arg(count);
switch ( QMessageBox::warning(this,tr("Delete"),msg
,tr("Yes"),tr("No"),0,0,1) )
@@ -174,86 +171,86 @@ void AdvancedFm::doDelete() {
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
myFile = (*it);
if( myFile.find(" -> ",0,TRUE) != -1)
myFile = myFile.left( myFile.find(" -> ",0,TRUE));
QString f = CurrentDir()->canonicalPath();
if(f.right(1).find("/",0,TRUE) == -1)
f += "/";
f += myFile;
if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
//if file is a directory
- switch ( QMessageBox::warning( this, tr("Delete Directory?"),
+ switch ( QMessageBox::warning( this, tr("Delete Directory?"),
tr("Really delete %1\nand all it's contents ?" ).arg( f ) ,
tr("Yes"), tr("No"), 0, 0, 1) ) {
case 0:
{
f=f.left(f.length()-1);
QString cmd="rm -rf "+f;
startProcess( (const QString)cmd.latin1() );
- populateView();
+ populateView();
}
break;
case 1:
// exit
break;
};
} else {
if(doMsg) {
switch ( QMessageBox::warning(this,tr("Delete"),
tr("Really delete\n%1?").arg( myFile ),
tr("Yes"), tr("No"), 0, 0, 1) ) {
case 1:
return;
break;
};
}
-
+
QString cmd="rm "+f;
QFile file(f);
QFileInfo fi(myFile);
if( fi.fileName().find("../",0,TRUE)==-1) {
// qDebug("remove link files "+myFile);
-
+
// DocLnk lnk(f);
DocLnk *lnk;
lnk = new DocLnk(f);
// qDebug("Deleting doclnk " + lnk->linkFile());
if(lnk->isValid())
lnk->removeLinkFile();
// delete lnk;
file.remove();
}
}
}
}
- populateView();
+ populateView();
}
void AdvancedFm::filePerms() {
QStringList curFileList = getPath();
QString filePath;
filePath = CurrentDir()->canonicalPath()+"/";
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
filePermissions *filePerm;
filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it));
QPEApplication::execDialog( filePerm );
if( filePerm )
delete filePerm;
}
- populateView();
+ populateView();
}
void AdvancedFm::doProperties() {
#if defined(QT_QWS_OPIE)
QStringList curFileList = getPath();
QString filePath;
filePath = CurrentDir()->canonicalPath()+"/";
// qDebug("%d",curFileList.count());
@@ -267,25 +264,25 @@ void AdvancedFm::doProperties() {
}
void AdvancedFm::upDir() {
QDir *thisDir = CurrentDir();
QString current = thisDir->canonicalPath();
QDir dir(current);
dir.cdUp();
current = dir.canonicalPath();
chdir( current.latin1() );
thisDir->cd( current, TRUE);
- populateView();
+ populateView();
update();
}
void AdvancedFm::copy() {
qApp->processEvents();
QStringList curFileList = getPath();
QDir *thisDir = CurrentDir();
QDir *thatDir = OtherDir();
bool doMsg=true;
int count=curFileList.count();
@@ -328,26 +325,26 @@ void AdvancedFm::copy() {
break;
};
}
f.remove();
}
if( !copyFile( curFile, destFile) ) {
QMessageBox::message("AdvancedFm",
tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) );
return;
}
}
- setOtherTabCurrent();
- rePopulate();
+ setOtherTabCurrent();
+ rePopulate();
}
}
void AdvancedFm::copyAs() {
qApp->processEvents();
QStringList curFileList = getPath();
QString curFile, item;
InputDialog *fileDlg;
QDir *thisDir = CurrentDir();
QDir *thatDir = OtherDir();
@@ -378,26 +375,26 @@ void AdvancedFm::copyAs() {
break;
};
}
if( !copyFile( curFile, destFile) ) {
QMessageBox::message("AdvancedFm",tr("Could not copy\n")
+curFile +tr("to\n")+destFile);
return;
}
}
delete fileDlg;
}
- rePopulate();
- setOtherTabCurrent();
+ rePopulate();
+ setOtherTabCurrent();
}
void AdvancedFm::copySameDir() {
qApp->processEvents();
QStringList curFileList = getPath();
QString curFile, item, destFile;
InputDialog *fileDlg;
QDir *thisDir = CurrentDir();
for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
item=(*it);
@@ -427,136 +424,136 @@ void AdvancedFm::copySameDir() {
};
}
if(!copyFile( curFile,destFile) ) {
QMessageBox::message("AdvancedFm",tr("Could not copy\n")
+curFile +tr("to\n")+destFile);
return;
}
// qDebug("copy "+curFile+" as "+destFile);
}
delete fileDlg;
}
- rePopulate();
+ rePopulate();
}
void AdvancedFm::move() {
qApp->processEvents();
QStringList curFileList = getPath();
if( curFileList.count() > 0) {
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;
// qDebug("Destination file is "+destFile);
curFile = thisDir->canonicalPath();
if(curFile.right(1).find("/",0,TRUE) == -1)
- curFile +="/";
+ curFile +="/";
curFile+= item;
// qDebug("CurrentFile file is " + curFile);
if(QFileInfo(curFile).isDir()) {
- moveDirectory( curFile, destFile );
- rePopulate();
- return;
+ moveDirectory( curFile, destFile );
+ rePopulate();
+ return;
}
- QFile f( curFile);
+ QFile f( curFile);
if( f.exists()) {
- if( !copyFile( curFile, destFile) ) {
- QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
- return;
+ if( !copyFile( curFile, destFile) ) {
+ QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
+ return;
} else
- QFile::remove(curFile);
+ QFile::remove(curFile);
}
- }
+ }
}
- rePopulate();
- setOtherTabCurrent();
+ 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("Could not move\n") + src);
- return false;
- }
- return true;
+ 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("Could not move\n") + src);
+ return false;
+ }
+ return true;
}
bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
- QString cmd = "/bin/cp -fpR " + src + " " + dest;
+ QString cmd = "/bin/cp -fpR " + src + " " + dest;
qWarning(cmd);
- int err = system( (const char *) cmd );
- if ( err != 0 ) {
- QMessageBox::message("AdvancedFm",
- tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) );
- return false;
- }
+ int err = system( (const char *) cmd );
+ if ( err != 0 ) {
+ QMessageBox::message("AdvancedFm",
+ tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) );
+ return false;
+ }
- return true;
+ return true;
}
-
+
bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
-
- if(QFileInfo(src).isDir()) {
- if( copyDirectory( src, dest )) {
- setOtherTabCurrent();
- populateView();
- return true;
- }
- else
- return false;
- }
-
-
- bool success = true;
- struct stat status;
- QFile srcFile(src);
- QFile destFile(dest);
- int err=0;
- int read_fd=0;
+
+ if(QFileInfo(src).isDir()) {
+ if( copyDirectory( src, dest )) {
+ setOtherTabCurrent();
+ populateView();
+ 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)) {
// qWarning("open failed");
return success = false;
}
read_fd = srcFile.handle();
if(read_fd != -1) {
fstat (read_fd, &stat_buf);
if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
// qWarning("destfile open failed");
return success = false;
}
- write_fd = destFile.handle();
+ 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;
// qWarning(msg);
@@ -668,27 +665,27 @@ void AdvancedFm::mkSym() {
}
QString curFile = thisDir->canonicalPath()+"/"+(*it);
if( curFile.right(1) == "/") {
curFile = curFile.left( curFile.length() -1);
}
cmd = "ln -s "+curFile+" "+destName;
// qDebug(cmd);
startProcess( (const QString)cmd );
}
- rePopulate();
- setOtherTabCurrent();
- }
+ 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) == "/") {
@@ -722,25 +719,25 @@ void AdvancedFm::startProcess(const QString & cmd) {
connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)),
this, SLOT( oprocessStderr(OProcess *, char *, int)));
command << "/bin/sh";
command << "-c";
command << cmd.latin1();
*process << command;
if(!process->start(OProcess::NotifyOnExit, OProcess::All) )
qDebug("could not start process");
}
void AdvancedFm::processEnded(OProcess *) {
- rePopulate();
+ rePopulate();
}
void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) {
// qWarning("received stderrt %d bytes", buflen);
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 ) {
@@ -788,63 +785,63 @@ void AdvancedFm::cancelRename() {
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() )
+ 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() );
+ renameBox->resize( r.size() );
- view->viewport()->setFocusProxy( renameBox );
+ view->viewport()->setFocusProxy( renameBox );
- renameBox->setFocus();
+ renameBox->setFocus();
renameBox->show();
}
void AdvancedFm::renameIt() {
- if( !CurrentView()->currentItem()) return;
+ if( !CurrentView()->currentItem()) return;
- QListView *thisView = CurrentView();
+ QListView *thisView = CurrentView();
oldName = thisView->currentItem()->text(0);
doRename( thisView );
}
void AdvancedFm::okRename() {
if( !CurrentView()->currentItem()) return;
QString newName = renameBox->text();
- cancelRename();
- QListView * view = CurrentView();
+ cancelRename();
+ QListView * view = CurrentView();
QString path = CurrentDir()->canonicalPath() + "/";
oldName = path + oldName;
newName = path + newName;
if( rename( oldName.latin1(), newName.latin1())== -1)
QMessageBox::message(tr("Note"),tr("Could not rename"));
else
oldName = "";
view->takeItem( view->currentItem() );
delete view->currentItem();
- rePopulate();
+ rePopulate();
}
void AdvancedFm::openSearch() {
QMessageBox::message(tr("Note"),tr("Not Yet Implemented"));
}