summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-5.0.08
-rw-r--r--src/corelib/io/qfile.cpp78
-rw-r--r--src/corelib/io/qfile.h33
-rw-r--r--src/corelib/io/qfile_p.h4
4 files changed, 51 insertions, 72 deletions
diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0
index eebfb6d4dc..3b37473d75 100644
--- a/dist/changes-5.0.0
+++ b/dist/changes-5.0.0
@@ -347,6 +347,14 @@ QtCore
QCoreApplication::Encoding value CodecForTr is now obsolete, use
DefaultCodec instead. For reasoning, see the codecForCStrings() removal above.
+* QFile::setEncodingFunction and QFile::setDecodingFunction are obsolete and do
+ nothing in Qt 5. The QFile::encodeName and QFile::decodeName functions are now
+ hardcoded to operate on QString::fromLocal8Bit and QString::toLocal8Bit
+ only. Therefore, it's still possible to obtain the old behaviour by calling
+ QTextCodec::setCodecForLocale. However, that is not recommended: new code
+ should not make assumptions about the filesystem encoding and older code should
+ have those assumptions removed.
+
* QIntValidator and QDoubleValidator no longer fall back to using the C locale if
the requested locale fails to validate the input.
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