Diffstat (limited to 'noncore/apps/advancedfm/advancedfm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 200 |
1 files changed, 44 insertions, 156 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index 74654fc..fc6c3bf 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -65,26 +65,28 @@ #include <string.h> #include <errno.h> #include <sys/vfs.h> #include <mntent.h> #include <sys/utsname.h> AdvancedFm::AdvancedFm( ) : QMainWindow( ) { init(); renameBox = 0; initConnections(); - populateLocalView(); - populateRemoteView(); + TabWidget->setCurrentTab(1); + populateView(); + TabWidget->setCurrentTab(0); + populateView(); currentPathCombo->setFocus(); } AdvancedFm::~AdvancedFm() { } void AdvancedFm::cleanUp() { QString sfile=QDir::homeDirPath(); if(sfile.right(1) != "/") sfile+="/._temp"; @@ -106,67 +108,74 @@ void AdvancedFm::tabChanged(QWidget *w) QString path = CurrentDir()->canonicalPath(); currentPathCombo->lineEdit()->setText( path ); viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); QString fs= getFileSystemType( (const QString &) path); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace( (const QString &) path )+ " kB free" ); chdir( path.latin1()); +//2 populateView(); } -void AdvancedFm::populateLocalView() +void AdvancedFm::populateView() { QPixmap pm; - Local_View->clear(); - currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); - currentDir.setMatchAllDirs(TRUE); - currentDir.setNameFilter(filterStr); + 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 &) currentDir.canonicalPath()); + QString fs= getFileSystemType((const QString &) path); setCaption("AdvancedFm :: "+fs+" :: " - +checkDiskSpace((const QString &) currentDir.canonicalPath())+" kB free" ); + +checkDiskSpace((const QString &) path)+" kB free" ); bool isDir=FALSE; - const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); + 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.sprintf( "%s -> %s", fi->fileName().data(),sym.filePath().data() ); fileDate = sym.lastModified().toString(); } else { fileS.sprintf( "%10i", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); fileDate= fi->lastModified().toString(); - if( QDir(QDir::cleanDirPath( currentDir.canonicalPath()+"/"+fileL)).exists() ) + if( QDir(QDir::cleanDirPath( path +"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; } } - QFileInfo fileInfo( currentDir.canonicalPath()+"/"+fileL); + + QFileInfo fileInfo( path + "/" + fileL); + if(fileL !="./" && fi->exists()) { - item= new QListViewItem( Local_View, fileL, fileS , fileDate); + 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"); @@ -194,177 +203,56 @@ void AdvancedFm::populateLocalView() 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(currentDir.canonicalPath().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( currentDir.canonicalPath().latin1())) != NULL) + 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( Local_View, fileL, fileS, fileDate); + item= new QListViewItem( thisView, fileL, fileS, fileDate); pm = Resource::loadPixmap( "UnknownDocument-14" ); item->setPixmap( 0,pm); } } closedir(dir); } - Local_View->setSorting( 3,FALSE); - fillCombo( (const QString &) currentDir.canonicalPath()); + thisView->setSorting( 3,FALSE); + fillCombo( (const QString &) path ); } -void AdvancedFm::populateRemoteView() -{ - QPixmap pm; - Remote_View->clear(); - currentRemoteDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); - currentRemoteDir.setMatchAllDirs(TRUE); - currentRemoteDir.setNameFilter(filterStr); - QString fileL, fileS, fileDate; - - QString fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath()); - setCaption("AdvancedFm :: "+fs+" :: " - +checkDiskSpace((const QString &) currentRemoteDir.canonicalPath())+" kB free" ); - bool isDir=FALSE; - const QFileInfoList *list = currentRemoteDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); - QFileInfoListIterator it(*list); - QFileInfo *fi; - while ( (fi=it.current()) ) - { - if (fi->isSymLink() ) - { - QString symLink=fi->readLink(); - // qDebug("Symlink detected "+symLink); - QFileInfo sym( symLink); - fileS.sprintf( "%10i", sym.size() ); - fileL.sprintf( "%s -> %s", fi->fileName().data(),sym.filePath().data() ); - fileDate = sym.lastModified().toString(); - } - else - { - // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); - fileS.sprintf( "%10i", fi->size() ); - fileL.sprintf( "%s",fi->fileName().data() ); - fileDate= fi->lastModified().toString(); - - if( QDir(QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+fileL)).exists() ) - { - fileL+="/"; - isDir=TRUE; - // qDebug( fileL); - } - } - - QFileInfo fileInfo( currentRemoteDir.canonicalPath()+"/"+fileL); - if(fileL !="./" && fi->exists()) - { - item= new QListViewItem( Remote_View, fileL, fileS, fileDate); - QPixmap pm; - - if(isDir || fileL.find("/",0,TRUE) != -1) - { - if( !QDir( fi->filePath() ).isReadable()) - 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 - { - MimeType mt(fi->filePath()); - pm=mt.pixmap(); //sets the correct pixmap for mimetype - if(pm.isNull()) - pm = Resource::loadPixmap( "UnknownDocument-14" ); - } - 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 ) ); - } - item->setPixmap( 0, pm); - } - isDir=FALSE; - ++it; - } - - if(currentRemoteDir.canonicalPath().find("dev",0,TRUE) != -1) - { - struct stat buf; - DIR *dir; - struct dirent *mydirent; - if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) - - while ((mydirent = readdir(dir)) != NULL) - { - lstat( mydirent->d_name, &buf); -// qDebug(mydirent->d_name); - fileL.sprintf("%s", mydirent->d_name); - fileS.sprintf("%d,%d", (int) (buf.st_dev>>8)&0xFF, (int) buf.st_dev &0xFF); - fileDate.sprintf("%s", ctime( &buf.st_mtime)); - - if( fileL.find(".") == -1 ) - { - item= new QListViewItem( Remote_View, fileL, fileS, fileDate); - pm = Resource::loadPixmap( "UnknownDocument-14" ); - item->setPixmap( 0,pm); - } - } - - closedir(dir); - } - - Remote_View->setSorting( 3,FALSE); - fillCombo( (const QString &) currentRemoteDir.canonicalPath() ); -} - void AdvancedFm::ListClicked(QListViewItem *selectedItem) { if(selectedItem) { QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); strSize=strSize.stripWhiteSpace(); bool isDirectory = false; QString strItem2; if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 )//if symlink { @@ -374,25 +262,25 @@ void AdvancedFm::ListClicked(QListViewItem *selectedItem) } if( strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { if(QDir(strItem).exists()) isDirectory = true; } if( isDirectory ) { CurrentDir()->cd( strItem, TRUE); - PopulateView(); + populateView(); CurrentView()->ensureItemVisible( CurrentView()->firstChild()); } chdir( strItem.latin1()); } } void AdvancedFm::ListPressed( int mouse, QListViewItem *, const QPoint& , int ) { switch (mouse) { case 1: { if(renameBox != 0 ) { @@ -425,25 +313,25 @@ void AdvancedFm::readConfig() } void AdvancedFm::writeConfig() { Config cfg("AdvancedFm"); } void AdvancedFm::currentPathComboChanged() { if(QDir( currentPathCombo->lineEdit()->text()).exists()) { CurrentDir()->setPath( currentPathCombo->lineEdit()->text() ); - PopulateView(); + populateView(); } else { QMessageBox::message(tr("Note"),tr("That directory does not exist")); } } void AdvancedFm::fillCombo(const QString ¤tPath) { // qDebug("%d",TabWidget->getCurrentTab()); if ( whichTab == 1) { @@ -462,25 +350,25 @@ void AdvancedFm::fillCombo(const QString ¤tPath) { currentPathCombo->clear(); remoteDirPathStringList.prepend( currentPath ); currentPathCombo->insertStringList( remoteDirPathStringList,-1); } } } void AdvancedFm::currentPathComboActivated(const QString & currentPath) { chdir( currentPath.latin1() ); CurrentDir()->cd( currentPath, TRUE); - PopulateView(); + populateView(); update(); } QStringList AdvancedFm::getPath() { QStringList strList; QListView *thisView=CurrentView(); QList<QListViewItem> * getSelectedItems( QListView * thisView ); QListViewItemIterator it( thisView ); for ( ; it.current(); ++it ) { if ( it.current()->isSelected() ) @@ -488,58 +376,58 @@ QStringList AdvancedFm::getPath() strList << it.current()->text(0); // qDebug(it.current()->text(0)); } } return strList; } void AdvancedFm::homeButtonPushed() { QString current = QDir::homeDirPath(); chdir( current.latin1() ); CurrentDir()->cd( current, TRUE); - PopulateView(); + populateView(); update(); } void AdvancedFm::docButtonPushed() { QString current = QPEApplication::documentDir(); chdir( current.latin1() ); CurrentDir()->cd( current, TRUE); - PopulateView(); + populateView(); update(); } void AdvancedFm::SDButtonPushed() { QString current = "/mnt/card";// this can change so fix chdir( current.latin1() ); CurrentDir()->cd( current, TRUE); - PopulateView(); + populateView(); update(); } void AdvancedFm::CFButtonPushed() { QString current; if(zaurusDevice) current= "/mnt/cf"; //zaurus else current = "/mnt/hda"; //ipaq chdir( current.latin1() ); CurrentDir()->cd( current, TRUE); - PopulateView(); + populateView(); update(); } void AdvancedFm::doAbout() { QMessageBox::message("AdvancedFm",tr("Advanced FileManager\n" "is copyright 2002-2003 by\n" "L.J.Potter<llornkcor@handhelds.org>\n" "and is licensed by the GPL")); } @@ -622,25 +510,25 @@ void AdvancedFm::keyPressEvent( QKeyEvent *e) void AdvancedFm::keyReleaseEvent( QKeyEvent *e) { if( CurrentView()->hasFocus() ) e->ignore(); } void AdvancedFm::QPEButtonPushed() { QString current = QPEApplication::qpeDir(); chdir( current.latin1() ); CurrentDir()->cd( current, TRUE); - PopulateView(); + populateView(); update(); } void AdvancedFm::parsetab(const QString &fileName) { fileSystemTypeList.clear(); fsList.clear(); struct mntent *me; FILE *mntfp = setmntent( fileName.latin1(), "r" ); if ( mntfp ) { @@ -939,25 +827,25 @@ void AdvancedFm::gotoCustomDir(const QString &dir) } if( curDir == s_removeBookmark) { removeCustomDir( ); } else { if(QDir( curDir).exists() ) { thisDir->setPath( curDir ); chdir( curDir.latin1() ); thisDir->cd( curDir, TRUE); - PopulateView(); + populateView(); } } } QDir *AdvancedFm::CurrentDir() { if ( whichTab == 1) { return ¤tDir; } else { @@ -968,35 +856,35 @@ QDir *AdvancedFm::CurrentDir() QDir *AdvancedFm::OtherDir() { if ( whichTab == 1) { return ¤tRemoteDir; } else { return ¤tDir; } } -void AdvancedFm::PopulateView() -{ - if ( whichTab == 1) - populateLocalView(); - else - populateRemoteView(); -} - QListView * AdvancedFm::CurrentView() { if ( whichTab == 1) return Local_View; else return Remote_View; } QListView * AdvancedFm::OtherView() { if ( whichTab == 1) return Remote_View; else return Local_View; } + +void AdvancedFm::setOtherTabCurrent() +{ + if ( whichTab == 1) + TabWidget->setCurrentTab(1); + else + TabWidget->setCurrentTab(0); +} |