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.cpp940
1 files changed, 940 insertions, 0 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
new file mode 100644
index 0000000..7ee5065
--- a/dev/null
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -0,0 +1,940 @@
1/***************************************************************************
2 AdvancedFm.cpp
3 -------------------
4 ** Created: Sat Mar 9 23:33:09 2002
5 copyright : (C) 2002 by ljp
6 email : ljp@llornkcor.com
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 *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 ***************************************************************************/
12#include "advancedfm.h"
13#include "inputDialog.h"
14#include "output.h"
15#include "filePermissions.h"
16
17#include <qpe/lnkproperties.h>
18#include <qpe/qpeapplication.h>
19#include <qpe/qpemenubar.h>
20#include <qpe/qpetoolbar.h>
21#include <qpe/resource.h>
22#include <qpe/qcopenvelope_qws.h>
23#include <qpe/applnk.h>
24#include <qpe/ir.h>
25
26#include <qmessagebox.h>
27#include <qmultilineedit.h>
28
29#include <qstring.h>
30
31#include <qlayout.h>
32#include <qpixmap.h>
33#include <qcombobox.h>
34#include <qpopupmenu.h>
35#include <qtabwidget.h>
36#include <qtoolbutton.h>
37#include <qtabwidget.h>
38#include <qlineedit.h>
39#include <qlistview.h>
40
41#include <stdlib.h>
42#include <unistd.h>
43#include <sys/stat.h>
44#include <dirent.h>
45
46
47void AdvancedFm::doLocalCd() {
48 localListClicked( Local_View->currentItem());
49}
50
51void AdvancedFm::doRemoteCd() {
52 localListClicked( Remote_View->currentItem());
53}
54
55void AdvancedFm::showMenuHidden() {
56 showHidden();
57 if(b) b= false; else b=true;
58 showRemoteHidden();
59}
60
61void AdvancedFm::showHidden() {
62 if (b) {
63 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
64 fileMenu->setItemChecked( fileMenu->idAt(0),TRUE);
65 b=FALSE;
66
67 } else {
68 currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
69 fileMenu->setItemChecked( fileMenu->idAt(0),FALSE);
70 b=TRUE;
71 }
72 populateLocalView();
73
74}
75
76void AdvancedFm::showRemoteHidden() {
77 if (b) {
78 currentRemoteDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All);
79 b=TRUE;
80
81 } else {
82 currentRemoteDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All);
83 b=FALSE;
84 }
85 populateRemoteView();
86}
87
88void AdvancedFm::runThis() {
89 QString fs;
90 if (TabWidget->currentPageIndex() == 0) {
91 QString curFile = Local_View->currentItem()->text(0);
92 if(curFile != "../") {
93
94 fs= getFileSystemType((const QString &) currentDir.canonicalPath());
95 QFileInfo fileInfo( currentDir.canonicalPath()+"/"+curFile);
96 qDebug( fileInfo.owner());
97 if( (fileInfo.permission( QFileInfo::ExeUser)
98 | fileInfo.permission( QFileInfo::ExeGroup)
99 | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) {
100 | fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
101 QCopEnvelope e("QPE/System", "execute(QString)" );
102 e << curFile;
103 } else {
104 curFile = currentDir.canonicalPath()+"/"+curFile;
105 DocLnk nf(curFile);
106 QString execStr = nf.exec();
107 qDebug( execStr);
108 if( execStr.isEmpty() ) {
109 } else {
110 nf.execute();
111 }
112 }
113 }
114 } else {
115 QString curFile = Remote_View->currentItem()->text(0);
116 if(curFile != "../") {
117
118 fs= getFileSystemType((const QString &) currentRemoteDir.canonicalPath());
119 qDebug("Filesystemtype is "+fs);
120 QFileInfo fileInfo( currentRemoteDir.canonicalPath()+"/"+curFile);
121 if( (fileInfo.permission( QFileInfo::ExeUser)
122 | fileInfo.permission( QFileInfo::ExeGroup)
123 | fileInfo.permission( QFileInfo::ExeOther)) // & fs.find("vfat",0,TRUE) == -1) {
124 | fs == "vfat" && fileInfo.filePath().contains("/bin") ) {
125 QCopEnvelope e("QPE/System", "execute(QString)" );
126 e << curFile;
127 } else {
128 curFile = currentRemoteDir.canonicalPath()+"/"+curFile;
129 DocLnk nf(curFile);
130 QString execStr = nf.exec();
131 qDebug(execStr);
132 if( execStr.isEmpty() ) {
133 } else {
134 nf.execute();
135 }
136 }
137 }
138 }
139}
140
141void AdvancedFm::runText() {
142 if (TabWidget->currentPageIndex() == 0) {
143 QString curFile = Local_View->currentItem()->text(0);
144 if(curFile != "../") {
145 curFile = currentDir.canonicalPath()+"/"+curFile;
146 QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" );
147 e << curFile;
148 }
149 } else {
150 QString curFile = Remote_View->currentItem()->text(0);
151 if(curFile != "../") {
152 curFile = currentRemoteDir.canonicalPath()+"/"+curFile;
153 DocLnk nf(curFile);
154 QCopEnvelope e("QPE/Application/textedit", "setDocument(QString)" );
155 e << curFile;
156 }
157 }
158}
159
160void AdvancedFm::localMakDir() {
161 InputDialog *fileDlg;
162 fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
163 fileDlg->exec();
164 if( fileDlg->result() == 1 ) {
165 QString filename = fileDlg->LineEdit1->text();
166 currentDir.mkdir( currentDir.canonicalPath()+"/"+filename);
167 }
168 populateLocalView();
169}
170
171void AdvancedFm::remoteMakDir() {
172 InputDialog *fileDlg;
173 fileDlg = new InputDialog(this,tr("Make Directory"),TRUE, 0);
174 fileDlg->exec();
175 if( fileDlg->result() == 1 ) {
176 QString filename = fileDlg->LineEdit1->text();
177 currentRemoteDir.mkdir( currentRemoteDir.canonicalPath()+"/"+filename);
178 }
179 populateRemoteView();
180}
181
182void AdvancedFm::localDelete() {
183 QStringList curFileList = getPath();
184 if(curFileList.count() > 0) {
185 QString myFile;
186 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
187 myFile = (*it);
188 if( myFile.find(" -> ",0,TRUE) != -1)
189 myFile = myFile.left( myFile.find(" -> ",0,TRUE));
190
191 QString f = currentDir.canonicalPath();
192 if(f.right(1).find("/",0,TRUE) == -1)
193 f+="/";
194 f+=myFile;
195 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
196 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+
197 "\nand all it's contents ?"
198 ,tr("Yes"),tr("No"),0,0,1) ) {
199 case 0: {
200 f=f.left(f.length()-1);
201 QString cmd="rm -rf "+f;
202 system( cmd.latin1());
203 populateLocalView();
204 }
205 break;
206 case 1:
207 // exit
208 break;
209 };
210
211 } else {
212 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f
213 +" ?",tr("Yes"),tr("No"),0,0,1) ) {
214 case 0: {
215 QString cmd="rm "+f;
216 QFile file(f);
217 file.remove();
218 // system( cmd.latin1());
219 populateLocalView();
220 }
221 break;
222 case 1:
223 // exit
224 break;
225 };
226 }
227 }
228 }
229}
230
231void AdvancedFm::remoteDelete() {
232 QStringList curFileList = getPath();
233 if( curFileList.count() > 0) {
234 QString myFile;
235
236 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
237 myFile = (*it);
238 if(myFile.find(" -> ",0,TRUE) != -1)
239 myFile = myFile.left(myFile.find(" -> ",0,TRUE));
240 QString f = currentRemoteDir.canonicalPath();
241 if(f.right(1).find("/",0,TRUE) == -1)
242 f+="/";
243 f+=myFile;
244 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
245 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f+
246 "\nand all it's contents ?",
247 tr("Yes"),tr("No"),0,0,1) ) {
248 case 0: {
249 f=f.left(f.length()-1);
250 QString cmd="rm -rf "+f;
251 system( cmd.latin1());
252 populateRemoteView();
253 }
254 break;
255 case 1:
256 // exit
257 break;
258 };
259
260 } else {
261 switch ( QMessageBox::warning(this,tr("Delete"),tr("Do you really want to delete\n")+f
262 +" ?",tr("Yes"),tr("No"),0,0,1) ) {
263 case 0: {
264 QString cmd="rm "+f;
265 QFile file(f);
266 file.remove();
267 // system( cmd.latin1());
268 populateRemoteView();
269 }
270 break;
271 case 1:
272 // exit
273 break;
274 };
275 }
276 }
277 }
278}
279
280void AdvancedFm::localRename() {
281 QString curFile = Local_View->currentItem()->text(0);
282 qDebug("currentItem "+curFile);
283 if( curFile !="../") {
284 InputDialog *fileDlg;
285 fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0);
286 fileDlg->setInputText((const QString &)curFile);
287 fileDlg->exec();
288 if( fileDlg->result() == 1 ) {
289 QString oldname = currentDir.canonicalPath() + "/" + curFile;
290 QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();
291//+".playlist";
292 if( rename(oldname.latin1(), newName.latin1())== -1)
293 QMessageBox::message(tr("Note"),tr("Could not rename"));
294 }
295 populateLocalView();
296 }
297}
298
299void AdvancedFm::remoteRename()
300{
301 QString curFile = Remote_View->currentItem()->text(0);
302 if( curFile !="../") {
303 InputDialog *fileDlg;
304 fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0);
305 fileDlg->setInputText((const QString &)curFile);
306 fileDlg->exec();
307 if( fileDlg->result() == 1 ) {
308 QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile;
309 QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text();
310//+".playlist";
311 if( rename(oldname.latin1(), newName.latin1())== -1)
312 QMessageBox::message(tr("Note"),tr("Could not rename"));
313 }
314 populateRemoteView();
315 }
316}
317
318
319void AdvancedFm::filePerms() {
320
321 QStringList curFileList = getPath();
322 QString filePath;
323
324 if (TabWidget->currentPageIndex() == 0) {
325 filePath = currentDir.canonicalPath()+"/";
326 } else {
327 filePath= currentRemoteDir.canonicalPath()+"/";
328 }
329
330 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
331 filePermissions *filePerm;
332 filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)(filePath+*it));
333 filePerm->showMaximized();
334 filePerm->exec();
335 if( filePerm)
336 delete filePerm;
337 }
338 if (TabWidget->currentPageIndex() == 0) {
339 populateLocalView();
340 } else {
341 populateRemoteView();
342 }
343}
344
345void AdvancedFm::doProperties() {
346 QStringList curFileList = getPath();
347 QString filePath;
348 if (TabWidget->currentPageIndex() == 0) {
349 filePath = currentDir.canonicalPath()+"/";
350 } else {
351 filePath= currentRemoteDir.canonicalPath()+"/";
352 }
353 // qDebug("%d",curFileList.count());
354 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
355 qDebug((filePath+*it));
356 DocLnk lnk( (filePath+*it));
357 LnkProperties prop( &lnk );
358 prop.showMaximized();
359 prop.exec();
360 }
361}
362
363void AdvancedFm::upDir() {
364 if (TabWidget->currentPageIndex() == 0) {
365 QString current = currentDir.canonicalPath();
366 QDir dir(current);
367 dir.cdUp();
368 current = dir.canonicalPath();
369 chdir( current.latin1() );
370 currentDir.cd( current, TRUE);
371 populateLocalView();
372 update();
373 } else {
374 QString current = currentRemoteDir.canonicalPath();
375 QDir dir(current);
376 dir.cdUp();
377 current = dir.canonicalPath();
378 chdir( current.latin1() );
379 currentRemoteDir.cd( current, TRUE);
380 populateRemoteView();
381 update();
382 }
383}
384
385void AdvancedFm::copy() {
386 qApp->processEvents();
387 QStringList curFileList = getPath();
388 if( curFileList.count() > 0) {
389 QString curFile, item, destFile;
390 if (TabWidget->currentPageIndex() == 0) {
391 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
392 item=(*it);
393
394 if(item.find("->",0,TRUE)) //symlink
395 item = item.left(item.find("->",0,TRUE));
396
397 destFile = currentRemoteDir.canonicalPath()+"/"+ item;
398 qDebug("Destination file is "+destFile);
399
400 curFile = currentDir.canonicalPath()+"/"+ item;
401 qDebug("CurrentFile file is " + curFile);
402
403 QFile f(destFile);
404 if( f.exists()) {
405 switch ( QMessageBox::warning(this,tr("Delete"),
406 destFile+tr(" already exists\nDo you really want to delete it?"),
407 tr("Yes"),tr("No"),0,0,1) ) {
408 case 0:
409 f.remove();
410 break;
411 case 1:
412 return;
413 break;
414 };
415 }
416 if(!copyFile(destFile, curFile) ) {
417 QMessageBox::message("AdvancedFm","Could not copy\n"+curFile +"to\n"+destFile);
418 return;
419 }
420 }
421 populateRemoteView();
422 TabWidget->setCurrentPage(1);
423
424 } else {
425 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
426 item= (*it);
427
428 if(item.find("->",0,TRUE)) //symlink
429 item = item.left(item.find("->",0,TRUE));
430
431 destFile = currentDir.canonicalPath()+"/"+ item;
432 qDebug("Destination file is "+destFile);
433
434 curFile = currentRemoteDir.canonicalPath()+"/"+ item;;
435 qDebug("CurrentFile file is " + curFile);
436
437 QFile f(destFile);
438 if( f.exists()) {
439 switch ( QMessageBox::warning(this,tr("Delete"),
440 destFile+tr(" already exists\nDo you really want to delete it?"),
441 tr("Yes"),tr("No"),0,0,1) ) {
442 case 0:
443 f.remove();
444 break;
445 case 1:
446 return;
447 break;
448 };
449 }
450 if(!copyFile(destFile, curFile) ) {
451 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
452 +curFile +tr("to\n")+destFile);
453 return;
454
455 }
456 }
457 populateLocalView();
458 TabWidget->setCurrentPage(0);
459 }
460
461 }
462}
463
464void AdvancedFm::copyAs() {
465 qApp->processEvents();
466
467 QStringList curFileList = getPath();
468 QString curFile;
469 InputDialog *fileDlg;
470 if (TabWidget->currentPageIndex() == 0) {
471 qDebug("tab 1");
472 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
473 QString destFile;
474 curFile = currentDir.canonicalPath()+"/"+(*it);
475 fileDlg = new InputDialog( this,tr("Copy "+curFile+" As"), TRUE, 0);
476
477 fileDlg->setInputText((const QString &) destFile );
478 fileDlg->exec();
479
480 if( fileDlg->result() == 1 ) {
481 QString filename = fileDlg->LineEdit1->text();
482 destFile = currentRemoteDir.canonicalPath()+"/"+filename;
483
484 QFile f(destFile);
485 if( f.exists()) {
486 switch (QMessageBox::warning(this,tr("Delete"),
487 destFile+tr(" already exists\nDo you really want to delete it?"),
488 tr("Yes"),tr("No"),0,0,1) ) {
489 case 0:
490 f.remove();
491 break;
492 case 1:
493 return;
494 break;
495 };
496 }
497 if(!copyFile(destFile, curFile) ) {
498 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
499 +curFile +tr("to\n")+destFile);
500 return;
501 }
502 }
503 delete fileDlg;
504
505 }
506 populateRemoteView();
507 TabWidget->setCurrentPage(1);
508
509 } else {
510 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
511
512 curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
513 fileDlg = new InputDialog( this,tr("Copy "+curFile+" As"), TRUE, 0);
514
515 QString destFile;
516 fileDlg->setInputText((const QString &) destFile);
517 fileDlg->exec();
518
519 if( fileDlg->result() == 1 ) {
520 QString filename = fileDlg->LineEdit1->text();
521 destFile = currentDir.canonicalPath()+"/"+filename;
522
523 QFile f( destFile);
524 if( f.exists()) {
525 switch ( QMessageBox::warning(this,tr("Delete"),
526 destFile+tr(" already exists\nDo you really want to delete it?"),
527 tr("Yes"),tr("No"),0,0,1) ) {
528 case 0:
529 f.remove();
530 break;
531 case 1:
532 return;
533 break;
534 };
535 }
536 if(!copyFile(destFile, curFile) ) {
537 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
538 +curFile +tr("to\n")+destFile);
539 return;
540 }
541
542 }
543 delete fileDlg;
544
545 }
546 populateLocalView();
547 TabWidget->setCurrentPage(0);
548 }
549}
550
551void AdvancedFm::copySameDir() {
552 qApp->processEvents();
553 QStringList curFileList = getPath();
554 QString curFile, item, destFile;
555 InputDialog *fileDlg;
556
557 if (TabWidget->currentPageIndex() == 0) {
558
559 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
560 item=(*it);
561 curFile = currentDir.canonicalPath()+"/"+ item;
562
563 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
564 fileDlg->setInputText((const QString &) destFile );
565 fileDlg->exec();
566
567 if( fileDlg->result() == 1 ) {
568
569 QString filename = fileDlg->LineEdit1->text();
570 destFile = currentDir.canonicalPath()+"/"+filename;
571
572 QFile f(destFile);
573 if( f.exists()) {
574 switch (QMessageBox::warning(this,tr("Delete"),
575 destFile+tr(" already exists\nDo you really want to delete it?"),
576 tr("Yes"),tr("No"),0,0,1) ) {
577 case 0:
578
579 f.remove();
580 break;
581 case 1:
582 return;
583 break;
584 };
585 }
586 if(!copyFile(destFile, curFile) ) {
587 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
588 +curFile +tr("to\n")+destFile);
589 return;
590 }
591
592 qDebug("copy "+curFile+" as "+destFile);
593 }
594 delete fileDlg;
595 }
596 populateLocalView();
597
598 } else {
599 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
600 item=(*it);
601 curFile = currentRemoteDir.canonicalPath()+"/"+ item;
602
603 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
604 fileDlg->setInputText((const QString &) destFile);
605 fileDlg->exec();
606 if( fileDlg->result() == 1 ) {
607 QString filename = fileDlg->LineEdit1->text();
608
609 destFile = currentRemoteDir.canonicalPath()+"/"+filename;
610
611 QFile f(destFile);
612 if( f.exists()) {
613 switch ( QMessageBox::warning(this,tr("Delete"),
614 destFile+tr(" already exists\nDo you really want to delete it?"),
615 tr("Yes"),tr("No"),0,0,1) ) {
616 case 0:
617 f.remove();
618 break;
619 case 1:
620 return;
621 break;
622 };
623 }
624 if(!copyFile(destFile, curFile) ) {
625 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
626 +curFile +tr("to\n")+destFile);
627 return;
628 }
629 qDebug("copy "+curFile+" as "+destFile);
630 }
631 delete fileDlg;
632 }
633 populateRemoteView();
634 }
635}
636
637void AdvancedFm::move() {
638 qApp->processEvents();
639
640 QStringList curFileList = getPath();
641 if( curFileList.count() > 0) {
642 QString curFile, destFile, item;
643
644 if (TabWidget->currentPageIndex() == 0) {
645
646 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
647 item=(*it);
648 QString destFile = currentRemoteDir.canonicalPath();
649
650 if(destFile.right(1).find("/",0,TRUE) == -1)
651 destFile+="/";
652 destFile += item;
653 curFile = currentDir.canonicalPath();
654
655 qDebug("Destination file is "+destFile);
656
657 if(curFile.right(1).find("/",0,TRUE) == -1)
658 curFile +="/";
659
660 curFile+= item;
661 qDebug("CurrentFile file is " + curFile);
662
663 QFile f( curFile);
664 if( f.exists()) {
665 if(!copyFile( destFile, curFile) ) {
666 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
667 return;
668 } else
669 QFile::remove(curFile);
670 }
671 }
672
673 TabWidget->setCurrentPage(1);
674
675 } else { //view 2
676
677 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
678 item = (*it);
679 QString destFile = currentDir.canonicalPath();
680
681 if(destFile.right(1).find("/",0,TRUE) == -1)
682 destFile+="/";
683
684 destFile += item;
685
686 qDebug("Destination file is "+destFile);
687
688 curFile = currentRemoteDir.canonicalPath();
689
690 if(curFile.right(1).find("/",0,TRUE) == -1)
691 curFile +="/";
692 curFile+= item;
693 qDebug("CurrentFile file is " + curFile);
694
695 QFile f( curFile);
696 if( f.exists()) {
697 if(!copyFile( destFile, curFile) ) {
698 QMessageBox::message(tr("Note"),tr("Could not move\n") + curFile);
699 return;
700 } else
701 QFile::remove( curFile);
702 }
703 TabWidget->setCurrentPage(0);
704 }
705 }
706 populateRemoteView();
707 populateLocalView();
708 }
709}
710
711bool AdvancedFm::copyFile( const QString & dest, const QString & src ) {
712 char bf[ 50000 ];
713 int bytesRead;
714 bool success = TRUE;
715 struct stat status;
716
717 QFile s( src );
718 QFile d( dest );
719
720 if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) ) {
721 while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) ) {
722 if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
723 success = FALSE;
724 break;
725 }
726 }
727 if( success && (bytesRead > 0) ){
728 d.writeBlock( bf, bytesRead );
729 }
730 } else {
731 success = FALSE;
732 }
733
734 // Set file permissions
735 if( stat( (const char *) src, &status ) == 0 ){
736 chmod( (const char *) dest, status.st_mode );
737 }
738
739 return success;
740}
741
742void AdvancedFm::runCommand() {
743 QString curFile;
744 if (TabWidget->currentPageIndex() == 0) {
745 if( Local_View->currentItem())
746 curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0);
747 } else {
748 if(Remote_View->currentItem())
749 curFile = currentRemoteDir.canonicalPath() + "/"+Remote_View->currentItem()->text(0);
750 }
751
752 InputDialog *fileDlg;
753 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
754 fileDlg->setInputText(curFile);
755 fileDlg->exec();
756 QString command;
757 if( fileDlg->result() == 1 ) {
758 command = fileDlg->LineEdit1->text();
759
760 Output *outDlg;
761 outDlg = new Output(this, tr("AdvancedFm Output"),FALSE);
762 outDlg->showMaximized();
763 outDlg->show();
764 qApp->processEvents();
765 FILE *fp;
766 char line[130];
767 sleep(1);
768 command +=" 2>&1";
769 fp = popen( (const char *) command, "r");
770 if ( !fp ) {
771 qDebug("Could not execute '" + command + "'! err=%d", fp);
772 QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") );
773 pclose(fp);
774 return;
775 } else {
776 while ( fgets( line, sizeof line, fp)) {
777 QString lineStr = line;
778 lineStr=lineStr.left(lineStr.length()-1);
779 outDlg->OutputEdit->append(lineStr);
780 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
781 }
782 }
783 pclose(fp);
784
785 }
786}
787
788void AdvancedFm::runCommandStd() {
789 QString curFile;
790 if (TabWidget->currentPageIndex() == 0) {
791 if( Local_View->currentItem())
792 curFile = currentDir.canonicalPath() +"/"+ Local_View->currentItem()->text(0);
793 } else {
794 if(Remote_View->currentItem())
795 curFile = currentRemoteDir.canonicalPath() +"/"
796 + Remote_View->currentItem()->text(0);
797 }
798
799 InputDialog *fileDlg;
800 fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0);
801 fileDlg->setInputText(curFile);
802 fileDlg->exec();
803 QString command;
804 if( fileDlg->result() == 1 ) {
805 qApp->processEvents();
806 command = fileDlg->LineEdit1->text() + " &";
807 system(command.latin1());
808 }
809}
810
811void AdvancedFm::fileStatus() {
812 QString curFile;
813 if (TabWidget->currentPageIndex() == 0) {
814 curFile = Local_View->currentItem()->text(0);
815 } else {
816 curFile = Remote_View->currentItem()->text(0);
817 }
818 QString command = " stat -l "+ curFile +" 2>&1";
819 Output *outDlg;
820 outDlg = new Output(this, tr("AdvancedFm Output"),FALSE);
821 outDlg->showMaximized();
822 outDlg->show();
823 qApp->processEvents();
824 FILE *fp;
825 char line[130];
826 sleep(1);
827 fp = popen( (const char *) command, "r");
828 if ( !fp ) {
829 qDebug("Could not execute '" + command + "'! err=%d", fp);
830 QMessageBox::warning( this, "AdvancedFm", tr("command failed!"), tr("&OK") );
831 pclose(fp);
832 return;
833 } else {
834 while ( fgets( line, sizeof line, fp)) {
835 outDlg->OutputEdit->append(line);
836 outDlg->OutputEdit->setCursorPosition(outDlg->OutputEdit->numLines() + 1,0,FALSE);
837
838 }
839
840 }
841 pclose(fp);
842}
843
844void AdvancedFm::mkDir() {
845 if (TabWidget->currentPageIndex() == 0)
846 localMakDir();
847 else
848 remoteMakDir();
849
850}
851
852void AdvancedFm::rn() {
853 if (TabWidget->currentPageIndex() == 0)
854 localRename();
855 else
856 remoteRename();
857
858}
859
860void AdvancedFm::del() {
861 if (TabWidget->currentPageIndex() == 0)
862 localDelete();
863 else
864 remoteDelete();
865}
866
867void AdvancedFm::mkSym() {
868 QString cmd;
869 QStringList curFileList = getPath();
870 if( curFileList.count() > 0) {
871
872 if (TabWidget->currentPageIndex() == 0) {
873 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
874
875 QString destName = currentRemoteDir.canonicalPath()+"/"+(*it);
876 if(destName.right(1) == "/") destName = destName.left( destName.length() -1);
877 QString curFile = currentDir.canonicalPath()+"/"+(*it);
878 if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1);
879 cmd = "ln -s "+curFile+" "+destName;
880 qDebug(cmd);
881 system(cmd.latin1() );
882 }
883 populateRemoteView();
884 TabWidget->setCurrentPage(1);
885 } else {
886 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
887
888 QString destName = currentDir.canonicalPath()+"/"+(*it);
889 if(destName.right(1) == "/") destName = destName.left( destName.length() -1);
890 QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
891 if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1);
892
893 cmd = "ln -s "+curFile+" "+destName;
894 qDebug(cmd);
895 system(cmd.latin1() );
896 }
897 populateLocalView();
898 TabWidget->setCurrentPage(0);
899 }
900 }
901}
902
903void AdvancedFm::doBeam() {
904 Ir ir;
905 if(!ir.supported()){
906 } else {
907
908 QStringList curFileList = getPath();
909 if( curFileList.count() > 0) {
910
911 if (TabWidget->currentPageIndex() == 0) {
912 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
913
914 QString curFile = currentDir.canonicalPath()+"/"+(*it);
915 if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1);
916 Ir *file = new Ir(this, "IR");
917 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * )));
918 file->send( curFile, curFile );
919 }
920
921 } else {
922 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
923
924 QString curFile = currentRemoteDir.canonicalPath()+"/"+(*it);
925 if( curFile.right(1) == "/") curFile = curFile.left( curFile.length() -1);
926 Ir *file = new Ir(this, "IR");
927 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * )));
928 file->send( curFile, curFile );
929
930 }
931 }
932 }
933 }
934
935}
936
937void AdvancedFm::fileBeamFinished( Ir *) {
938 QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") );
939
940}