-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 71 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 267 |
2 files changed, 150 insertions, 188 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 60558e7..77dca49 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -108,123 +108,109 @@ void AdvancedFm::populateView() QListView *thisView = CurrentView(); QDir *thisDir = CurrentDir(); QString path = thisDir->canonicalPath(); thisView->clear(); thisDir->setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); thisDir->setMatchAllDirs(TRUE); thisDir->setNameFilter(filterStr); QString fileL, fileS, fileDate; QString fs= getFileSystemType((const QString &) path); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) path)+" kB free" ); bool isDir=FALSE; const QFileInfoList *list = thisDir->entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); QFileInfoListIterator it(*list); QFileInfo *fi; - while ( (fi=it.current()) ) - { - if (fi->isSymLink() ) - { + while ( (fi=it.current()) ) { + if (fi->isSymLink() ) { QString symLink=fi->readLink(); QFileInfo sym( symLink); fileS.sprintf( "%10i", sym.size() ); - fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.filePath().data() ); + fileL = fi->fileName() +" -> " + sym.filePath().data(); fileDate = sym.lastModified().toString(); - } - else - { + } else { fileS.sprintf( "%10i", fi->size() ); - fileL.sprintf( "%s",fi->fileName().data() ); + fileL = fi->fileName(); fileDate= fi->lastModified().toString(); - if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) - { + if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; } } - QFileInfo fileInfo( path + "/" + fileL); - if(fileL !="./" && fi->exists()) - { - item= new QListViewItem( thisView, fileL, fileS , fileDate); + if(fileL !="./" && fi->exists()) { + item = new QListViewItem( thisView, fileL, fileS , fileDate); - if(isDir || fileL.find("/",0,TRUE) != -1) - { + if(isDir || fileL.find("/",0,TRUE) != -1) { if( !QDir( fi->filePath() ).isReadable()) //is directory pm = Resource::loadPixmap( "lockedfolder" ); else pm= Resource::loadPixmap( "folder" ); } - else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) - { - pm = Resource::loadPixmap( "exec"); + else if ( fs == "vfat" && fileInfo.filePath().contains("/bin") ) { + pm = Resource::loadPixmap( "exec"); } else if( (fileInfo.permission( QFileInfo::ExeUser) | fileInfo.permission( QFileInfo::ExeGroup) - | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) - { + | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { pm = Resource::loadPixmap( "exec"); } - else if( !fi->isReadable() ) - { + else if( !fi->isReadable() ) { pm = Resource::loadPixmap( "locked" ); } else { //everything else goes by mimetype MimeType mt(fi->filePath()); pm=mt.pixmap(); //sets the correct pixmap for mimetype if(pm.isNull()) { pm = unknownXpm; } } - if( fi->isSymLink() && fileL.find("->",0,TRUE) != -1) - { - // overlay link image - pm= Resource::loadPixmap( "folder" ); - QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); - QPainter painter( &pm ); - painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); - pm.setMask( pm.createHeuristicMask( FALSE ) ); + if( fi->isSymLink() || fileL.find("->",0,TRUE) != -1) { + // qDebug(" overlay link image"); + pm= Resource::loadPixmap( "advancedfm/symlink" ); + // pm= Resource::loadPixmap( "folder" ); +// QPixmap lnk = Resource::loadPixmap( "opie/symlink" ); +// QPainter painter( &pm ); +// painter.drawPixmap( pm.width()-lnk.width(), pm.height()-lnk.height(), lnk ); +// pm.setMask( pm.createHeuristicMask( FALSE ) ); } item->setPixmap( 0,pm); } isDir=FALSE; ++it; } - if( path.find("dev",0,TRUE) != -1) - { + if( path.find("dev",0,TRUE) != -1) { struct stat buf; dev_t devT; DIR *dir; struct dirent *mydirent; if((dir = opendir( path.latin1())) != NULL) - while ((mydirent = readdir(dir)) != NULL) - { + while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); // qDebug(mydirent->d_name); fileL.sprintf("%s", mydirent->d_name); devT = buf.st_dev; fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); fileDate.sprintf("%s", ctime( &buf.st_mtime)); - if( fileL.find(".") == -1 ) - { + if( fileL.find(".") == -1 ) { item= new QListViewItem( thisView, fileL, fileS, fileDate); pm = unknownXpm; item->setPixmap( 0,pm); } } closedir(dir); } thisView->setSorting( 3,FALSE); fillCombo( (const QString &) path ); } void AdvancedFm::rePopulate() { int tmpTab = whichTab; @@ -667,42 +653,41 @@ QString AdvancedFm::checkDiskSpace(const QString &path) long mult = blkSize / 1024; long div = 1024 / blkSize; if ( !mult ) mult = 1; if ( !div ) div = 1; return QString::number(availBlks * mult / div); } return ""; } void AdvancedFm::addToDocs() { QStringList strListPaths = getPath(); QDir *thisDir = CurrentDir(); - if( strListPaths.count() > 0) - { + if( strListPaths.count() > 0) { QString curFile; - for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) - { + for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = thisDir->canonicalPath()+"/"+(*it); // qDebug(curFile); + QFileInfo fi(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); - f.setName((*it)); + f.setName(fi.baseName() ); f.setFile( curFile); f.writeLink(); } } } void AdvancedFm::customDirsToMenu() { Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QStringList list = cfg.readListEntry( "CustomDir", ','); menuButton->insertItems(list ); diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 9f21245..00d0e07 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -25,39 +25,41 @@ #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 <errno.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 @@ -157,115 +159,111 @@ 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(); } 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) ) - { - case 0: - doMsg=false; - break; - case 1: - return; - break; - }; + 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) ) + { + case 0: + doMsg=false; + break; + case 1: + return; + break; + }; } QString myFile; - 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?"), - 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(); - } - break; - case 1: - // exit - break; - }; - } else { - if(doMsg) { - switch ( QMessageBox::warning(this,tr("Delete"), - tr("Really delete\n%1?").arg( 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) { - qDebug("remove link files "+f); -// AppLnk lnk(f); -// qDebug(lnk.linkFile()); -// lnk.removeLinkFile(); - file.remove(); - } + 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?"), + 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(); + } + 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)); filePerm->showMaximized(); filePerm->exec(); if( filePerm) @@ -354,34 +352,33 @@ void AdvancedFm::copy() 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) ) { case 1: return; break; }; } f.remove(); } - if( !copyFile( curFile, destFile) ) - { + if( !copyFile( curFile, destFile) ) { QMessageBox::message("AdvancedFm", tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); return; } } setOtherTabCurrent(); populateView(); } } void AdvancedFm::copyAs() { qApp->processEvents(); QStringList curFileList = getPath(); QString curFile, item; @@ -407,34 +404,33 @@ void AdvancedFm::copyAs() QFile f( destFile); if( f.exists()) { switch (QMessageBox::warning(this,tr("File Exists!"), item+tr("\nexists. Ok to overwrite?"), tr("Yes"),tr("No"),0,0,1) ) { case 0: f.remove(); break; case 1: return; break; }; } - if( !copyFile( curFile, destFile) ) - { + if( !copyFile( curFile, destFile) ) { QMessageBox::message("AdvancedFm",tr("Could not copy\n") +curFile +tr("to\n")+destFile); return; } } delete fileDlg; } setOtherTabCurrent(); populateView(); } void AdvancedFm::copySameDir() { qApp->processEvents(); QStringList curFileList = getPath(); @@ -460,34 +456,33 @@ void AdvancedFm::copySameDir() QFile f(destFile); if( f.exists()) { switch (QMessageBox::warning(this,tr("Delete"), destFile+tr(" already exists.\nDo you really want to delete it?"), tr("Yes"),tr("No"),0,0,1) ) { case 0: f.remove(); break; case 1: return; break; }; } - if(!copyFile( curFile,destFile) ) - { + 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; } populateView(); } void AdvancedFm::move() { qApp->processEvents(); @@ -503,103 +498,92 @@ void AdvancedFm::move() 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+= item; qDebug("CurrentFile file is " + curFile); QFile f( curFile); if( f.exists()) { - if( !copyFile( curFile, destFile) ) - { + 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; - -// QFile s( src ); -// QFile d( dest ); - + 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; - read_fd = ::open(src.latin1(), O_RDONLY); + 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); - write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode); + if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { + qWarning("destfile open failed"); + return success = false; + } + write_fd = destFile.handle(); if(write_fd != -1) { - if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) { - success = false; + 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); } } else { success = false; } } else { success = false; } - - ::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; -// } - + srcFile.close(); + destFile.close(); // Set file permissions - if( stat( (const char *) src, &status ) == 0 ) - { + 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); @@ -699,56 +683,49 @@ void AdvancedFm::mkSym() if( curFile.right(1) == "/") { curFile = curFile.left( curFile.length() -1); } cmd = "ln -s "+curFile+" "+destName; qDebug(cmd); startProcess( (const QString)cmd ); } setOtherTabCurrent(); populateView(); } } void AdvancedFm::doBeam() { - Ir ir; - if(!ir.supported()) - { - } - else - { + 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 = CurrentDir()->canonicalPath()+"/"+(*it); - if( curFile.right(1) == "/") - { - curFile = curFile.left( curFile.length() -1); - } - Ir *file = new Ir(this, "IR"); - connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); - file->send( curFile, curFile ); + 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() { // if (TabWidget->currentTab() == 0) { QListView *thisView = CurrentView(); thisView->selectAll(true); thisView->setSelected( thisView->firstChild(),false); // } else { // Remote_View->selectAll(true); // Remote_View->setSelected( Remote_View->firstChild(),false); |