From fa1e47631442d509e9c1603684bdc9e9590cf866 Mon Sep 17 00:00:00 2001 From: llornkcor Date: Fri, 07 Nov 2003 12:37:57 +0000 Subject: from 1.0, needs fix --- (limited to 'noncore/apps/advancedfm') diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 2fc4b49..ecf471d 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -102,112 +102,115 @@ void AdvancedFm::tabChanged(QWidget *) { void AdvancedFm::populateView() { - QPixmap pm; - QListView *thisView = CurrentView(); - QDir *thisDir = CurrentDir(); - QString path = thisDir->canonicalPath(); -// qWarning("path is "+path); - 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(tr("AdvancedFm :: ")+fs+" :: " - +checkDiskSpace((const QString &) path)+ tr(" 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() ) { - QString symLink=fi->readLink(); - QFileInfo sym( symLink); - fileS.sprintf( "%10i", sym.size() ); - fileL = fi->fileName() +" -> " + sym.filePath().data(); - fileDate = sym.lastModified().toString(); - } else { - fileS.sprintf( "%10i", fi->size() ); - fileL = fi->fileName(); - fileDate= fi->lastModified().toString(); - if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { -// if(fileL == "..") - fileL += "/"; - isDir=TRUE; - } - } - QFileInfo fileInfo( path + "/" + fileL); - if(fileL !="./" && fi->exists()) { - item = new QListViewItem( thisView, fileL, fileS , fileDate); - - 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( (fileInfo.permission( QFileInfo::ExeUser) - | fileInfo.permission( QFileInfo::ExeGroup) - | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { - pm = Resource::loadPixmap( "exec"); - } - 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) { - // qDebug(" overlay link image"); - pm= Resource::loadPixmap( "advancedfm/symlink" ); - // pm= Resource::loadPixmap( "folder" ); +qWarning("PopulateView"); + QPixmap pm; + QListView *thisView = CurrentView(); + QDir *thisDir = CurrentDir(); + QString path = thisDir->canonicalPath(); + +qWarning("path is "+path); + 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(tr("AdvancedFm :: ")+fs+" :: " + +checkDiskSpace((const QString &) path)+ tr(" 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() ) { + QString symLink=fi->readLink(); + QFileInfo sym( symLink); + fileS.sprintf( "%10i", sym.size() ); + fileL = fi->fileName() +" -> " + sym.filePath().data(); + fileDate = sym.lastModified().toString(); + } else { + fileS.sprintf( "%10i", fi->size() ); + fileL = fi->fileName(); + fileDate= fi->lastModified().toString(); + if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { +// if(fileL == "..") + fileL += "/"; + isDir=TRUE; + } + } + QFileInfo fileInfo( path + "/" + fileL); + + if(fileL !="./" && fi->exists()) { + item = new QListViewItem( thisView, fileL, fileS , fileDate); + + 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( (fileInfo.permission( QFileInfo::ExeUser) + | fileInfo.permission( QFileInfo::ExeGroup) + | fileInfo.permission( QFileInfo::ExeOther)) && fs != "vfat" ) { + pm = Resource::loadPixmap( "exec"); + } + 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) { + // 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) { - struct stat buf; - dev_t devT; - DIR *dir; - struct dirent *mydirent; - - if((dir = opendir( path.latin1())) != NULL) - while ((mydirent = readdir(dir)) != NULL) { - lstat( mydirent->d_name, &buf); + } + item->setPixmap( 0,pm); + + } + isDir=FALSE; + ++it; + } + + 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) { + 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 ) { - item= new QListViewItem( thisView, fileL, fileS, fileDate); - pm = unknownXpm; - item->setPixmap( 0,pm); - } - } + 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 ) { + item= new QListViewItem( thisView, fileL, fileS, fileDate); + pm = unknownXpm; + item->setPixmap( 0,pm); + } + } - closedir(dir); - } + closedir(dir); + } - thisView->setSorting( 3,FALSE); - fillCombo( (const QString &) path ); + thisView->setSorting( 3,FALSE); + fillCombo( (const QString &) path ); } void AdvancedFm::rePopulate() { @@ -809,7 +812,7 @@ QListView * AdvancedFm::OtherView() { } void AdvancedFm::setOtherTabCurrent() { -// qWarning("setOtherTabCurrent()"); + qWarning("setOtherTabCurrent() %d", whichTab); if ( whichTab == 1) { TabWidget->setCurrentWidget(1); } else { diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 5f6eabb..be574c4 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -154,7 +154,9 @@ protected slots: void doAbout(); void doBeam(); void fileBeamFinished( Ir *); - + bool copyDirectory( const QString & , const QString & ); +// void navigateToSelected(); + bool moveDirectory( const QString & , const QString & ); // void slotSwitchtoLocal(int); private: diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index c0be948..90c887f 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -68,8 +68,8 @@ void AdvancedFm::showMenuHidden() { OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); } - rePopulate(); b = !b; + populateView(); } void AdvancedFm::showHidden() { @@ -80,7 +80,7 @@ void AdvancedFm::showHidden() { CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); } - rePopulate(); + populateView(); } QString AdvancedFm::dealWithSymName(const QString &fileName) { @@ -146,7 +146,7 @@ void AdvancedFm::makeDir() { QString filename = fileDlg->LineEdit1->text(); thisDir->mkdir( thisDir->canonicalPath()+"/"+filename); } - populateView(); + populateView(); } void AdvancedFm::doDelete() { @@ -191,7 +191,7 @@ void AdvancedFm::doDelete() { f=f.left(f.length()-1); QString cmd="rm -rf "+f; startProcess( (const QString)cmd.latin1() ); - populateView(); + populateView(); } break; case 1: @@ -228,7 +228,7 @@ void AdvancedFm::doDelete() { } } } - populateView(); + populateView(); } void AdvancedFm::filePerms() { @@ -245,7 +245,7 @@ void AdvancedFm::filePerms() { if( filePerm) delete filePerm; } - populateView(); + populateView(); } void AdvancedFm::doProperties() { @@ -278,7 +278,7 @@ void AdvancedFm::upDir() { chdir( current.latin1() ); thisDir->cd( current, TRUE); - populateView(); + populateView(); update(); } @@ -339,8 +339,8 @@ void AdvancedFm::copy() { return; } } - rePopulate(); - setOtherTabCurrent(); + setOtherTabCurrent(); + rePopulate(); } } @@ -389,8 +389,8 @@ void AdvancedFm::copyAs() { delete fileDlg; } - rePopulate(); - setOtherTabCurrent(); + rePopulate(); + setOtherTabCurrent(); } void AdvancedFm::copySameDir() { @@ -438,7 +438,7 @@ void AdvancedFm::copySameDir() { } delete fileDlg; } - populateView(); + rePopulate(); } void AdvancedFm::move() { @@ -461,32 +461,80 @@ void AdvancedFm::move() { curFile = thisDir->canonicalPath(); if(curFile.right(1).find("/",0,TRUE) == -1) - curFile +="/"; + curFile +="/"; curFile+= item; // qDebug("CurrentFile file is " + curFile); - QFile f( curFile); + if(QFileInfo(curFile).isDir()) { + moveDirectory( curFile, destFile ); + rePopulate(); + return; + } + + 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; } +bool AdvancedFm::copyDirectory( const QString & src, const QString & 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; + } + + return true; +} + + bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { - 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; @@ -633,9 +681,9 @@ void AdvancedFm::mkSym() { // qDebug(cmd); startProcess( (const QString)cmd ); } - rePopulate(); - setOtherTabCurrent(); - } + rePopulate(); + setOtherTabCurrent(); + } } void AdvancedFm::doBeam() { @@ -687,7 +735,7 @@ void AdvancedFm::startProcess(const QString & cmd) { } void AdvancedFm::processEnded(OProcess *) { - populateView(); + rePopulate(); } void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { @@ -775,7 +823,7 @@ void AdvancedFm::renameIt() { QListView *thisView = CurrentView(); oldName = thisView->currentItem()->text(0); doRename( thisView ); - populateView(); + rePopulate(); } void AdvancedFm::okRename() { @@ -794,7 +842,7 @@ void AdvancedFm::okRename() { view->takeItem( view->currentItem() ); delete view->currentItem(); - populateView(); + rePopulate(); } void AdvancedFm::openSearch() { -- cgit v0.9.0.2