author | zecke <zecke> | 2004-03-25 20:13:01 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-25 20:13:01 (UTC) |
commit | 1db459f8a2e3846397bef77bd0f47b70a0e01612 (patch) (unidiff) | |
tree | 4fc77e5b0f6f9cb77adee3e816e9c057c1c6264c | |
parent | 875064bec847768670d33cddf8553ce89ef4a5d5 (diff) | |
download | opie-1db459f8a2e3846397bef77bd0f47b70a0e01612.zip opie-1db459f8a2e3846397bef77bd0f47b70a0e01612.tar.gz opie-1db459f8a2e3846397bef77bd0f47b70a0e01612.tar.bz2 |
Do not rely on Qt magic.
Get the item, take it from the list, delete it
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 2461e26..81a4318 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -447,392 +447,393 @@ void AdvancedFm::move() { | |||
447 | 447 | ||
448 | curFile = thisDir->canonicalPath(); | 448 | curFile = thisDir->canonicalPath(); |
449 | if(curFile.right(1).find("/",0,TRUE) == -1) | 449 | if(curFile.right(1).find("/",0,TRUE) == -1) |
450 | curFile +="/"; | 450 | curFile +="/"; |
451 | curFile+= item; | 451 | curFile+= item; |
452 | // qDebug("CurrentFile file is " + curFile); | 452 | // qDebug("CurrentFile file is " + curFile); |
453 | 453 | ||
454 | if(QFileInfo(curFile).isDir()) { | 454 | if(QFileInfo(curFile).isDir()) { |
455 | moveDirectory( curFile, destFile ); | 455 | moveDirectory( curFile, destFile ); |
456 | rePopulate(); | 456 | rePopulate(); |
457 | return; | 457 | return; |
458 | } | 458 | } |
459 | 459 | ||
460 | QFile f( curFile); | 460 | QFile f( curFile); |
461 | if( f.exists()) { | 461 | if( f.exists()) { |
462 | if( !copyFile( curFile, destFile) ) { | 462 | if( !copyFile( curFile, destFile) ) { |
463 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); | 463 | QMessageBox::message(tr("Note"),tr("Could not move\n")+curFile); |
464 | return; | 464 | return; |
465 | } else | 465 | } else |
466 | QFile::remove(curFile); | 466 | QFile::remove(curFile); |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | } | 470 | } |
471 | rePopulate(); | 471 | rePopulate(); |
472 | setOtherTabCurrent(); | 472 | setOtherTabCurrent(); |
473 | } | 473 | } |
474 | 474 | ||
475 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { | 475 | bool AdvancedFm::moveDirectory( const QString & src, const QString & dest ) { |
476 | int err = 0; | 476 | int err = 0; |
477 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; | 477 | if( copyDirectory( src, dest ) ) { QString cmd = "rm -rf " + src; |
478 | err = system((const char*)cmd); | 478 | err = system((const char*)cmd); |
479 | } else | 479 | } else |
480 | err = -1; | 480 | err = -1; |
481 | 481 | ||
482 | if(err!=0) { | 482 | if(err!=0) { |
483 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); | 483 | QMessageBox::message(tr("Note"),tr("Could not move\n") + src); |
484 | return false; | 484 | return false; |
485 | } | 485 | } |
486 | return true; | 486 | return true; |
487 | } | 487 | } |
488 | 488 | ||
489 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { | 489 | bool AdvancedFm::copyDirectory( const QString & src, const QString & dest ) { |
490 | 490 | ||
491 | QString cmd = "/bin/cp -fpR " + src + " " + dest; | 491 | QString cmd = "/bin/cp -fpR " + src + " " + dest; |
492 | qWarning(cmd); | 492 | qWarning(cmd); |
493 | int err = system( (const char *) cmd ); | 493 | int err = system( (const char *) cmd ); |
494 | if ( err != 0 ) { | 494 | if ( err != 0 ) { |
495 | QMessageBox::message("AdvancedFm", | 495 | QMessageBox::message("AdvancedFm", |
496 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); | 496 | tr( "Could not copy \n%1 \nto \n%2").arg( src ).arg( dest ) ); |
497 | return false; | 497 | return false; |
498 | } | 498 | } |
499 | 499 | ||
500 | return true; | 500 | return true; |
501 | } | 501 | } |
502 | 502 | ||
503 | 503 | ||
504 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | 504 | bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { |
505 | 505 | ||
506 | 506 | ||
507 | if(QFileInfo(src).isDir()) { | 507 | if(QFileInfo(src).isDir()) { |
508 | if( copyDirectory( src, dest )) { | 508 | if( copyDirectory( src, dest )) { |
509 | setOtherTabCurrent(); | 509 | setOtherTabCurrent(); |
510 | populateView(); | 510 | populateView(); |
511 | return true; | 511 | return true; |
512 | } | 512 | } |
513 | else | 513 | else |
514 | return false; | 514 | return false; |
515 | } | 515 | } |
516 | 516 | ||
517 | 517 | ||
518 | bool success = true; | 518 | bool success = true; |
519 | struct stat status; | 519 | struct stat status; |
520 | QFile srcFile(src); | 520 | QFile srcFile(src); |
521 | QFile destFile(dest); | 521 | QFile destFile(dest); |
522 | int err=0; | 522 | int err=0; |
523 | int read_fd=0; | 523 | int read_fd=0; |
524 | int write_fd=0; | 524 | int write_fd=0; |
525 | struct stat stat_buf; | 525 | struct stat stat_buf; |
526 | off_t offset = 0; | 526 | off_t offset = 0; |
527 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { | 527 | if(!srcFile.open( IO_ReadOnly|IO_Raw)) { |
528 | // qWarning("open failed"); | 528 | // qWarning("open failed"); |
529 | return success = false; | 529 | return success = false; |
530 | } | 530 | } |
531 | read_fd = srcFile.handle(); | 531 | read_fd = srcFile.handle(); |
532 | if(read_fd != -1) { | 532 | if(read_fd != -1) { |
533 | fstat (read_fd, &stat_buf); | 533 | fstat (read_fd, &stat_buf); |
534 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 534 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
535 | // qWarning("destfile open failed"); | 535 | // qWarning("destfile open failed"); |
536 | return success = false; | 536 | return success = false; |
537 | } | 537 | } |
538 | write_fd = destFile.handle(); | 538 | write_fd = destFile.handle(); |
539 | if(write_fd != -1) { | 539 | if(write_fd != -1) { |
540 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 540 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
541 | if( err == -1) { | 541 | if( err == -1) { |
542 | QString msg; | 542 | QString msg; |
543 | switch(err) { | 543 | switch(err) { |
544 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 544 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; |
545 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 545 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
546 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 546 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
547 | case EIO: msg = "Unspecified error while reading from in_fd."; | 547 | case EIO: msg = "Unspecified error while reading from in_fd."; |
548 | }; | 548 | }; |
549 | success = false; | 549 | success = false; |
550 | // qWarning(msg); | 550 | // qWarning(msg); |
551 | } | 551 | } |
552 | } else { | 552 | } else { |
553 | success = false; | 553 | success = false; |
554 | } | 554 | } |
555 | } else { | 555 | } else { |
556 | success = false; | 556 | success = false; |
557 | } | 557 | } |
558 | srcFile.close(); | 558 | srcFile.close(); |
559 | destFile.close(); | 559 | destFile.close(); |
560 | // Set file permissions | 560 | // Set file permissions |
561 | if( stat( (const char *) src, &status ) == 0 ) { | 561 | if( stat( (const char *) src, &status ) == 0 ) { |
562 | chmod( (const char *) dest, status.st_mode ); | 562 | chmod( (const char *) dest, status.st_mode ); |
563 | } | 563 | } |
564 | 564 | ||
565 | return success; | 565 | return success; |
566 | } | 566 | } |
567 | 567 | ||
568 | void AdvancedFm::runCommand() { | 568 | void AdvancedFm::runCommand() { |
569 | if( !CurrentView()->currentItem()) return; | 569 | if( !CurrentView()->currentItem()) return; |
570 | QDir *thisDir = CurrentDir(); | 570 | QDir *thisDir = CurrentDir(); |
571 | 571 | ||
572 | QString curFile; | 572 | QString curFile; |
573 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 573 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
574 | 574 | ||
575 | InputDialog *fileDlg; | 575 | InputDialog *fileDlg; |
576 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 576 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
577 | fileDlg->setInputText(curFile); | 577 | fileDlg->setInputText(curFile); |
578 | fileDlg->exec(); | 578 | fileDlg->exec(); |
579 | //QString command; | 579 | //QString command; |
580 | 580 | ||
581 | if( fileDlg->result() == 1 ) { | 581 | if( fileDlg->result() == 1 ) { |
582 | // qDebug(fileDlg->LineEdit1->text()); | 582 | // qDebug(fileDlg->LineEdit1->text()); |
583 | QStringList command; | 583 | QStringList command; |
584 | 584 | ||
585 | command << "/bin/sh"; | 585 | command << "/bin/sh"; |
586 | command << "-c"; | 586 | command << "-c"; |
587 | command << fileDlg->LineEdit1->text(); | 587 | command << fileDlg->LineEdit1->text(); |
588 | Output *outDlg; | 588 | Output *outDlg; |
589 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 589 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
590 | QPEApplication::execDialog( outDlg ); | 590 | QPEApplication::execDialog( outDlg ); |
591 | qApp->processEvents(); | 591 | qApp->processEvents(); |
592 | 592 | ||
593 | } | 593 | } |
594 | } | 594 | } |
595 | 595 | ||
596 | void AdvancedFm::runCommandStd() { | 596 | void AdvancedFm::runCommandStd() { |
597 | if( !CurrentView()->currentItem()) return; | 597 | if( !CurrentView()->currentItem()) return; |
598 | QString curFile; | 598 | QString curFile; |
599 | QDir *thisDir = CurrentDir(); | 599 | QDir *thisDir = CurrentDir(); |
600 | QListView *thisView = CurrentView(); | 600 | QListView *thisView = CurrentView(); |
601 | if( thisView->currentItem()) | 601 | if( thisView->currentItem()) |
602 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); | 602 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); |
603 | 603 | ||
604 | InputDialog *fileDlg; | 604 | InputDialog *fileDlg; |
605 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 605 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
606 | fileDlg->setInputText(curFile); | 606 | fileDlg->setInputText(curFile); |
607 | fileDlg->exec(); | 607 | fileDlg->exec(); |
608 | 608 | ||
609 | if( fileDlg->result() == 1 ) { | 609 | if( fileDlg->result() == 1 ) { |
610 | qApp->processEvents(); | 610 | qApp->processEvents(); |
611 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); | 611 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); |
612 | } | 612 | } |
613 | } | 613 | } |
614 | 614 | ||
615 | void AdvancedFm::fileStatus() { | 615 | void AdvancedFm::fileStatus() { |
616 | if( !CurrentView()->currentItem()) return; | 616 | if( !CurrentView()->currentItem()) return; |
617 | QString curFile; | 617 | QString curFile; |
618 | curFile = CurrentView()->currentItem()->text(0); | 618 | curFile = CurrentView()->currentItem()->text(0); |
619 | 619 | ||
620 | QStringList command; | 620 | QStringList command; |
621 | command << "/bin/sh"; | 621 | command << "/bin/sh"; |
622 | command << "-c"; | 622 | command << "-c"; |
623 | command << "stat -l "+ curFile; | 623 | command << "stat -l "+ curFile; |
624 | 624 | ||
625 | Output *outDlg; | 625 | Output *outDlg; |
626 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 626 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
627 | QPEApplication::execDialog( outDlg ); | 627 | QPEApplication::execDialog( outDlg ); |
628 | qApp->processEvents(); | 628 | qApp->processEvents(); |
629 | } | 629 | } |
630 | 630 | ||
631 | 631 | ||
632 | void AdvancedFm::mkDir() { | 632 | void AdvancedFm::mkDir() { |
633 | makeDir(); | 633 | makeDir(); |
634 | } | 634 | } |
635 | 635 | ||
636 | void AdvancedFm::rn() { | 636 | void AdvancedFm::rn() { |
637 | renameIt(); | 637 | renameIt(); |
638 | } | 638 | } |
639 | 639 | ||
640 | void AdvancedFm::del() { | 640 | void AdvancedFm::del() { |
641 | doDelete(); | 641 | doDelete(); |
642 | } | 642 | } |
643 | 643 | ||
644 | void AdvancedFm::mkSym() { | 644 | void AdvancedFm::mkSym() { |
645 | QString cmd; | 645 | QString cmd; |
646 | QStringList curFileList = getPath(); | 646 | QStringList curFileList = getPath(); |
647 | if( curFileList.count() > 0) { | 647 | if( curFileList.count() > 0) { |
648 | QDir *thisDir = CurrentDir(); | 648 | QDir *thisDir = CurrentDir(); |
649 | QDir * thatDir = OtherDir(); | 649 | QDir * thatDir = OtherDir(); |
650 | 650 | ||
651 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 651 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
652 | 652 | ||
653 | QString destName = thatDir->canonicalPath()+"/"+(*it); | 653 | QString destName = thatDir->canonicalPath()+"/"+(*it); |
654 | if(destName.right(1) == "/") { | 654 | if(destName.right(1) == "/") { |
655 | destName = destName.left( destName.length() -1); | 655 | destName = destName.left( destName.length() -1); |
656 | } | 656 | } |
657 | 657 | ||
658 | QString curFile = thisDir->canonicalPath()+"/"+(*it); | 658 | QString curFile = thisDir->canonicalPath()+"/"+(*it); |
659 | 659 | ||
660 | if( curFile.right(1) == "/") { | 660 | if( curFile.right(1) == "/") { |
661 | curFile = curFile.left( curFile.length() -1); | 661 | curFile = curFile.left( curFile.length() -1); |
662 | } | 662 | } |
663 | 663 | ||
664 | cmd = "ln -s "+curFile+" "+destName; | 664 | cmd = "ln -s "+curFile+" "+destName; |
665 | // qDebug(cmd); | 665 | // qDebug(cmd); |
666 | startProcess( (const QString)cmd ); | 666 | startProcess( (const QString)cmd ); |
667 | } | 667 | } |
668 | rePopulate(); | 668 | rePopulate(); |
669 | setOtherTabCurrent(); | 669 | setOtherTabCurrent(); |
670 | } | 670 | } |
671 | } | 671 | } |
672 | 672 | ||
673 | void AdvancedFm::doBeam() { | 673 | void AdvancedFm::doBeam() { |
674 | Ir ir; | 674 | Ir ir; |
675 | if(!ir.supported()) { | 675 | if(!ir.supported()) { |
676 | } else { | 676 | } else { |
677 | QStringList curFileList = getPath(); | 677 | QStringList curFileList = getPath(); |
678 | if( curFileList.count() > 0) { | 678 | if( curFileList.count() > 0) { |
679 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 679 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
680 | QString curFile = (*it); | 680 | QString curFile = (*it); |
681 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; | 681 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; |
682 | if( curFilePath.right(1) == "/") { | 682 | if( curFilePath.right(1) == "/") { |
683 | curFilePath = curFilePath.left( curFilePath.length() -1); | 683 | curFilePath = curFilePath.left( curFilePath.length() -1); |
684 | } | 684 | } |
685 | Ir *file = new Ir(this, "IR"); | 685 | Ir *file = new Ir(this, "IR"); |
686 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*))); | 686 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished(Ir*))); |
687 | file->send( curFilePath, curFile ); | 687 | file->send( curFilePath, curFile ); |
688 | } | 688 | } |
689 | } | 689 | } |
690 | } | 690 | } |
691 | } | 691 | } |
692 | 692 | ||
693 | void AdvancedFm::fileBeamFinished( Ir *) { | 693 | void AdvancedFm::fileBeamFinished( Ir *) { |
694 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); | 694 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); |
695 | } | 695 | } |
696 | 696 | ||
697 | void AdvancedFm::selectAll() { | 697 | void AdvancedFm::selectAll() { |
698 | QListView *thisView = CurrentView(); | 698 | QListView *thisView = CurrentView(); |
699 | thisView->selectAll(true); | 699 | thisView->selectAll(true); |
700 | thisView->setSelected( thisView->firstChild(),false); | 700 | thisView->setSelected( thisView->firstChild(),false); |
701 | } | 701 | } |
702 | 702 | ||
703 | void AdvancedFm::startProcess(const QString & cmd) { | 703 | void AdvancedFm::startProcess(const QString & cmd) { |
704 | QStringList command; | 704 | QStringList command; |
705 | OProcess *process; | 705 | OProcess *process; |
706 | process = new OProcess(); | 706 | process = new OProcess(); |
707 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), | 707 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), |
708 | this, SLOT( processEnded(Opie::Core::OProcess*))); | 708 | this, SLOT( processEnded(Opie::Core::OProcess*))); |
709 | 709 | ||
710 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), | 710 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), |
711 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); | 711 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); |
712 | 712 | ||
713 | command << "/bin/sh"; | 713 | command << "/bin/sh"; |
714 | command << "-c"; | 714 | command << "-c"; |
715 | command << cmd.latin1(); | 715 | command << cmd.latin1(); |
716 | *process << command; | 716 | *process << command; |
717 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) | 717 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) |
718 | qDebug("could not start process"); | 718 | qDebug("could not start process"); |
719 | } | 719 | } |
720 | 720 | ||
721 | void AdvancedFm::processEnded(OProcess *) { | 721 | void AdvancedFm::processEnded(OProcess *) { |
722 | rePopulate(); | 722 | rePopulate(); |
723 | } | 723 | } |
724 | 724 | ||
725 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { | 725 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { |
726 | // qWarning("received stderrt %d bytes", buflen); | 726 | // qWarning("received stderrt %d bytes", buflen); |
727 | 727 | ||
728 | QString lineStr = buffer; | 728 | QString lineStr = buffer; |
729 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); | 729 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); |
730 | } | 730 | } |
731 | 731 | ||
732 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | 732 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { |
733 | if ( o->inherits( "QLineEdit" ) ) { | 733 | if ( o->inherits( "QLineEdit" ) ) { |
734 | if ( e->type() == QEvent::KeyPress ) { | 734 | if ( e->type() == QEvent::KeyPress ) { |
735 | QKeyEvent *ke = (QKeyEvent*)e; | 735 | QKeyEvent *ke = (QKeyEvent*)e; |
736 | if ( ke->key() == Key_Return || | 736 | if ( ke->key() == Key_Return || |
737 | ke->key() == Key_Enter ) { | 737 | ke->key() == Key_Enter ) { |
738 | okRename(); | 738 | okRename(); |
739 | return true; | 739 | return true; |
740 | } | 740 | } |
741 | else if ( ke->key() == Key_Escape ) { | 741 | else if ( ke->key() == Key_Escape ) { |
742 | cancelRename(); | 742 | cancelRename(); |
743 | return true; | 743 | return true; |
744 | } | 744 | } |
745 | } | 745 | } |
746 | else if ( e->type() == QEvent::FocusOut ) { | 746 | else if ( e->type() == QEvent::FocusOut ) { |
747 | cancelRename(); | 747 | cancelRename(); |
748 | return true; | 748 | return true; |
749 | } | 749 | } |
750 | } | 750 | } |
751 | if ( o->inherits( "QListView" ) ) { | 751 | if ( o->inherits( "QListView" ) ) { |
752 | if ( e->type() == QEvent::FocusIn ) { | 752 | if ( e->type() == QEvent::FocusIn ) { |
753 | if( o == Local_View) { //keep track of which view | 753 | if( o == Local_View) { //keep track of which view |
754 | whichTab=1; | 754 | whichTab=1; |
755 | } | 755 | } |
756 | else { | 756 | else { |
757 | whichTab=2; | 757 | whichTab=2; |
758 | } | 758 | } |
759 | } | 759 | } |
760 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection | 760 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection |
761 | } | 761 | } |
762 | 762 | ||
763 | return QWidget::eventFilter( o, e ); | 763 | return QWidget::eventFilter( o, e ); |
764 | } | 764 | } |
765 | 765 | ||
766 | 766 | ||
767 | void AdvancedFm::cancelRename() { | 767 | void AdvancedFm::cancelRename() { |
768 | // qDebug("cancel rename"); | 768 | // qDebug("cancel rename"); |
769 | QListView * view; | 769 | QListView * view; |
770 | view = CurrentView(); | 770 | view = CurrentView(); |
771 | 771 | ||
772 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | 772 | bool resetFocus = view->viewport()->focusProxy() == renameBox; |
773 | delete renameBox; | 773 | delete renameBox; |
774 | renameBox = 0; | 774 | renameBox = 0; |
775 | if ( resetFocus ) { | 775 | if ( resetFocus ) { |
776 | view->viewport()->setFocusProxy( view); | 776 | view->viewport()->setFocusProxy( view); |
777 | view->setFocus(); | 777 | view->setFocus(); |
778 | } | 778 | } |
779 | } | 779 | } |
780 | 780 | ||
781 | void AdvancedFm::doRename(QListView * view) { | 781 | void AdvancedFm::doRename(QListView * view) { |
782 | if( !CurrentView()->currentItem()) return; | 782 | if( !CurrentView()->currentItem()) return; |
783 | 783 | ||
784 | QRect r = view->itemRect( view->currentItem( )); | 784 | QRect r = view->itemRect( view->currentItem( )); |
785 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | 785 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); |
786 | r.setX( view->contentsX() ); | 786 | r.setX( view->contentsX() ); |
787 | 787 | ||
788 | if ( r.width() > view->visibleWidth() ) | 788 | if ( r.width() > view->visibleWidth() ) |
789 | r.setWidth( view->visibleWidth() ); | 789 | r.setWidth( view->visibleWidth() ); |
790 | 790 | ||
791 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | 791 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); |
792 | renameBox->setFrame(true); | 792 | renameBox->setFrame(true); |
793 | 793 | ||
794 | renameBox->setText( view->currentItem()->text(0) ); | 794 | renameBox->setText( view->currentItem()->text(0) ); |
795 | 795 | ||
796 | renameBox->selectAll(); | 796 | renameBox->selectAll(); |
797 | renameBox->installEventFilter( this ); | 797 | renameBox->installEventFilter( this ); |
798 | 798 | ||
799 | view->addChild( renameBox, r.x(), r.y() ); | 799 | view->addChild( renameBox, r.x(), r.y() ); |
800 | 800 | ||
801 | renameBox->resize( r.size() ); | 801 | renameBox->resize( r.size() ); |
802 | 802 | ||
803 | view->viewport()->setFocusProxy( renameBox ); | 803 | view->viewport()->setFocusProxy( renameBox ); |
804 | 804 | ||
805 | renameBox->setFocus(); | 805 | renameBox->setFocus(); |
806 | renameBox->show(); | 806 | renameBox->show(); |
807 | } | 807 | } |
808 | 808 | ||
809 | 809 | ||
810 | void AdvancedFm::renameIt() { | 810 | void AdvancedFm::renameIt() { |
811 | if( !CurrentView()->currentItem()) return; | 811 | if( !CurrentView()->currentItem()) return; |
812 | 812 | ||
813 | QListView *thisView = CurrentView(); | 813 | QListView *thisView = CurrentView(); |
814 | oldName = thisView->currentItem()->text(0); | 814 | oldName = thisView->currentItem()->text(0); |
815 | doRename( thisView ); | 815 | doRename( thisView ); |
816 | } | 816 | } |
817 | 817 | ||
818 | void AdvancedFm::okRename() { | 818 | void AdvancedFm::okRename() { |
819 | if( !renameBox) return; | 819 | if( !renameBox) return; |
820 | 820 | ||
821 | QString newName = renameBox->text(); | 821 | QString newName = renameBox->text(); |
822 | cancelRename(); | 822 | cancelRename(); |
823 | QListView * view = CurrentView(); | 823 | QListView * view = CurrentView(); |
824 | QString path = CurrentDir()->canonicalPath() + "/"; | 824 | QString path = CurrentDir()->canonicalPath() + "/"; |
825 | oldName = path + oldName; | 825 | oldName = path + oldName; |
826 | newName = path + newName; | 826 | newName = path + newName; |
827 | if( rename( oldName.latin1(), newName.latin1())== -1) | 827 | if( rename( oldName.latin1(), newName.latin1())== -1) |
828 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 828 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
829 | else | 829 | else |
830 | oldName = ""; | 830 | oldName = ""; |
831 | view->takeItem( view->currentItem() ); | 831 | QListViewItem *item = view->currentItem(); |
832 | delete view->currentItem(); | 832 | view->takeItem( item ); |
833 | delete item; | ||
833 | rePopulate(); | 834 | rePopulate(); |
834 | } | 835 | } |
835 | 836 | ||
836 | void AdvancedFm::openSearch() { | 837 | void AdvancedFm::openSearch() { |
837 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); | 838 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); |
838 | } | 839 | } |