summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp26
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
@@ -59,12 +59,22 @@
using namespace Opie::Ui::Internal;
namespace Opie {
namespace Ui {
namespace Internal {
+/*
+ * Create a path by adding a '/'/QDir::seperator in between
+ * base and ending, but only if base is not empty
+ */
+static inline QString createNewPath(const QString& base, const QString &ending) {
+ return base == QString::fromLatin1("/") ?
+ base + ending : base + "/" + ending;
+}
+
+
OFileViewInterface::OFileViewInterface( OFileSelector* _selector )
: m_selector( _selector )
{
selector()->registerView( this );
}
@@ -467,13 +477,13 @@ void OFileViewFileListView::reread( bool all )
/*
* It is a symlink we try to resolve it now but don't let us attack by DOS
*
*/
if( fi->isSymLink() )
{
- QString file = fi->dirPath( true ) + "/" + fi->readLink();
+ QString file = createNewPath(fi->dirPath( true ),fi->readLink());
for( int i = 0; i<=4; i++)
{ // 5 tries to prevent dos
QFileInfo info( file );
if( !info.exists() )
{
addSymlink( fi, TRUE );
@@ -488,13 +498,13 @@ void OFileViewFileListView::reread( bool all )
{
addFile( fi, TRUE );
break;
}
else if( info.isSymLink() )
{
- file = info.dirPath(true ) + "/" + info.readLink() ;
+ file = createNewPath(info.dirPath(true ),info.readLink());
break;
}
else if( i == 4)
{ // couldn't resolve symlink add it as symlink
addSymlink( fi );
}
@@ -560,13 +570,13 @@ void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
selector()->m_lneEdit->setText( sel->text(1) );
// if in fileselector mode we will emit selected
if ( selector()->mode() == OFileSelector::FileSelector )
{
odebug << "slot Current Changed" << oendl;
QStringList str = QStringList::split("->", sel->text(1) );
- QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
+ QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace());
emit selector()->fileSelected( path );
DocLnk lnk( path );
emit selector()->fileSelected( lnk );
}
}
#endif
@@ -580,21 +590,21 @@ void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const
OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
if (!sel->isLocked() )
{
QStringList str = QStringList::split("->", sel->text(1) );
if (sel->isDir() )
{
- m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
+ m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace());
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
else
{ // file
odebug << "slot Clicked" << oendl;
selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
- QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
+ QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace());
emit selector()->fileSelected( path );
DocLnk lnk( path );
emit selector()->fileSelected( lnk );
}
} // not locked
}
@@ -614,13 +624,13 @@ void OFileViewFileListView::addFile( QFileInfo* info, bool symlink )
matrix.scale( .4, .4 );
pix = pixer.xForm( matrix );
}
dir = info->dirPath( true );
locked = false;
if ( symlink )
- name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
+ name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink());
else
{
name = info->fileName();
if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
{
@@ -645,13 +655,13 @@ void OFileViewFileListView::addDir( QFileInfo* info, bool symlink )
else
pix = Resource::loadPixmap( "lockedfolder" );
}
else
pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
- name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
+ name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) :
info->fileName();
(void)new OFileSelectorItem( m_view, pix, name,
info->lastModified().toString(),
QString::number( info->size() ),
info->dirPath( true ), locked, true );
@@ -777,13 +787,13 @@ QString OFileViewFileSystem::selectedName()const
{
if (!m_view )
return QString::null;
QString cFN=currentFileName();
if (cFN.startsWith("/")) return cFN;
- return m_view->currentDir() + "/" + cFN;
+ return createNewPath(m_view->currentDir(),cFN);
}
QString OFileViewFileSystem::selectedPath()const
{
return QString::null;
}