-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 93203cd..eae86a4 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -15,65 +15,66 @@ #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> #include <qstring.h> #include <qlayout.h> #include <qpixmap.h> #include <qcombobox.h> #include <qpopupmenu.h> #include <qtabwidget.h> #include <qtoolbutton.h> #include <qtabwidget.h> #include <qlineedit.h> #include <qlistview.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> #include <dirent.h> - +#include <sys/sendfile.h> +#include <fcntl.h> void AdvancedFm::doDirChange() { ListClicked( CurrentView()->currentItem()); } 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); // b=FALSE; } 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=TRUE; } rePopulate(); // if(b) qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<< true"); if(b) b = false; else b = true; } void AdvancedFm::showHidden() { if (b) { @@ -283,65 +284,65 @@ void AdvancedFm::doProperties() #endif } 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(); update(); } void AdvancedFm::copy() { qApp->processEvents(); QStringList curFileList = getPath(); QDir *thisDir = CurrentDir(); QDir *thatDir = OtherDir(); bool doMsg=true; int count=curFileList.count(); if( count > 0) { if(count > 1 ){ QString msg; msg=tr("Really copy\n%1 files?").arg(count); - switch ( QMessageBox::warning(this,tr("Delete"),msg + switch ( QMessageBox::warning(this,tr("Copy"),msg ,tr("Yes"),tr("No"),0,0,1) ) { case 0: doMsg=false; break; case 1: return; break; }; } QString curFile, item, destFile; for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { item=(*it); if(item.find("->",0,TRUE)) //symlink item = item.left(item.find("->",0,TRUE)); curFile = thisDir->canonicalPath()+"/"+ item; destFile = thatDir->canonicalPath()+"/"+ item; qDebug("Destination file is "+destFile); qDebug("CurrentFile file is " + curFile); QFile f(destFile); if( f.exists()) { if(doMsg) { switch ( QMessageBox::warning(this,tr("File Exists!"), tr("%1 exists. Ok to overwrite?").arg( item ), tr("Yes"),tr("No"),0,0,1) ) @@ -491,90 +492,114 @@ void AdvancedFm::move() 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+= item; qDebug("CurrentFile file is " + curFile); QFile f( curFile); if( f.exists()) { if( !copyFile( curFile, destFile) ) { QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); return; } else QFile::remove(curFile); } } } setOtherTabCurrent(); populateView(); // populateLocalView(); } bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { - char bf[ 50000 ]; - int bytesRead; - bool success = TRUE; - struct stat status; +// char bf[ 50000 ]; +// int bytesRead; + bool success = true; + struct stat status; + +// QFile s( src ); +// QFile d( dest ); + + int read_fd=0; + int write_fd=0; + struct stat stat_buf; + off_t offset = 0; + read_fd = ::open(src.latin1(), O_RDONLY); + if(read_fd != -1) { + fstat (read_fd, &stat_buf); + write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode); + if(write_fd != -1) { + if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) { + success = false; + } + } else { + success = false; + } + } else { + success = false; + } - QFile s( src ); - QFile d( dest ); + ::close (read_fd); + ::close (write_fd); - if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) - { - while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) - { - if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ - success = FALSE; - break; - } - } - if( success && (bytesRead > 0) ) - { - d.writeBlock( bf, bytesRead ); - } - } - else - { - success = FALSE; - } + +// if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) +// { +// while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) +// { +// if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){ +// success = FALSE; +// break; +// } +// } +// if( success && (bytesRead > 0) ) +// { +// d.writeBlock( bf, bytesRead ); +// } + +// } +// else +// { +// success = FALSE; +// } // Set file permissions if( stat( (const char *) src, &status ) == 0 ) { chmod( (const char *) dest, status.st_mode ); } return success; } void AdvancedFm::runCommand() { 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 ) { qDebug(fileDlg->LineEdit1->text()); QStringList command; command << "/bin/sh"; command << "-c"; command << fileDlg->LineEdit1->text(); Output *outDlg; |