author | llornkcor <llornkcor> | 2003-02-21 22:44:28 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-21 22:44:28 (UTC) |
commit | a7448ec87d97a0128618e83ad7526bd884ef8853 (patch) (side-by-side diff) | |
tree | 0dda2db8da959c26d0ec089bec161ae28486d2cc | |
parent | d48baa03492fd4785ca273defb4e21bf8c0d1c08 (diff) | |
download | opie-a7448ec87d97a0128618e83ad7526bd884ef8853.zip opie-a7448ec87d97a0128618e83ad7526bd884ef8853.tar.gz opie-a7448ec87d97a0128618e83ad7526bd884ef8853.tar.bz2 |
fix rename cancel.. hehehe
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.cpp | 34 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 26 |
2 files changed, 45 insertions, 15 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.cpp b/noncore/apps/advancedfm/advancedfm.cpp index c653b90..9edf7c1 100644 --- a/noncore/apps/advancedfm/advancedfm.cpp +++ b/noncore/apps/advancedfm/advancedfm.cpp @@ -6,128 +6,130 @@ 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/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 <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(); 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) { qDebug("tab changed %d",TabWidget->getCurrentTab()); if ( w == tab) { // if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { currentPathCombo->lineEdit()->setText( currentDir.canonicalPath()); viewMenu->setItemChecked(viewMenu->idAt(0),TRUE); viewMenu->setItemChecked(viewMenu->idAt(1),FALSE); QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) currentDir.canonicalPath())+" kB free" ); } if ( w == tab_2) { // if (TabWidget->getCurrentTab() == 1) { // if (TabWidget->currentPageIndex() == 1) { currentPathCombo->lineEdit()->setText( currentRemoteDir.canonicalPath()); viewMenu->setItemChecked(viewMenu->idAt(1),TRUE); viewMenu->setItemChecked(viewMenu->idAt(0),FALSE); QString fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath()); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) currentRemoteDir.canonicalPath())+" kB free" ); } } void AdvancedFm::populateLocalView() { QPixmap pm; Local_View->clear(); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); currentDir.setNameFilter(filterStr); QString fileL, fileS, fileDate; QString fs= getFileSystemType((const QString &) currentDir.canonicalPath()); setCaption("AdvancedFm :: "+fs+" :: " +checkDiskSpace((const QString &) currentDir.canonicalPath())+" kB free" ); bool isDir=FALSE; const QFileInfoList *list = currentDir.entryInfoList( /*QDir::All*/ /*, QDir::SortByMask*/); QFileInfoListIterator it(*list); QFileInfo *fi; while ( (fi=it.current()) ) { if (fi->isSymLink() ) { @@ -341,146 +343,161 @@ void AdvancedFm::localListClicked(QListViewItem *selectedItem) { populateLocalView(); } } else { strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); if( QFile::exists(strItem ) ) { // qDebug("clicked item "+strItem); // DocLnk doc( strItem, FALSE ); // doc.execute(); // Local_View->clearSelection(); } } //end not symlink chdir(strItem.latin1()); } } } void AdvancedFm::remoteListClicked(QListViewItem *selectedItem) { if(selectedItem) { QString strItem=selectedItem->text(0); QString strSize=selectedItem->text(1); strSize=strSize.stripWhiteSpace(); if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink QString strItem2 = dealWithSymName((const QString&)strItem); // QString strItem2 = strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); currentRemoteDir.cd(strItem2, TRUE); populateRemoteView(); } else { // not a symlink if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { if(QDir(QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem)).exists() ) { strItem=QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem); currentRemoteDir.cd(strItem,FALSE); populateRemoteView(); Remote_View->ensureItemVisible(Remote_View->firstChild()); } else { currentRemoteDir.cdUp(); populateRemoteView(); Remote_View->ensureItemVisible(Remote_View->firstChild()); } if(QDir(strItem).exists()){ currentRemoteDir.cd(strItem, TRUE); populateRemoteView(); Remote_View->ensureItemVisible(Remote_View->firstChild()); } } else { strItem=QDir::cleanDirPath( currentRemoteDir.canonicalPath()+"/"+strItem); if( QFile::exists(strItem ) ) { // qDebug("clicked item "+strItem); // DocLnk doc( strItem, FALSE ); // doc.execute(); // Remote_View->clearSelection(); } } //end not symlink chdir(strItem.latin1()); } } } void AdvancedFm::localListPressed( int mouse, QListViewItem *, const QPoint& , int ) { // qDebug("list pressed"); switch (mouse) { case 1: + { + if(renameBox != 0 ) + { + qDebug("cancel rename"); + cancelRename(); + } + + } break; case 2: menuTimer.start( 500, TRUE ); qDebug("Start menu timer\n"); break; }; } void AdvancedFm::remoteListPressed( int mouse, QListViewItem*, const QPoint&, int ) { - switch (mouse) { - case 1: - break; - case 2: - menuTimer.start( 500, TRUE ); - qDebug("Start menu timer"); - break; - }; + switch (mouse) { + case 1: + { + if(renameBox != 0 ) + { + qDebug("cancel rename"); + cancelRename(); + } + } + break; + case 2: + menuTimer.start( 500, TRUE ); + qDebug("Start menu timer"); + 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 (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { if(QDir( currentPathCombo->lineEdit()->text()).exists()) { currentDir.setPath( currentPathCombo->lineEdit()->text() ); populateLocalView(); } else { QMessageBox::message(tr("Note"),tr("That directory does not exist")); } } if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { if(QDir( currentPathCombo->lineEdit()->text()).exists()) { currentRemoteDir.setPath( currentPathCombo->lineEdit()->text() ); populateRemoteView(); } else { QMessageBox::message(tr("Note"),tr("That directory does not exist")); } } } void AdvancedFm::fillCombo(const QString ¤tPath) { qDebug("%d",TabWidget->getCurrentTab()); if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { 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) { if (TabWidget->getCurrentTab() == 0) { @@ -818,64 +835,65 @@ void AdvancedFm::showFileMenu() { if(Ir::supported()) m->insertItem( tr( "Beam File" ), this, SLOT( doBeam() )); m->setFocus(); m->exec( QPoint( 4,QCursor::pos().y()) ); if(m) delete m; } void AdvancedFm::cancelMenuTimer() { // qDebug("selectionChanged: cancel menu timer"); if( menuTimer.isActive() ) menuTimer.stop(); } QString AdvancedFm::checkDiskSpace(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::addToDocs() { QStringList strListPaths = getPath(); if( strListPaths.count() > 0) { QString curFile; if (TabWidget->getCurrentTab() == 0) { // if (TabWidget->currentPageIndex() == 0) { for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = currentDir.canonicalPath()+"/"+(*it); qDebug(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); f.setName((*it)); f.setFile( curFile); f.writeLink(); } } else { for ( QStringList::Iterator it = strListPaths.begin(); it != strListPaths.end(); ++it ) { curFile = currentRemoteDir.canonicalPath()+"/"+(*it); qDebug(curFile); DocLnk f; // curFile.replace(QRegExp("\\..*"),""); f.setName((*it)); f.setFile( curFile); f.writeLink(); } } } } + diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index f067013..2ddcabc 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -966,160 +966,172 @@ void AdvancedFm::doBeam() { 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) { Local_View->selectAll(true); Local_View->setSelected( Local_View->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(); } 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() { +void AdvancedFm::cancelRename() +{ qDebug("cancel rename"); QListView * view; - if (TabWidget->getCurrentTab() == 0) { - view = Local_View; - } + if (TabWidget->getCurrentTab() == 0) + { + view = Local_View; + } else { view = Remote_View; } bool resetFocus = view->viewport()->focusProxy() == renameBox; delete renameBox; renameBox = 0; if ( resetFocus ) { view->viewport()->setFocusProxy( view); view->setFocus(); } } -void AdvancedFm::doRename(QListView * view) { +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::localRename() { +void AdvancedFm::localRename() +{ oldName = Local_View->currentItem()->text(0); doRename(Local_View ); populateLocalView(); } void AdvancedFm::remoteRename() { oldName = Remote_View->currentItem()->text(0); doRename(Local_View ); populateRemoteView(); } -void AdvancedFm::okRename() { +void AdvancedFm::okRename() +{ QString newName = renameBox->text(); cancelRename(); int tabs=0; QListView * view; tabs = TabWidget->getCurrentTab(); if ( tabs == 0) { view = Local_View; QString path = currentDir.canonicalPath() + "/"; oldName = path + oldName; newName = path + newName; } else { view = Remote_View; QString path = currentRemoteDir.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(); if ( tabs == 0) populateLocalView(); else populateRemoteView(); } |