author | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
commit | d48baa03492fd4785ca273defb4e21bf8c0d1c08 (patch) (side-by-side diff) | |
tree | 3235810cc1113a6f6d25b4f1c60d3d2aa430b7e7 | |
parent | e09381c4b3d482c6b553a61c5fb0502a089dcc5f (diff) | |
download | opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.zip opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.tar.gz opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.tar.bz2 |
inline rename - no popup now, after selecting rename from menu, enter to commit the rename, cancel to cancel
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 13 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 152 |
2 files changed, 124 insertions, 41 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 7ced056..42775ee 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -1,158 +1,165 @@ /*************************************************************************** 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 QPushButton; class QToolButton; class Ir; class AdvancedFm : public QMainWindow { Q_OBJECT public: AdvancedFm(); ~AdvancedFm(); OTabWidget *TabWidget; // QTabWidget *TabWidget; QWidget *tab, *tab_2, *tab_3; QListView *Local_View, *Remote_View; QLineEdit *currentPathEdit; QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu; QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; // 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 selectAll(); void addToDocs(); void doLocalCd(); void doRemoteCd(); // void copy(); void mkDir(); void del(); void rn(); void populateLocalView(); void populateRemoteView(); void showHidden(); void showMenuHidden(); void showRemoteHidden(); void writeConfig(); void readConfig(); void localListClicked(QListViewItem *); void remoteListClicked(QListViewItem *); void localListPressed( int, QListViewItem *, const QPoint&, int); void remoteListPressed( int, QListViewItem *, const QPoint&, int); void localMakDir(); void localDelete(); void remoteMakDir(); void remoteDelete(); /* bool remoteDirList(const QString &); */ /* bool remoteChDir(const QString &); */ void tabChanged(QWidget*); void cleanUp(); void remoteRename(); void localRename(); void runThis(); void runText(); void filePerms(); void doProperties(); void runCommand(); void runCommandStd(); QStringList getPath(); void mkSym(); void switchToLocalTab(); void switchToRemoteTab(); protected: bool zaurusDevice; QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; - + QLineEdit *renameBox; + void init(); void initConnections(); void keyReleaseEvent( QKeyEvent *); QString getFileSystemType(const QString &); QString getDiskSpace(const QString &); void parsetab(const QString &fileName); QString checkDiskSpace(const QString &); QString dealWithSymName(const QString &); protected slots: 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: - QTimer menuTimer; - void startProcess(const QString &); + QString oldName; + QTimer menuTimer; + void startProcess(const QString &); + bool eventFilter( QObject * , QEvent * ); + void cancelRename(); + void doRename(QListView *); + void okRename(); private slots: void processEnded(); }; #endif // ADVANCEDFM_H diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 98d024d..f067013 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -294,134 +294,96 @@ void AdvancedFm::remoteDelete() { }; } 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 = currentRemoteDir.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 ); populateRemoteView(); } 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(); } } } populateRemoteView(); } -void AdvancedFm::localRename() { - QString curFile = Local_View->currentItem()->text(0); - qDebug("currentItem "+curFile); - if( curFile !="../") { - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); - fileDlg->setInputText((const QString &)curFile); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - QString oldname = currentDir.canonicalPath() + "/" + curFile; - QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); -//+".playlist"; - if( rename(oldname.latin1(), newName.latin1())== -1) - QMessageBox::message(tr("Note"),tr("Could not rename")); - } - populateLocalView(); - } -} - -void AdvancedFm::remoteRename() -{ - QString curFile = Remote_View->currentItem()->text(0); - if( curFile !="../") { - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); - fileDlg->setInputText((const QString &)curFile); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile; - QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); -//+".playlist"; - if( rename(oldname.latin1(), newName.latin1())== -1) - QMessageBox::message(tr("Note"),tr("Could not rename")); - } - populateRemoteView(); - } -} - void AdvancedFm::filePerms() { QStringList curFileList = getPath(); QString filePath; if (TabWidget->getCurrentTab() == 0) { filePath = currentDir.canonicalPath()+"/"; } else { filePath= currentRemoteDir.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; } if (TabWidget->getCurrentTab() == 0) { populateLocalView(); } else { populateRemoteView(); } } void AdvancedFm::doProperties() { #if defined(QT_QWS_OPIE) QStringList curFileList = getPath(); QString filePath; if (TabWidget->getCurrentTab() == 0) { filePath = currentDir.canonicalPath()+"/"; } else { filePath= currentRemoteDir.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 @@ -1002,48 +964,162 @@ void AdvancedFm::doBeam() { QString curFile = currentRemoteDir.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) { 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; + } + } + return QWidget::eventFilter( o, e ); +} + + +void AdvancedFm::cancelRename() { + qDebug("cancel rename"); + QListView * 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) { + + 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() { + 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() { + 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(); +} |