author | llornkcor <llornkcor> | 2004-09-25 05:50:48 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-09-25 05:50:48 (UTC) |
commit | dba0864dd99dfc86a33bde72809634be7f0da9c4 (patch) (unidiff) | |
tree | 074ccc67cc4e7474d697117357bca2c1b19cef16 | |
parent | 244945237bc55945ba41f86d5f175204e00592ea (diff) | |
download | opie-dba0864dd99dfc86a33bde72809634be7f0da9c4.zip opie-dba0864dd99dfc86a33bde72809634be7f0da9c4.tar.gz opie-dba0864dd99dfc86a33bde72809634be7f0da9c4.tar.bz2 |
fix move overwrite
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 114 |
1 files changed, 60 insertions, 54 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index b5a05d3..f14f588 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -352,259 +352,265 @@ void AdvancedFm::copyAs() { | |||
352 | QString destFile; | 352 | QString destFile; |
353 | item=(*it); | 353 | item=(*it); |
354 | curFile = thisDir->canonicalPath()+"/"+(*it); | 354 | curFile = thisDir->canonicalPath()+"/"+(*it); |
355 | fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0); | 355 | fileDlg = new InputDialog( this, tr("Copy %1 As").arg(curFile), TRUE, 0); |
356 | 356 | ||
357 | fileDlg->setInputText((const QString &) destFile ); | 357 | fileDlg->setInputText((const QString &) destFile ); |
358 | fileDlg->exec(); | 358 | fileDlg->exec(); |
359 | 359 | ||
360 | if( fileDlg->result() == 1 ) { | 360 | if( fileDlg->result() == 1 ) { |
361 | QString filename = fileDlg->LineEdit1->text(); | 361 | QString filename = fileDlg->LineEdit1->text(); |
362 | destFile = thatDir->canonicalPath()+"/"+filename; | 362 | destFile = thatDir->canonicalPath()+"/"+filename; |
363 | 363 | ||
364 | QFile f( destFile); | 364 | QFile f( destFile); |
365 | if( f.exists()) { | 365 | if( f.exists()) { |
366 | switch (QMessageBox::warning(this,tr("File Exists!"), | 366 | switch (QMessageBox::warning(this,tr("File Exists!"), |
367 | tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item), | 367 | tr("<P> %1 already exists. Ok to overwrite?</p>").arg(item), |
368 | tr("Yes"),tr("No"),0,0,1) ) { | 368 | tr("Yes"),tr("No"),0,0,1) ) { |
369 | case 0: | 369 | case 0: |
370 | f.remove(); | 370 | f.remove(); |
371 | break; | 371 | break; |
372 | case 1: | 372 | case 1: |
373 | return; | 373 | return; |
374 | break; | 374 | break; |
375 | }; | 375 | }; |
376 | } | 376 | } |
377 | if( !copyFile( curFile, destFile) ) { | 377 | if( !copyFile( curFile, destFile) ) { |
378 | QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); | 378 | QMessageBox::message("AdvancedFm",tr("<p>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); |
379 | return; | 379 | return; |
380 | } | 380 | } |
381 | } | 381 | } |
382 | delete fileDlg; | 382 | delete fileDlg; |
383 | 383 | ||
384 | } | 384 | } |
385 | rePopulate(); | 385 | rePopulate(); |
386 | // setOtherTabCurrent(); | 386 | // setOtherTabCurrent(); |
387 | qApp->processEvents(); | 387 | qApp->processEvents(); |
388 | 388 | ||
389 | } | 389 | } |
390 | 390 | ||
391 | void AdvancedFm::copySameDirTimer() { | 391 | void AdvancedFm::copySameDirTimer() { |
392 | QTimer::singleShot(125,this,SLOT(copySameDir())); | 392 | QTimer::singleShot(125,this,SLOT(copySameDir())); |
393 | } | 393 | } |
394 | 394 | ||
395 | void AdvancedFm::copySameDir() { | 395 | void AdvancedFm::copySameDir() { |
396 | qApp->processEvents(); | 396 | qApp->processEvents(); |
397 | QStringList curFileList = getPath(); | 397 | QStringList curFileList = getPath(); |
398 | QString curFile, item, destFile; | 398 | QString curFile, item, destFile; |
399 | InputDialog *fileDlg; | 399 | InputDialog *fileDlg; |
400 | 400 | ||
401 | QDir *thisDir = CurrentDir(); | 401 | QDir *thisDir = CurrentDir(); |
402 | 402 | ||
403 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 403 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
404 | item=(*it); | 404 | item=(*it); |
405 | curFile = thisDir->canonicalPath()+"/"+ item; | 405 | curFile = thisDir->canonicalPath()+"/"+ item; |
406 | 406 | ||
407 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); | 407 | fileDlg = new InputDialog(this,tr("Copy ")+curFile+tr(" As"),TRUE, 0); |
408 | fileDlg->setInputText((const QString &) destFile ); | 408 | fileDlg->setInputText((const QString &) destFile ); |
409 | fileDlg->exec(); | 409 | fileDlg->exec(); |
410 | 410 | ||
411 | if( fileDlg->result() == 1 ) { | 411 | if( fileDlg->result() == 1 ) { |
412 | 412 | ||
413 | QString filename = fileDlg->LineEdit1->text(); | 413 | QString filename = fileDlg->LineEdit1->text(); |
414 | destFile = thisDir->canonicalPath()+"/"+filename; | 414 | destFile = thisDir->canonicalPath()+"/"+filename; |
415 | 415 | ||
416 | QFile f(destFile); | 416 | QFile f(destFile); |
417 | if( f.exists()) { | 417 | if( f.exists()) { |
418 | switch (QMessageBox::warning(this,tr("Delete"), | 418 | switch (QMessageBox::warning(this,tr("Delete"), |
419 | tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile), | 419 | tr("<p> %1 already exists. Do you really want to delete it?</P>").arg(destFile), |
420 | tr("Yes"),tr("No"),0,0,1) ) { | 420 | tr("Yes"),tr("No"),0,0,1) ) { |
421 | case 0: | 421 | case 0: |
422 | 422 | ||
423 | f.remove(); | 423 | f.remove(); |
424 | break; | 424 | break; |
425 | case 1: | 425 | case 1: |
426 | return; | 426 | return; |
427 | break; | 427 | break; |
428 | }; | 428 | }; |
429 | } | 429 | } |
430 | if(!copyFile( curFile,destFile) ) { | 430 | if(!copyFile( curFile,destFile) ) { |
431 | QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); | 431 | QMessageBox::message("AdvancedFm",tr("<P>Could not copy %1 to %2</P>").arg(curFile).arg(destFile)); |
432 | return; | 432 | return; |
433 | } | 433 | } |
434 | 434 | ||
435 | // odebug << "copy "+curFile+" as "+destFile << oendl; | 435 | // odebug << "copy "+curFile+" as "+destFile << oendl; |
436 | } | 436 | } |
437 | delete fileDlg; | 437 | delete fileDlg; |
438 | } | 438 | } |
439 | rePopulate(); | 439 | rePopulate(); |
440 | } | 440 | } |
441 | 441 | ||
442 | void AdvancedFm::moveTimer() { | 442 | void AdvancedFm::moveTimer() { |
443 | QTimer::singleShot(125,this,SLOT(move())); | 443 | QTimer::singleShot(125,this,SLOT(move())); |
444 | } | 444 | } |
445 | 445 | ||
446 | void AdvancedFm::move() { | 446 | void AdvancedFm::move() { |
447 | 447 | ||
448 | QStringList curFileList = getPath(); | 448 | QStringList curFileList = getPath(); |
449 | if( curFileList.count() > 0) { | 449 | if( curFileList.count() > 0) { |
450 | QString curFile, destFile, item; | 450 | QString curFile, destFile, item; |
451 | 451 | ||
452 | QDir *thisDir = CurrentDir(); | 452 | QDir *thisDir = CurrentDir(); |
453 | QDir *thatDir = OtherDir(); | 453 | QDir *thatDir = OtherDir(); |
454 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 454 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
455 | item=(*it); | 455 | item=(*it); |
456 | QString destFile = thatDir->canonicalPath(); | 456 | QString destFile = thatDir->canonicalPath(); |
457 | 457 | ||
458 | if(destFile.right(1).find("/",0,TRUE) == -1) | 458 | if(destFile.right(1).find("/",0,TRUE) == -1) |
459 | destFile+="/"; | 459 | destFile+="/"; |
460 | destFile += item; | 460 | destFile += item; |
461 | // odebug << "Destination file is "+destFile << oendl; | 461 | // odebug << "Destination file is "+destFile << oendl; |
462 | 462 | ||
463 | curFile = thisDir->canonicalPath(); | 463 | curFile = thisDir->canonicalPath(); |
464 | if(curFile.right(1).find("/",0,TRUE) == -1) | 464 | if(curFile.right(1).find("/",0,TRUE) == -1) |
465 | curFile +="/"; | 465 | curFile +="/"; |
466 | curFile+= item; | 466 | curFile+= item; |
467 | // odebug << "CurrentFile file is " + curFile << oendl; | 467 | // odebug << "CurrentFile file is " + curFile << oendl; |
468 | 468 | ||
469 | if(QFileInfo(curFile).isDir()) { | 469 | if(QFileInfo(curFile).isDir()) { |
470 | moveDirectory( curFile, destFile ); | 470 | moveDirectory( curFile, destFile ); |
471 | rePopulate(); | 471 | rePopulate(); |
472 | return; | 472 | return; |
473 | } | 473 | } |
474 | QFile f( curFile); | 474 | QFile f( destFile); |
475 | if( f.exists()) { | 475 | if( f.exists()) { |
476 | if( !copyFile( curFile, destFile) ) { | 476 | switch ( QMessageBox::warning(this,tr("File Exists!"), |
477 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); | 477 | tr("<p>%1 already exists. Ok to overwrite?</P>").arg(destFile), |
478 | return; | 478 | tr("Yes"),tr("No"),0,0,1)) { |
479 | } else | 479 | case 1: |
480 | QFile::remove(curFile); | 480 | return; |
481 | } | 481 | break; |
482 | } | 482 | }; |
483 | 483 | if( !copyFile( curFile, destFile) ) { | |
484 | } | 484 | QMessageBox::message(tr("Note"),tr("<p>Could not move %1</p>").arg(curFile)); |
485 | rePopulate(); | 485 | return; |
486 | } else | ||
487 | QFile::remove(curFile); | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | rePopulate(); | ||
486 | //setOtherTabCurrent(); | 492 | //setOtherTabCurrent(); |
487 | } | 493 | } |
488 | 494 | ||
489 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { | 495 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { |
490 | int err = 0; | 496 | int err = 0; |
491 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; | 497 | if( copyDirectory( src, dest ) ) { |
492 | err = system((const char*)cmd); | 498 | QString cmd = "rm -rf " + src; |
493 | } else | 499 | err = system((const char*)cmd); |
494 | err = -1; | 500 | } else |
495 | 501 | err = -1; | |
496 | if(err!=0) { | 502 | |
497 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); | 503 | if(err!=0) { |
498 | return false; | 504 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); |
499 | } | 505 | return false; |
500 | return true; | 506 | } |
507 | return true; | ||
501 | } | 508 | } |
502 | 509 | ||
503 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { | 510 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { |
504 | 511 | ||
505 | QString cmd = "/bin/cp -fpR " + src + " " + dest; | 512 | QString cmd = "/bin/cp -fpR " + src + " " + dest; |
506 | owarn << cmd << oendl; | 513 | owarn << cmd << oendl; |
507 | int err = system( (const char *) cmd ); | 514 | int err = system( (const char *) cmd ); |
508 | if ( err != 0 ) { | 515 | if ( err != 0 ) { |
509 | QMessageBox::message("AdvancedFm", | 516 | QMessageBox::message("AdvancedFm", tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); |
510 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); | 517 | return false; |
511 | return false; | 518 | } |
512 | } | ||
513 | 519 | ||
514 | return true; | 520 | return true; |
515 | } | 521 | } |
516 | 522 | ||
517 | 523 | ||
518 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | 524 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { |
519 | if(QFileInfo(src).isDir()) { | 525 | if(QFileInfo(src).isDir()) { |
520 | if( copyDirectory( src, dest )) { | 526 | if( copyDirectory( src, dest )) { |
521 | // setOtherTabCurrent(); | 527 | // setOtherTabCurrent(); |
522 | rePopulate(); | 528 | rePopulate(); |
523 | return true; | 529 | return true; |
524 | } | 530 | } |
525 | else | 531 | else |
526 | return false; | 532 | return false; |
527 | } | 533 | } |
528 | 534 | ||
529 | 535 | ||
530 | bool success = true; | 536 | bool success = true; |
531 | struct stat status; | 537 | struct stat status; |
532 | QFile srcFile(src); | 538 | QFile srcFile(src); |
533 | QFile destFile(dest); | 539 | QFile destFile(dest); |
534 | int err=0; | 540 | int err=0; |
535 | int read_fd=0; | 541 | int read_fd=0; |
536 | int write_fd=0; | 542 | int write_fd=0; |
537 | struct stat stat_buf; | 543 | struct stat stat_buf; |
538 | off_t offset = 0; | 544 | off_t offset = 0; |
539 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 545 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
540 | // owarn << "open failed" << oendl; | 546 | // owarn << "open failed" << oendl; |
541 | return success = false; | 547 | return success = false; |
542 | } | 548 | } |
543 | read_fd = srcFile.handle(); | 549 | read_fd = srcFile.handle(); |
544 | if(read_fd != -1) { | 550 | if(read_fd != -1) { |
545 | fstat (read_fd, &stat_buf); | 551 | fstat (read_fd, &stat_buf); |
546 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 552 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
547 | // owarn << "destfile open failed" << oendl; | 553 | // owarn << "destfile open failed" << oendl; |
548 | return success = false; | 554 | return success = false; |
549 | } | 555 | } |
550 | write_fd = destFile.handle(); | 556 | write_fd = destFile.handle(); |
551 | if(write_fd != -1) { | 557 | if(write_fd != -1) { |
552 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 558 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
553 | if( err == -1) { | 559 | if( err == -1) { |
554 | QString msg; | 560 | QString msg; |
555 | switch(err) { | 561 | switch(err) { |
556 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 562 | 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. "; | 563 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
558 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 564 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
559 | case EIO: msg = "Unspecified error while reading from in_fd."; | 565 | case EIO: msg = "Unspecified error while reading from in_fd."; |
560 | }; | 566 | }; |
561 | success = false; | 567 | success = false; |
562 | // owarn << msg << oendl; | 568 | // owarn << msg << oendl; |
563 | } | 569 | } |
564 | } else { | 570 | } else { |
565 | success = false; | 571 | success = false; |
566 | } | 572 | } |
567 | } else { | 573 | } else { |
568 | success = false; | 574 | success = false; |
569 | } | 575 | } |
570 | srcFile.close(); | 576 | srcFile.close(); |
571 | destFile.close(); | 577 | destFile.close(); |
572 | // Set file permissions | 578 | // Set file permissions |
573 | if( stat( QFile::encodeName(src), &status ) == 0 ) { | 579 | if( stat( QFile::encodeName(src), &status ) == 0 ) { |
574 | chmod( QFile::encodeName(dest), status.st_mode ); | 580 | chmod( QFile::encodeName(dest), status.st_mode ); |
575 | } | 581 | } |
576 | 582 | ||
577 | return success; | 583 | return success; |
578 | } | 584 | } |
579 | 585 | ||
580 | void AdvancedFm::runCommand() { | 586 | void AdvancedFm::runCommand() { |
581 | if( !CurrentView()->currentItem()) return; | 587 | if( !CurrentView()->currentItem()) return; |
582 | QDir *thisDir = CurrentDir(); | 588 | QDir *thisDir = CurrentDir(); |
583 | 589 | ||
584 | QString curFile; | 590 | QString curFile; |
585 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 591 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
586 | 592 | ||
587 | InputDialog *fileDlg; | 593 | InputDialog *fileDlg; |
588 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 594 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
589 | fileDlg->setInputText(curFile); | 595 | fileDlg->setInputText(curFile); |
590 | fileDlg->exec(); | 596 | fileDlg->exec(); |
591 | //QString command; | 597 | //QString command; |
592 | 598 | ||
593 | if( fileDlg->result() == 1 ) { | 599 | if( fileDlg->result() == 1 ) { |
594 | // odebug << fileDlg->LineEdit1->text() << oendl; | 600 | // odebug << fileDlg->LineEdit1->text() << oendl; |
595 | QStringList command; | 601 | QStringList command; |
596 | 602 | ||
597 | command << "/bin/sh"; | 603 | command << "/bin/sh"; |
598 | command << "-c"; | 604 | command << "-c"; |
599 | command << fileDlg->LineEdit1->text(); | 605 | command << fileDlg->LineEdit1->text(); |
600 | Output *outDlg; | 606 | Output *outDlg; |
601 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 607 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
602 | QPEApplication::execDialog( outDlg ); | 608 | QPEApplication::execDialog( outDlg ); |
603 | qApp->processEvents(); | 609 | qApp->processEvents(); |
604 | 610 | ||
605 | } | 611 | } |
606 | } | 612 | } |
607 | 613 | ||
608 | void AdvancedFm::runCommandStd() { | 614 | void AdvancedFm::runCommandStd() { |
609 | if( !CurrentView()->currentItem()) return; | 615 | if( !CurrentView()->currentItem()) return; |
610 | QString curFile; | 616 | QString curFile; |