-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 | |||
@@ -57,16 +57,26 @@ | |||
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 | {} |
@@ -465,17 +475,17 @@ void OFileViewFileListView::reread( bool all ) | |||
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 | } |
@@ -486,17 +496,17 @@ void OFileViewFileListView::reread( bool all ) | |||
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 | } |
@@ -558,17 +568,17 @@ void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) | |||
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 | ||
@@ -578,25 +588,25 @@ void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const | |||
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 ) |
@@ -612,17 +622,17 @@ void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) | |||
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 | } |
@@ -643,17 +653,17 @@ void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) | |||
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 | ||
@@ -775,17 +785,17 @@ OFileViewFileSystem::~OFileViewFileSystem() | |||
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 |