Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 161 |
1 files changed, 79 insertions, 82 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 78f9da2..18bbd43 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -1,598 +1,595 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | AdvancedFm.cpp | 2 | AdvancedFm.cpp |
3 | ------------------- | 3 | ------------------- |
4 | ** Created: Sat Mar 9 23:33:09 2002 | 4 | ** Created: Sat Mar 9 23:33:09 2002 |
5 | copyright : (C) 2002 by ljp | 5 | copyright : (C) 2002 by ljp |
6 | email : ljp@llornkcor.com | 6 | email : ljp@llornkcor.com |
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * |
11 | ***************************************************************************/ | 11 | ***************************************************************************/ |
12 | #include "advancedfm.h" | 12 | #include "advancedfm.h" |
13 | #include "output.h" | 13 | #include "output.h" |
14 | #include "filePermissions.h" | 14 | #include "filePermissions.h" |
15 | 15 | ||
16 | #include <opie/otabwidget.h> | ||
17 | #include <opie/oprocess.h> | ||
18 | |||
19 | #include <qpe/lnkproperties.h> | 16 | #include <qpe/lnkproperties.h> |
20 | #include <qpe/qpeapplication.h> | 17 | #include <qpe/qpeapplication.h> |
21 | #include <qpe/resource.h> | 18 | #include <qpe/resource.h> |
22 | #include <qpe/qcopenvelope_qws.h> | 19 | #include <qpe/qcopenvelope_qws.h> |
23 | #include <qpe/applnk.h> | 20 | #include <qpe/applnk.h> |
24 | #include <qpe/ir.h> | 21 | #include <qpe/ir.h> |
25 | 22 | ||
26 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
27 | #include <qmultilineedit.h> | 24 | #include <qmultilineedit.h> |
28 | 25 | ||
29 | #include <qstring.h> | 26 | #include <qstring.h> |
30 | 27 | ||
31 | #include <qlayout.h> | 28 | #include <qlayout.h> |
32 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
33 | #include <qcombobox.h> | 30 | #include <qcombobox.h> |
34 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
35 | #include <qtabwidget.h> | 32 | #include <qtabwidget.h> |
36 | #include <qtoolbutton.h> | 33 | #include <qtoolbutton.h> |
37 | #include <qlineedit.h> | 34 | #include <qlineedit.h> |
38 | #include <qlistview.h> | 35 | #include <qlistview.h> |
39 | 36 | ||
40 | #include <errno.h> | 37 | #include <errno.h> |
41 | #include <stdlib.h> | 38 | #include <stdlib.h> |
42 | #include <unistd.h> | 39 | #include <unistd.h> |
43 | #include <sys/stat.h> | 40 | #include <sys/stat.h> |
44 | #include <dirent.h> | 41 | #include <dirent.h> |
45 | #include <sys/sendfile.h> | 42 | #include <sys/sendfile.h> |
46 | #include <fcntl.h> | 43 | #include <fcntl.h> |
47 | 44 | ||
48 | 45 | ||
49 | void AdvancedFm::doDirChange() { | 46 | void AdvancedFm::doDirChange() { |
50 | QString pathItem = CurrentView()->currentItem()->text(0); | 47 | QString pathItem = CurrentView()->currentItem()->text(0); |
51 | if( pathItem == "../") { | 48 | if( pathItem == "../") { |
52 | ListClicked( CurrentView()->currentItem()); | 49 | ListClicked( CurrentView()->currentItem()); |
53 | } else { | 50 | } else { |
54 | if( pathItem.find(" -> ",0,TRUE) != -1) | 51 | if( pathItem.find(" -> ",0,TRUE) != -1) |
55 | pathItem = dealWithSymName((const QString&)pathItem)+"/"; | 52 | pathItem = dealWithSymName((const QString&)pathItem)+"/"; |
56 | // qWarning(pathItem); | 53 | // qWarning(pathItem); |
57 | gotoDirectory( CurrentDir()->path()+"/"+pathItem.left( pathItem.length() - 1) ); | 54 | gotoDirectory( CurrentDir()->path()+"/"+pathItem.left( pathItem.length() - 1) ); |
58 | } | 55 | } |
59 | } | 56 | } |
60 | 57 | ||
61 | void AdvancedFm::showMenuHidden() { | 58 | void AdvancedFm::showMenuHidden() { |
62 | if (b) { | 59 | if (b) { |
63 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 60 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
64 | OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 61 | OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
65 | fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); | 62 | fileMenu->setItemChecked( fileMenu->idAt(0),TRUE); |
66 | } else { | 63 | } else { |
67 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 64 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
68 | OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 65 | OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
69 | fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); | 66 | fileMenu->setItemChecked( fileMenu->idAt(0),FALSE); |
70 | } | 67 | } |
71 | b = !b; | 68 | b = !b; |
72 | populateView(); | 69 | populateView(); |
73 | } | 70 | } |
74 | 71 | ||
75 | void AdvancedFm::showHidden() { | 72 | void AdvancedFm::showHidden() { |
76 | if (b) { | 73 | if (b) { |
77 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 74 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
78 | OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); | 75 | OtherDir()->setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); |
79 | } else { | 76 | } else { |
80 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 77 | CurrentDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
81 | OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); | 78 | OtherDir()->setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); |
82 | } | 79 | } |
83 | populateView(); | 80 | populateView(); |
84 | } | 81 | } |
85 | 82 | ||
86 | QString AdvancedFm::dealWithSymName(const QString &fileName) { | 83 | QString AdvancedFm::dealWithSymName(const QString &fileName) { |
87 | QString strItem = fileName; | 84 | QString strItem = fileName; |
88 | return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); | 85 | return strItem.right( (strItem.length() - strItem.find("->",0,TRUE)) - 4); |
89 | } | 86 | } |
90 | 87 | ||
91 | void AdvancedFm::runThis() { | 88 | void AdvancedFm::runThis() { |
92 | if( !CurrentView()->currentItem()) return; | 89 | if( !CurrentView()->currentItem()) return; |
93 | QString fs; | 90 | QString fs; |
94 | QDir *thisDir = CurrentDir(); | 91 | QDir *thisDir = CurrentDir(); |
95 | 92 | ||
96 | QString curFile = CurrentView()->currentItem()->text(0); | 93 | QString curFile = CurrentView()->currentItem()->text(0); |
97 | QString path = thisDir->canonicalPath(); | 94 | QString path = thisDir->canonicalPath(); |
98 | 95 | ||
99 | if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink | 96 | if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink |
100 | 97 | ||
101 | curFile = dealWithSymName((const QString&)curFile); | 98 | curFile = dealWithSymName((const QString&)curFile); |
102 | 99 | ||
103 | if(curFile != "../") { | 100 | if(curFile != "../") { |
104 | 101 | ||
105 | fs = getFileSystemType((const QString &) path); | 102 | fs = getFileSystemType((const QString &) path); |
106 | QFileInfo fileInfo( path + "/" + curFile); | 103 | QFileInfo fileInfo( path + "/" + curFile); |
107 | // qDebug( fileInfo.owner()); | 104 | // qDebug( fileInfo.owner()); |
108 | 105 | ||
109 | if( (fileInfo.permission( QFileInfo::ExeUser) | 106 | if( (fileInfo.permission( QFileInfo::ExeUser) |
110 | | fileInfo.permission( QFileInfo::ExeGroup) | 107 | | fileInfo.permission( QFileInfo::ExeGroup) |
111 | | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) { | 108 | | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) { |
112 | | fs == "vfat" && fileInfo.filePath().contains("/bin") ) { | 109 | | fs == "vfat" && fileInfo.filePath().contains("/bin") ) { |
113 | QCopEnvelope e("QPE/System", "execute(QString)" ); | 110 | QCopEnvelope e("QPE/System", "execute(QString)" ); |
114 | e << curFile; | 111 | e << curFile; |
115 | } else { | 112 | } else { |
116 | curFile = path + "/" + curFile; | 113 | curFile = path + "/" + curFile; |
117 | DocLnk nf(curFile); | 114 | DocLnk nf(curFile); |
118 | QString execStr = nf.exec(); | 115 | QString execStr = nf.exec(); |
119 | // qDebug( execStr); | 116 | // qDebug( execStr); |
120 | if( execStr.isEmpty() ) { | 117 | if( execStr.isEmpty() ) { |
121 | } else { | 118 | } else { |
122 | nf.execute(); | 119 | nf.execute(); |
123 | } | 120 | } |
124 | } | 121 | } |
125 | } | 122 | } |
126 | } | 123 | } |
127 | 124 | ||
128 | void AdvancedFm::runText() { | 125 | void AdvancedFm::runText() { |
129 | if( !CurrentView()->currentItem()) return; | 126 | if( !CurrentView()->currentItem()) return; |
130 | QString curFile = CurrentView()->currentItem()->text(0); | 127 | QString curFile = CurrentView()->currentItem()->text(0); |
131 | if(curFile != "../") { | 128 | if(curFile != "../") { |
132 | if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink | 129 | if( curFile.find("@",0,TRUE) !=-1 || curFile.find("->",0,TRUE) !=-1 ) //if symlink |
133 | curFile = dealWithSymName((const QString&)curFile); | 130 | curFile = dealWithSymName((const QString&)curFile); |
134 | curFile = CurrentDir()->canonicalPath()+"/"+curFile; | 131 | curFile = CurrentDir()->canonicalPath()+"/"+curFile; |
135 | QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); | 132 | QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" ); |
136 | e << curFile; | 133 | e << curFile; |
137 | } | 134 | } |
138 | } | 135 | } |
139 | 136 | ||
140 | void AdvancedFm::makeDir() { | 137 | void AdvancedFm::makeDir() { |
141 | InputDialog *fileDlg; | 138 | InputDialog *fileDlg; |
142 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); | 139 | fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0); |
143 | fileDlg->exec(); | 140 | fileDlg->exec(); |
144 | if( fileDlg->result() == 1 ) { | 141 | if( fileDlg->result() == 1 ) { |
145 | QDir *thisDir = CurrentDir(); | 142 | QDir *thisDir = CurrentDir(); |
146 | QString filename = fileDlg->LineEdit1->text(); | 143 | QString filename = fileDlg->LineEdit1->text(); |
147 | thisDir->mkdir( thisDir->canonicalPath()+"/"+filename); | 144 | thisDir->mkdir( thisDir->canonicalPath()+"/"+filename); |
148 | } | 145 | } |
149 | populateView(); | 146 | populateView(); |
150 | } | 147 | } |
151 | 148 | ||
152 | void AdvancedFm::doDelete() { | 149 | void AdvancedFm::doDelete() { |
153 | QStringList curFileList = getPath(); | 150 | QStringList curFileList = getPath(); |
154 | bool doMsg=true; | 151 | bool doMsg=true; |
155 | int count = curFileList.count(); | 152 | int count = curFileList.count(); |
156 | if( count > 0) { | 153 | if( count > 0) { |
157 | if(count > 1 ) { | 154 | if(count > 1 ) { |
158 | QString msg; | 155 | QString msg; |
159 | msg=tr("Really delete\n%1 files?").arg(count); | 156 | msg=tr("Really delete\n%1 files?").arg(count); |
160 | switch ( QMessageBox::warning(this,tr("Delete"),msg | 157 | switch ( QMessageBox::warning(this,tr("Delete"),msg |
161 | ,tr("Yes"),tr("No"),0,0,1) ) | 158 | ,tr("Yes"),tr("No"),0,0,1) ) |
162 | { | 159 | { |
163 | case 0: | 160 | case 0: |
164 | doMsg=false; | 161 | doMsg=false; |
165 | break; | 162 | break; |
166 | case 1: | 163 | case 1: |
167 | return; | 164 | return; |
168 | break; | 165 | break; |
169 | }; | 166 | }; |
170 | } | 167 | } |
171 | 168 | ||
172 | QString myFile; | 169 | QString myFile; |
173 | 170 | ||
174 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 171 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
175 | myFile = (*it); | 172 | myFile = (*it); |
176 | if( myFile.find(" -> ",0,TRUE) != -1) | 173 | if( myFile.find(" -> ",0,TRUE) != -1) |
177 | myFile = myFile.left( myFile.find(" -> ",0,TRUE)); | 174 | myFile = myFile.left( myFile.find(" -> ",0,TRUE)); |
178 | 175 | ||
179 | QString f = CurrentDir()->canonicalPath(); | 176 | QString f = CurrentDir()->canonicalPath(); |
180 | if(f.right(1).find("/",0,TRUE) == -1) | 177 | if(f.right(1).find("/",0,TRUE) == -1) |
181 | f += "/"; | 178 | f += "/"; |
182 | f += myFile; | 179 | f += myFile; |
183 | if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) { | 180 | if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) { |
184 | //if file is a directory | 181 | //if file is a directory |
185 | 182 | ||
186 | switch ( QMessageBox::warning( this, tr("Delete Directory?"), | 183 | switch ( QMessageBox::warning( this, tr("Delete Directory?"), |
187 | tr("Really delete %1\nand all it's contents ?" ).arg( f ) , | 184 | tr("Really delete %1\nand all it's contents ?" ).arg( f ) , |
188 | tr("Yes"), tr("No"), 0, 0, 1) ) { | 185 | tr("Yes"), tr("No"), 0, 0, 1) ) { |
189 | case 0: | 186 | case 0: |
190 | { | 187 | { |
191 | f=f.left(f.length()-1); | 188 | f=f.left(f.length()-1); |
192 | QString cmd="rm -rf "+f; | 189 | QString cmd="rm -rf "+f; |
193 | startProcess( (const QString)cmd.latin1() ); | 190 | startProcess( (const QString)cmd.latin1() ); |
194 | populateView(); | 191 | populateView(); |
195 | } | 192 | } |
196 | break; | 193 | break; |
197 | case 1: | 194 | case 1: |
198 | // exit | 195 | // exit |
199 | break; | 196 | break; |
200 | }; | 197 | }; |
201 | 198 | ||
202 | } else { | 199 | } else { |
203 | if(doMsg) { | 200 | if(doMsg) { |
204 | switch ( QMessageBox::warning(this,tr("Delete"), | 201 | switch ( QMessageBox::warning(this,tr("Delete"), |
205 | tr("Really delete\n%1?").arg( myFile ), | 202 | tr("Really delete\n%1?").arg( myFile ), |
206 | tr("Yes"), tr("No"), 0, 0, 1) ) { | 203 | tr("Yes"), tr("No"), 0, 0, 1) ) { |
207 | case 1: | 204 | case 1: |
208 | return; | 205 | return; |
209 | break; | 206 | break; |
210 | }; | 207 | }; |
211 | } | 208 | } |
212 | 209 | ||
213 | QString cmd="rm "+f; | 210 | QString cmd="rm "+f; |
214 | QFile file(f); | 211 | QFile file(f); |
215 | QFileInfo fi(myFile); | 212 | QFileInfo fi(myFile); |
216 | if( fi.fileName().find("../",0,TRUE)==-1) { | 213 | if( fi.fileName().find("../",0,TRUE)==-1) { |
217 | // qDebug("remove link files "+myFile); | 214 | // qDebug("remove link files "+myFile); |
218 | 215 | ||
219 | // DocLnk lnk(f); | 216 | // DocLnk lnk(f); |
220 | DocLnk *lnk; | 217 | DocLnk *lnk; |
221 | lnk = new DocLnk(f); | 218 | lnk = new DocLnk(f); |
222 | // qDebug("Deleting doclnk " + lnk->linkFile()); | 219 | // qDebug("Deleting doclnk " + lnk->linkFile()); |
223 | if(lnk->isValid()) | 220 | if(lnk->isValid()) |
224 | lnk->removeLinkFile(); | 221 | lnk->removeLinkFile(); |
225 | // delete lnk; | 222 | // delete lnk; |
226 | file.remove(); | 223 | file.remove(); |
227 | } | 224 | } |
228 | } | 225 | } |
229 | } | 226 | } |
230 | } | 227 | } |
231 | populateView(); | 228 | populateView(); |
232 | } | 229 | } |
233 | 230 | ||
234 | void AdvancedFm::filePerms() { | 231 | void AdvancedFm::filePerms() { |
235 | QStringList curFileList = getPath(); | 232 | QStringList curFileList = getPath(); |
236 | QString filePath; | 233 | QString filePath; |
237 | 234 | ||
238 | filePath = CurrentDir()->canonicalPath()+"/"; | 235 | filePath = CurrentDir()->canonicalPath()+"/"; |
239 | 236 | ||
240 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 237 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
241 | filePermissions *filePerm; | 238 | filePermissions *filePerm; |
242 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it)); | 239 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it)); |
243 | QPEApplication::execDialog( filePerm ); | 240 | QPEApplication::execDialog( filePerm ); |
244 | if( filePerm ) | 241 | if( filePerm ) |
245 | delete filePerm; | 242 | delete filePerm; |
246 | } | 243 | } |
247 | populateView(); | 244 | populateView(); |
248 | } | 245 | } |
249 | 246 | ||
250 | void AdvancedFm::doProperties() { | 247 | void AdvancedFm::doProperties() { |
251 | #if defined(QT_QWS_OPIE) | 248 | #if defined(QT_QWS_OPIE) |
252 | 249 | ||
253 | QStringList curFileList = getPath(); | 250 | QStringList curFileList = getPath(); |
254 | 251 | ||
255 | QString filePath; | 252 | QString filePath; |
256 | filePath = CurrentDir()->canonicalPath()+"/"; | 253 | filePath = CurrentDir()->canonicalPath()+"/"; |
257 | 254 | ||
258 | // qDebug("%d",curFileList.count()); | 255 | // qDebug("%d",curFileList.count()); |
259 | 256 | ||
260 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 257 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
261 | // qDebug((filePath+*it)); | 258 | // qDebug((filePath+*it)); |
262 | DocLnk lnk( (filePath+*it)); | 259 | DocLnk lnk( (filePath+*it)); |
263 | LnkProperties prop( &lnk ); | 260 | LnkProperties prop( &lnk ); |
264 | QPEApplication::execDialog( &prop ); | 261 | QPEApplication::execDialog( &prop ); |
265 | } | 262 | } |
266 | #endif | 263 | #endif |
267 | 264 | ||
268 | } | 265 | } |
269 | 266 | ||
270 | void AdvancedFm::upDir() { | 267 | void AdvancedFm::upDir() { |
271 | QDir *thisDir = CurrentDir(); | 268 | QDir *thisDir = CurrentDir(); |
272 | QString current = thisDir->canonicalPath(); | 269 | QString current = thisDir->canonicalPath(); |
273 | QDir dir(current); | 270 | QDir dir(current); |
274 | dir.cdUp(); | 271 | dir.cdUp(); |
275 | current = dir.canonicalPath(); | 272 | current = dir.canonicalPath(); |
276 | chdir( current.latin1() ); | 273 | chdir( current.latin1() ); |
277 | thisDir->cd( current, TRUE); | 274 | thisDir->cd( current, TRUE); |
278 | 275 | ||
279 | populateView(); | 276 | populateView(); |
280 | update(); | 277 | update(); |
281 | } | 278 | } |
282 | 279 | ||
283 | void AdvancedFm::copy() { | 280 | void AdvancedFm::copy() { |
284 | qApp->processEvents(); | 281 | qApp->processEvents(); |
285 | QStringList curFileList = getPath(); | 282 | QStringList curFileList = getPath(); |
286 | 283 | ||
287 | QDir *thisDir = CurrentDir(); | 284 | QDir *thisDir = CurrentDir(); |
288 | QDir *thatDir = OtherDir(); | 285 | QDir *thatDir = OtherDir(); |
289 | 286 | ||
290 | bool doMsg=true; | 287 | bool doMsg=true; |
291 | int count=curFileList.count(); | 288 | int count=curFileList.count(); |
292 | if( count > 0) { | 289 | if( count > 0) { |
293 | if(count > 1 ){ | 290 | if(count > 1 ){ |
294 | QString msg; | 291 | QString msg; |
295 | msg=tr("Really copy\n%1 files?").arg(count); | 292 | msg=tr("Really copy\n%1 files?").arg(count); |
296 | switch ( QMessageBox::warning(this,tr("Copy"),msg | 293 | switch ( QMessageBox::warning(this,tr("Copy"),msg |
297 | ,tr("Yes"),tr("No"),0,0,1) ) | 294 | ,tr("Yes"),tr("No"),0,0,1) ) |
298 | { | 295 | { |
299 | case 0: | 296 | case 0: |
300 | doMsg=false; | 297 | doMsg=false; |
301 | break; | 298 | break; |
302 | case 1: | 299 | case 1: |
303 | return; | 300 | return; |
304 | break; | 301 | break; |
305 | }; | 302 | }; |
306 | } | 303 | } |
307 | 304 | ||
308 | QString curFile, item, destFile; | 305 | QString curFile, item, destFile; |
309 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 306 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
310 | item=(*it); | 307 | item=(*it); |
311 | if(item.find("->",0,TRUE)) //symlink | 308 | if(item.find("->",0,TRUE)) //symlink |
312 | item = item.left(item.find("->",0,TRUE)); | 309 | item = item.left(item.find("->",0,TRUE)); |
313 | 310 | ||
314 | curFile = thisDir->canonicalPath()+"/"+ item; | 311 | curFile = thisDir->canonicalPath()+"/"+ item; |
315 | destFile = thatDir->canonicalPath()+"/"+ item; | 312 | destFile = thatDir->canonicalPath()+"/"+ item; |
316 | 313 | ||
317 | // qDebug("Destination file is "+destFile); | 314 | // qDebug("Destination file is "+destFile); |
318 | // qDebug("CurrentFile file is " + curFile); | 315 | // qDebug("CurrentFile file is " + curFile); |
319 | 316 | ||
320 | QFile f(destFile); | 317 | QFile f(destFile); |
321 | if( f.exists()) { | 318 | if( f.exists()) { |
322 | if(doMsg) { | 319 | if(doMsg) { |
323 | switch ( QMessageBox::warning(this,tr("File Exists!"), | 320 | switch ( QMessageBox::warning(this,tr("File Exists!"), |
324 | tr("%1 exists. Ok to overwrite?").arg( item ), | 321 | tr("%1 exists. Ok to overwrite?").arg( item ), |
325 | tr("Yes"),tr("No"),0,0,1) ) { | 322 | tr("Yes"),tr("No"),0,0,1) ) { |
326 | case 1: | 323 | case 1: |
327 | return; | 324 | return; |
328 | break; | 325 | break; |
329 | }; | 326 | }; |
330 | } | 327 | } |
331 | f.remove(); | 328 | f.remove(); |
332 | } | 329 | } |
333 | 330 | ||
334 | if( !copyFile( curFile, destFile) ) { | 331 | if( !copyFile( curFile, destFile) ) { |
335 | QMessageBox::message("AdvancedFm", | 332 | QMessageBox::message("AdvancedFm", |
336 | tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); | 333 | tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); |
337 | return; | 334 | return; |
338 | } | 335 | } |
339 | } | 336 | } |
340 | setOtherTabCurrent(); | 337 | setOtherTabCurrent(); |
341 | rePopulate(); | 338 | rePopulate(); |
342 | } | 339 | } |
343 | } | 340 | } |
344 | 341 | ||
345 | void AdvancedFm::copyAs() { | 342 | void AdvancedFm::copyAs() { |
346 | qApp->processEvents(); | 343 | qApp->processEvents(); |
347 | 344 | ||
348 | QStringList curFileList = getPath(); | 345 | QStringList curFileList = getPath(); |
349 | QString curFile, item; | 346 | QString curFile, item; |
350 | InputDialog *fileDlg; | 347 | InputDialog *fileDlg; |
351 | 348 | ||
352 | QDir *thisDir = CurrentDir(); | 349 | QDir *thisDir = CurrentDir(); |
353 | QDir *thatDir = OtherDir(); | 350 | QDir *thatDir = OtherDir(); |
354 | 351 | ||
355 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 352 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
356 | QString destFile; | 353 | QString destFile; |
357 | item=(*it); | 354 | item=(*it); |
358 | curFile = thisDir->canonicalPath()+"/"+(*it); | 355 | curFile = thisDir->canonicalPath()+"/"+(*it); |
359 | fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); | 356 | fileDlg = new InputDialog( this, tr("Copy "+curFile+" As"), TRUE, 0); |
360 | 357 | ||
361 | fileDlg->setInputText((const QString &) destFile ); | 358 | fileDlg->setInputText((const QString &) destFile ); |
362 | fileDlg->exec(); | 359 | fileDlg->exec(); |
363 | 360 | ||
364 | if( fileDlg->result() == 1 ) { | 361 | if( fileDlg->result() == 1 ) { |
365 | QString filename = fileDlg->LineEdit1->text(); | 362 | QString filename = fileDlg->LineEdit1->text(); |
366 | destFile = thatDir->canonicalPath()+"/"+filename; | 363 | destFile = thatDir->canonicalPath()+"/"+filename; |
367 | 364 | ||
368 | QFile f( destFile); | 365 | QFile f( destFile); |
369 | if( f.exists()) { | 366 | if( f.exists()) { |
370 | switch (QMessageBox::warning(this,tr("File Exists!"), | 367 | switch (QMessageBox::warning(this,tr("File Exists!"), |
371 | item+tr("\nexists. Ok to overwrite?"), | 368 | item+tr("\nexists. Ok to overwrite?"), |
372 | tr("Yes"),tr("No"),0,0,1) ) { | 369 | tr("Yes"),tr("No"),0,0,1) ) { |
373 | case 0: | 370 | case 0: |
374 | f.remove(); | 371 | f.remove(); |
375 | break; | 372 | break; |
376 | case 1: | 373 | case 1: |
377 | return; | 374 | return; |
378 | break; | 375 | break; |
379 | }; | 376 | }; |
380 | } | 377 | } |
381 | if( !copyFile( curFile, destFile) ) { | 378 | if( !copyFile( curFile, destFile) ) { |
382 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") | 379 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") |
383 | +curFile +tr("to\n")+destFile); | 380 | +curFile +tr("to\n")+destFile); |
384 | return; | 381 | return; |
385 | } | 382 | } |
386 | } | 383 | } |
387 | delete fileDlg; | 384 | delete fileDlg; |
388 | 385 | ||
389 | } | 386 | } |
390 | rePopulate(); | 387 | rePopulate(); |
391 | setOtherTabCurrent(); | 388 | setOtherTabCurrent(); |
392 | } | 389 | } |
393 | 390 | ||
394 | void AdvancedFm::copySameDir() { | 391 | void AdvancedFm::copySameDir() { |
395 | qApp->processEvents(); | 392 | qApp->processEvents(); |
396 | QStringList curFileList = getPath(); | 393 | QStringList curFileList = getPath(); |
397 | QString curFile, item, destFile; | 394 | QString curFile, item, destFile; |
398 | InputDialog *fileDlg; | 395 | InputDialog *fileDlg; |
399 | 396 | ||
400 | QDir *thisDir = CurrentDir(); | 397 | QDir *thisDir = CurrentDir(); |
401 | 398 | ||
402 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 399 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
403 | item=(*it); | 400 | item=(*it); |
404 | curFile = thisDir->canonicalPath()+"/"+ item; | 401 | curFile = thisDir->canonicalPath()+"/"+ item; |
405 | 402 | ||
406 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); | 403 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); |
407 | fileDlg->setInputText((const QString &) destFile ); | 404 | fileDlg->setInputText((const QString &) destFile ); |
408 | fileDlg->exec(); | 405 | fileDlg->exec(); |
409 | 406 | ||
410 | if( fileDlg->result() == 1 ) { | 407 | if( fileDlg->result() == 1 ) { |
411 | 408 | ||
412 | QString filename = fileDlg->LineEdit1->text(); | 409 | QString filename = fileDlg->LineEdit1->text(); |
413 | destFile = thisDir->canonicalPath()+"/"+filename; | 410 | destFile = thisDir->canonicalPath()+"/"+filename; |
414 | 411 | ||
415 | QFile f(destFile); | 412 | QFile f(destFile); |
416 | if( f.exists()) { | 413 | if( f.exists()) { |
417 | switch (QMessageBox::warning(this,tr("Delete"), | 414 | switch (QMessageBox::warning(this,tr("Delete"), |
418 | destFile+tr(" already exists.\nDo you really want to delete it?"), | 415 | destFile+tr(" already exists.\nDo you really want to delete it?"), |
419 | tr("Yes"),tr("No"),0,0,1) ) { | 416 | tr("Yes"),tr("No"),0,0,1) ) { |
420 | case 0: | 417 | case 0: |
421 | 418 | ||
422 | f.remove(); | 419 | f.remove(); |
423 | break; | 420 | break; |
424 | case 1: | 421 | case 1: |
425 | return; | 422 | return; |
426 | break; | 423 | break; |
427 | }; | 424 | }; |
428 | } | 425 | } |
429 | if(!copyFile( curFile,destFile) ) { | 426 | if(!copyFile( curFile,destFile) ) { |
430 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") | 427 | QMessageBox::message("AdvancedFm",tr("Could not copy\n") |
431 | +curFile +tr("to\n")+destFile); | 428 | +curFile +tr("to\n")+destFile); |
432 | return; | 429 | return; |
433 | } | 430 | } |
434 | 431 | ||
435 | // qDebug("copy "+curFile+" as "+destFile); | 432 | // qDebug("copy "+curFile+" as "+destFile); |
436 | } | 433 | } |
437 | delete fileDlg; | 434 | delete fileDlg; |
438 | } | 435 | } |
439 | rePopulate(); | 436 | rePopulate(); |
440 | } | 437 | } |
441 | 438 | ||
442 | void AdvancedFm::move() { | 439 | void AdvancedFm::move() { |
443 | qApp->processEvents(); | 440 | qApp->processEvents(); |
444 | 441 | ||
445 | QStringList curFileList = getPath(); | 442 | QStringList curFileList = getPath(); |
446 | if( curFileList.count() > 0) { | 443 | if( curFileList.count() > 0) { |
447 | QString curFile, destFile, item; | 444 | QString curFile, destFile, item; |
448 | 445 | ||
449 | QDir *thisDir = CurrentDir(); | 446 | QDir *thisDir = CurrentDir(); |
450 | QDir *thatDir = OtherDir(); | 447 | QDir *thatDir = OtherDir(); |
451 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 448 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
452 | item=(*it); | 449 | item=(*it); |
453 | QString destFile = thatDir->canonicalPath(); | 450 | QString destFile = thatDir->canonicalPath(); |
454 | 451 | ||
455 | if(destFile.right(1).find("/",0,TRUE) == -1) | 452 | if(destFile.right(1).find("/",0,TRUE) == -1) |
456 | destFile+="/"; | 453 | destFile+="/"; |
457 | destFile += item; | 454 | destFile += item; |
458 | // qDebug("Destination file is "+destFile); | 455 | // qDebug("Destination file is "+destFile); |
459 | 456 | ||
460 | curFile = thisDir->canonicalPath(); | 457 | curFile = thisDir->canonicalPath(); |
461 | if(curFile.right(1).find("/",0,TRUE) == -1) | 458 | if(curFile.right(1).find("/",0,TRUE) == -1) |
462 | curFile +="/"; | 459 | curFile +="/"; |
463 | curFile+= item; | 460 | curFile+= item; |
464 | // qDebug("CurrentFile file is " + curFile); | 461 | // qDebug("CurrentFile file is " + curFile); |
465 | 462 | ||
466 | if(QFileInfo(curFile).isDir()) { | 463 | if(QFileInfo(curFile).isDir()) { |
467 | moveDirectory( curFile, destFile ); | 464 | moveDirectory( curFile, destFile ); |
468 | rePopulate(); | 465 | rePopulate(); |
469 | return; | 466 | return; |
470 | } | 467 | } |
471 | 468 | ||
472 | QFile f( curFile); | 469 | QFile f( curFile); |
473 | if( f.exists()) { | 470 | if( f.exists()) { |
474 | if( !copyFile( curFile, destFile) ) { | 471 | if( !copyFile( curFile, destFile) ) { |
475 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); | 472 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); |
476 | return; | 473 | return; |
477 | } else | 474 | } else |
478 | QFile::remove(curFile); | 475 | QFile::remove(curFile); |
479 | } | 476 | } |
480 | } | 477 | } |
481 | 478 | ||
482 | } | 479 | } |
483 | rePopulate(); | 480 | rePopulate(); |
484 | setOtherTabCurrent(); | 481 | setOtherTabCurrent(); |
485 | } | 482 | } |
486 | 483 | ||
487 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { | 484 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { |
488 | int err = 0; | 485 | int err = 0; |
489 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; | 486 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; |
490 | err = system((const char*)cmd); | 487 | err = system((const char*)cmd); |
491 | } else | 488 | } else |
492 | err = -1; | 489 | err = -1; |
493 | 490 | ||
494 | if(err!=0) { | 491 | if(err!=0) { |
495 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); | 492 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); |
496 | return false; | 493 | return false; |
497 | } | 494 | } |
498 | return true; | 495 | return true; |
499 | } | 496 | } |
500 | 497 | ||
501 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { | 498 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { |
502 | 499 | ||
503 | QStringcmd = "/bin/cp -fpR " + src + " " + dest; | 500 | QString cmd = "/bin/cp -fpR " + src + " " + dest; |
504 | qWarning(cmd); | 501 | qWarning(cmd); |
505 | interr = system( (const char *) cmd ); | 502 | int err = system( (const char *) cmd ); |
506 | if ( err != 0 ) { | 503 | if ( err != 0 ) { |
507 | QMessageBox::message("AdvancedFm", | 504 | QMessageBox::message("AdvancedFm", |
508 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); | 505 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); |
509 | return false; | 506 | return false; |
510 | } | 507 | } |
511 | 508 | ||
512 | return true; | 509 | return true; |
513 | } | 510 | } |
514 | 511 | ||
515 | 512 | ||
516 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | 513 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { |
517 | 514 | ||
518 | 515 | ||
519 | if(QFileInfo(src).isDir()) { | 516 | if(QFileInfo(src).isDir()) { |
520 | if( copyDirectory( src, dest )) { | 517 | if( copyDirectory( src, dest )) { |
521 | setOtherTabCurrent(); | 518 | setOtherTabCurrent(); |
522 | populateView(); | 519 | populateView(); |
523 | return true; | 520 | return true; |
524 | } | 521 | } |
525 | else | 522 | else |
526 | return false; | 523 | return false; |
527 | } | 524 | } |
528 | 525 | ||
529 | 526 | ||
530 | bool success = true; | 527 | bool success = true; |
531 | struct stat status; | 528 | struct stat status; |
532 | QFile srcFile(src); | 529 | QFile srcFile(src); |
533 | QFile destFile(dest); | 530 | QFile destFile(dest); |
534 | int err=0; | 531 | int err=0; |
535 | int read_fd=0; | 532 | int read_fd=0; |
536 | int write_fd=0; | 533 | int write_fd=0; |
537 | struct stat stat_buf; | 534 | struct stat stat_buf; |
538 | off_t offset = 0; | 535 | off_t offset = 0; |
539 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 536 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
540 | // qWarning("open failed"); | 537 | // qWarning("open failed"); |
541 | return success = false; | 538 | return success = false; |
542 | } | 539 | } |
543 | read_fd = srcFile.handle(); | 540 | read_fd = srcFile.handle(); |
544 | if(read_fd != -1) { | 541 | if(read_fd != -1) { |
545 | fstat (read_fd, &stat_buf); | 542 | fstat (read_fd, &stat_buf); |
546 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 543 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
547 | // qWarning("destfile open failed"); | 544 | // qWarning("destfile open failed"); |
548 | return success = false; | 545 | return success = false; |
549 | } | 546 | } |
550 | write_fd = destFile.handle(); | 547 | write_fd = destFile.handle(); |
551 | if(write_fd != -1) { | 548 | if(write_fd != -1) { |
552 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 549 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
553 | if( err == -1) { | 550 | if( err == -1) { |
554 | QString msg; | 551 | QString msg; |
555 | switch(err) { | 552 | switch(err) { |
556 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 553 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; |
557 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 554 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
558 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 555 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
559 | case EIO: msg = "Unspecified error while reading from in_fd."; | 556 | case EIO: msg = "Unspecified error while reading from in_fd."; |
560 | }; | 557 | }; |
561 | success = false; | 558 | success = false; |
562 | // qWarning(msg); | 559 | // qWarning(msg); |
563 | } | 560 | } |
564 | } else { | 561 | } else { |
565 | success = false; | 562 | success = false; |
566 | } | 563 | } |
567 | } else { | 564 | } else { |
568 | success = false; | 565 | success = false; |
569 | } | 566 | } |
570 | srcFile.close(); | 567 | srcFile.close(); |
571 | destFile.close(); | 568 | destFile.close(); |
572 | // Set file permissions | 569 | // Set file permissions |
573 | if( stat( (const char *) src, &status ) == 0 ) { | 570 | if( stat( (const char *) src, &status ) == 0 ) { |
574 | chmod( (const char *) dest, status.st_mode ); | 571 | chmod( (const char *) dest, status.st_mode ); |
575 | } | 572 | } |
576 | 573 | ||
577 | return success; | 574 | return success; |
578 | } | 575 | } |
579 | 576 | ||
580 | void AdvancedFm::runCommand() { | 577 | void AdvancedFm::runCommand() { |
581 | if( !CurrentView()->currentItem()) return; | 578 | if( !CurrentView()->currentItem()) return; |
582 | QDir *thisDir = CurrentDir(); | 579 | QDir *thisDir = CurrentDir(); |
583 | 580 | ||
584 | QString curFile; | 581 | QString curFile; |
585 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 582 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
586 | 583 | ||
587 | InputDialog *fileDlg; | 584 | InputDialog *fileDlg; |
588 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 585 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
589 | fileDlg->setInputText(curFile); | 586 | fileDlg->setInputText(curFile); |
590 | fileDlg->exec(); | 587 | fileDlg->exec(); |
591 | //QString command; | 588 | //QString command; |
592 | 589 | ||
593 | if( fileDlg->result() == 1 ) { | 590 | if( fileDlg->result() == 1 ) { |
594 | // qDebug(fileDlg->LineEdit1->text()); | 591 | // qDebug(fileDlg->LineEdit1->text()); |
595 | QStringList command; | 592 | QStringList command; |
596 | 593 | ||
597 | command << "/bin/sh"; | 594 | command << "/bin/sh"; |
598 | command << "-c"; | 595 | command << "-c"; |
@@ -632,219 +629,219 @@ void AdvancedFm::fileStatus() { | |||
632 | QStringList command; | 629 | QStringList command; |
633 | command << "/bin/sh"; | 630 | command << "/bin/sh"; |
634 | command << "-c"; | 631 | command << "-c"; |
635 | command << "stat -l "+ curFile; | 632 | command << "stat -l "+ curFile; |
636 | 633 | ||
637 | Output *outDlg; | 634 | Output *outDlg; |
638 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 635 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
639 | QPEApplication::execDialog( outDlg ); | 636 | QPEApplication::execDialog( outDlg ); |
640 | qApp->processEvents(); | 637 | qApp->processEvents(); |
641 | } | 638 | } |
642 | 639 | ||
643 | 640 | ||
644 | void AdvancedFm::mkDir() { | 641 | void AdvancedFm::mkDir() { |
645 | makeDir(); | 642 | makeDir(); |
646 | } | 643 | } |
647 | 644 | ||
648 | void AdvancedFm::rn() { | 645 | void AdvancedFm::rn() { |
649 | renameIt(); | 646 | renameIt(); |
650 | } | 647 | } |
651 | 648 | ||
652 | void AdvancedFm::del() { | 649 | void AdvancedFm::del() { |
653 | doDelete(); | 650 | doDelete(); |
654 | } | 651 | } |
655 | 652 | ||
656 | void AdvancedFm::mkSym() { | 653 | void AdvancedFm::mkSym() { |
657 | QString cmd; | 654 | QString cmd; |
658 | QStringList curFileList = getPath(); | 655 | QStringList curFileList = getPath(); |
659 | if( curFileList.count() > 0) { | 656 | if( curFileList.count() > 0) { |
660 | QDir *thisDir = CurrentDir(); | 657 | QDir *thisDir = CurrentDir(); |
661 | QDir * thatDir = OtherDir(); | 658 | QDir * thatDir = OtherDir(); |
662 | 659 | ||
663 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 660 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
664 | 661 | ||
665 | QString destName = thatDir->canonicalPath()+"/"+(*it); | 662 | QString destName = thatDir->canonicalPath()+"/"+(*it); |
666 | if(destName.right(1) == "/") { | 663 | if(destName.right(1) == "/") { |
667 | destName = destName.left( destName.length() -1); | 664 | destName = destName.left( destName.length() -1); |
668 | } | 665 | } |
669 | 666 | ||
670 | QString curFile = thisDir->canonicalPath()+"/"+(*it); | 667 | QString curFile = thisDir->canonicalPath()+"/"+(*it); |
671 | 668 | ||
672 | if( curFile.right(1) == "/") { | 669 | if( curFile.right(1) == "/") { |
673 | curFile = curFile.left( curFile.length() -1); | 670 | curFile = curFile.left( curFile.length() -1); |
674 | } | 671 | } |
675 | 672 | ||
676 | cmd = "ln -s "+curFile+" "+destName; | 673 | cmd = "ln -s "+curFile+" "+destName; |
677 | // qDebug(cmd); | 674 | // qDebug(cmd); |
678 | startProcess( (const QString)cmd ); | 675 | startProcess( (const QString)cmd ); |
679 | } | 676 | } |
680 | rePopulate(); | 677 | rePopulate(); |
681 | setOtherTabCurrent(); | 678 | setOtherTabCurrent(); |
682 | } | 679 | } |
683 | } | 680 | } |
684 | 681 | ||
685 | void AdvancedFm::doBeam() { | 682 | void AdvancedFm::doBeam() { |
686 | Ir ir; | 683 | Ir ir; |
687 | if(!ir.supported()) { | 684 | if(!ir.supported()) { |
688 | } else { | 685 | } else { |
689 | QStringList curFileList = getPath(); | 686 | QStringList curFileList = getPath(); |
690 | if( curFileList.count() > 0) { | 687 | if( curFileList.count() > 0) { |
691 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 688 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
692 | QString curFile = (*it); | 689 | QString curFile = (*it); |
693 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; | 690 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; |
694 | if( curFilePath.right(1) == "/") { | 691 | if( curFilePath.right(1) == "/") { |
695 | curFilePath = curFilePath.left( curFilePath.length() -1); | 692 | curFilePath = curFilePath.left( curFilePath.length() -1); |
696 | } | 693 | } |
697 | Ir *file = new Ir(this, "IR"); | 694 | Ir *file = new Ir(this, "IR"); |
698 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); | 695 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); |
699 | file->send( curFilePath, curFile ); | 696 | file->send( curFilePath, curFile ); |
700 | } | 697 | } |
701 | } | 698 | } |
702 | } | 699 | } |
703 | } | 700 | } |
704 | 701 | ||
705 | void AdvancedFm::fileBeamFinished( Ir *) { | 702 | void AdvancedFm::fileBeamFinished( Ir *) { |
706 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); | 703 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); |
707 | } | 704 | } |
708 | 705 | ||
709 | void AdvancedFm::selectAll() { | 706 | void AdvancedFm::selectAll() { |
710 | QListView *thisView = CurrentView(); | 707 | QListView *thisView = CurrentView(); |
711 | thisView->selectAll(true); | 708 | thisView->selectAll(true); |
712 | thisView->setSelected( thisView->firstChild(),false); | 709 | thisView->setSelected( thisView->firstChild(),false); |
713 | } | 710 | } |
714 | 711 | ||
715 | void AdvancedFm::startProcess(const QString & cmd) { | 712 | void AdvancedFm::startProcess(const QString & cmd) { |
716 | QStringList command; | 713 | QStringList command; |
717 | OProcess *process; | 714 | OProcess *process; |
718 | process = new OProcess(); | 715 | process = new OProcess(); |
719 | connect(process, SIGNAL(processExited(OProcess *)), | 716 | connect(process, SIGNAL(processExited(OProcess *)), |
720 | this, SLOT( processEnded(OProcess *))); | 717 | this, SLOT( processEnded(OProcess *))); |
721 | 718 | ||
722 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), | 719 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), |
723 | this, SLOT( oprocessStderr(OProcess *, char *, int))); | 720 | this, SLOT( oprocessStderr(OProcess *, char *, int))); |
724 | 721 | ||
725 | command << "/bin/sh"; | 722 | command << "/bin/sh"; |
726 | command << "-c"; | 723 | command << "-c"; |
727 | command << cmd.latin1(); | 724 | command << cmd.latin1(); |
728 | *process << command; | 725 | *process << command; |
729 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) | 726 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) |
730 | qDebug("could not start process"); | 727 | qDebug("could not start process"); |
731 | } | 728 | } |
732 | 729 | ||
733 | void AdvancedFm::processEnded(OProcess *) { | 730 | void AdvancedFm::processEnded(OProcess *) { |
734 | rePopulate(); | 731 | rePopulate(); |
735 | } | 732 | } |
736 | 733 | ||
737 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { | 734 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { |
738 | // qWarning("received stderrt %d bytes", buflen); | 735 | // qWarning("received stderrt %d bytes", buflen); |
739 | 736 | ||
740 | QString lineStr = buffer; | 737 | QString lineStr = buffer; |
741 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); | 738 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); |
742 | } | 739 | } |
743 | 740 | ||
744 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | 741 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { |
745 | if ( o->inherits( "QLineEdit" ) ) { | 742 | if ( o->inherits( "QLineEdit" ) ) { |
746 | if ( e->type() == QEvent::KeyPress ) { | 743 | if ( e->type() == QEvent::KeyPress ) { |
747 | QKeyEvent *ke = (QKeyEvent*)e; | 744 | QKeyEvent *ke = (QKeyEvent*)e; |
748 | if ( ke->key() == Key_Return || | 745 | if ( ke->key() == Key_Return || |
749 | ke->key() == Key_Enter ) { | 746 | ke->key() == Key_Enter ) { |
750 | okRename(); | 747 | okRename(); |
751 | return true; | 748 | return true; |
752 | } | 749 | } |
753 | else if ( ke->key() == Key_Escape ) { | 750 | else if ( ke->key() == Key_Escape ) { |
754 | cancelRename(); | 751 | cancelRename(); |
755 | return true; | 752 | return true; |
756 | } | 753 | } |
757 | } | 754 | } |
758 | else if ( e->type() == QEvent::FocusOut ) { | 755 | else if ( e->type() == QEvent::FocusOut ) { |
759 | cancelRename(); | 756 | cancelRename(); |
760 | return true; | 757 | return true; |
761 | } | 758 | } |
762 | } | 759 | } |
763 | if ( o->inherits( "QListView" ) ) { | 760 | if ( o->inherits( "QListView" ) ) { |
764 | if ( e->type() == QEvent::FocusIn ) { | 761 | if ( e->type() == QEvent::FocusIn ) { |
765 | if( o == Local_View) { //keep track of which view | 762 | if( o == Local_View) { //keep track of which view |
766 | whichTab=1; | 763 | whichTab=1; |
767 | } | 764 | } |
768 | else { | 765 | else { |
769 | whichTab=2; | 766 | whichTab=2; |
770 | } | 767 | } |
771 | } | 768 | } |
772 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection | 769 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection |
773 | } | 770 | } |
774 | 771 | ||
775 | return QWidget::eventFilter( o, e ); | 772 | return QWidget::eventFilter( o, e ); |
776 | } | 773 | } |
777 | 774 | ||
778 | 775 | ||
779 | void AdvancedFm::cancelRename() { | 776 | void AdvancedFm::cancelRename() { |
780 | // qDebug("cancel rename"); | 777 | // qDebug("cancel rename"); |
781 | QListView * view; | 778 | QListView * view; |
782 | view = CurrentView(); | 779 | view = CurrentView(); |
783 | 780 | ||
784 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | 781 | bool resetFocus = view->viewport()->focusProxy() == renameBox; |
785 | delete renameBox; | 782 | delete renameBox; |
786 | renameBox = 0; | 783 | renameBox = 0; |
787 | if ( resetFocus ) { | 784 | if ( resetFocus ) { |
788 | view->viewport()->setFocusProxy( view); | 785 | view->viewport()->setFocusProxy( view); |
789 | view->setFocus(); | 786 | view->setFocus(); |
790 | } | 787 | } |
791 | } | 788 | } |
792 | 789 | ||
793 | void AdvancedFm::doRename(QListView * view) { | 790 | void AdvancedFm::doRename(QListView * view) { |
794 | if( !CurrentView()->currentItem()) return; | 791 | if( !CurrentView()->currentItem()) return; |
795 | 792 | ||
796 | QRect r = view->itemRect( view->currentItem( )); | 793 | QRect r = view->itemRect( view->currentItem( )); |
797 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | 794 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); |
798 | r.setX( view->contentsX() ); | 795 | r.setX( view->contentsX() ); |
799 | 796 | ||
800 | if ( r.width() > view->visibleWidth() ) | 797 | if ( r.width() > view->visibleWidth() ) |
801 | r.setWidth( view->visibleWidth() ); | 798 | r.setWidth( view->visibleWidth() ); |
802 | 799 | ||
803 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | 800 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); |
804 | renameBox->setFrame(true); | 801 | renameBox->setFrame(true); |
805 | 802 | ||
806 | renameBox->setText( view->currentItem()->text(0) ); | 803 | renameBox->setText( view->currentItem()->text(0) ); |
807 | 804 | ||
808 | renameBox->selectAll(); | 805 | renameBox->selectAll(); |
809 | renameBox->installEventFilter( this ); | 806 | renameBox->installEventFilter( this ); |
810 | 807 | ||
811 | view->addChild( renameBox, r.x(), r.y() ); | 808 | view->addChild( renameBox, r.x(), r.y() ); |
812 | 809 | ||
813 | renameBox->resize( r.size() ); | 810 | renameBox->resize( r.size() ); |
814 | 811 | ||
815 | view->viewport()->setFocusProxy( renameBox ); | 812 | view->viewport()->setFocusProxy( renameBox ); |
816 | 813 | ||
817 | renameBox->setFocus(); | 814 | renameBox->setFocus(); |
818 | renameBox->show(); | 815 | renameBox->show(); |
819 | } | 816 | } |
820 | 817 | ||
821 | 818 | ||
822 | void AdvancedFm::renameIt() { | 819 | void AdvancedFm::renameIt() { |
823 | if( !CurrentView()->currentItem()) return; | 820 | if( !CurrentView()->currentItem()) return; |
824 | 821 | ||
825 | QListView *thisView = CurrentView(); | 822 | QListView *thisView = CurrentView(); |
826 | oldName = thisView->currentItem()->text(0); | 823 | oldName = thisView->currentItem()->text(0); |
827 | doRename( thisView ); | 824 | doRename( thisView ); |
828 | } | 825 | } |
829 | 826 | ||
830 | void AdvancedFm::okRename() { | 827 | void AdvancedFm::okRename() { |
831 | if( !CurrentView()->currentItem()) return; | 828 | if( !CurrentView()->currentItem()) return; |
832 | 829 | ||
833 | QString newName = renameBox->text(); | 830 | QString newName = renameBox->text(); |
834 | cancelRename(); | 831 | cancelRename(); |
835 | QListView * view = CurrentView(); | 832 | QListView * view = CurrentView(); |
836 | QString path = CurrentDir()->canonicalPath() + "/"; | 833 | QString path = CurrentDir()->canonicalPath() + "/"; |
837 | oldName = path + oldName; | 834 | oldName = path + oldName; |
838 | newName = path + newName; | 835 | newName = path + newName; |
839 | if( rename( oldName.latin1(), newName.latin1())== -1) | 836 | if( rename( oldName.latin1(), newName.latin1())== -1) |
840 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 837 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
841 | else | 838 | else |
842 | oldName = ""; | 839 | oldName = ""; |
843 | view->takeItem( view->currentItem() ); | 840 | view->takeItem( view->currentItem() ); |
844 | delete view->currentItem(); | 841 | delete view->currentItem(); |
845 | rePopulate(); | 842 | rePopulate(); |
846 | } | 843 | } |
847 | 844 | ||
848 | void AdvancedFm::openSearch() { | 845 | void AdvancedFm::openSearch() { |
849 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); | 846 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); |
850 | } | 847 | } |