-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 90c887f..26bc36d 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp | |||
@@ -547,304 +547,308 @@ bool AdvancedFm::copyFile( const QString & src, const QString & dest ) { | |||
547 | fstat (read_fd, &stat_buf); | 547 | fstat (read_fd, &stat_buf); |
548 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { | 548 | if( !destFile.open( IO_WriteOnly|IO_Raw ) ) { |
549 | // qWarning("destfile open failed"); | 549 | // qWarning("destfile open failed"); |
550 | return success = false; | 550 | return success = false; |
551 | } | 551 | } |
552 | write_fd = destFile.handle(); | 552 | write_fd = destFile.handle(); |
553 | if(write_fd != -1) { | 553 | if(write_fd != -1) { |
554 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); | 554 | err = sendfile(write_fd, read_fd, &offset, stat_buf.st_size); |
555 | if( err == -1) { | 555 | if( err == -1) { |
556 | QString msg; | 556 | QString msg; |
557 | switch(err) { | 557 | switch(err) { |
558 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; | 558 | case EBADF : msg = "The input file was not opened for reading or the output file was not opened for writing. "; |
559 | case EINVAL: msg = "Descriptor is not valid or locked. "; | 559 | case EINVAL: msg = "Descriptor is not valid or locked. "; |
560 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; | 560 | case ENOMEM: msg = "Insufficient memory to read from in_fd."; |
561 | case EIO: msg = "Unspecified error while reading from in_fd."; | 561 | case EIO: msg = "Unspecified error while reading from in_fd."; |
562 | }; | 562 | }; |
563 | success = false; | 563 | success = false; |
564 | // qWarning(msg); | 564 | // qWarning(msg); |
565 | } | 565 | } |
566 | } else { | 566 | } else { |
567 | success = false; | 567 | success = false; |
568 | } | 568 | } |
569 | } else { | 569 | } else { |
570 | success = false; | 570 | success = false; |
571 | } | 571 | } |
572 | srcFile.close(); | 572 | srcFile.close(); |
573 | destFile.close(); | 573 | destFile.close(); |
574 | // Set file permissions | 574 | // Set file permissions |
575 | if( stat( (const char *) src, &status ) == 0 ) { | 575 | if( stat( (const char *) src, &status ) == 0 ) { |
576 | chmod( (const char *) dest, status.st_mode ); | 576 | chmod( (const char *) dest, status.st_mode ); |
577 | } | 577 | } |
578 | 578 | ||
579 | return success; | 579 | return success; |
580 | } | 580 | } |
581 | 581 | ||
582 | void AdvancedFm::runCommand() { | 582 | void AdvancedFm::runCommand() { |
583 | if( !CurrentView()->currentItem()) return; | 583 | if( !CurrentView()->currentItem()) return; |
584 | QDir *thisDir = CurrentDir(); | 584 | QDir *thisDir = CurrentDir(); |
585 | 585 | ||
586 | QString curFile; | 586 | QString curFile; |
587 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); | 587 | curFile = thisDir->canonicalPath() +"/"+ CurrentView()->currentItem()->text(0); |
588 | 588 | ||
589 | InputDialog *fileDlg; | 589 | InputDialog *fileDlg; |
590 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 590 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
591 | fileDlg->setInputText(curFile); | 591 | fileDlg->setInputText(curFile); |
592 | fileDlg->exec(); | 592 | fileDlg->exec(); |
593 | //QString command; | 593 | //QString command; |
594 | 594 | ||
595 | if( fileDlg->result() == 1 ) { | 595 | if( fileDlg->result() == 1 ) { |
596 | // qDebug(fileDlg->LineEdit1->text()); | 596 | // qDebug(fileDlg->LineEdit1->text()); |
597 | QStringList command; | 597 | QStringList command; |
598 | 598 | ||
599 | command << "/bin/sh"; | 599 | command << "/bin/sh"; |
600 | command << "-c"; | 600 | command << "-c"; |
601 | command << fileDlg->LineEdit1->text(); | 601 | command << fileDlg->LineEdit1->text(); |
602 | Output *outDlg; | 602 | Output *outDlg; |
603 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 603 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
604 | outDlg->showMaximized(); | 604 | outDlg->showMaximized(); |
605 | outDlg->exec(); | 605 | outDlg->exec(); |
606 | qApp->processEvents(); | 606 | qApp->processEvents(); |
607 | 607 | ||
608 | } | 608 | } |
609 | } | 609 | } |
610 | 610 | ||
611 | void AdvancedFm::runCommandStd() { | 611 | void AdvancedFm::runCommandStd() { |
612 | if( !CurrentView()->currentItem()) return; | 612 | if( !CurrentView()->currentItem()) return; |
613 | QString curFile; | 613 | QString curFile; |
614 | QDir *thisDir = CurrentDir(); | 614 | QDir *thisDir = CurrentDir(); |
615 | QListView *thisView = CurrentView(); | 615 | QListView *thisView = CurrentView(); |
616 | if( thisView->currentItem()) | 616 | if( thisView->currentItem()) |
617 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); | 617 | curFile = thisDir->canonicalPath() +"/"+ thisView->currentItem()->text(0); |
618 | 618 | ||
619 | InputDialog *fileDlg; | 619 | InputDialog *fileDlg; |
620 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); | 620 | fileDlg = new InputDialog(this,tr("Run Command"),TRUE, 0); |
621 | fileDlg->setInputText(curFile); | 621 | fileDlg->setInputText(curFile); |
622 | fileDlg->exec(); | 622 | fileDlg->exec(); |
623 | 623 | ||
624 | if( fileDlg->result() == 1 ) { | 624 | if( fileDlg->result() == 1 ) { |
625 | qApp->processEvents(); | 625 | qApp->processEvents(); |
626 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); | 626 | startProcess( (const QString)fileDlg->LineEdit1->text().latin1()); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | 629 | ||
630 | void AdvancedFm::fileStatus() { | 630 | void AdvancedFm::fileStatus() { |
631 | if( !CurrentView()->currentItem()) return; | 631 | if( !CurrentView()->currentItem()) return; |
632 | QString curFile; | 632 | QString curFile; |
633 | curFile = CurrentView()->currentItem()->text(0); | 633 | curFile = CurrentView()->currentItem()->text(0); |
634 | 634 | ||
635 | QStringList command; | 635 | QStringList command; |
636 | command << "/bin/sh"; | 636 | command << "/bin/sh"; |
637 | command << "-c"; | 637 | command << "-c"; |
638 | command << "stat -l "+ curFile; | 638 | command << "stat -l "+ curFile; |
639 | 639 | ||
640 | Output *outDlg; | 640 | Output *outDlg; |
641 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); | 641 | outDlg = new Output( command, this, tr("AdvancedFm Output"), true); |
642 | outDlg->showMaximized(); | 642 | outDlg->showMaximized(); |
643 | outDlg->exec(); | 643 | outDlg->exec(); |
644 | qApp->processEvents(); | 644 | qApp->processEvents(); |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | void AdvancedFm::mkDir() { | 648 | void AdvancedFm::mkDir() { |
649 | makeDir(); | 649 | makeDir(); |
650 | } | 650 | } |
651 | 651 | ||
652 | void AdvancedFm::rn() { | 652 | void AdvancedFm::rn() { |
653 | renameIt(); | 653 | renameIt(); |
654 | } | 654 | } |
655 | 655 | ||
656 | void AdvancedFm::del() { | 656 | void AdvancedFm::del() { |
657 | doDelete(); | 657 | doDelete(); |
658 | } | 658 | } |
659 | 659 | ||
660 | void AdvancedFm::mkSym() { | 660 | void AdvancedFm::mkSym() { |
661 | QString cmd; | 661 | QString cmd; |
662 | QStringList curFileList = getPath(); | 662 | QStringList curFileList = getPath(); |
663 | if( curFileList.count() > 0) { | 663 | if( curFileList.count() > 0) { |
664 | QDir *thisDir = CurrentDir(); | 664 | QDir *thisDir = CurrentDir(); |
665 | QDir * thatDir = OtherDir(); | 665 | QDir * thatDir = OtherDir(); |
666 | 666 | ||
667 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 667 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
668 | 668 | ||
669 | QString destName = thatDir->canonicalPath()+"/"+(*it); | 669 | QString destName = thatDir->canonicalPath()+"/"+(*it); |
670 | if(destName.right(1) == "/") { | 670 | if(destName.right(1) == "/") { |
671 | destName = destName.left( destName.length() -1); | 671 | destName = destName.left( destName.length() -1); |
672 | } | 672 | } |
673 | 673 | ||
674 | QString curFile = thisDir->canonicalPath()+"/"+(*it); | 674 | QString curFile = thisDir->canonicalPath()+"/"+(*it); |
675 | 675 | ||
676 | if( curFile.right(1) == "/") { | 676 | if( curFile.right(1) == "/") { |
677 | curFile = curFile.left( curFile.length() -1); | 677 | curFile = curFile.left( curFile.length() -1); |
678 | } | 678 | } |
679 | 679 | ||
680 | cmd = "ln -s "+curFile+" "+destName; | 680 | cmd = "ln -s "+curFile+" "+destName; |
681 | // qDebug(cmd); | 681 | // qDebug(cmd); |
682 | startProcess( (const QString)cmd ); | 682 | startProcess( (const QString)cmd ); |
683 | } | 683 | } |
684 | rePopulate(); | 684 | rePopulate(); |
685 | setOtherTabCurrent(); | 685 | setOtherTabCurrent(); |
686 | } | 686 | } |
687 | } | 687 | } |
688 | 688 | ||
689 | void AdvancedFm::doBeam() { | 689 | void AdvancedFm::doBeam() { |
690 | Ir ir; | 690 | Ir ir; |
691 | if(!ir.supported()) { | 691 | if(!ir.supported()) { |
692 | } else { | 692 | } else { |
693 | QStringList curFileList = getPath(); | 693 | QStringList curFileList = getPath(); |
694 | if( curFileList.count() > 0) { | 694 | if( curFileList.count() > 0) { |
695 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { | 695 | for ( QStringList::Iterator it = curFileList.begin(); it != curFileList.end(); ++it ) { |
696 | QString curFile = (*it); | 696 | QString curFile = (*it); |
697 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; | 697 | QString curFilePath = CurrentDir()->canonicalPath()+"/"+curFile; |
698 | if( curFilePath.right(1) == "/") { | 698 | if( curFilePath.right(1) == "/") { |
699 | curFilePath = curFilePath.left( curFilePath.length() -1); | 699 | curFilePath = curFilePath.left( curFilePath.length() -1); |
700 | } | 700 | } |
701 | Ir *file = new Ir(this, "IR"); | 701 | Ir *file = new Ir(this, "IR"); |
702 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); | 702 | connect(file, SIGNAL(done(Ir*)), this, SLOT( fileBeamFinished( Ir * ))); |
703 | file->send( curFilePath, curFile ); | 703 | file->send( curFilePath, curFile ); |
704 | } | 704 | } |
705 | } | 705 | } |
706 | } | 706 | } |
707 | } | 707 | } |
708 | 708 | ||
709 | void AdvancedFm::fileBeamFinished( Ir *) { | 709 | void AdvancedFm::fileBeamFinished( Ir *) { |
710 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); | 710 | QMessageBox::message( tr("Advancedfm Beam out"), tr("Ir sent.") ,tr("Ok") ); |
711 | } | 711 | } |
712 | 712 | ||
713 | void AdvancedFm::selectAll() { | 713 | void AdvancedFm::selectAll() { |
714 | QListView *thisView = CurrentView(); | 714 | QListView *thisView = CurrentView(); |
715 | thisView->selectAll(true); | 715 | thisView->selectAll(true); |
716 | thisView->setSelected( thisView->firstChild(),false); | 716 | thisView->setSelected( thisView->firstChild(),false); |
717 | } | 717 | } |
718 | 718 | ||
719 | void AdvancedFm::startProcess(const QString & cmd) { | 719 | void AdvancedFm::startProcess(const QString & cmd) { |
720 | QStringList command; | 720 | QStringList command; |
721 | OProcess *process; | 721 | OProcess *process; |
722 | process = new OProcess(); | 722 | process = new OProcess(); |
723 | connect(process, SIGNAL(processExited(OProcess *)), | 723 | connect(process, SIGNAL(processExited(OProcess *)), |
724 | this, SLOT( processEnded(OProcess *))); | 724 | this, SLOT( processEnded(OProcess *))); |
725 | 725 | ||
726 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), | 726 | connect(process, SIGNAL( receivedStderr(OProcess *, char *, int)), |
727 | this, SLOT( oprocessStderr(OProcess *, char *, int))); | 727 | this, SLOT( oprocessStderr(OProcess *, char *, int))); |
728 | 728 | ||
729 | command << "/bin/sh"; | 729 | command << "/bin/sh"; |
730 | command << "-c"; | 730 | command << "-c"; |
731 | command << cmd.latin1(); | 731 | command << cmd.latin1(); |
732 | *process << command; | 732 | *process << command; |
733 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) | 733 | if(!process->start(OProcess::NotifyOnExit, OProcess::All) ) |
734 | qDebug("could not start process"); | 734 | qDebug("could not start process"); |
735 | } | 735 | } |
736 | 736 | ||
737 | void AdvancedFm::processEnded(OProcess *) { | 737 | void AdvancedFm::processEnded(OProcess *) { |
738 | rePopulate(); | 738 | rePopulate(); |
739 | } | 739 | } |
740 | 740 | ||
741 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { | 741 | void AdvancedFm::oprocessStderr(OProcess*, char *buffer, int ) { |
742 | // qWarning("received stderrt %d bytes", buflen); | 742 | // qWarning("received stderrt %d bytes", buflen); |
743 | 743 | ||
744 | QString lineStr = buffer; | 744 | QString lineStr = buffer; |
745 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); | 745 | QMessageBox::warning( this, tr("Error"), lineStr ,tr("Ok") ); |
746 | } | 746 | } |
747 | 747 | ||
748 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | 748 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { |
749 | if ( o->inherits( "QLineEdit" ) ) { | 749 | if ( o->inherits( "QLineEdit" ) ) { |
750 | if ( e->type() == QEvent::KeyPress ) { | 750 | if ( e->type() == QEvent::KeyPress ) { |
751 | QKeyEvent *ke = (QKeyEvent*)e; | 751 | QKeyEvent *ke = (QKeyEvent*)e; |
752 | if ( ke->key() == Key_Return || | 752 | if ( ke->key() == Key_Return || |
753 | ke->key() == Key_Enter ) { | 753 | ke->key() == Key_Enter ) { |
754 | okRename(); | 754 | okRename(); |
755 | return true; | 755 | return true; |
756 | } | 756 | } |
757 | else if ( ke->key() == Key_Escape ) { | 757 | else if ( ke->key() == Key_Escape ) { |
758 | cancelRename(); | 758 | cancelRename(); |
759 | return true; | 759 | return true; |
760 | } | 760 | } |
761 | } | 761 | } |
762 | else if ( e->type() == QEvent::FocusOut ) { | 762 | else if ( e->type() == QEvent::FocusOut ) { |
763 | cancelRename(); | 763 | cancelRename(); |
764 | return true; | 764 | return true; |
765 | } | 765 | } |
766 | } | 766 | } |
767 | if ( o->inherits( "QListView" ) ) { | 767 | if ( o->inherits( "QListView" ) ) { |
768 | if ( e->type() == QEvent::FocusIn ) { | 768 | if ( e->type() == QEvent::FocusIn ) { |
769 | if( o == Local_View) { //keep track of which view | 769 | if( o == Local_View) { //keep track of which view |
770 | whichTab=1; | 770 | whichTab=1; |
771 | } | 771 | } |
772 | else { | 772 | else { |
773 | whichTab=2; | 773 | whichTab=2; |
774 | } | 774 | } |
775 | } | 775 | } |
776 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection | 776 | OtherView()->setSelected( OtherView()->currentItem(), FALSE );//make sure there's correct selection |
777 | } | 777 | } |
778 | 778 | ||
779 | return QWidget::eventFilter( o, e ); | 779 | return QWidget::eventFilter( o, e ); |
780 | } | 780 | } |
781 | 781 | ||
782 | 782 | ||
783 | void AdvancedFm::cancelRename() { | 783 | void AdvancedFm::cancelRename() { |
784 | // qDebug("cancel rename"); | 784 | // qDebug("cancel rename"); |
785 | QListView * view; | 785 | QListView * view; |
786 | view = CurrentView(); | 786 | view = CurrentView(); |
787 | 787 | ||
788 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | 788 | bool resetFocus = view->viewport()->focusProxy() == renameBox; |
789 | delete renameBox; | 789 | delete renameBox; |
790 | renameBox = 0; | 790 | renameBox = 0; |
791 | if ( resetFocus ) { | 791 | if ( resetFocus ) { |
792 | view->viewport()->setFocusProxy( view); | 792 | view->viewport()->setFocusProxy( view); |
793 | view->setFocus(); | 793 | view->setFocus(); |
794 | } | 794 | } |
795 | } | 795 | } |
796 | 796 | ||
797 | void AdvancedFm::doRename(QListView * view) { | 797 | void AdvancedFm::doRename(QListView * view) { |
798 | if( !CurrentView()->currentItem()) return; | 798 | if( !CurrentView()->currentItem()) return; |
799 | 799 | ||
800 | QRect r = view->itemRect( view->currentItem( )); | 800 | QRect r = view->itemRect( view->currentItem( )); |
801 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | 801 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); |
802 | r.setX( view->contentsX() ); | 802 | r.setX( view->contentsX() ); |
803 | if ( r.width() > view->visibleWidth() ) | 803 | |
804 | if ( r.width() > view->visibleWidth() ) | ||
804 | r.setWidth( view->visibleWidth() ); | 805 | r.setWidth( view->visibleWidth() ); |
805 | 806 | ||
806 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | 807 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); |
807 | renameBox->setFrame(true); | 808 | renameBox->setFrame(true); |
808 | 809 | ||
809 | renameBox->setText( view->currentItem()->text(0) ); | 810 | renameBox->setText( view->currentItem()->text(0) ); |
810 | 811 | ||
811 | renameBox->selectAll(); | 812 | renameBox->selectAll(); |
812 | renameBox->installEventFilter( this ); | 813 | renameBox->installEventFilter( this ); |
814 | |||
813 | view->addChild( renameBox, r.x(), r.y() ); | 815 | view->addChild( renameBox, r.x(), r.y() ); |
814 | renameBox->resize( r.size() ); | 816 | |
815 | view->viewport()->setFocusProxy( renameBox ); | 817 | renameBox->resize( r.size() ); |
816 | renameBox->setFocus(); | 818 | |
819 | view->viewport()->setFocusProxy( renameBox ); | ||
820 | |||
821 | renameBox->setFocus(); | ||
817 | renameBox->show(); | 822 | renameBox->show(); |
818 | } | 823 | } |
819 | 824 | ||
820 | 825 | ||
821 | void AdvancedFm::renameIt() { | 826 | void AdvancedFm::renameIt() { |
822 | if( !CurrentView()->currentItem()) return; | 827 | if( !CurrentView()->currentItem()) return; |
823 | QListView *thisView = CurrentView(); | 828 | |
829 | QListView *thisView = CurrentView(); | ||
824 | oldName = thisView->currentItem()->text(0); | 830 | oldName = thisView->currentItem()->text(0); |
825 | doRename( thisView ); | 831 | doRename( thisView ); |
826 | rePopulate(); | ||
827 | } | 832 | } |
828 | 833 | ||
829 | void AdvancedFm::okRename() { | 834 | void AdvancedFm::okRename() { |
830 | if( !CurrentView()->currentItem()) return; | 835 | if( !CurrentView()->currentItem()) return; |
836 | |||
831 | QString newName = renameBox->text(); | 837 | QString newName = renameBox->text(); |
832 | cancelRename(); | 838 | cancelRename(); |
833 | QListView * view = CurrentView(); | 839 | QListView * view = CurrentView(); |
834 | QString path = CurrentDir()->canonicalPath() + "/"; | 840 | QString path = CurrentDir()->canonicalPath() + "/"; |
835 | oldName = path + oldName; | 841 | oldName = path + oldName; |
836 | newName = path + newName; | 842 | newName = path + newName; |
837 | |||
838 | if( rename( oldName.latin1(), newName.latin1())== -1) | 843 | if( rename( oldName.latin1(), newName.latin1())== -1) |
839 | QMessageBox::message(tr("Note"),tr("Could not rename")); | 844 | QMessageBox::message(tr("Note"),tr("Could not rename")); |
840 | else | 845 | else |
841 | oldName = ""; | 846 | oldName = ""; |
842 | |||
843 | view->takeItem( view->currentItem() ); | 847 | view->takeItem( view->currentItem() ); |
844 | delete view->currentItem(); | 848 | delete view->currentItem(); |
845 | rePopulate(); | 849 | rePopulate(); |
846 | } | 850 | } |
847 | 851 | ||
848 | void AdvancedFm::openSearch() { | 852 | void AdvancedFm::openSearch() { |
849 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); | 853 | QMessageBox::message(tr("Note"),tr("Not Yet Implemented")); |
850 | } | 854 | } |