-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index 718f743..74aca96 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp | |||
@@ -49,32 +49,42 @@ | |||
49 | #include <qhbox.h> | 49 | #include <qhbox.h> |
50 | #include <qheader.h> | 50 | #include <qheader.h> |
51 | #include <qlabel.h> | 51 | #include <qlabel.h> |
52 | #include <qlayout.h> | 52 | #include <qlayout.h> |
53 | #include <qlineedit.h> | 53 | #include <qlineedit.h> |
54 | #include <qlistview.h> | 54 | #include <qlistview.h> |
55 | #include <qpopupmenu.h> | 55 | #include <qpopupmenu.h> |
56 | #include <qwidgetstack.h> | 56 | #include <qwidgetstack.h> |
57 | #include <qregexp.h> | 57 | #include <qregexp.h> |
58 | #include <qobjectlist.h> | 58 | #include <qobjectlist.h> |
59 | 59 | ||
60 | using namespace Opie::Ui::Internal; | 60 | using namespace Opie::Ui::Internal; |
61 | 61 | ||
62 | namespace Opie { | 62 | namespace Opie { |
63 | namespace Ui { | 63 | namespace Ui { |
64 | namespace Internal { | 64 | namespace Internal { |
65 | /* | ||
66 | * Create a path by adding a '/'/QDir::seperator in between | ||
67 | * base and ending, but only if base is not empty | ||
68 | */ | ||
69 | static inline QString createNewPath(const QString& base, const QString &ending) { | ||
70 | return base == QString::fromLatin1("/") ? | ||
71 | base + ending : base + "/" + ending; | ||
72 | } | ||
73 | |||
74 | |||
65 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) | 75 | OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) |
66 | : m_selector( _selector ) | 76 | : m_selector( _selector ) |
67 | { | 77 | { |
68 | selector()->registerView( this ); | 78 | selector()->registerView( this ); |
69 | } | 79 | } |
70 | 80 | ||
71 | OFileViewInterface::~OFileViewInterface() | 81 | OFileViewInterface::~OFileViewInterface() |
72 | {} | 82 | {} |
73 | 83 | ||
74 | QString OFileViewInterface::name()const | 84 | QString OFileViewInterface::name()const |
75 | { | 85 | { |
76 | return m_name; | 86 | return m_name; |
77 | } | 87 | } |
78 | 88 | ||
79 | void OFileViewInterface::setName( const QString& name ) | 89 | void OFileViewInterface::setName( const QString& name ) |
80 | { | 90 | { |
@@ -457,54 +467,54 @@ void OFileViewFileListView::reread( bool all ) | |||
457 | QFileInfoListIterator it( *list ); | 467 | QFileInfoListIterator it( *list ); |
458 | QFileInfo *fi; | 468 | QFileInfo *fi; |
459 | while( (fi=it.current() ) ) | 469 | while( (fi=it.current() ) ) |
460 | { | 470 | { |
461 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) | 471 | if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) |
462 | { | 472 | { |
463 | ++it; | 473 | ++it; |
464 | continue; | 474 | continue; |
465 | } | 475 | } |
466 | 476 | ||
467 | /* | 477 | /* |
468 | * It is a symlink we try to resolve it now but don't let us attack by DOS | 478 | * It is a symlink we try to resolve it now but don't let us attack by DOS |
469 | * | 479 | * |
470 | */ | 480 | */ |
471 | if( fi->isSymLink() ) | 481 | if( fi->isSymLink() ) |
472 | { | 482 | { |
473 | QString file = fi->dirPath( true ) + "/" + fi->readLink(); | 483 | QString file = createNewPath(fi->dirPath( true ),fi->readLink()); |
474 | for( int i = 0; i<=4; i++) | 484 | for( int i = 0; i<=4; i++) |
475 | { // 5 tries to prevent dos | 485 | { // 5 tries to prevent dos |
476 | QFileInfo info( file ); | 486 | QFileInfo info( file ); |
477 | if( !info.exists() ) | 487 | if( !info.exists() ) |
478 | { | 488 | { |
479 | addSymlink( fi, TRUE ); | 489 | addSymlink( fi, TRUE ); |
480 | break; | 490 | break; |
481 | } | 491 | } |
482 | else if( info.isDir() ) | 492 | else if( info.isDir() ) |
483 | { | 493 | { |
484 | addDir( fi, TRUE ); | 494 | addDir( fi, TRUE ); |
485 | break; | 495 | break; |
486 | } | 496 | } |
487 | else if( info.isFile() ) | 497 | else if( info.isFile() ) |
488 | { | 498 | { |
489 | addFile( fi, TRUE ); | 499 | addFile( fi, TRUE ); |
490 | break; | 500 | break; |
491 | } | 501 | } |
492 | else if( info.isSymLink() ) | 502 | else if( info.isSymLink() ) |
493 | { | 503 | { |
494 | file = info.dirPath(true ) + "/" + info.readLink() ; | 504 | file = createNewPath(info.dirPath(true ),info.readLink()); |
495 | break; | 505 | break; |
496 | } | 506 | } |
497 | else if( i == 4) | 507 | else if( i == 4) |
498 | { // couldn't resolve symlink add it as symlink | 508 | { // couldn't resolve symlink add it as symlink |
499 | addSymlink( fi ); | 509 | addSymlink( fi ); |
500 | } | 510 | } |
501 | } // off for loop for symlink resolving | 511 | } // off for loop for symlink resolving |
502 | } | 512 | } |
503 | else if( fi->isDir() ) | 513 | else if( fi->isDir() ) |
504 | addDir( fi ); | 514 | addDir( fi ); |
505 | else if( fi->isFile() ) | 515 | else if( fi->isFile() ) |
506 | addFile( fi ); | 516 | addFile( fi ); |
507 | 517 | ||
508 | ++it; | 518 | ++it; |
509 | } // of while loop | 519 | } // of while loop |
510 | m_view->sort(); | 520 | m_view->sort(); |
@@ -550,118 +560,118 @@ void OFileViewFileListView::connectSlots() | |||
550 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | 560 | void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) |
551 | { | 561 | { |
552 | if (!item) | 562 | if (!item) |
553 | return; | 563 | return; |
554 | #if 0 | 564 | #if 0 |
555 | 565 | ||
556 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 566 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
557 | 567 | ||
558 | if (!sel->isDir() ) | 568 | if (!sel->isDir() ) |
559 | { | 569 | { |
560 | selector()->m_lneEdit->setText( sel->text(1) ); | 570 | selector()->m_lneEdit->setText( sel->text(1) ); |
561 | // if in fileselector mode we will emit selected | 571 | // if in fileselector mode we will emit selected |
562 | if ( selector()->mode() == OFileSelector::FileSelector ) | 572 | if ( selector()->mode() == OFileSelector::FileSelector ) |
563 | { | 573 | { |
564 | odebug << "slot Current Changed" << oendl; | 574 | odebug << "slot Current Changed" << oendl; |
565 | QStringList str = QStringList::split("->", sel->text(1) ); | 575 | QStringList str = QStringList::split("->", sel->text(1) ); |
566 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 576 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
567 | emit selector()->fileSelected( path ); | 577 | emit selector()->fileSelected( path ); |
568 | DocLnk lnk( path ); | 578 | DocLnk lnk( path ); |
569 | emit selector()->fileSelected( lnk ); | 579 | emit selector()->fileSelected( lnk ); |
570 | } | 580 | } |
571 | } | 581 | } |
572 | #endif | 582 | #endif |
573 | } | 583 | } |
574 | 584 | ||
575 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) | 585 | void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) |
576 | { | 586 | { |
577 | if (!item || ( button != Qt::LeftButton) ) | 587 | if (!item || ( button != Qt::LeftButton) ) |
578 | return; | 588 | return; |
579 | 589 | ||
580 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); | 590 | OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); |
581 | if (!sel->isLocked() ) | 591 | if (!sel->isLocked() ) |
582 | { | 592 | { |
583 | QStringList str = QStringList::split("->", sel->text(1) ); | 593 | QStringList str = QStringList::split("->", sel->text(1) ); |
584 | if (sel->isDir() ) | 594 | if (sel->isDir() ) |
585 | { | 595 | { |
586 | m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace(); | 596 | m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
587 | emit selector()->dirSelected( m_currentDir ); | 597 | emit selector()->dirSelected( m_currentDir ); |
588 | reread( m_all ); | 598 | reread( m_all ); |
589 | } | 599 | } |
590 | else | 600 | else |
591 | { // file | 601 | { // file |
592 | odebug << "slot Clicked" << oendl; | 602 | odebug << "slot Clicked" << oendl; |
593 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); | 603 | selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); |
594 | QString path = sel->directory() + "/" + str[0].stripWhiteSpace(); | 604 | QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); |
595 | emit selector()->fileSelected( path ); | 605 | emit selector()->fileSelected( path ); |
596 | DocLnk lnk( path ); | 606 | DocLnk lnk( path ); |
597 | emit selector()->fileSelected( lnk ); | 607 | emit selector()->fileSelected( lnk ); |
598 | } | 608 | } |
599 | } // not locked | 609 | } // not locked |
600 | } | 610 | } |
601 | 611 | ||
602 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | 612 | void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) |
603 | { | 613 | { |
604 | MimeType type( info->absFilePath() ); | 614 | MimeType type( info->absFilePath() ); |
605 | if (!compliesMime( type.id() ) ) | 615 | if (!compliesMime( type.id() ) ) |
606 | return; | 616 | return; |
607 | 617 | ||
608 | QPixmap pix = type.pixmap(); | 618 | QPixmap pix = type.pixmap(); |
609 | QString dir, name; bool locked; | 619 | QString dir, name; bool locked; |
610 | if ( pix.isNull() ) | 620 | if ( pix.isNull() ) |
611 | { | 621 | { |
612 | QWMatrix matrix; | 622 | QWMatrix matrix; |
613 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); | 623 | QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); |
614 | matrix.scale( .4, .4 ); | 624 | matrix.scale( .4, .4 ); |
615 | pix = pixer.xForm( matrix ); | 625 | pix = pixer.xForm( matrix ); |
616 | } | 626 | } |
617 | dir = info->dirPath( true ); | 627 | dir = info->dirPath( true ); |
618 | locked = false; | 628 | locked = false; |
619 | if ( symlink ) | 629 | if ( symlink ) |
620 | name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink(); | 630 | name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); |
621 | else | 631 | else |
622 | { | 632 | { |
623 | name = info->fileName(); | 633 | name = info->fileName(); |
624 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || | 634 | if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || |
625 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) | 635 | ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) |
626 | { | 636 | { |
627 | locked = true; pix = Resource::loadPixmap("locked"); | 637 | locked = true; pix = Resource::loadPixmap("locked"); |
628 | } | 638 | } |
629 | } | 639 | } |
630 | (void)new OFileSelectorItem( m_view, pix, name, | 640 | (void)new OFileSelectorItem( m_view, pix, name, |
631 | info->lastModified().toString(), QString::number( info->size() ), | 641 | info->lastModified().toString(), QString::number( info->size() ), |
632 | dir, locked ); | 642 | dir, locked ); |
633 | } | 643 | } |
634 | 644 | ||
635 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | 645 | void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) |
636 | { | 646 | { |
637 | bool locked = false; QString name; QPixmap pix; | 647 | bool locked = false; QString name; QPixmap pix; |
638 | 648 | ||
639 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || | 649 | if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || |
640 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) | 650 | ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) |
641 | { | 651 | { |
642 | locked = true; | 652 | locked = true; |
643 | if ( symlink ) | 653 | if ( symlink ) |
644 | pix = Resource::loadPixmap( "opie/symlink" ); | 654 | pix = Resource::loadPixmap( "opie/symlink" ); |
645 | else | 655 | else |
646 | pix = Resource::loadPixmap( "lockedfolder" ); | 656 | pix = Resource::loadPixmap( "lockedfolder" ); |
647 | } | 657 | } |
648 | else | 658 | else |
649 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); | 659 | pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); |
650 | 660 | ||
651 | name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() : | 661 | name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : |
652 | info->fileName(); | 662 | info->fileName(); |
653 | 663 | ||
654 | (void)new OFileSelectorItem( m_view, pix, name, | 664 | (void)new OFileSelectorItem( m_view, pix, name, |
655 | info->lastModified().toString(), | 665 | info->lastModified().toString(), |
656 | QString::number( info->size() ), | 666 | QString::number( info->size() ), |
657 | info->dirPath( true ), locked, true ); | 667 | info->dirPath( true ), locked, true ); |
658 | 668 | ||
659 | 669 | ||
660 | } | 670 | } |
661 | 671 | ||
662 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) | 672 | void OFileViewFileListView::addSymlink( QFileInfo* , bool ) |
663 | { | 673 | { |
664 | } | 674 | } |
665 | 675 | ||
666 | void OFileViewFileListView::cdUP() | 676 | void OFileViewFileListView::cdUP() |
667 | { | 677 | { |
@@ -767,33 +777,33 @@ OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) | |||
767 | { | 777 | { |
768 | m_view = 0; | 778 | m_view = 0; |
769 | m_all = false; | 779 | m_all = false; |
770 | } | 780 | } |
771 | 781 | ||
772 | OFileViewFileSystem::~OFileViewFileSystem() | 782 | OFileViewFileSystem::~OFileViewFileSystem() |
773 | { | 783 | { |
774 | } | 784 | } |
775 | 785 | ||
776 | QString OFileViewFileSystem::selectedName()const | 786 | QString OFileViewFileSystem::selectedName()const |
777 | { | 787 | { |
778 | if (!m_view ) | 788 | if (!m_view ) |
779 | return QString::null; | 789 | return QString::null; |
780 | 790 | ||
781 | QString cFN=currentFileName(); | 791 | QString cFN=currentFileName(); |
782 | if (cFN.startsWith("/")) return cFN; | 792 | if (cFN.startsWith("/")) return cFN; |
783 | return m_view->currentDir() + "/" + cFN; | 793 | return createNewPath(m_view->currentDir(),cFN); |
784 | } | 794 | } |
785 | 795 | ||
786 | QString OFileViewFileSystem::selectedPath()const | 796 | QString OFileViewFileSystem::selectedPath()const |
787 | { | 797 | { |
788 | return QString::null; | 798 | return QString::null; |
789 | } | 799 | } |
790 | 800 | ||
791 | QString OFileViewFileSystem::directory()const | 801 | QString OFileViewFileSystem::directory()const |
792 | { | 802 | { |
793 | if (!m_view) | 803 | if (!m_view) |
794 | return QString::null; | 804 | return QString::null; |
795 | 805 | ||
796 | OFileSelectorItem* item = m_view->currentItem(); | 806 | OFileSelectorItem* item = m_view->currentItem(); |
797 | if (!item ) | 807 | if (!item ) |
798 | return QString::null; | 808 | return QString::null; |
799 | 809 | ||