author | llornkcor <llornkcor> | 2003-02-24 02:38:01 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-24 02:38:01 (UTC) |
commit | e144592570ddacf26d27f3e2759dbe7f2370d0a0 (patch) (side-by-side diff) | |
tree | 054221a40b03bd91945161570a8996a5427e6456 | |
parent | 56b89312a374b62ee20f6ad2b62b6426183d4d26 (diff) | |
download | opie-e144592570ddacf26d27f3e2759dbe7f2370d0a0.zip opie-e144592570ddacf26d27f3e2759dbe7f2370d0a0.tar.gz opie-e144592570ddacf26d27f3e2759dbe7f2370d0a0.tar.bz2 |
cleanup
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 200 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 6 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 76 |
3 files changed, 74 insertions, 208 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 @@ -1,730 +1,618 @@ /*************************************************************************** AdvancedFm.cpp ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #define DEVELOPERS_VERSION #include "advancedfm.h" #include <opie/otabwidget.h> // #include <opie/ofileselector.h> // #include <opie/ofiledialog.h> #include <qpe/config.h> #include <qpe/filemanager.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/qpeapplication.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/config.h> #include <qpe/mimetype.h> #include <qpe/applnk.h> #include <qpe/ir.h> #include <qpe/resource.h> #include <qpe/menubutton.h> #include <qregexp.h> #include <qtabwidget.h> #include <qtextstream.h> #include <qpushbutton.h> #include <qdatetime.h> #include <qdir.h> #include <qfile.h> #include <qstring.h> #include <qcombobox.h> #include <qpopupmenu.h> #include <qlistview.h> #include <qmainwindow.h> #include <qlabel.h> #include <qprogressbar.h> #include <qspinbox.h> #include <qwidget.h> #include <qlayout.h> #include <qimage.h> #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> #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"; else sfile+="._temp"; QFile file( sfile); if(file.exists()) file.remove(); } void AdvancedFm::tabChanged(QWidget *w) { if( w == tab) whichTab = 1; else whichTab = 2; // qDebug("tab changed %d", whichTab ); 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"); } 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 = Resource::loadPixmap( "UnknownDocument-14" ); } 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; ++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 { strItem2 = dealWithSymName((const QString&)strItem); if(QDir(strItem2).exists() ) strItem = strItem2; } 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 ) { cancelRename(); } } break; case 2: menuTimer.start( 500, TRUE ); break; }; } void AdvancedFm::switchToLocalTab() { TabWidget->setCurrentTab(0); Local_View->setFocus(); } void AdvancedFm::switchToRemoteTab() { TabWidget->setCurrentTab(1); Remote_View->setFocus(); } void AdvancedFm::readConfig() { Config cfg("AdvancedFm"); } 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) { currentPathCombo->lineEdit()->setText( currentPath); if( localDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { currentPathCombo->clear(); localDirPathStringList.prepend( currentPath ); currentPathCombo->insertStringList( localDirPathStringList,-1); } } else { currentPathCombo->lineEdit()->setText( currentPath); if( remoteDirPathStringList.grep( currentPath,TRUE).isEmpty() ) { 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() ) { 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")); } void AdvancedFm::keyPressEvent( QKeyEvent *e) { // e->accept(); if( CurrentView()->hasFocus() ) { switch ( e->key() ) { case Key_Delete: del(); break; case Key_A: copyAs(); break; case Key_C: copy(); break; case Key_E: runThis(); break; case Key_G: { currentPathCombo->lineEdit()->setFocus(); } break; case Key_H: showHidden(); break; case Key_I: fileStatus(); break; case Key_M: move(); break; case Key_N: mkDir(); break; case Key_P: filePerms(); break; case Key_R: rn(); break; case Key_U: upDir(); break; case Key_1: switchToLocalTab(); break; case Key_2: switchToRemoteTab(); break; case Key_3: CFButtonPushed(); break; case Key_4: SDButtonPushed(); break; case Key_5: homeButtonPushed(); break; case Key_6: docButtonPushed(); break; case Key_7: break; case Key_8: break; case Key_9: break; case Key_0: break; }; e->accept(); } } 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 ) { 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; 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; } QString AdvancedFm::getDiskSpace( const QString &path) { struct statfs fss; if ( !statfs( path.latin1(), &fss ) ) { int blkSize = fss.f_bsize; // int totalBlks = fs.f_blocks; int availBlks = fss.f_bavail; 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::showFileMenu() { QString curApp; curApp = CurrentView()->currentItem()->text(0); MimeType mt( curApp ); const AppLnk* app = mt.application(); QFile fi(curApp); QPopupMenu *m = new QPopupMenu(0); QPopupMenu *n = new QPopupMenu(0); // QPopupMenu *o = new QPopupMenu(0); m->insertItem( tr( "Show Hidden Files" ), this, SLOT( showHidden() )); if ( QFileInfo(fi).isDir() ) { m->insertSeparator(); m->insertItem( tr( "Change Directory" ), this, SLOT( doDirChange() )); } else { if ( app ) m->insertItem( app->pixmap(), tr( "Open in " + app->name() ), this, SLOT( runThis() ) ); else if( QFileInfo(fi).isExecutable() ) //damn opie doesnt like this m->insertItem( tr( "Execute" ), this, SLOT( runThis() ) ); m->insertItem( Resource::loadPixmap( "txt" ), tr( "Open as text" ),this, SLOT( runText() ) ); } @@ -855,148 +743,148 @@ void AdvancedFm::dirMenuSelected(int item) break; }; } void AdvancedFm::addCustomDir() { Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QString dir; QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); dir = CurrentDir()->canonicalPath(); bool addIt=true; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if( dir == (*it)) { addIt=false; } } if(addIt) { menuButton->insertItem(dir); // customDirMenu->insertItem(dir); list << dir; } cfg.writeEntry("CustomDir", list, ','); cfg.write(); } void AdvancedFm::removeCustomDir() { // qDebug("remove custom dir"); Config cfg("AdvancedFm"); cfg.setGroup("Menu"); QString dir; QStringList list = cfg.readListEntry( (const QString &)"CustomDir", (const QChar)','); QStringList list2; dir = CurrentDir()->canonicalPath(); int ramble=2; // int ramble=-24; //first remove list if(list.grep(dir,true).isEmpty()) { QMessageBox::message("AdvancedFm",tr("Cannot remove current directory\nfrom bookmarks.\nIt is not bookmarked!!")); } else { for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if((*it) != dir)//current item is not our current dir, so add it to temp list { list2 <<(*it); } else { // customDirMenu->removeItem( ramble); menuButton->remove( ramble); } ramble++; // ramble--; } cfg.writeEntry("CustomDir", list2, ','); cfg.write(); } // customDirsToMenu(); } void AdvancedFm::gotoCustomDir(const QString &dir) { // qDebug("gotoCustomDir(const QString &dir) " +dir ); QString curDir = dir; QDir *thisDir = CurrentDir(); // if( curDir.isEmpty()) { // } if( curDir == s_addBookmark) { addCustomDir(); } 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 { return ¤tRemoteDir; } } 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); +} diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 8eec6ba..024ab29 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -1,171 +1,169 @@ /*************************************************************************** advancedfm.h ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #ifndef ADVANCEDFM_H #define ADVANCEDFM_H #define QTOPIA_INTERNAL_FSLP // to get access to fileproperties #define QT_QWS_OPIE //#include <opie/otabwidget.h> #include <qpe/ir.h> #include <qvariant.h> #include <qdialog.h> #include <qmainwindow.h> #include <qstringlist.h> #include <qdir.h> #include <qstring.h> #include <qpoint.h> #include <qtimer.h> class OTabWidget; class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QComboBox; class QListView; class QListviewItem; class QLabel; class QProgressBar; class QSpinBox; class QTabWidget; class QWidget; class QPEToolBar; class QPEMenuBar; class QPopupMenu; class QFile; class QListViewItem; class QLineEdit; class MenuButton; //class QPushButton; class QToolButton; class Ir; class AdvancedFm : public QMainWindow { Q_OBJECT public: AdvancedFm(); ~AdvancedFm(); protected slots: void selectAll(); void addToDocs(); void doDirChange(); void mkDir(); void del(); void rn(); - void populateLocalView(); - void populateRemoteView(); + void populateView(); void showHidden(); void showMenuHidden(); -// void showRemoteHidden(); void writeConfig(); void readConfig(); void ListClicked(QListViewItem *); void ListPressed( int, QListViewItem *, const QPoint&, int); void makeDir(); void doDelete(); void tabChanged(QWidget*); void cleanUp(); void renameIt(); void runThis(); void runText(); void filePerms(); void doProperties(); void runCommand(); void runCommandStd(); QStringList getPath(); void mkSym(); void switchToLocalTab(); void switchToRemoteTab(); protected: OTabWidget *TabWidget; int whichTab; // QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; QLineEdit *currentPathEdit; QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu /*, *customDirMenu*/; QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; // QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; QDir currentDir, currentRemoteDir; QComboBox *currentPathCombo; QString filterStr, s_addBookmark, s_removeBookmark; QListViewItem * item; bool b; QStringList fileSystemTypeList, fsList; int currentServerConfig; bool zaurusDevice; QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; QLineEdit *renameBox; void init(); void initConnections(); void keyReleaseEvent( QKeyEvent *); void keyPressEvent( QKeyEvent *); QString getFileSystemType(const QString &); QString getDiskSpace(const QString &); void parsetab(const QString &fileName); QString checkDiskSpace(const QString &); QString dealWithSymName(const QString &); QDir *CurrentDir(); QDir *OtherDir(); QListView *CurrentView(); QListView *OtherView(); - void PopulateView(); + void setOtherTabCurrent(); protected slots: void dirMenuSelected(int); void showFileMenu(); void cancelMenuTimer(); void homeButtonPushed(); void docButtonPushed(); void SDButtonPushed(); void CFButtonPushed(); void QPEButtonPushed(); void upDir(); void currentPathComboChanged(); void copy(); void copyAs(); void copySameDir(); void currentPathComboActivated(const QString &); void fillCombo(const QString &); bool copyFile( const QString & , const QString & ); void move(); void fileStatus(); void doAbout(); void doBeam(); void fileBeamFinished( Ir *); private: MenuButton *menuButton; QString oldName; QTimer menuTimer; void startProcess(const QString &); bool eventFilter( QObject * , QEvent * ); void cancelRename(); void doRename(QListView *); void okRename(); void customDirsToMenu(); void addCustomDir(); void removeCustomDir(); private slots: void processEnded(); void gotoCustomDir(const QString &); }; #endif // ADVANCEDFM_H diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 13dad33..c553017 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -1,869 +1,849 @@ /*************************************************************************** AdvancedFm.cpp ------------------- ** Created: Sat Mar 9 23:33:09 2002 copyright : (C) 2002 by ljp email : ljp@llornkcor.com * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "advancedfm.h" #include "output.h" #include "filePermissions.h" #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> void AdvancedFm::doDirChange() { ListClicked( CurrentView()->currentItem()); } void AdvancedFm::showMenuHidden() { if (b) { currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); currentRemoteDir.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); currentRemoteDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); // b=TRUE; } - populateLocalView(); - populateRemoteView(); + populateView(); +// populateRemoteView(); // if(b) qDebug("<<<<<<<<<<<<<<<<<<<<<<<<<<<< true"); if(b) b = false; else b = true; } void AdvancedFm::showHidden() { if (b) { CurrentDir()->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); // fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); // b=TRUE; } - PopulateView(); + populateView(); } QString AdvancedFm::dealWithSymName(const QString &fileName) { QString strItem = fileName; return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); } void AdvancedFm::runThis() { QString fs; QDir *thisDir = CurrentDir(); QString curFile = CurrentView()->currentItem()->text(0); QString path = thisDir->canonicalPath(); if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink curFile = dealWithSymName((const QString&)curFile); if(curFile != "../") { fs = getFileSystemType((const QString &) path); QFileInfo fileInfo( path + "/" + curFile); qDebug( fileInfo.owner()); if( (fileInfo.permission( QFileInfo::ExeUser) | fileInfo.permission( QFileInfo::ExeGroup) | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) { | fs == "vfat" && fileInfo.filePath().contains("/bin") ) { QCopEnvelope e("QPE/System", "execute(QString)" ); e << curFile; } else { curFile = path + "/" + curFile; DocLnk nf(curFile); QString execStr = nf.exec(); qDebug( execStr); if( execStr.isEmpty() ) { } else { nf.execute(); } } } } void AdvancedFm::runText() { QString curFile = CurrentView()->currentItem()->text(0); if(curFile != "../") { if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink curFile = dealWithSymName((const QString&)curFile); curFile = CurrentDir()->canonicalPath()+"/"+curFile; QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); e << curFile; } } 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(); + 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; }; } 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() ) { switch ( QMessageBox::warning( this, tr("Delete Directory?"), tr("Really delete\n") + f + "\nand all it's contents ?" ,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(); + populateView(); } break; case 1: // exit break; }; } else { if(doMsg) { switch ( QMessageBox::warning(this,tr("Delete"),tr("Really delete\n")+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) 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) delete filePerm; } - PopulateView(); + populateView(); } void AdvancedFm::doProperties() { #if defined(QT_QWS_OPIE) QStringList curFileList = getPath(); QString filePath; filePath = CurrentDir()->canonicalPath()+"/"; qDebug("%d",curFileList.count()); for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { qDebug((filePath+*it)); DocLnk lnk( (filePath+*it)); LnkProperties prop( &lnk ); prop.showMaximized(); prop.exec(); } #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(); + 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 ,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) ) { case 1: return; break; }; } f.remove(); } if( !copyFile( curFile, destFile) ) { QMessageBox::message("AdvancedFm", tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); return; } } - - PopulateView(); -// TabWidget->setCurrentTab(1); + setOtherTabCurrent(); + populateView(); } } void AdvancedFm::copyAs() { qApp->processEvents(); QStringList curFileList = getPath(); QString curFile, item; InputDialog *fileDlg; QDir *thisDir = CurrentDir(); QDir *thatDir = OtherDir(); for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { QString destFile; item=(*it); curFile = thisDir->canonicalPath()+"/"+(*it); fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); fileDlg->setInputText((const QString &) destFile ); fileDlg->exec(); if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text(); destFile = thatDir->canonicalPath()+"/"+filename; 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) ) { QMessageBox::message("AdvancedFm",tr("Could not copy\n") +curFile +tr("to\n")+destFile); return; } } delete fileDlg; } - PopulateView(); + setOtherTabCurrent(); + populateView(); } void AdvancedFm::copySameDir() { qApp->processEvents(); QStringList curFileList = getPath(); QString curFile, item, destFile; InputDialog *fileDlg; QDir *thisDir = CurrentDir(); for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { item=(*it); curFile = thisDir->canonicalPath()+"/"+ item; fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); fileDlg->setInputText((const QString &) destFile ); fileDlg->exec(); if( fileDlg->result() == 1 ) { QString filename = fileDlg->LineEdit1->text(); destFile = thisDir->canonicalPath()+"/"+filename; 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) ) { QMessageBox::message("AdvancedFm",tr("Could not copy\n") +curFile +tr("to\n")+destFile); return; } qDebug("copy "+curFile+" as "+destFile); } delete fileDlg; } - PopulateView(); + populateView(); } void AdvancedFm::move() { qApp->processEvents(); QStringList curFileList = getPath(); if( curFileList.count() > 0) { QString curFile, destFile, item; QDir *thisDir = CurrentDir(); QDir *thatDir = OtherDir(); for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 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) ) { QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); return; } else QFile::remove(curFile); } } } - populateRemoteView(); - populateLocalView(); + 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 ); 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; outDlg = new Output( command, this, tr("AdvancedFm Output"), true); outDlg->showMaximized(); outDlg->exec(); qApp->processEvents(); } } void AdvancedFm::runCommandStd() { QString curFile; QDir *thisDir = CurrentDir(); QListView *thisView = CurrentView(); if( thisView->currentItem()) curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); InputDialog *fileDlg; fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); fileDlg->setInputText(curFile); fileDlg->exec(); if( fileDlg->result() == 1 ) { qApp->processEvents(); startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); } } void AdvancedFm::fileStatus() { QString curFile; curFile = CurrentView()->currentItem()->text(0); QStringList command; command << "/bin/sh"; command << "-c"; command << "stat -l "+ curFile; Output *outDlg; outDlg = new Output( command, this, tr("AdvancedFm Output"), true); outDlg->showMaximized(); outDlg->exec(); qApp->processEvents(); } void AdvancedFm::mkDir() { makeDir(); } void AdvancedFm::rn() { renameIt(); } void AdvancedFm::del() { doDelete(); } void AdvancedFm::mkSym() { QString cmd; QStringList curFileList = getPath(); if( curFileList.count() > 0) { - if ( whichTab == 1) - { - for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) - { + QDir *thisDir = CurrentDir(); + QDir * thatDir = OtherDir(); - QString destName = currentRemoteDir.canonicalPath()+"/"+(*it); - if(destName.right(1) == "/") - { - destName = destName.left( destName.length() -1); - } - QString curFile = currentDir.canonicalPath()+"/"+(*it); - if( curFile.right(1) == "/") - { - curFile = curFile.left( curFile.length() -1); - } - cmd = "ln -s "+curFile+" "+destName; - qDebug(cmd); - startProcess( (const QString)cmd ); - } - populateRemoteView(); - TabWidget->setCurrentTab(1); - } - else - { for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { - QString destName = currentDir.canonicalPath()+"/"+(*it); + QString destName = thatDir->canonicalPath()+"/"+(*it); if(destName.right(1) == "/") { destName = destName.left( destName.length() -1); } - QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it); + + QString curFile = thisDir->canonicalPath()+"/"+(*it); + if( curFile.right(1) == "/") { curFile = curFile.left( curFile.length() -1); } cmd = "ln -s "+curFile+" "+destName; qDebug(cmd); startProcess( (const QString)cmd ); } - populateLocalView(); - TabWidget->setCurrentTab(0); - } + setOtherTabCurrent(); + populateView(); } } void AdvancedFm::doBeam() { 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 ); } } } } void AdvancedFm::fileBeamFinished( Ir *) { QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); } void AdvancedFm::selectAll() { // if (TabWidget->getCurrentTab() == 0) { QListView *thisView = CurrentView(); thisView->selectAll(true); thisView->setSelected( thisView->firstChild(),false); // } else { // Remote_View->selectAll(true); // Remote_View->setSelected( Remote_View->firstChild(),false); // } } void AdvancedFm::startProcess(const QString & cmd) { QStringList command; OProcess *process; process = new OProcess(); connect(process, SIGNAL(processExited(OProcess *)), this, SLOT( processEnded())); command << "/bin/sh"; command << "-c"; command << cmd.latin1(); *process << command; if(!process->start(OProcess::NotifyOnExit) ) qDebug("could not start process"); } void AdvancedFm::processEnded() { - populateLocalView(); - populateRemoteView(); +// populateLocalView(); + populateView(); } bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { if ( o->inherits( "QLineEdit" ) ) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent*)e; if ( ke->key() == Key_Return || ke->key() == Key_Enter ) { okRename(); return true; } else if ( ke->key() == Key_Escape ) { cancelRename(); return true; } } else if ( e->type() == QEvent::FocusOut ) { cancelRename(); return true; } } if ( o->inherits( "QListView" ) ) { if ( e->type() == QEvent::FocusOut ) { printf("focusIn\n"); } } return QWidget::eventFilter( o, e ); } void AdvancedFm::cancelRename() { qDebug("cancel rename"); QListView * view; view = CurrentView(); bool resetFocus = view->viewport()->focusProxy() == renameBox; delete renameBox; renameBox = 0; if ( resetFocus ) { view->viewport()->setFocusProxy( view); view->setFocus(); } } void AdvancedFm::doRename(QListView * view) { QRect r = view->itemRect( view->currentItem( )); r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); r.setX( view->contentsX() ); if ( r.width() > view->visibleWidth() ) r.setWidth( view->visibleWidth() ); renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); renameBox->setFrame(true); renameBox->setText( view->currentItem()->text(0) ); renameBox->selectAll(); renameBox->installEventFilter( this ); view->addChild( renameBox, r.x(), r.y() ); renameBox->resize( r.size() ); view->viewport()->setFocusProxy( renameBox ); renameBox->setFocus(); renameBox->show(); } void AdvancedFm::renameIt() { QListView *thisView = CurrentView(); oldName = thisView->currentItem()->text(0); doRename( thisView ); - PopulateView(); + populateView(); } void AdvancedFm::okRename() { QString newName = renameBox->text(); cancelRename(); // int tabs=0; QListView * view = CurrentView(); QString path = CurrentDir()->canonicalPath() + "/"; oldName = path + oldName; newName = path + newName; if( view->currentItem() == NULL) return; if( rename( oldName.latin1(), newName.latin1())== -1) QMessageBox::message(tr("Note"),tr("Could not rename")); else oldName = ""; view->takeItem( view->currentItem() ); delete view->currentItem(); - PopulateView(); + populateView(); } |