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