summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2009-08-21 12:28:51 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2009-08-21 12:28:51 (GMT)
commit6b8e0e831093f35fe5e47633c1a0abd22e6811b0 (patch)
tree69d7bfcf587446d02f7888f728d26dda1723c632 /src
parent1e5ad7ed3f1e6f66a8367318c32df6e5dd68250a (diff)
downloadQt-6b8e0e831093f35fe5e47633c1a0abd22e6811b0.zip
Qt-6b8e0e831093f35fe5e47633c1a0abd22e6811b0.tar.gz
Qt-6b8e0e831093f35fe5e47633c1a0abd22e6811b0.tar.bz2
Review inspired fixes to Symbian file engine
- Refactored symbian specific public method out of qfsfileengine.h into a static method. - Utilized PathInfo class for getting home, root, and temp paths. - Cosmetic changes. Reviewed-by: Janne Koskinen
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/io.pri1
-rw-r--r--src/corelib/io/qdir.cpp3
-rw-r--r--src/corelib/io/qfile.cpp2
-rw-r--r--src/corelib/io/qfsfileengine.h3
-rw-r--r--src/corelib/io/qfsfileengine_unix.cpp99
-rw-r--r--src/corelib/io/qtemporaryfile.cpp4
6 files changed, 62 insertions, 50 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri
index b49554e..e58e4ad 100644
--- a/src/corelib/io/io.pri
+++ b/src/corelib/io/io.pri
@@ -89,5 +89,6 @@ win32 {
symbian {
SOURCES += io/qfilesystemwatcher_symbian.cpp
HEADERS += io/qfilesystemwatcher_symbian_p.h
+ contains(QT_CONFIG, s60): LIBS += -lplatformenv
}
}
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp
index 91d41f1..9c96b8a 100644
--- a/src/corelib/io/qdir.cpp
+++ b/src/corelib/io/qdir.cpp
@@ -1930,8 +1930,7 @@ QString QDir::currentPath()
Under non-Windows operating systems the \c HOME environment
variable is used if it exists, otherwise the path returned by the
- rootPath() function is used, except in Symbian, where c:\\data is
- returned.
+ rootPath().
\sa home(), currentPath(), rootPath(), tempPath()
*/
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 5e1a5e7..a4b5ebc 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -747,7 +747,7 @@ QFile::rename(const QString &newName)
if (error) {
out.remove();
} else {
- fileEngine()->setFileName(newName);
+ fileEngine()->setFileName(newName);
setPermissions(permissions());
unsetError();
setFileName(newName);
diff --git a/src/corelib/io/qfsfileengine.h b/src/corelib/io/qfsfileengine.h
index f6db91c..9be8a4c 100644
--- a/src/corelib/io/qfsfileengine.h
+++ b/src/corelib/io/qfsfileengine.h
@@ -83,9 +83,6 @@ public:
FileFlags fileFlags(FileFlags type) const;
bool setPermissions(uint perms);
QString fileName(FileName file) const;
-#ifdef Q_OS_SYMBIAN
- QString fileNameSymbian(FileName file) const;
-#endif
uint ownerId(FileOwner) const;
QString owner(FileOwner) const;
QDateTime fileTime(FileTime time) const;
diff --git a/src/corelib/io/qfsfileengine_unix.cpp b/src/corelib/io/qfsfileengine_unix.cpp
index 620d82f..2a58356 100644
--- a/src/corelib/io/qfsfileengine_unix.cpp
+++ b/src/corelib/io/qfsfileengine_unix.cpp
@@ -60,6 +60,7 @@
#if defined(Q_OS_SYMBIAN)
# include <syslimits.h>
# include <f32file.h>
+# include <pathinfo.h>
# include "private/qcore_symbian_p.h"
#endif
#include <errno.h>
@@ -79,9 +80,9 @@ QT_BEGIN_NAMESPACE
static bool isRelativePathSymbian(const QString& fileName)
{
return !(fileName.startsWith(QLatin1Char('/'))
- || (fileName.length() >= 2
- && ((fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':'))
- || (fileName.at(0) == QLatin1Char('/') && fileName.at(1) == QLatin1Char('/')))));
+ || (fileName.length() >= 2
+ && ((fileName.at(0).isLetter() && fileName.at(1) == QLatin1Char(':'))
+ || (fileName.at(0) == QLatin1Char('/') && fileName.at(1) == QLatin1Char('/')))));
}
#endif
@@ -573,11 +574,10 @@ QString QFSFileEngine::currentPath(const QString &)
QString QFSFileEngine::homePath()
{
- QString home = QFile::decodeName(qgetenv("HOME"));
#if defined(Q_OS_SYMBIAN)
- if (home.isEmpty())
- home = QLatin1String("C:/Data");
+ QString home = rootPath();
#else
+ QString home = QFile::decodeName(qgetenv("HOME"));
if (home.isNull())
home = rootPath();
#endif
@@ -587,7 +587,13 @@ QString QFSFileEngine::homePath()
QString QFSFileEngine::rootPath()
{
#if defined(Q_OS_SYMBIAN)
- return QString::fromLatin1("C:/");
+# ifdef Q_WS_S60
+ TFileName symbianPath = PathInfo::PhoneMemoryRootPath();
+ return QDir::cleanPath(QDir::fromNativeSeparators(qt_TDesC2QString(symbianPath)));
+# else
+# warning No fallback implementation of QFSFileEngine::rootPath()
+ return QString();
+# endif
#else
return QString::fromLatin1("/");
#endif
@@ -596,12 +602,18 @@ QString QFSFileEngine::rootPath()
QString QFSFileEngine::tempPath()
{
#ifdef Q_OS_SYMBIAN
- QString temp = QDir::currentPath().left(2);
- temp += QString::fromLatin1( "/system/temp/");
+# ifdef Q_WS_S60
+ TFileName symbianPath = PathInfo::PhoneMemoryRootPath();
+ QString temp = QDir::fromNativeSeparators(qt_TDesC2QString(symbianPath));
+ temp += QString::fromLatin1( "temp/");
+# else
+# warning No fallback implementation of QFSFileEngine::tempPath()
+ return QString();
+# endif
#else
- QString temp = QFile::decodeName(qgetenv("TMPDIR"));
- if (temp.isEmpty())
- temp = QString::fromLatin1("/tmp/");
+ QString temp = QFile::decodeName(qgetenv("TMPDIR"));
+ if (temp.isEmpty())
+ temp = QString::fromLatin1("/tmp/");
#endif
return temp;
}
@@ -794,7 +806,8 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const
ret |= ExistsFlag;
#if defined(Q_OS_SYMBIAN)
if (d->filePath == QLatin1String("/")
- || (d->filePath.at(0).isLetter() && d->filePath.mid(1,d->filePath.length()) == QLatin1String(":/")))
+ || (d->filePath.at(0).isLetter()
+ && d->filePath.mid(1,d->filePath.length()) == QLatin1String(":/")))
ret |= RootFlag;
// In Symbian, all symlinks have hidden attribute for some reason;
@@ -823,11 +836,12 @@ QAbstractFileEngine::FileFlags QFSFileEngine::fileFlags(FileFlags type) const
}
#ifdef Q_OS_SYMBIAN
-QString QFSFileEngine::fileNameSymbian(FileName file) const
+static QString symbianFileName(QAbstractFileEngine::FileName file, const QFSFileEngine *engine,
+ const QFSFileEnginePrivate * const d)
{
- Q_D(const QFSFileEngine);
- if(file == BaseName) {
- int slash = d->filePath.lastIndexOf(QLatin1Char('/'));
+ const QLatin1Char slashChar('/');
+ if(file == QAbstractFileEngine::BaseName) {
+ int slash = d->filePath.lastIndexOf(slashChar);
if(slash == -1) {
int colon = d->filePath.lastIndexOf(QLatin1Char(':'));
if(colon != -1)
@@ -835,11 +849,11 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
return d->filePath;
}
return d->filePath.mid(slash + 1);
- } else if(file == PathName) {
+ } else if(file == QAbstractFileEngine::PathName) {
if(!d->filePath.size())
return d->filePath;
- int slash = d->filePath.lastIndexOf(QLatin1Char('/'));
+ int slash = d->filePath.lastIndexOf(slashChar);
if(slash == -1) {
if(d->filePath.length() >= 2 && d->filePath.at(1) == QLatin1Char(':'))
return d->filePath.left(2);
@@ -851,26 +865,26 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
slash++;
return d->filePath.left(slash);
}
- } else if(file == AbsoluteName || file == AbsolutePathName) {
+ } else if(file == QAbstractFileEngine::AbsoluteName || file == QAbstractFileEngine::AbsolutePathName) {
QString ret;
- if (!isRelativePath()) {
+ if (!isRelativePathSymbian(d->filePath)) {
if (d->filePath.size() > 2 && d->filePath.at(1) == QLatin1Char(':')
- && d->filePath.at(2) != QLatin1Char('/') || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt
- d->filePath.startsWith(QLatin1Char('/')) // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt
+ && d->filePath.at(2) != slashChar || // It's a drive-relative path, so Z:a.txt -> Z:\currentpath\a.txt
+ d->filePath.startsWith(slashChar) // It's a absolute path to the current drive, so \a.txt -> Z:\a.txt
) {
ret = QString(QDir::currentPath().left(2) + QDir::fromNativeSeparators(d->filePath));
} else {
ret = d->filePath;
}
} else {
- ret = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + d->filePath);
+ ret = QDir::cleanPath(QDir::currentPath() + slashChar + d->filePath);
}
// The path should be absolute at this point.
// From the docs :
// Absolute paths begin with the directory separator "/"
// (optionally preceded by a drive specification under Windows).
- if (ret.at(0) != QLatin1Char('/')) {
+ if (ret.at(0) != slashChar) {
Q_ASSERT(ret.length() >= 2);
Q_ASSERT(ret.at(0).isLetter());
Q_ASSERT(ret.at(1) == QLatin1Char(':'));
@@ -879,23 +893,23 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
ret[0] = ret.at(0).toUpper();
}
- if (file == AbsolutePathName) {
- int slash = ret.lastIndexOf(QLatin1Char('/'));
+ if (file == QAbstractFileEngine::AbsolutePathName) {
+ int slash = ret.lastIndexOf(slashChar);
if (slash < 0)
return ret;
- else if (ret.at(0) != QLatin1Char('/') && slash == 2)
+ else if (ret.at(0) != slashChar && slash == 2)
return ret.left(3); // include the slash
else
return ret.left(slash > 0 ? slash : 1);
}
return ret;
- } else if(file == CanonicalName || file == CanonicalPathName) {
- if (!(fileFlags(ExistsFlag) & ExistsFlag))
+ } else if(file == QAbstractFileEngine::CanonicalName || file == QAbstractFileEngine::CanonicalPathName) {
+ if (!(engine->fileFlags(QAbstractFileEngine::ExistsFlag) & QAbstractFileEngine::ExistsFlag))
return QString();
- QString ret = QFSFileEnginePrivate::canonicalized(fileName(AbsoluteName));
- if (!ret.isEmpty() && file == CanonicalPathName) {
- int slash = ret.lastIndexOf(QLatin1Char('/'));
+ QString ret = QFSFileEnginePrivate::canonicalized(symbianFileName(QAbstractFileEngine::AbsoluteName, engine, d));
+ if (!ret.isEmpty() && file == QAbstractFileEngine::CanonicalPathName) {
+ int slash = ret.lastIndexOf(slashChar);
if (slash == -1)
ret = QDir::fromNativeSeparators(QDir::currentPath());
else if (slash == 0)
@@ -903,7 +917,7 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
ret = ret.left(slash);
}
return ret;
- } else if(file == LinkName) {
+ } else if(file == QAbstractFileEngine::LinkName) {
if (d->isSymlink()) {
char s[PATH_MAX+1];
int len = readlink(d->nativeFilePath.constData(), s, PATH_MAX);
@@ -913,20 +927,20 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
if (isRelativePathSymbian(ret)) {
if (!isRelativePathSymbian(d->filePath)) {
- ret.prepend(d->filePath.left(d->filePath.lastIndexOf(QLatin1Char('/')))
- + QLatin1Char('/'));
+ ret.prepend(d->filePath.left(d->filePath.lastIndexOf(slashChar))
+ + slashChar);
} else {
- ret.prepend(QDir::currentPath() + QLatin1Char('/'));
+ ret.prepend(QDir::currentPath() + slashChar);
}
}
ret = QDir::cleanPath(ret);
- if (ret.size() > 1 && ret.endsWith(QLatin1Char('/')))
+ if (ret.size() > 1 && ret.endsWith(slashChar))
ret.chop(1);
return ret;
}
}
return QString();
- } else if(file == BundleName) {
+ } else if(file == QAbstractFileEngine::BundleName) {
return QString();
}
return d->filePath;
@@ -935,10 +949,10 @@ QString QFSFileEngine::fileNameSymbian(FileName file) const
QString QFSFileEngine::fileName(FileName file) const
{
-#ifdef Q_OS_SYMBIAN
- return fileNameSymbian(file);
-#endif
Q_D(const QFSFileEngine);
+#ifdef Q_OS_SYMBIAN
+ return symbianFileName(file, this, d);
+#else
if (file == BundleName) {
#if !defined(QWS) && defined(Q_OS_MAC)
QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, QCFString(d->filePath),
@@ -1072,6 +1086,7 @@ QString QFSFileEngine::fileName(FileName file) const
return QString();
}
return d->filePath;
+#endif // Q_OS_SYMBIAN
}
bool QFSFileEngine::isRelativePath() const
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index d76e99b..3db0564 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -515,8 +515,8 @@ QTemporaryFile::QTemporaryFile()
Q_D(QTemporaryFile);
d->templateName = QDir::tempPath() + QLatin1String("/qt_temp.XXXXXX");
#ifdef Q_OS_SYMBIAN
- //Just for verify that folder really exist on hardware
- fileEngine()->mkdir( QDir::tempPath(), true );
+ //Just to verify that folder really exist on hardware
+ fileEngine()->mkdir(QDir::tempPath(), true);
#endif
}