diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-05-14 15:43:57 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-15 04:57:29 +0200 |
commit | 57c755fef00c8269b083817228f046e4d950a580 (patch) | |
tree | 1d1ecdc34e6461754c41549ff5dd5e56ebc93ed7 /src/corelib/io | |
parent | e5f77fe31be0ea2c891eacd3e866bb9db4e0a238 (diff) |
Deprecate the ability to change the FS encoding separate from the locale
Changing the encoding used by filenames separately from the locale
encoding is a broken concept and cannot work properly. This creates
ambiguity depending on the data source and how it's being treated.
Instead, enforce that the locale encoding is the only possibility to
deal with file names.
The QFile::encodeName and decodeName functions are retained due to the
Mac-specific issues and due to the sheer number of current
uses. There's no point in deprecating them and moving away from them.
Change-Id: Iedb2d8715d166a59a824f05bc11d107fd44f9c17
Discussed-on: http://lists.qt-project.org/pipermail/development/2012-May/003782.html
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfile.cpp | 78 | ||||
-rw-r--r-- | src/corelib/io/qfile.h | 33 | ||||
-rw-r--r-- | src/corelib/io/qfile_p.h | 4 |
3 files changed, 43 insertions, 72 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index b3e3bdde53..193ebe96b8 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -59,30 +59,7 @@ QT_BEGIN_NAMESPACE -static QByteArray locale_encode(const QString &f) -{ -#if defined(Q_OS_DARWIN) - // Mac always expects UTF-8... and decomposed... - return f.normalized(QString::NormalizationForm_D).toUtf8(); -#else - return f.toLocal8Bit(); -#endif -} - -static QString locale_decode(const QByteArray &f) -{ -#if defined(Q_OS_DARWIN) - // Mac always gives us UTF-8 and decomposed, we want that composed... - return QString::fromUtf8(f).normalized(QString::NormalizationForm_C); -#else - return QString::fromLocal8Bit(f); -#endif -} - //************* QFilePrivate -QFile::EncoderFn QFilePrivate::encoder = locale_encode; -QFile::DecoderFn QFilePrivate::decoder = locale_decode; - QFilePrivate::QFilePrivate() { } @@ -358,22 +335,19 @@ QFile::setFileName(const QString &name) */ /*! - By default, this function converts \a fileName to the local 8-bit + \fn QByteArray QFile::encodeName(const QString &fileName) + + Converts \a fileName to the local 8-bit encoding determined by the user's locale. This is sufficient for file names that the user chooses. File names hard-coded into the application should only use 7-bit ASCII filename characters. - \sa decodeName(), setEncodingFunction() + \sa decodeName() */ -QByteArray -QFile::encodeName(const QString &fileName) -{ - return (*QFilePrivate::encoder)(fileName); -} - /*! \typedef QFile::EncoderFn + \obsolete This is a typedef for a pointer to a function with the following signature: @@ -384,36 +358,24 @@ QFile::encodeName(const QString &fileName) */ /*! + \fn QString QFile::decodeName(const QByteArray &localFileName) + This does the reverse of QFile::encodeName() using \a localFileName. - \sa setDecodingFunction(), encodeName() + \sa encodeName() */ -QString -QFile::decodeName(const QByteArray &localFileName) -{ - return (*QFilePrivate::decoder)(localFileName); -} - /*! \fn void QFile::setEncodingFunction(EncoderFn function) + \obsolete - \nonreentrant - - Sets the \a function for encoding Unicode file names. The - default encodes in the locale-specific 8-bit encoding. + This function does nothing. It is provided for compatibility with Qt 4 code + that attempted to set a different encoding function for file names. That + feature is flawed and no longer supported in Qt 5. \sa encodeName(), setDecodingFunction() */ -void -QFile::setEncodingFunction(EncoderFn f) -{ - if (!f) - f = locale_encode; - QFilePrivate::encoder = f; -} - /*! \typedef QFile::DecoderFn @@ -427,23 +389,15 @@ QFile::setEncodingFunction(EncoderFn f) /*! \fn void QFile::setDecodingFunction(DecoderFn function) + \obsolete - \nonreentrant - - Sets the \a function for decoding 8-bit file names. The - default uses the locale-specific 8-bit encoding. + This function does nothing. It is provided for compatibility with Qt 4 code + that attempted to set a different decoding function for file names. That + feature is flawed and no longer supported in Qt 5. \sa setEncodingFunction(), decodeName() */ -void -QFile::setDecodingFunction(DecoderFn f) -{ - if (!f) - f = locale_decode; - QFilePrivate::decoder = f; -} - /*! \overload diff --git a/src/corelib/io/qfile.h b/src/corelib/io/qfile.h index 0ee8f39d95..565701befb 100644 --- a/src/corelib/io/qfile.h +++ b/src/corelib/io/qfile.h @@ -76,14 +76,35 @@ public: QString fileName() const; void setFileName(const QString &name); - typedef QByteArray (*EncoderFn)(const QString &fileName); - typedef QString (*DecoderFn)(const QByteArray &localfileName); - static QByteArray encodeName(const QString &fileName); - static QString decodeName(const QByteArray &localFileName); +#if defined(Q_OS_DARWIN) + // Mac always expects filenames in UTF-8... and decomposed... + static inline QByteArray encodeName(const QString &fileName) + { + return fileName.normalized(QString::NormalizationForm_D).toUtf8(); + } + static QString decodeName(const QByteArray &localFileName) + { + return QString::fromUtf8(localFileName).normalized(QString::NormalizationForm_C); + } +#else + static inline QByteArray encodeName(const QString &fileName) + { + return fileName.toLocal8Bit(); + } + static QString decodeName(const QByteArray &localFileName) + { + return QString::fromLocal8Bit(localFileName); + } +#endif inline static QString decodeName(const char *localFileName) { return decodeName(QByteArray(localFileName)); } - static void setEncodingFunction(EncoderFn); - static void setDecodingFunction(DecoderFn); + +#if QT_DEPRECATED_SINCE(5,0) + typedef QByteArray (*EncoderFn)(const QString &fileName); + typedef QString (*DecoderFn)(const QByteArray &localfileName); + QT_DEPRECATED static void setEncodingFunction(EncoderFn) {} + QT_DEPRECATED static void setDecodingFunction(DecoderFn) {} +#endif bool exists() const; static bool exists(const QString &fileName); diff --git a/src/corelib/io/qfile_p.h b/src/corelib/io/qfile_p.h index aacdc78ce0..390dedf592 100644 --- a/src/corelib/io/qfile_p.h +++ b/src/corelib/io/qfile_p.h @@ -75,10 +75,6 @@ protected: virtual QAbstractFileEngine *engine() const; QString fileName; - -private: - static QFile::EncoderFn encoder; - static QFile::DecoderFn decoder; }; QT_END_NAMESPACE |