-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 216 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 6 |
2 files changed, 141 insertions, 81 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index b5fcccf..ee3f736 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -53,24 +53,27 @@ #include <qpixmap.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qregexp.h> #include <unistd.h> #include <stdlib.h> #include <sys/stat.h> #include <dirent.h> #include <stdio.h> #include <time.h> #include <fcntl.h> +#include <mntent.h> +#include <string.h> +#include <errno.h> AdvancedFm::AdvancedFm( ) : QMainWindow( ) { setCaption( tr( "AdvancedFm" ) ); QGridLayout *layout = new QGridLayout( this ); layout->setSpacing( 2); layout->setMargin( 2); connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); @@ -262,111 +265,105 @@ void AdvancedFm::tabChanged(QWidget *w) viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); } if (TabWidget->currentPageIndex() == 1) { currentPathCombo->lineEdit()->setText( currentRemoteDir.canonicalPath()); viewMenu->setItemChecked(viewMenu->idAt(1),TRUE); viewMenu->setItemChecked(viewMenu->idAt(0),FALSE); } } void AdvancedFm::populateLocalView() { -// QList<QListViewItem> * getSelectedItems( QListView * Local_View ); -// QListViewItemIterator it( Local_View ); -// for ( ; it.current(); ++it ) { -// if ( it.current()->isSelected() ) { -// QString strItem = it.current()->text(0); -// QString localFile = currentDir.canonicalPath()+"/"+strItem; -// QFileInfo fi(localFile); -// } -// } QPixmap pm; Local_View->clear(); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter(filterStr); QString fileL, fileS, fileDate; // qDebug(currentDir.canonicalPath()); - +// struct stat buf; +// mode_t mode; + QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); + setCaption("AdvancedFm :: "+fs); bool isDir=FALSE; const QFileInfoList *list = currentDir.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( "%10li", sym.size() ); fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); fileDate = sym.lastModified().toString(); } else { fileS.sprintf( "%10li", fi->size() ); fileL.sprintf( "%s",fi->fileName().data() ); fileDate= fi->lastModified().toString(); - if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { + if( QDir(QDir::cleanDirPath( currentDir.canonicalPath()+"/"+fileL)).exists() ) { fileL+="/"; isDir=TRUE; // qDebug( fileL); } } + QFileInfo fileInfo( currentDir.canonicalPath()+"/"+fileL); if(fileL !="./" && fi->exists()) { item= new QListViewItem( Local_View, fileL, fileS , fileDate); + if(isDir || fileL.find("/",0,TRUE) != -1) { - if( !QDir( fi->filePath() ).isReadable()) + + if( !QDir( fi->filePath() ).isReadable()) //is directory pm = Resource::loadPixmap( "lockedfolder" ); else pm= Resource::loadPixmap( "folder" ); - item->setPixmap( 0,pm ); - } else { -// if(fi->isExecutable()) { -// pm = Resource::loadPixmap( "exec"); -// item->setPixmap( 0,pm); -// } - if( !fi->isReadable() ) { - pm = Resource::loadPixmap( "locked" ); - item->setPixmap( 0,pm); - - } - else { - MimeType mt(fi->filePath()); - pm=mt.pixmap(); //sets the correct pixmap for mimetype - if(pm.isNull()) - pm = Resource::loadPixmap( "UnknownDocument-14" ); - item->setPixmap( 0,pm); - } +// item->setPixmap( 0,pm ); + } else if( fileInfo.isExecutable() || fs == "vfat" && fi->filePath().contains("/bin") ) { //is exec + pm = Resource::loadPixmap( "exec"); +// item->setPixmap( 0,pm); + } else if( !fi->isReadable() ) { + pm = Resource::loadPixmap( "locked" ); +// item->setPixmap( 0,pm); + } else { //everything else goes by mimetype + MimeType mt(fi->filePath()); + pm=mt.pixmap(); //sets the correct pixmap for mimetype + if(pm.isNull()) + pm = Resource::loadPixmap( "UnknownDocument-14" ); +// item->setPixmap( 0,pm); } - if( fileL.find("->",0,TRUE) != -1) { + item->setPixmap( 0,pm); + 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; + } + isDir=FALSE; ++it; } if(currentDir.canonicalPath().find("dev",0,TRUE) != -1) { struct stat buf; - struct stat st; +// struct stat st; dev_t devT; - mode_t mode; +// mode_t mode; DIR *dir; - int fd = 0; +// int fd = 0; struct dirent *mydirent; - int i = 1; +// int i = 1; if((dir = opendir( currentDir.canonicalPath().latin1())) != NULL) while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); qDebug(mydirent->d_name); // mode = buf.st_mode; fileL.sprintf("%s", mydirent->d_name); // fileS.sprintf("%d, %d", ); //this isn't correct devT = buf.st_dev; fileS.sprintf("%d, %d", (int) ( devT >>8) &0xFF, (int)devT &0xFF); // fileS.sprintf("%d,%d", devT, devT); fileDate.sprintf("%s", ctime( &buf.st_mtime)); if( fileL.find(".") == -1 ){ @@ -392,24 +389,27 @@ void AdvancedFm::populateRemoteView() // if ( it.current()->isSelected() ) { // QString strItem = it.current()->text(0); // QString localFile = currentRemoteDir.canonicalPath()+"/"+strItem; // QFileInfo fi(localFile); // } // } 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); 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( "%10li", sym.size() ); fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); fileDate = sym.lastModified().toString(); @@ -424,62 +424,61 @@ void AdvancedFm::populateRemoteView() // qDebug( 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" ); - item->setPixmap( 0,pm ); +// item->setPixmap( 0,pm ); + } else if( fi->isExecutable() || fs == "vfat" && fi->filePath().contains("/bin") ) { + pm = Resource::loadPixmap( "exec"); +// item->setPixmap( 0,pm); + } else if( !fi->isReadable() ) { + pm = Resource::loadPixmap( "locked" ); +// item->setPixmap( 0,pm); } else { -// if(fi->isExecutable()) { -// pm = Resource::loadPixmap( "exec"); + MimeType mt(fi->filePath()); + pm=mt.pixmap(); //sets the correct pixmap for mimetype + if(pm.isNull()) + pm = Resource::loadPixmap( "UnknownDocument-14" ); // item->setPixmap( 0,pm); -// } - if( !fi->isReadable() ) { - pm = Resource::loadPixmap( "locked" ); - item->setPixmap( 0,pm); - } else { - MimeType mt(fi->filePath()); - pm=mt.pixmap(); //sets the correct pixmap for mimetype - if(pm.isNull()) - pm = Resource::loadPixmap( "UnknownDocument-14" ); - item->setPixmap( 0,pm); - } - } - if( 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; + 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); + } + item->setPixmap( 0, pm); + } + isDir=FALSE; ++it; } if(currentRemoteDir.canonicalPath().find("dev",0,TRUE) != -1) { struct stat buf; - struct stat st; - mode_t mode; +// struct stat st; +// mode_t mode; DIR *dir; - int fd = 0; +// int fd = 0; struct dirent *mydirent; - int i = 1; +// int i = 1; if((dir = opendir( currentRemoteDir.canonicalPath().latin1())) != NULL) while ((mydirent = readdir(dir)) != NULL) { lstat( mydirent->d_name, &buf); qDebug(mydirent->d_name); // mode = buf.st_mode; fileL.sprintf("%s", mydirent->d_name); // fileS.sprintf("%d, %d", ); //this isn't correct 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" ); @@ -651,24 +650,25 @@ void AdvancedFm::showLocalMenu(QListViewItem * item) m.insertItem( tr( "Change Directory" ), this, SLOT( doLocalCd() )); else m.insertItem( tr( "Open" ), this, SLOT( runThis() )); m.insertItem( tr( "Open as Text" ), this, SLOT( runText() )); m.insertItem( tr( "Make Directory" ), this, SLOT( localMakDir() )); m.insertItem( tr( "Make Symlink" ), this, SLOT( mkSym() )); m.insertSeparator(); m.insertItem( tr( "Rename" ), this, SLOT( localRename() )); m.insertItem( tr( "Copy" ), this, SLOT( copy() )); m.insertItem( tr( "Copy As" ), this, SLOT( copyAs() )); m.insertItem( tr( "Move" ), this, SLOT( move() )); m.insertSeparator(); + m.insertItem( tr( "Rescan" ), this, SLOT( populateLocalView() )); m.insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); m.insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( localDelete() )); m.insertSeparator(); m.insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); m.insertItem( tr( "Properties" ), this, SLOT( doProperties() )); m.setCheckable(TRUE); if (!b) m.setItemChecked(m.idAt(0),TRUE); else m.setItemChecked(m.idAt(0),FALSE); @@ -686,75 +686,82 @@ void AdvancedFm::showRemoteMenu(QListViewItem * item) m.insertItem( tr( "Change Directory" ), this, SLOT( doRemoteCd() )); else m.insertItem( tr( "Open" ), this, SLOT( runThis() )); m.insertItem( tr( "Open as Text" ), this, SLOT( runText() )); m.insertItem( tr( "Make Directory" ), this, SLOT( remoteMakDir() )); m.insertItem( tr( "Make Symlink" ), this, SLOT( mkSym() )); m.insertSeparator(); m.insertItem( tr( "Rename" ), this, SLOT( remoteRename() )); m.insertItem( tr( "Copy" ), this, SLOT( copy() )); m.insertItem( tr( "Copy As" ), this, SLOT( copyAs() )); m.insertItem( tr( "Move" ), this, SLOT( move() )); m.insertSeparator(); + m.insertItem( tr( "Rescan" ), this, SLOT( populateRemoteView() )); m.insertItem( tr( "Run Command" ), this, SLOT( runCommand() )); m.insertItem( tr( "File Info" ), this, SLOT( fileStatus() )); m.insertSeparator(); m.insertItem( tr( "Delete" ), this, SLOT( remoteDelete() )); m.insertSeparator(); m.insertItem( tr( "Set Permissions" ), this, SLOT( filePerms() )); m.insertItem( tr( "Properties" ), this, SLOT( doProperties() )); m.setCheckable(TRUE); if (!b) m.setItemChecked(m.idAt(0),TRUE); else m.setItemChecked(m.idAt(0),FALSE); m.exec( QCursor::pos() ); } } void AdvancedFm::runThis() { // QFileInfo *fi; +QString fs; if (TabWidget->currentPageIndex() == 0) { QString curFile = Local_View->currentItem()->text(0); + + fs= getFileSystemType((const QString &) currentDir.canonicalPath()); QFileInfo fileInfo( currentDir.canonicalPath()+"/"+curFile); -// if(fileInfo.isExecutable()) { -// QCopEnvelope e("QPE/System", "execute(QString)" ); -// e << curFile; -// } else { + qDebug( fileInfo.owner()); + if( fileInfo.isExecutable() || fs == "vfat" && fileInfo.filePath().contains("/bin") ) { + QCopEnvelope e("QPE/System", "execute(QString)" ); + e << curFile; + } else { curFile = currentDir.canonicalPath()+"/"+curFile; DocLnk nf(curFile); QString execStr = nf.exec(); qDebug( execStr); if( execStr.isEmpty() ) { } else { nf.execute(); } -// } + } // MimeType mt( curFile); } else { QString curFile = Remote_View->currentItem()->text(0); + fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath()); + qDebug("Filesystemtype is "+fs); QFileInfo fileInfo( currentRemoteDir.canonicalPath()+"/"+curFile); -// if(fileInfo.isExecutable()) { -// QCopEnvelope e("QPE/System", "execute(QString)" ); -// e << curFile; -// } else { + if(fileInfo.isExecutable() || fs == "vfat" && fileInfo.filePath().contains("/bin") ) { + QCopEnvelope e("QPE/System", "execute(QString)" ); + e << curFile; + } else { curFile = currentRemoteDir.canonicalPath()+"/"+curFile; DocLnk nf(curFile); QString execStr = nf.exec(); qDebug(execStr); if( execStr.isEmpty() ) { } else { nf.execute(); } -// } + } // MimeType mt( curFile); } } void AdvancedFm::runText() { if (TabWidget->currentPageIndex() == 0) { QString curFile = Local_View->currentItem()->text(0); curFile = currentDir.canonicalPath()+"/"+curFile; QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); e << curFile; } else { QString curFile = Remote_View->currentItem()->text(0); @@ -1335,25 +1342,25 @@ void AdvancedFm::runCommand() { if(Remote_View->currentItem()) curFile = currentRemoteDir.canonicalPath() + Remote_View->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 ) { command = fileDlg->LineEdit1->text(); - int err=0; +// int err=0; Output *outDlg; outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); outDlg->showMaximized(); outDlg->show(); qApp->processEvents(); FILE *fp; char line[130]; sleep(1); // if(command.find("2>",0,TRUE) != -1) command +=" 2>&1"; fp = popen( (const char *) command, "r"); if ( !fp ) { @@ -1393,25 +1400,25 @@ void AdvancedFm::runCommandStd() { system(command.latin1()); } } void AdvancedFm::fileStatus() { QString curFile; if (TabWidget->currentPageIndex() == 0) { curFile = Local_View->currentItem()->text(0); } else { curFile = Remote_View->currentItem()->text(0); } QString command = " stat -l "+ curFile +" 2>&1"; - int err=0; +// int err=0; Output *outDlg; outDlg = new Output(this, tr("AdvancedFm Output"),FALSE); outDlg->showMaximized(); outDlg->show(); qApp->processEvents(); FILE *fp; char line[130]; sleep(1); fp = popen( (const char *) command, "r"); if ( !fp ) { qDebug("Could not execute '" + command + "'! err=%d", fp); QMessageBox::warning( this, tr("AdvancedFm"), tr("command failed!"), tr("&OK") ); @@ -1510,29 +1517,25 @@ void AdvancedFm::keyReleaseEvent( QKeyEvent *e) break; case Key_6: docButtonPushed(); break; case Key_7: break; case Key_8: break; case Key_9: break; case Key_0: break; - - - } - } void AdvancedFm::mkSym() { QString cmd; QStringList curFileList = getPath(); if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destName = currentRemoteDir.canonicalPath()+"/"+(*it); QString curFile = currentDir.canonicalPath()+"/"+(*it); cmd = "ln -s "+curFile+" "+destName; @@ -1558,14 +1561,67 @@ void AdvancedFm::mkSym() { void AdvancedFm::QPEButtonPushed() { QString current = QPEApplication::qpeDir(); chdir( current.latin1() ); if (TabWidget->currentPageIndex() == 0) { currentDir.cd( current, TRUE); populateLocalView(); } else { currentRemoteDir.cd( current, TRUE); populateRemoteView(); } update(); +} +void AdvancedFm::parsetab(const QString &fileName) { + + fileSystemTypeList.clear(); + fsList.clear(); + struct mntent *me; +// if(fileName == "/etc/mtab") { + FILE *mntfp = setmntent( fileName.latin1(), "r" ); + if ( mntfp ) { + while ( (me = getmntent( mntfp )) != 0 ) { + QString deviceName = me->mnt_fsname; + QString filesystemType = me->mnt_type; + QString mountDir = me->mnt_dir; + if(deviceName != "none") { + if( fsList.contains(filesystemType) == 0 + & filesystemType.find("proc",0,TRUE) == -1 + & filesystemType.find("cramfs",0,TRUE) == -1 + & filesystemType.find("auto",0,TRUE) == -1) + fsList << filesystemType; +// deviceList << deviceName; +// qDebug(mountDir+"::"+filesystemType); + fileSystemTypeList << mountDir+"::"+filesystemType; + } + } + } + endmntent( mntfp ); } + +QString AdvancedFm::getFileSystemType(const QString ¤tText) { + parsetab("/etc/mtab"); //why did TT forget filesystem type? + QString current = currentText;//.right( currentText.length()-1); + QString baseFs; + for ( QStringList::Iterator it = fileSystemTypeList.begin(); it != fileSystemTypeList.end(); ++it ) { + QString temp = (*it); + QString path = temp.left(temp.find("::",0,TRUE) ); + path = path.right( path.length()-1); + if(path.isEmpty()) baseFs = temp.right( temp.length() - temp.find("::",0,TRUE) - 2); + if( current.find( path,0,TRUE) != -1 && !path.isEmpty()) { + return temp.right( temp.length() - temp.find("::",0,TRUE) - 2); + } + } + return baseFs; +} + + +// QList<QListViewItem> * getSelectedItems( QListView * Local_View ); +// QListViewItemIterator it( Local_View ); +// for ( ; it.current(); ++it ) { +// if ( it.current()->isSelected() ) { +// QString strItem = it.current()->text(0); +// QString localFile = currentDir.canonicalPath()+"/"+strItem; +// QFileInfo fi(localFile); +// } +// } diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 5c2719e..90619ba 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -49,24 +49,25 @@ public: QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; QLineEdit *currentPathEdit; QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu; QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; QDir currentDir, currentRemoteDir; QComboBox *currentPathCombo; QString filterStr; QListViewItem * item; bool b; + QStringList fileSystemTypeList, fsList; int currentServerConfig; protected slots: void showLocalMenu( QListViewItem *); void showRemoteMenu( QListViewItem *); void doLocalCd(); void doRemoteCd(); // void copy(); void mkDir(); void del(); void rn(); void populateLocalView(); void populateRemoteView(); @@ -93,25 +94,28 @@ protected slots: void filePerms(); void doProperties(); void runCommand(); void runCommandStd(); QStringList getPath(); void mkSym(); void switchToLocalTab(); void switchToRemoteTab(); protected: QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; - void keyReleaseEvent( QKeyEvent *); + void keyReleaseEvent( QKeyEvent *); + QString getFileSystemType(const QString &); + void parsetab(const QString &fileName); + protected slots: void homeButtonPushed(); void docButtonPushed(); void SDButtonPushed(); void CFButtonPushed(); void QPEButtonPushed(); void upDir(); void currentPathComboChanged(); void copy(); void copyAs(); void currentPathComboActivated(const QString &); void fillCombo(const QString &); |