summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-10-13 21:53:13 (UTC)
committer llornkcor <llornkcor>2004-10-13 21:53:13 (UTC)
commit1f59ac9b59393b46a7ae5d4e1a46e1c1aaf05b23 (patch) (unidiff)
tree85461425e52ee7e90b40ffeaed7450122a8cb0b0
parentff1e5cf77abe865c4ca9beda114577ad4a13e61f (diff)
downloadopie-1f59ac9b59393b46a7ae5d4e1a46e1c1aaf05b23.zip
opie-1f59ac9b59393b46a7ae5d4e1a46e1c1aaf05b23.tar.gz
opie-1f59ac9b59393b46a7ae5d4e1a46e1c1aaf05b23.tar.bz2
fix move
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/advancedfm/advancedfmMenu.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp
index f25048a..8b98898 100644
--- a/noncore/apps/advancedfm/advancedfmMenu.cpp
+++ b/noncore/apps/advancedfm/advancedfmMenu.cpp
@@ -397,205 +397,207 @@ void AdvancedFm::copyAs() {
397 // setOtherTabCurrent(); 397 // setOtherTabCurrent();
398 qApp->processEvents(); 398 qApp->processEvents();
399 399
400} 400}
401 401
402void AdvancedFm::copySameDirTimer() { 402void AdvancedFm::copySameDirTimer() {
403 QTimer::singleShot(125,this,SLOT(copySameDir())); 403 QTimer::singleShot(125,this,SLOT(copySameDir()));
404} 404}
405 405
406void AdvancedFm::copySameDir() { 406void AdvancedFm::copySameDir() {
407 qApp->processEvents(); 407 qApp->processEvents();
408 QStringList curFileList = getPath(); 408 QStringList curFileList = getPath();
409 QString curFile, item, destFile; 409 QString curFile, item, destFile;
410 InputDialog *fileDlg; 410 InputDialog *fileDlg;
411 411
412 QDir *thisDir = CurrentDir(); 412 QDir *thisDir = CurrentDir();
413 413
414 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 414 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
415 item=(*it); 415 item=(*it);
416 curFile = thisDir->canonicalPath()+"/"+ item; 416 curFile = thisDir->canonicalPath()+"/"+ item;
417 417
418 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); 418 fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0);
419 fileDlg->setInputText((const QString &) destFile ); 419 fileDlg->setInputText((const QString &) destFile );
420 fileDlg->exec(); 420 fileDlg->exec();
421 421
422 if( fileDlg->result() == 1 ) { 422 if( fileDlg->result() == 1 ) {
423 423
424 QString filename = fileDlg->LineEdit1->text(); 424 QString filename = fileDlg->LineEdit1->text();
425 destFile = thisDir->canonicalPath()+"/"+filename; 425 destFile = thisDir->canonicalPath()+"/"+filename;
426 426
427 QFile f(destFile); 427 QFile f(destFile);
428 if( f.exists()) { 428 if( f.exists()) {
429 switch (QMessageBox::warning(this,tr("Delete"), 429 switch (QMessageBox::warning(this,tr("Delete"),
430 tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile), 430 tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile),
431 tr("Yes"),tr("No"),0,0,1) ) { 431 tr("Yes"),tr("No"),0,0,1) ) {
432 case 0: 432 case 0:
433 433
434 f.remove(); 434 f.remove();
435 break; 435 break;
436 case 1: 436 case 1:
437 return; 437 return;
438 break; 438 break;
439 default: 439 default:
440 return; 440 return;
441 break; 441 break;
442 }; 442 };
443 } 443 }
444 if(!copyFile( curFile,destFile) ) { 444 if(!copyFile( curFile,destFile) ) {
445 QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); 445 QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile));
446 return; 446 return;
447 } 447 }
448 448
449// odebug << "copy "+curFile+" as "+destFile << oendl; 449// odebug << "copy "+curFile+" as "+destFile << oendl;
450 } 450 }
451 delete fileDlg; 451 delete fileDlg;
452 } 452 }
453 rePopulate(); 453 rePopulate();
454} 454}
455 455
456void AdvancedFm::moveTimer() { 456void AdvancedFm::moveTimer() {
457 QTimer::singleShot(125,this,SLOT(move())); 457 QTimer::singleShot(125,this,SLOT(move()));
458} 458}
459 459
460void AdvancedFm::move() { 460void AdvancedFm::move() {
461 461
462 QStringList curFileList = getPath(); 462 QStringList curFileList = getPath();
463 if( curFileList.count() > 0) { 463 if( curFileList.count() > 0) {
464 QString curFile, destFile, item; 464 QString curFile, destFile, item;
465 465
466 QDir *thisDir = CurrentDir(); 466 QDir *thisDir = CurrentDir();
467 QDir *thatDir = OtherDir(); 467 QDir *thatDir = OtherDir();
468 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { 468 for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) {
469 item=(*it); 469 item=(*it);
470 QString destFile = thatDir->canonicalPath(); 470 QString destFile = thatDir->canonicalPath();
471 471
472 if(destFile.right(1).find("/",0,TRUE) == -1) 472 if(destFile.right(1).find("/",0,TRUE) == -1)
473 destFile+="/"; 473 destFile+="/";
474 destFile += item; 474 destFile += item;
475// odebug << "Destination file is "+destFile << oendl; 475// odebug << "Destination file is "+destFile << oendl;
476 476
477 curFile = thisDir->canonicalPath(); 477 curFile = thisDir->canonicalPath();
478 if(curFile.right(1).find("/",0,TRUE) == -1) 478 if(curFile.right(1).find("/",0,TRUE) == -1)
479 curFile +="/"; 479 curFile +="/";
480 curFile+= item; 480 curFile+= item;
481// odebug << "CurrentFile file is " + curFile << oendl; 481// odebug << "CurrentFile file is " + curFile << oendl;
482 482
483 if(QFileInfo(curFile).isDir()) { 483 if(QFileInfo(curFile).isDir()) {
484 moveDirectory( curFile, destFile ); 484 moveDirectory( curFile, destFile );
485 rePopulate(); 485 rePopulate();
486 return; 486 return;
487 } 487 }
488 QFile f( destFile); 488 QFile f( destFile);
489 if( f.exists()) { 489 if( f.exists()) {
490 switch ( QMessageBox::warning(this,tr("File Exists!"), 490 switch ( QMessageBox::warning(this,tr("File Exists!"),
491 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile), 491 tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile),
492 tr("Yes"),tr("No"),0,0,1)) { 492 tr("Yes"),tr("No"),0,0,1)) {
493 case 0:
494 break;
493 case 1: 495 case 1:
494 return; 496 return;
495 break; 497 break;
496 default: 498 default:
497 return; 499 return;
498 break; 500 break;
499 }; 501 };
502 }
500 if( !copyFile( curFile, destFile) ) { 503 if( !copyFile( curFile, destFile) ) {
501 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile)); 504 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile));
502 return; 505 return;
503 } else 506 } else
504 QFile::remove(curFile); 507 QFile::remove(curFile);
505 }
506 } 508 }
507 } 509 }
508 rePopulate(); 510 rePopulate();
509 //setOtherTabCurrent(); 511 //setOtherTabCurrent();
510} 512}
511 513
512bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { 514bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) {
513 int err = 0; 515 int err = 0;
514 if( copyDirectory( src, dest ) ) { 516 if( copyDirectory( src, dest ) ) {
515 QString cmd = "rm -rf " + src; 517 QString cmd = "rm -rf " + src;
516 err = system((const char*)cmd); 518 err = system((const char*)cmd);
517 } else 519 } else
518 err = -1; 520 err = -1;
519 521
520 if(err!=0) { 522 if(err!=0) {
521 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src)); 523 QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg( src));
522 return false; 524 return false;
523 } 525 }
524 return true; 526 return true;
525} 527}
526 528
527bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { 529bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) {
528 530
529 QString cmd = "/bin/cp -fpR " + src + " " + dest; 531 QString cmd = "/bin/cp -fpR " + src + " " + dest;
530 owarn << cmd << oendl; 532 owarn << cmd << oendl;
531 int err = system( (const char *) cmd ); 533 int err = system( (const char *) cmd );
532 if ( err != 0 ) { 534 if ( err != 0 ) {
533 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) ); 535 QMessageBox::message("AdvancedFm", tr( "<p>Could not copy %1 to %2</p>").arg( src ).arg( dest ) );
534 return false; 536 return false;
535 } 537 }
536 538
537 return true; 539 return true;
538} 540}
539 541
540 542
541bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { 543bool AdvancedFm::copyFile( const QString & src, const QString & dest ) {
542 if(QFileInfo(src).isDir()) { 544 if(QFileInfo(src).isDir()) {
543 if( copyDirectory( src, dest )) { 545 if( copyDirectory( src, dest )) {
544 // setOtherTabCurrent(); 546 // setOtherTabCurrent();
545 rePopulate(); 547 rePopulate();
546 return true; 548 return true;
547 } 549 }
548 else 550 else
549 return false; 551 return false;
550 } 552 }
551 553
552 554
553 bool success = true; 555 bool success = true;
554 struct stat status; 556 struct stat status;
555 QFile srcFile(src); 557 QFile srcFile(src);
556 QFile destFile(dest); 558 QFile destFile(dest);
557 int err=0; 559 int err=0;
558 int read_fd=0; 560 int read_fd=0;
559 int write_fd=0; 561 int write_fd=0;
560 struct stat stat_buf; 562 struct stat stat_buf;
561 off_t offset = 0; 563 off_t offset = 0;
562 if(!srcFile.open( IO_ReadOnly|IO_Raw)) { 564 if(!srcFile.open( IO_ReadOnly|IO_Raw)) {
563// owarn << "open failed" << oendl; 565// owarn << "open failed" << oendl;
564 return success = false; 566 return success = false;
565 } 567 }
566 read_fd = srcFile.handle(); 568 read_fd = srcFile.handle();
567 if(read_fd != -1) { 569 if(read_fd != -1) {
568 fstat (read_fd, &stat_buf); 570 fstat (read_fd, &stat_buf);
569 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { 571 if( !destFile.open( IO_WriteOnly|IO_Raw ) ) {
570// owarn << "destfile open failed" << oendl; 572// owarn << "destfile open failed" << oendl;
571 return success = false; 573 return success = false;
572 } 574 }
573 write_fd = destFile.handle(); 575 write_fd = destFile.handle();
574 if(write_fd != -1) { 576 if(write_fd != -1) {
575 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); 577 err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size);
576 if( err == -1) { 578 if( err == -1) {
577 QString msg; 579 QString msg;
578 switch(err) { 580 switch(err) {
579 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; 581 case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. ";
580 case EINVAL: msg = "Descriptor is not valid or locked. "; 582 case EINVAL: msg = "Descriptor is not valid or locked. ";
581 case ENOMEM: msg = "Insufficient memory to read from in_fd."; 583 case ENOMEM: msg = "Insufficient memory to read from in_fd.";
582 case EIO: msg = "Unspecified error while reading from in_fd."; 584 case EIO: msg = "Unspecified error while reading from in_fd.";
583 }; 585 };
584 success = false; 586 success = false;
585// owarn << msg << oendl; 587// owarn << msg << oendl;
586 } 588 }
587 } else { 589 } else {
588 success = false; 590 success = false;
589 } 591 }
590 } else { 592 } else {
591 success = false; 593 success = false;
592 } 594 }
593 srcFile.close(); 595 srcFile.close();
594 destFile.close(); 596 destFile.close();
595 // Set file permissions 597 // Set file permissions
596 if( stat( QFile::encodeName(src), &status ) == 0 ) { 598 if( stat( QFile::encodeName(src), &status ) == 0 ) {
597 chmod( QFile::encodeName(dest), status.st_mode ); 599 chmod( QFile::encodeName(dest), status.st_mode );
598 } 600 }
599 601
600 return success; 602 return success;
601} 603}