From 57c755fef00c8269b083817228f046e4d950a580 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 14 May 2012 15:43:57 +0200 Subject: 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 --- src/corelib/io/qfile.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/corelib/io/qfile.h') 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); -- cgit v1.2.3