summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Zander <t.zander@nokia.com>2010-08-24 10:23:44 (GMT)
committerThomas Zander <t.zander@nokia.com>2010-08-24 10:43:48 (GMT)
commitb5905172d3c68f9b64334d9a2796bdf1df65e607 (patch)
treed98db2569d494e5c7ff86a150628beb682d5cbbd /src
parent68f5623c6efcc76163fc3c5f8154aecf90c618f8 (diff)
downloadQt-b5905172d3c68f9b64334d9a2796bdf1df65e607.zip
Qt-b5905172d3c68f9b64334d9a2796bdf1df65e607.tar.gz
Qt-b5905172d3c68f9b64334d9a2796bdf1df65e607.tar.bz2
Add constructors and basic getters to QFilesystemEntry
Reviewed-by: Prasanth Ullattil
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qfilesystementry.cpp67
-rw-r--r--src/corelib/io/qfilesystementry_p.h24
2 files changed, 91 insertions, 0 deletions
diff --git a/src/corelib/io/qfilesystementry.cpp b/src/corelib/io/qfilesystementry.cpp
index 36ec012..1cc82ef 100644
--- a/src/corelib/io/qfilesystementry.cpp
+++ b/src/corelib/io/qfilesystementry.cpp
@@ -39,3 +39,70 @@
**
****************************************************************************/
+#include "qfilesystementry_p.h"
+#include "qdir.h"
+
+QFileSystemEntry::QFileSystemEntry(const QString &filePath)
+ : m_filePath(filePath),
+ m_lastSeparator(-2)
+{
+}
+
+QFileSystemEntry::QFileSystemEntry(const QByteArray &nativeFilePath)
+ : m_nativeFilePath(nativeFilePath),
+ m_lastSeparator(-2)
+{
+}
+
+QFileSystemEntry::QFileSystemEntry(const QByteArray &nativeFilePath, const QString &filePath)
+ : m_filePath(filePath),
+ m_nativeFilePath(nativeFilePath),
+ m_lastSeparator(-2)
+{
+}
+
+QString QFileSystemEntry::filePath() const
+{
+ resolveFilePath();
+ return m_filePath;
+}
+
+QByteArray QFileSystemEntry::nativeFileName() const
+{
+ resolveNativeFilePath();
+ return m_nativeFilePath;
+}
+
+void QFileSystemEntry::resolveFilePath() const
+{
+ if (m_filePath.isEmpty() && !m_nativeFilePath.isEmpty()) {
+ m_filePath = QDir::fromNativeSeparators(QString::fromLocal8Bit(m_nativeFilePath));
+ }
+}
+
+void QFileSystemEntry::resolveNativeFilePath() const
+{
+ if (!m_filePath.isEmpty() && m_nativeFilePath.isEmpty()) {
+ m_nativeFilePath = m_filePath.toLocal8Bit();
+ }
+}
+
+QString QFileSystemEntry::fileName() const
+{
+ findLastSeparator();
+ return m_filePath.mid(m_lastSeparator + 1);
+}
+
+void QFileSystemEntry::findLastSeparator() const
+{
+ resolveFilePath();
+ if (m_lastSeparator == -2) {
+ m_lastSeparator = -1;
+ for (int i = m_filePath.size() - 1; i >= 0; --i) {
+ if (m_filePath[i].unicode() == '/') {
+ m_lastSeparator = i;
+ break;
+ }
+ }
+ }
+}
diff --git a/src/corelib/io/qfilesystementry_p.h b/src/corelib/io/qfilesystementry_p.h
index 2054f62..3e67174 100644
--- a/src/corelib/io/qfilesystementry_p.h
+++ b/src/corelib/io/qfilesystementry_p.h
@@ -53,10 +53,34 @@
// We mean it.
//
+#include <QtCore/qstring.h>
+#include <QtCore/qbytearray.h>
+
QT_BEGIN_NAMESPACE
class QFileSystemEntry
{
+ QFileSystemEntry(const QString &filePath);
+ QFileSystemEntry(const QByteArray &nativeFilePath);
+ QFileSystemEntry(const QByteArray &nativeFilePath, const QString &filePath);
+
+ QString filePath() const;
+ QString fileName() const;
+ QByteArray nativeFileName() const;
+
+private:
+ // creates the QString version out of the bytearray version
+ void resolveFilePath() const;
+ // creates the bytearray version out of the QString version
+ void resolveNativeFilePath() const;
+ void findLastSeparator() const;
+
+ mutable QString m_filePath; // always has slashes as separator
+ mutable QByteArray m_nativeFilePath; // native encoding and separators
+
+ mutable int m_lastSeparator : 16;
+
+ int dummy : 16;
};
QT_END_NAMESPACE