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