author | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
commit | d48baa03492fd4785ca273defb4e21bf8c0d1c08 (patch) (unidiff) | |
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 | |||
@@ -23,48 +23,49 @@ | |||
23 | #include <qstringlist.h> | 23 | #include <qstringlist.h> |
24 | #include <qdir.h> | 24 | #include <qdir.h> |
25 | #include <qstring.h> | 25 | #include <qstring.h> |
26 | #include <qpoint.h> | 26 | #include <qpoint.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | 28 | ||
29 | class OTabWidget; | 29 | class OTabWidget; |
30 | class QVBoxLayout; | 30 | class QVBoxLayout; |
31 | class QHBoxLayout; | 31 | class QHBoxLayout; |
32 | class QGridLayout; | 32 | class QGridLayout; |
33 | class QComboBox; | 33 | class QComboBox; |
34 | class QListView; | 34 | class QListView; |
35 | class QListviewItem; | 35 | class QListviewItem; |
36 | class QLabel; | 36 | class QLabel; |
37 | class QProgressBar; | 37 | class QProgressBar; |
38 | class QSpinBox; | 38 | class QSpinBox; |
39 | class QTabWidget; | 39 | class QTabWidget; |
40 | class QWidget; | 40 | class QWidget; |
41 | class QPEToolBar; | 41 | class QPEToolBar; |
42 | class QPEMenuBar; | 42 | class QPEMenuBar; |
43 | class QPopupMenu; | 43 | class QPopupMenu; |
44 | class QFile; | 44 | class QFile; |
45 | class QListViewItem; | 45 | class QListViewItem; |
46 | class QLineEdit; | 46 | class QLineEdit; |
47 | |||
47 | //class QPushButton; | 48 | //class QPushButton; |
48 | class QToolButton; | 49 | class QToolButton; |
49 | class Ir; | 50 | class Ir; |
50 | 51 | ||
51 | class AdvancedFm : public QMainWindow | 52 | class AdvancedFm : public QMainWindow |
52 | { | 53 | { |
53 | Q_OBJECT | 54 | Q_OBJECT |
54 | public: | 55 | public: |
55 | AdvancedFm(); | 56 | AdvancedFm(); |
56 | ~AdvancedFm(); | 57 | ~AdvancedFm(); |
57 | 58 | ||
58 | OTabWidget *TabWidget; | 59 | OTabWidget *TabWidget; |
59 | // QTabWidget *TabWidget; | 60 | // QTabWidget *TabWidget; |
60 | QWidget *tab, *tab_2, *tab_3; | 61 | QWidget *tab, *tab_2, *tab_3; |
61 | QListView *Local_View, *Remote_View; | 62 | QListView *Local_View, *Remote_View; |
62 | 63 | ||
63 | QLineEdit *currentPathEdit; | 64 | QLineEdit *currentPathEdit; |
64 | QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu; | 65 | QPopupMenu *fileMenu, *localMenu, *remoteMenu, *viewMenu; |
65 | QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; | 66 | QToolButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; |
66 | // QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; | 67 | // QPushButton *homeButton, *docButton, *cdUpButton, *sdButton, *cfButton, *qpeDirButton; |
67 | QDir currentDir, currentRemoteDir; | 68 | QDir currentDir, currentRemoteDir; |
68 | QComboBox *currentPathCombo; | 69 | QComboBox *currentPathCombo; |
69 | QString filterStr; | 70 | QString filterStr; |
70 | QListViewItem * item; | 71 | QListViewItem * item; |
@@ -95,64 +96,70 @@ protected slots: | |||
95 | void localDelete(); | 96 | void localDelete(); |
96 | void remoteMakDir(); | 97 | void remoteMakDir(); |
97 | void remoteDelete(); | 98 | void remoteDelete(); |
98 | /* bool remoteDirList(const QString &); */ | 99 | /* bool remoteDirList(const QString &); */ |
99 | /* bool remoteChDir(const QString &); */ | 100 | /* bool remoteChDir(const QString &); */ |
100 | void tabChanged(QWidget*); | 101 | void tabChanged(QWidget*); |
101 | void cleanUp(); | 102 | void cleanUp(); |
102 | void remoteRename(); | 103 | void remoteRename(); |
103 | void localRename(); | 104 | void localRename(); |
104 | void runThis(); | 105 | void runThis(); |
105 | void runText(); | 106 | void runText(); |
106 | void filePerms(); | 107 | void filePerms(); |
107 | void doProperties(); | 108 | void doProperties(); |
108 | void runCommand(); | 109 | void runCommand(); |
109 | void runCommandStd(); | 110 | void runCommandStd(); |
110 | QStringList getPath(); | 111 | QStringList getPath(); |
111 | void mkSym(); | 112 | void mkSym(); |
112 | void switchToLocalTab(); | 113 | void switchToLocalTab(); |
113 | void switchToRemoteTab(); | 114 | void switchToRemoteTab(); |
114 | 115 | ||
115 | protected: | 116 | protected: |
116 | bool zaurusDevice; | 117 | bool zaurusDevice; |
117 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; | 118 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; |
118 | QStringList remoteDirPathStringList, localDirPathStringList; | 119 | QStringList remoteDirPathStringList, localDirPathStringList; |
119 | 120 | QLineEdit *renameBox; | |
121 | |||
120 | void init(); | 122 | void init(); |
121 | void initConnections(); | 123 | void initConnections(); |
122 | void keyReleaseEvent( QKeyEvent *); | 124 | void keyReleaseEvent( QKeyEvent *); |
123 | QString getFileSystemType(const QString &); | 125 | QString getFileSystemType(const QString &); |
124 | QString getDiskSpace(const QString &); | 126 | QString getDiskSpace(const QString &); |
125 | void parsetab(const QString &fileName); | 127 | void parsetab(const QString &fileName); |
126 | QString checkDiskSpace(const QString &); | 128 | QString checkDiskSpace(const QString &); |
127 | QString dealWithSymName(const QString &); | 129 | QString dealWithSymName(const QString &); |
128 | 130 | ||
129 | protected slots: | 131 | protected slots: |
130 | void showFileMenu(); | 132 | void showFileMenu(); |
131 | void cancelMenuTimer(); | 133 | void cancelMenuTimer(); |
132 | void homeButtonPushed(); | 134 | void homeButtonPushed(); |
133 | void docButtonPushed(); | 135 | void docButtonPushed(); |
134 | void SDButtonPushed(); | 136 | void SDButtonPushed(); |
135 | void CFButtonPushed(); | 137 | void CFButtonPushed(); |
136 | void QPEButtonPushed(); | 138 | void QPEButtonPushed(); |
137 | void upDir(); | 139 | void upDir(); |
138 | void currentPathComboChanged(); | 140 | void currentPathComboChanged(); |
139 | void copy(); | 141 | void copy(); |
140 | void copyAs(); | 142 | void copyAs(); |
141 | void copySameDir(); | 143 | void copySameDir(); |
142 | void currentPathComboActivated(const QString &); | 144 | void currentPathComboActivated(const QString &); |
143 | void fillCombo(const QString &); | 145 | void fillCombo(const QString &); |
144 | bool copyFile( const QString & , const QString & ); | 146 | bool copyFile( const QString & , const QString & ); |
145 | void move(); | 147 | void move(); |
146 | void fileStatus(); | 148 | void fileStatus(); |
147 | void doAbout(); | 149 | void doAbout(); |
148 | void doBeam(); | 150 | void doBeam(); |
149 | void fileBeamFinished( Ir *); | 151 | void fileBeamFinished( Ir *); |
150 | 152 | ||
151 | private: | 153 | private: |
152 | QTimer menuTimer; | 154 | QString oldName; |
153 | void startProcess(const QString &); | 155 | QTimer menuTimer; |
156 | void startProcess(const QString &); | ||
157 | bool eventFilter( QObject * , QEvent * ); | ||
158 | void cancelRename(); | ||
159 | void doRename(QListView *); | ||
160 | void okRename(); | ||
154 | private slots: | 161 | private slots: |
155 | void processEnded(); | 162 | void processEnded(); |
156 | }; | 163 | }; |
157 | 164 | ||
158 | #endif // ADVANCEDFM_H | 165 | #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 | |||
@@ -318,86 +318,48 @@ void AdvancedFm::remoteDelete() { | |||
318 | case 1: | 318 | case 1: |
319 | // exit | 319 | // exit |
320 | break; | 320 | break; |
321 | }; | 321 | }; |
322 | 322 | ||
323 | } else { | 323 | } else { |
324 | if(doMsg) { | 324 | if(doMsg) { |
325 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Really delete\n")+f | 325 | switch ( QMessageBox::warning(this,tr("Delete"),tr("Really delete\n")+f |
326 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { | 326 | +" ?",tr("Yes"),tr("No"),0,0,1) ) { |
327 | case 1: | 327 | case 1: |
328 | return; | 328 | return; |
329 | break; | 329 | break; |
330 | }; | 330 | }; |
331 | } | 331 | } |
332 | QString cmd="rm "+f; | 332 | QString cmd="rm "+f; |
333 | QFile file(f); | 333 | QFile file(f); |
334 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) | 334 | if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) |
335 | file.remove(); | 335 | file.remove(); |
336 | } | 336 | } |
337 | } | 337 | } |
338 | } | 338 | } |
339 | populateRemoteView(); | 339 | populateRemoteView(); |
340 | } | 340 | } |
341 | 341 | ||
342 | void AdvancedFm::localRename() { | ||
343 | QString curFile = Local_View->currentItem()->text(0); | ||
344 | qDebug("currentItem "+curFile); | ||
345 | if( curFile !="../") { | ||
346 | InputDialog *fileDlg; | ||
347 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
348 | fileDlg->setInputText((const QString &)curFile); | ||
349 | fileDlg->exec(); | ||
350 | if( fileDlg->result() == 1 ) { | ||
351 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | ||
352 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); | ||
353 | //+".playlist"; | ||
354 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
355 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
356 | } | ||
357 | populateLocalView(); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | void AdvancedFm::remoteRename() | ||
362 | { | ||
363 | QString curFile = Remote_View->currentItem()->text(0); | ||
364 | if( curFile !="../") { | ||
365 | InputDialog *fileDlg; | ||
366 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
367 | fileDlg->setInputText((const QString &)curFile); | ||
368 | fileDlg->exec(); | ||
369 | if( fileDlg->result() == 1 ) { | ||
370 | QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile; | ||
371 | QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); | ||
372 | //+".playlist"; | ||
373 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
374 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
375 | } | ||
376 | populateRemoteView(); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | 342 | ||
381 | void AdvancedFm::filePerms() { | 343 | void AdvancedFm::filePerms() { |
382 | 344 | ||
383 | QStringList curFileList = getPath(); | 345 | QStringList curFileList = getPath(); |
384 | QString filePath; | 346 | QString filePath; |
385 | 347 | ||
386 | if (TabWidget->getCurrentTab() == 0) { | 348 | if (TabWidget->getCurrentTab() == 0) { |
387 | filePath = currentDir.canonicalPath()+"/"; | 349 | filePath = currentDir.canonicalPath()+"/"; |
388 | } else { | 350 | } else { |
389 | filePath= currentRemoteDir.canonicalPath()+"/"; | 351 | filePath= currentRemoteDir.canonicalPath()+"/"; |
390 | } | 352 | } |
391 | 353 | ||
392 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 354 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
393 | filePermissions *filePerm; | 355 | filePermissions *filePerm; |
394 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it)); | 356 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it)); |
395 | filePerm->showMaximized(); | 357 | filePerm->showMaximized(); |
396 | filePerm->exec(); | 358 | filePerm->exec(); |
397 | if( filePerm) | 359 | if( filePerm) |
398 | delete filePerm; | 360 | delete filePerm; |
399 | } | 361 | } |
400 | if (TabWidget->getCurrentTab() == 0) { | 362 | if (TabWidget->getCurrentTab() == 0) { |
401 | populateLocalView(); | 363 | populateLocalView(); |
402 | } else { | 364 | } else { |
403 | populateRemoteView(); | 365 | populateRemoteView(); |
@@ -1026,24 +988,138 @@ void AdvancedFm::selectAll() { | |||
1026 | Remote_View->selectAll(true); | 988 | Remote_View->selectAll(true); |
1027 | Remote_View->setSelected( Remote_View->firstChild(),false); | 989 | Remote_View->setSelected( Remote_View->firstChild(),false); |
1028 | } | 990 | } |
1029 | } | 991 | } |
1030 | 992 | ||
1031 | void AdvancedFm::startProcess(const QString & cmd) { | 993 | void AdvancedFm::startProcess(const QString & cmd) { |
1032 | QStringList command; | 994 | QStringList command; |
1033 | OProcess *process; | 995 | OProcess *process; |
1034 | process = new OProcess(); | 996 | process = new OProcess(); |
1035 | connect(process, SIGNAL(processExited(OProcess *)), | 997 | connect(process, SIGNAL(processExited(OProcess *)), |
1036 | this, SLOT( processEnded())); | 998 | this, SLOT( processEnded())); |
1037 | 999 | ||
1038 | command << "/bin/sh"; | 1000 | command << "/bin/sh"; |
1039 | command << "-c"; | 1001 | command << "-c"; |
1040 | command << cmd.latin1(); | 1002 | command << cmd.latin1(); |
1041 | *process << command; | 1003 | *process << command; |
1042 | if(!process->start(OProcess::NotifyOnExit) ) | 1004 | if(!process->start(OProcess::NotifyOnExit) ) |
1043 | qDebug("could not start process"); | 1005 | qDebug("could not start process"); |
1044 | } | 1006 | } |
1045 | 1007 | ||
1046 | void AdvancedFm::processEnded() { | 1008 | void AdvancedFm::processEnded() { |
1047 | populateLocalView(); | 1009 | populateLocalView(); |
1048 | populateRemoteView(); | 1010 | populateRemoteView(); |
1049 | } | 1011 | } |
1012 | |||
1013 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | ||
1014 | if ( o->inherits( "QLineEdit" ) ) { | ||
1015 | if ( e->type() == QEvent::KeyPress ) { | ||
1016 | QKeyEvent *ke = (QKeyEvent*)e; | ||
1017 | if ( ke->key() == Key_Return || | ||
1018 | ke->key() == Key_Enter ) { | ||
1019 | okRename(); | ||
1020 | return true; | ||
1021 | } else if ( ke->key() == Key_Escape ) { | ||
1022 | cancelRename(); | ||
1023 | return true; | ||
1024 | } | ||
1025 | } else if ( e->type() == QEvent::FocusOut ) { | ||
1026 | cancelRename(); | ||
1027 | return true; | ||
1028 | } | ||
1029 | } | ||
1030 | return QWidget::eventFilter( o, e ); | ||
1031 | } | ||
1032 | |||
1033 | |||
1034 | void AdvancedFm::cancelRename() { | ||
1035 | qDebug("cancel rename"); | ||
1036 | QListView * view; | ||
1037 | if (TabWidget->getCurrentTab() == 0) { | ||
1038 | view = Local_View; | ||
1039 | } | ||
1040 | else | ||
1041 | { | ||
1042 | view = Remote_View; | ||
1043 | } | ||
1044 | |||
1045 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | ||
1046 | delete renameBox; | ||
1047 | renameBox = 0; | ||
1048 | if ( resetFocus ) { | ||
1049 | view->viewport()->setFocusProxy( view); | ||
1050 | view->setFocus(); | ||
1051 | } | ||
1052 | } | ||
1053 | |||
1054 | void AdvancedFm::doRename(QListView * view) { | ||
1055 | |||
1056 | QRect r = view->itemRect( view->currentItem( )); | ||
1057 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | ||
1058 | r.setX( view->contentsX() ); | ||
1059 | if ( r.width() > view->visibleWidth() ) | ||
1060 | r.setWidth( view->visibleWidth() ); | ||
1061 | |||
1062 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | ||
1063 | renameBox->setFrame(true); | ||
1064 | |||
1065 | renameBox->setText( view->currentItem()->text(0) ); | ||
1066 | |||
1067 | renameBox->selectAll(); | ||
1068 | renameBox->installEventFilter( this ); | ||
1069 | view->addChild( renameBox, r.x(), r.y() ); | ||
1070 | renameBox->resize( r.size() ); | ||
1071 | view->viewport()->setFocusProxy( renameBox ); | ||
1072 | renameBox->setFocus(); | ||
1073 | renameBox->show(); | ||
1074 | |||
1075 | } | ||
1076 | |||
1077 | |||
1078 | void AdvancedFm::localRename() { | ||
1079 | oldName = Local_View->currentItem()->text(0); | ||
1080 | doRename(Local_View ); | ||
1081 | populateLocalView(); | ||
1082 | } | ||
1083 | |||
1084 | void AdvancedFm::remoteRename() | ||
1085 | { | ||
1086 | oldName = Remote_View->currentItem()->text(0); | ||
1087 | doRename(Local_View ); | ||
1088 | populateRemoteView(); | ||
1089 | } | ||
1090 | |||
1091 | void AdvancedFm::okRename() { | ||
1092 | QString newName = renameBox->text(); | ||
1093 | cancelRename(); | ||
1094 | int tabs=0; | ||
1095 | QListView * view; | ||
1096 | tabs = TabWidget->getCurrentTab(); | ||
1097 | if ( tabs == 0) | ||
1098 | { | ||
1099 | view = Local_View; | ||
1100 | QString path = currentDir.canonicalPath() + "/"; | ||
1101 | oldName = path + oldName; | ||
1102 | newName = path + newName; | ||
1103 | } | ||
1104 | else | ||
1105 | { | ||
1106 | view = Remote_View; | ||
1107 | QString path = currentRemoteDir.canonicalPath() + "/"; | ||
1108 | oldName = path + oldName; | ||
1109 | newName = path + newName; | ||
1110 | } | ||
1111 | |||
1112 | if( view->currentItem() == NULL) | ||
1113 | return; | ||
1114 | if( rename(oldName.latin1(), newName.latin1())== -1) | ||
1115 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
1116 | else | ||
1117 | oldName = ""; | ||
1118 | |||
1119 | view->takeItem( view->currentItem() ); | ||
1120 | delete view->currentItem(); | ||
1121 | if ( tabs == 0) | ||
1122 | populateLocalView(); | ||
1123 | else | ||
1124 | populateRemoteView(); | ||
1125 | } | ||