summaryrefslogtreecommitdiff
path: root/noncore/apps/advancedfm/advancedfmMenu.cpp
Unidiff
Diffstat (limited to 'noncore/apps/advancedfm/advancedfmMenu.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp149
1 files changed, 63 insertions, 86 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index 9f21245..00d0e07 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -38,6 +38,7 @@
38#include <qlineedit.h> 38#include <qlineedit.h>
39#include <qlistview.h> 39#include <qlistview.h>
40 40
41#include <errno.h>
41#include <stdlib.h> 42#include <stdlib.h>
42#include <unistd.h> 43#include <unistd.h>
43#include <sys/stat.h> 44#include <sys/stat.h>
@@ -45,6 +46,7 @@
45#include <sys/sendfile.h> 46#include <sys/sendfile.h>
46#include <fcntl.h> 47#include <fcntl.h>
47 48
49
48void AdvancedFm::doDirChange() 50void AdvancedFm::doDirChange()
49{ 51{
50 ListClicked( CurrentView()->currentItem()); 52 ListClicked( CurrentView()->currentItem());
@@ -170,14 +172,11 @@ void AdvancedFm::makeDir()
170 172
171void AdvancedFm::doDelete() 173void AdvancedFm::doDelete()
172{ 174{
173
174 QStringList curFileList = getPath(); 175 QStringList curFileList = getPath();
175 bool doMsg=true; 176 bool doMsg=true;
176 int count = curFileList.count(); 177 int count = curFileList.count();
177 if( count > 0) 178 if( count > 0) {
178 { 179 if(count > 1 ) {
179 if(count > 1 )
180 {
181 QString msg; 180 QString msg;
182 msg=tr("Really delete\n%1 files?").arg(count); 181 msg=tr("Really delete\n%1 files?").arg(count);
183 switch ( QMessageBox::warning(this,tr("Delete"),msg 182 switch ( QMessageBox::warning(this,tr("Delete"),msg
@@ -193,8 +192,8 @@ void AdvancedFm::doDelete()
193 } 192 }
194 193
195 QString myFile; 194 QString myFile;
196 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) 195
197 { 196 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
198 myFile = (*it); 197 myFile = (*it);
199 if( myFile.find(" -> ",0,TRUE) != -1) 198 if( myFile.find(" -> ",0,TRUE) != -1)
200 myFile = myFile.left( myFile.find(" -> ",0,TRUE)); 199 myFile = myFile.left( myFile.find(" -> ",0,TRUE));
@@ -203,16 +202,12 @@ void AdvancedFm::doDelete()
203 if(f.right(1).find("/",0,TRUE) == -1) 202 if(f.right(1).find("/",0,TRUE) == -1)
204 f += "/"; 203 f += "/";
205 f += myFile; 204 f += myFile;
206 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) //if file is a directory 205 if(QDir(f).exists() && !QFileInfo(f).isSymLink() ) {
207 { 206 //if file is a directory
207
208 switch ( QMessageBox::warning( this, tr("Delete Directory?"), 208 switch ( QMessageBox::warning( this, tr("Delete Directory?"),
209 tr("Really delete %1\nand all it's contents ?" ).arg( f ) , 209 tr("Really delete %1\nand all it's contents ?" ).arg( f ) ,
210 tr("Yes"), 210 tr("Yes"), tr("No"), 0, 0, 1) ) {
211 tr("No"),
212 0,
213 0,
214 1) )
215 {
216 case 0: 211 case 0:
217 { 212 {
218 f=f.left(f.length()-1); 213 f=f.left(f.length()-1);
@@ -229,24 +224,27 @@ void AdvancedFm::doDelete()
229 } else { 224 } else {
230 if(doMsg) { 225 if(doMsg) {
231 switch ( QMessageBox::warning(this,tr("Delete"), 226 switch ( QMessageBox::warning(this,tr("Delete"),
232 tr("Really delete\n%1?").arg( f ), 227 tr("Really delete\n%1?").arg( myFile ),
233 tr("Yes"), 228 tr("Yes"), tr("No"), 0, 0, 1) ) {
234 tr("No"),
235 0,
236 0,
237 1) ) {
238 case 1: 229 case 1:
239 return; 230 return;
240 break; 231 break;
241 }; 232 };
242 } 233 }
234
243 QString cmd="rm "+f; 235 QString cmd="rm "+f;
244 QFile file(f); 236 QFile file(f);
245 if(QFileInfo(myFile).fileName().find("../",0,TRUE)==-1) { 237 QFileInfo fi(myFile);
246 qDebug("remove link files "+f); 238 if( fi.fileName().find("../",0,TRUE)==-1) {
247// AppLnk lnk(f); 239 qDebug("remove link files "+myFile);
248// qDebug(lnk.linkFile()); 240
249// lnk.removeLinkFile(); 241// DocLnk lnk(f);
242 DocLnk *lnk;
243 lnk = new DocLnk(f);
244 qDebug("Deleting doclnk " + lnk->linkFile());
245 if(lnk->isValid())
246 lnk->removeLinkFile();
247 // delete lnk;
250 file.remove(); 248 file.remove();
251 } 249 }
252 } 250 }
@@ -367,8 +365,7 @@ void AdvancedFm::copy()
367 f.remove(); 365 f.remove();
368 } 366 }
369 367
370 if( !copyFile( curFile, destFile) ) 368 if( !copyFile( curFile, destFile) ) {
371 {
372 QMessageBox::message("AdvancedFm", 369 QMessageBox::message("AdvancedFm",
373 tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) ); 370 tr( "Could not copy %1 to %2").arg( curFile ).arg( destFile ) );
374 return; 371 return;
@@ -420,8 +417,7 @@ void AdvancedFm::copyAs()
420 break; 417 break;
421 }; 418 };
422 } 419 }
423 if( !copyFile( curFile, destFile) ) 420 if( !copyFile( curFile, destFile) ) {
424 {
425 QMessageBox::message("AdvancedFm",tr("Could not copy\n") 421 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
426 +curFile +tr("to\n")+destFile); 422 +curFile +tr("to\n")+destFile);
427 return; 423 return;
@@ -473,8 +469,7 @@ void AdvancedFm::copySameDir()
473 break; 469 break;
474 }; 470 };
475 } 471 }
476 if(!copyFile( curFile,destFile) ) 472 if(!copyFile( curFile,destFile) ) {
477 {
478 QMessageBox::message("AdvancedFm",tr("Could not copy\n") 473 QMessageBox::message("AdvancedFm",tr("Could not copy\n")
479 +curFile +tr("to\n")+destFile); 474 +curFile +tr("to\n")+destFile);
480 return; 475 return;
@@ -516,8 +511,7 @@ void AdvancedFm::move()
516 511
517 QFile f( curFile); 512 QFile f( curFile);
518 if( f.exists()) { 513 if( f.exists()) {
519 if( !copyFile( curFile, destFile) ) 514 if( !copyFile( curFile, destFile) ) {
520 {
521 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); 515 QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile);
522 return; 516 return;
523 } else 517 } else
@@ -533,25 +527,39 @@ void AdvancedFm::move()
533 527
534bool AdvancedFm::copyFile( const QString & src, const QString & dest ) 528bool AdvancedFm::copyFile( const QString & src, const QString & dest )
535{ 529{
536// char bf[ 50000 ];
537// int bytesRead;
538 bool success = true; 530 bool success = true;
539 struct stat status; 531 struct stat status;
540 532 QFile srcFile(src);
541// QFile s( src ); 533 QFile destFile(dest);
542// QFile d( dest ); 534 int err=0;
543
544 int read_fd=0; 535 int read_fd=0;
545 int write_fd=0; 536 int write_fd=0;
546 struct stat stat_buf; 537 struct stat stat_buf;
547 off_t offset = 0; 538 off_t offset = 0;
548 read_fd = ::open(src.latin1(), O_RDONLY); 539 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
540 qWarning("open failed");
541 return success = false;
542 }
543 read_fd = srcFile.handle();
549 if(read_fd != -1) { 544 if(read_fd != -1) {
550 fstat (read_fd, &stat_buf); 545 fstat (read_fd, &stat_buf);
551 write_fd = ::open(dest.latin1(), O_WRONLY | O_CREAT, stat_buf.st_mode); 546 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
547 qWarning("destfile open failed");
548 return success = false;
549 }
550 write_fd = destFile.handle();
552 if(write_fd != -1) { 551 if(write_fd != -1) {
553 if(sendfile(write_fd, read_fd, &offset, stat_buf.st_size) == -1) { 552 err =sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
553 if( err == -1) {
554 QString msg;
555 switch(err) {
556 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
557 case EINVAL: msg = "Descriptor is not valid or locked. ";
558 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
559 case EIO: msg = "Unspecified error while reading from in_fd.";
560 };
554 success = false; 561 success = false;
562 qWarning(msg);
555 } 563 }
556 } else { 564 } else {
557 success = false; 565 success = false;
@@ -559,34 +567,10 @@ bool AdvancedFm::copyFile( const QString & src, const QString & dest )
559 } else { 567 } else {
560 success = false; 568 success = false;
561 } 569 }
562 570 srcFile.close();
563 ::close (read_fd); 571 destFile.close();
564 ::close (write_fd);
565
566
567// if( s.open( IO_ReadOnly | IO_Raw ) && d.open( IO_WriteOnly | IO_Raw ) )
568// {
569// while( (bytesRead = s.readBlock( bf, sizeof( bf ) )) == sizeof( bf ) )
570// {
571// if( d.writeBlock( bf, sizeof( bf ) ) != sizeof( bf ) ){
572// success = FALSE;
573// break;
574// }
575// }
576// if( success && (bytesRead > 0) )
577// {
578// d.writeBlock( bf, bytesRead );
579// }
580
581// }
582// else
583// {
584// success = FALSE;
585// }
586
587 // Set file permissions 572 // Set file permissions
588 if( stat( (const char *) src, &status ) == 0 ) 573 if( stat( (const char *) src, &status ) == 0 ) {
589 {
590 chmod( (const char *) dest, status.st_mode ); 574 chmod( (const char *) dest, status.st_mode );
591 } 575 }
592 576
@@ -713,29 +697,22 @@ void AdvancedFm::mkSym()
713void AdvancedFm::doBeam() 697void AdvancedFm::doBeam()
714{ 698{
715 Ir ir; 699 Ir ir;
716 if(!ir.supported()) 700 if(!ir.supported()) {
717 { 701 } else {
718 }
719 else
720 {
721 QStringList curFileList = getPath(); 702 QStringList curFileList = getPath();
722 if( curFileList.count() > 0) 703 if( curFileList.count() > 0) {
723 { 704 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
724 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) 705 QString curFile = (*it);
725 { 706 QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile;
726 707 if( curFilePath.right(1) == "/") {
727 QString curFile = CurrentDir()->canonicalPath()+"/"+(*it); 708 curFilePath = curFilePath.left( curFilePath.length() -1);
728 if( curFile.right(1) == "/")
729 {
730 curFile = curFile.left( curFile.length() -1);
731 } 709 }
732 Ir *file = new Ir(this, "IR"); 710 Ir *file = new Ir(this, "IR");
733 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); 711 connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * )));
734 file->send( curFile, curFile ); 712 file->send( curFilePath, curFile );
735 } 713 }
736 } 714 }
737 } 715 }
738
739} 716}
740 717
741void AdvancedFm::fileBeamFinished( Ir *) 718void AdvancedFm::fileBeamFinished( Ir *)