diff options
Diffstat (limited to 'src/corelib')
57 files changed, 1020 insertions, 700 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index cedb43f..f834a80 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -161,7 +161,9 @@ QT_BEGIN_NAMESPACE +#ifndef QT_NO_THREAD Q_GLOBAL_STATIC(QThreadStorage<QUnifiedTimer *>, unifiedTimer) +#endif QUnifiedTimer::QUnifiedTimer() : QObject(), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), @@ -173,12 +175,17 @@ QUnifiedTimer::QUnifiedTimer() : QUnifiedTimer *QUnifiedTimer::instance() { QUnifiedTimer *inst; +#ifndef QT_NO_THREAD if (!unifiedTimer()->hasLocalData()) { inst = new QUnifiedTimer; unifiedTimer()->setLocalData(inst); } else { inst = unifiedTimer()->localData(); } +#else + static QUnifiedTimer unifiedTimer; + inst = &unifiedTimer; +#endif return inst; } @@ -242,7 +249,7 @@ void QUnifiedTimer::timerEvent(QTimerEvent *event) animationTimer.stop(); isPauseTimerActive = false; // invalidate the start reference time - time = QTime(); + time.invalidate(); } else { restartAnimationTimer(); if (!time.isValid()) { diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index ad35d89..8bc3224 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -58,6 +58,10 @@ #include <QtCore/qtimer.h> #include <private/qobject_p.h> +#ifdef Q_OS_WIN +#include <qt_windows.h> +#endif + #ifndef QT_NO_ANIMATION QT_BEGIN_NAMESPACE @@ -109,6 +113,61 @@ private: Q_DECLARE_PUBLIC(QAbstractAnimation) }; +class ElapsedTimer +{ +public: + ElapsedTimer() { + invalidate(); + } + + void invalidate() { + m_started = -1; + } + + bool isValid() const { + return m_started >= 0; + } + + void start() { + m_started = getTickCount_sys(); + } + + qint64 elapsed() const { + qint64 current = getTickCount_sys(); + qint64 delta = current - m_started; + if (delta < 0) + delta += getPeriod_sys(); //we wrapped around + return delta; + } + +private: + enum { + MSECS_PER_HOUR = 3600000, + MSECS_PER_MIN = 60000 + }; + + qint64 m_started; + + quint64 getPeriod_sys() const { +#ifdef Q_OS_WIN + return Q_UINT64_C(0x100000000); +#else + // fallback + return 86400 * 1000; +#endif + } + + qint64 getTickCount_sys() const { +#ifdef Q_OS_WIN + return ::GetTickCount(); +#else + // fallback + const QTime t = QTime::currentTime(); + return MSECS_PER_HOUR * t.hour() + MSECS_PER_MIN * t.minute() + 1000 * t.second() + t.msec(); +#endif + } +}; + class QUnifiedTimer : public QObject { @@ -162,7 +221,8 @@ private: // timer used to delay the check if we should start/stop the animation timer QBasicTimer startStopAnimationTimer; - QTime time; + ElapsedTimer time; + int lastTick; int timingInterval; int currentAnimationIdx; diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index cfd7cc2..37b79ba 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -118,7 +118,9 @@ void QPropertyAnimationPrivate::updateMetaProperty() propertyType = QVariant::Invalid; if (!targetValue->dynamicPropertyNames().contains(propertyName)) qWarning("QPropertyAnimation: you're trying to animate a non-existing property %s of your QObject", propertyName.constData()); - } + } else if (!targetValue->metaObject()->property(propertyIndex).isWritable()) { + qWarning("QPropertyAnimation: you're trying to animate the non-writable property %s of your QObject", propertyName.constData()); + } } void QPropertyAnimationPrivate::updateProperty(const QVariant &newValue) @@ -265,7 +267,9 @@ void QPropertyAnimation::updateState(QAbstractAnimation::State newState, QPropertyAnimation *animToStop = 0; { +#ifndef QT_NO_THREAD QMutexLocker locker(QMutexPool::globalInstanceGet(&staticMetaObject)); +#endif typedef QPair<QObject *, QByteArray> QPropertyAnimationPair; typedef QHash<QPropertyAnimationPair, QPropertyAnimation*> QPropertyAnimationHash; static QPropertyAnimationHash hash; diff --git a/src/corelib/animation/qvariantanimation.cpp b/src/corelib/animation/qvariantanimation.cpp index 115edbe..173802d 100644 --- a/src/corelib/animation/qvariantanimation.cpp +++ b/src/corelib/animation/qvariantanimation.cpp @@ -431,7 +431,9 @@ void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator fun { // will override any existing interpolators QInterpolatorVector *interpolators = registeredInterpolators(); +#ifndef QT_NO_THREAD QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); +#endif if (int(interpolationType) >= interpolators->count()) interpolators->resize(int(interpolationType) + 1); interpolators->replace(interpolationType, func); @@ -446,7 +448,9 @@ template<typename T> static inline QVariantAnimation::Interpolator castToInterpo QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) { QInterpolatorVector *interpolators = registeredInterpolators(); +#ifndef QT_NO_THREAD QMutexLocker locker(QMutexPool::globalInstanceGet(interpolators)); +#endif QVariantAnimation::Interpolator ret = 0; if (interpolationType < interpolators->count()) { ret = interpolators->at(interpolationType); diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index ff40af5..1c607a6 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1193,6 +1193,19 @@ QTextDecoder* QTextCodec::makeDecoder() const return new QTextDecoder(this); } +/*! + Creates a QTextDecoder with a specified \a flags to decode chunks + of \c{char *} data to create chunks of Unicode data. + + The caller is responsible for deleting the returned object. + + \since 4.7 +*/ +QTextDecoder* QTextCodec::makeDecoder(QTextCodec::ConversionFlags flags) const +{ + return new QTextDecoder(this, flags); +} + /*! Creates a QTextEncoder which stores enough state to encode chunks @@ -1206,6 +1219,19 @@ QTextEncoder* QTextCodec::makeEncoder() const } /*! + Creates a QTextEncoder with a specified \a flags to encode chunks + of Unicode data as \c{char *} data. + + The caller is responsible for deleting the returned object. + + \since 4.7 +*/ +QTextEncoder* QTextCodec::makeEncoder(QTextCodec::ConversionFlags flags) const +{ + return new QTextEncoder(this, flags); +} + +/*! \fn QByteArray QTextCodec::fromUnicode(const QChar *input, int number, ConverterState *state) const @@ -1346,6 +1372,17 @@ QString QTextCodec::toUnicode(const char *chars) const */ /*! + Constructs a text encoder for the given \a codec and conversion \a flags. + + \since 4.7 +*/ +QTextEncoder::QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags) + : c(codec), state() +{ + state.flags = flags; +} + +/*! Destroys the encoder. */ QTextEncoder::~QTextEncoder() @@ -1422,6 +1459,18 @@ QByteArray QTextEncoder::fromUnicode(const QString& uc, int& lenInOut) */ /*! + Constructs a text decoder for the given \a codec and conversion \a flags. + + \since 4.7 +*/ + +QTextDecoder::QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags) + : c(codec), state() +{ + state.flags = flags; +} + +/*! Destroys the decoder. */ QTextDecoder::~QTextDecoder() diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index a099dd9..5012b42 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -85,9 +85,6 @@ public: static QTextCodec *codecForUtfText(const QByteArray &ba); static QTextCodec *codecForUtfText(const QByteArray &ba, QTextCodec *defaultCodec); - QTextDecoder* makeDecoder() const; - QTextEncoder* makeEncoder() const; - bool canEncode(QChar) const; bool canEncode(const QString&) const; @@ -120,6 +117,12 @@ public: QByteArray fromUnicode(const QChar *in, int length, ConverterState *state = 0) const { return convertFromUnicode(in, length, state); } + // ### Qt 5: merge these functions. + QTextDecoder* makeDecoder() const; + QTextDecoder* makeDecoder(ConversionFlags flags) const; + QTextEncoder* makeEncoder() const; + QTextEncoder* makeEncoder(ConversionFlags flags) const; + virtual QByteArray name() const = 0; virtual QList<QByteArray> aliases() const; virtual int mibEnum() const = 0; @@ -157,6 +160,7 @@ class Q_CORE_EXPORT QTextEncoder { Q_DISABLE_COPY(QTextEncoder) public: explicit QTextEncoder(const QTextCodec *codec) : c(codec), state() {} + QTextEncoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags); ~QTextEncoder(); QByteArray fromUnicode(const QString& str); QByteArray fromUnicode(const QChar *uc, int len); @@ -178,6 +182,7 @@ class Q_CORE_EXPORT QTextDecoder { Q_DISABLE_COPY(QTextDecoder) public: explicit QTextDecoder(const QTextCodec *codec) : c(codec), state() {} + QTextDecoder(const QTextCodec *codec, QTextCodec::ConversionFlags flags); ~QTextDecoder(); QString toUnicode(const char* chars, int len); QString toUnicode(const QByteArray &ba); diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index abdafc3..b237659 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -44,11 +44,11 @@ #include <stddef.h> -#define QT_VERSION_STR "4.6.2" +#define QT_VERSION_STR "4.7.0" /* QT_VERSION is (major << 16) + (minor << 8) + patch. */ -#define QT_VERSION 0x040602 +#define QT_VERSION 0x040700 /* can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0)) */ @@ -275,7 +275,7 @@ namespace QT_NAMESPACE {} # endif #endif -#ifdef AUTODETECT_COCOA +#ifdef QT_AUTODETECT_COCOA # ifdef Q_OS_MAC64 # define QT_MAC_USE_COCOA 1 # define QT_BUILD_KEY QT_BUILD_KEY_COCOA @@ -672,8 +672,9 @@ namespace QT_NAMESPACE {} # define Q_ALIGNOF(type) __alignof__(type) # define Q_TYPEOF(expr) __typeof__(expr) # define Q_DECL_ALIGN(n) __attribute__((__aligned__(n))) -// using CC 5.9: Warning: attribute visibility is unsupported and will be skipped.. -//# define Q_DECL_EXPORT __attribute__((__visibility__("default"))) +# endif +# if __SUNPRO_CC >= 0x550 +# define Q_DECL_EXPORT __global # endif # if __SUNPRO_CC < 0x5a0 # define Q_NO_TEMPLATE_FRIENDS @@ -1540,6 +1541,7 @@ inline QT3_SUPPORT bool qt_winUnicode() { return true; } inline QT3_SUPPORT int qWinVersion() { return QSysInfo::WindowsVersion; } #endif +// ### Qt 5: remove Win9x support macros QT_WA and QT_WA_INLINE. #define QT_WA(unicode, ansi) unicode #define QT_WA_INLINE(unicode, ansi) (unicode) diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 177bee4..35ff8e7 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1235,7 +1235,10 @@ public: BusyCursor, OpenHandCursor, ClosedHandCursor, - LastCursor = ClosedHandCursor, + DragCopyCursor, + DragMoveCursor, + DragLinkCursor, + LastCursor = DragLinkCursor, BitmapCursor = 24, CustomCursor = 25 diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index 6627c76..3d49d60 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -2508,6 +2508,15 @@ operations that allow the user to interact with the application while they are performed in the background. + \value DragMoveCursor + A cursor that is usually used when dragging an item. + \value DragCopyCursor + A cursor that is usually used when dragging an item + to copy it. + \value DragLinkCursor + A cursor that is usually used when dragging an item + to make a link to it. + \value BitmapCursor \omitvalue LastCursor \omitvalue CustomCursor diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index 02a1586..2ed0e46 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -6,6 +6,7 @@ HEADERS += \ io/qbuffer.h \ io/qdatastream.h \ io/qdatastream_p.h \ + io/qdataurl_p.h \ io/qdebug.h \ io/qdir.h \ io/qdiriterator.h \ @@ -34,6 +35,7 @@ SOURCES += \ io/qabstractfileengine.cpp \ io/qbuffer.cpp \ io/qdatastream.cpp \ + io/qdataurl.cpp \ io/qdebug.cpp \ io/qdir.cpp \ io/qdiriterator.cpp \ diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 82d3b79..7c1887e 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -48,6 +48,7 @@ #include <stdio.h> #include <ctype.h> #include <stdlib.h> +#include "qendian.h" QT_BEGIN_NAMESPACE @@ -570,6 +571,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_4_4 Version 10 (Qt 4.4) \value Qt_4_5 Version 11 (Qt 4.5) \value Qt_4_6 Version 12 (Qt 4.6) + \value Qt_4_7 Same as Qt_4_6. \sa setVersion(), version() */ @@ -672,24 +674,12 @@ QDataStream &QDataStream::operator>>(qint16 &i) { i = 0; CHECK_STREAM_PRECOND(*this) - if (noswap) { - if (dev->read((char *)&i, 2) != 2) { - i = 0; - setStatus(ReadPastEnd); - } + if (dev->read((char *)&i, 2) != 2) { + i = 0; + setStatus(ReadPastEnd); } else { - union { - qint16 val1; - char val2[2]; - } x; - char *p = x.val2; - char b[2]; - if (dev->read(b, 2) == 2) { - *p++ = b[1]; - *p = b[0]; - i = x.val1; - } else { - setStatus(ReadPastEnd); + if (!noswap) { + i = qbswap(i); } } return *this; @@ -715,26 +705,12 @@ QDataStream &QDataStream::operator>>(qint32 &i) { i = 0; CHECK_STREAM_PRECOND(*this) - if (noswap) { - if (dev->read((char *)&i, 4) != 4) { - i = 0; - setStatus(ReadPastEnd); - } - } else { // swap bytes - union { - qint32 val1; - char val2[4]; - } x; - char *p = x.val2; - char b[4]; - if (dev->read(b, 4) == 4) { - *p++ = b[3]; - *p++ = b[2]; - *p++ = b[1]; - *p = b[0]; - i = x.val1; - } else { - setStatus(ReadPastEnd); + if (dev->read((char *)&i, 4) != 4) { + i = 0; + setStatus(ReadPastEnd); + } else { + if (!noswap) { + i = qbswap(i); } } return *this; @@ -763,31 +739,14 @@ QDataStream &QDataStream::operator>>(qint64 &i) quint32 i1, i2; *this >> i2 >> i1; i = ((quint64)i1 << 32) + i2; - } else if (noswap) { // no conversion needed + } else { if (dev->read((char *)&i, 8) != 8) { i = qint64(0); setStatus(ReadPastEnd); - } - } else { // swap bytes - union { - qint64 val1; - char val2[8]; - } x; - - char *p = x.val2; - char b[8]; - if (dev->read(b, 8) == 8) { - *p++ = b[7]; - *p++ = b[6]; - *p++ = b[5]; - *p++ = b[4]; - *p++ = b[3]; - *p++ = b[2]; - *p++ = b[1]; - *p = b[0]; - i = x.val1; } else { - setStatus(ReadPastEnd); + if (!noswap) { + i = qbswap(i); + } } } return *this; @@ -827,27 +786,17 @@ QDataStream &QDataStream::operator>>(float &f) f = 0.0f; CHECK_STREAM_PRECOND(*this) - if (noswap) { - if (dev->read((char *)&f, 4) != 4) { - f = 0.0f; - setStatus(ReadPastEnd); - } - } else { // swap bytes - union { - float val1; - char val2[4]; - } x; - - char *p = x.val2; - char b[4]; - if (dev->read(b, 4) == 4) { - *p++ = b[3]; - *p++ = b[2]; - *p++ = b[1]; - *p = b[0]; + if (dev->read((char *)&f, 4) != 4) { + f = 0.0f; + setStatus(ReadPastEnd); + } else { + if (!noswap) { + union { + float val1; + quint32 val2; + } x; + x.val2 = qbswap(*reinterpret_cast<quint32 *>(&f)); f = x.val1; - } else { - setStatus(ReadPastEnd); } } return *this; @@ -880,30 +829,17 @@ QDataStream &QDataStream::operator>>(double &f) f = 0.0; CHECK_STREAM_PRECOND(*this) #ifndef Q_DOUBLE_FORMAT - if (noswap) { - if (dev->read((char *)&f, 8) != 8) { - f = 0.0; - setStatus(ReadPastEnd); - } - } else { // swap bytes - union { - double val1; - char val2[8]; - } x; - char *p = x.val2; - char b[8]; - if (dev->read(b, 8) == 8) { - *p++ = b[7]; - *p++ = b[6]; - *p++ = b[5]; - *p++ = b[4]; - *p++ = b[3]; - *p++ = b[2]; - *p++ = b[1]; - *p = b[0]; + if (dev->read((char *)&f, 8) != 8) { + f = 0.0; + setStatus(ReadPastEnd); + } else { + if (!noswap) { + union { + double val1; + quint64 val2; + } x; + x.val2 = qbswap(*reinterpret_cast<quint64 *>(&f)); f = x.val1; - } else { - setStatus(ReadPastEnd); } } #else @@ -1075,20 +1011,10 @@ QDataStream &QDataStream::operator<<(qint8 i) QDataStream &QDataStream::operator<<(qint16 i) { CHECK_STREAM_PRECOND(*this) - if (noswap) { - dev->write((char *)&i, sizeof(qint16)); - } else { // swap bytes - union { - qint16 val1; - char val2[2]; - } x; - x.val1 = i; - char *p = x.val2; - char b[2]; - b[1] = *p++; - b[0] = *p; - dev->write(b, 2); + if (!noswap) { + i = qbswap(i); } + dev->write((char *)&i, sizeof(qint16)); return *this; } @@ -1102,22 +1028,10 @@ QDataStream &QDataStream::operator<<(qint16 i) QDataStream &QDataStream::operator<<(qint32 i) { CHECK_STREAM_PRECOND(*this) - if (noswap) { - dev->write((char *)&i, sizeof(qint32)); - } else { // swap bytes - union { - qint32 val1; - char val2[4]; - } x; - x.val1 = i; - char *p = x.val2; - char b[4]; - b[3] = *p++; - b[2] = *p++; - b[1] = *p++; - b[0] = *p; - dev->write(b, 4); + if (!noswap) { + i = qbswap(i); } + dev->write((char *)&i, sizeof(qint32)); return *this; } @@ -1143,25 +1057,11 @@ QDataStream &QDataStream::operator<<(qint64 i) quint32 i1 = i & 0xffffffff; quint32 i2 = i >> 32; *this << i2 << i1; - } else if (noswap) { // no conversion needed + } else { + if (!noswap) { + i = qbswap(i); + } dev->write((char *)&i, sizeof(qint64)); - } else { // swap bytes - union { - qint64 val1; - char val2[8]; - } x; - x.val1 = i; - char *p = x.val2; - char b[8]; - b[7] = *p++; - b[6] = *p++; - b[5] = *p++; - b[4] = *p++; - b[3] = *p++; - b[2] = *p++; - b[1] = *p++; - b[0] = *p; - dev->write(b, 8); } return *this; } @@ -1205,22 +1105,16 @@ QDataStream &QDataStream::operator<<(float f) CHECK_STREAM_PRECOND(*this) float g = f; // fixes float-on-stack problem - if (noswap) { // no conversion needed - dev->write((char *)&g, sizeof(float)); - } else { // swap bytes + if (!noswap) { union { float val1; - char val2[4]; + quint32 val2; } x; - x.val1 = f; - char *p = x.val2; - char b[4]; - b[3] = *p++; - b[2] = *p++; - b[1] = *p++; - b[0] = *p; - dev->write(b, 4); + x.val1 = g; + x.val2 = qbswap(x.val2); + g = x.val1; } + dev->write((char *)&g, sizeof(float)); return *this; } @@ -1244,26 +1138,16 @@ QDataStream &QDataStream::operator<<(double f) CHECK_STREAM_PRECOND(*this) #ifndef Q_DOUBLE_FORMAT - if (noswap) { - dev->write((char *)&f, sizeof(double)); - } else { + if (!noswap) { union { double val1; - char val2[8]; + quint64 val2; } x; x.val1 = f; - char *p = x.val2; - char b[8]; - b[7] = *p++; - b[6] = *p++; - b[5] = *p++; - b[4] = *p++; - b[3] = *p++; - b[2] = *p++; - b[1] = *p++; - b[0] = *p; - dev->write(b, 8); + x.val2 = qbswap(x.val2); + f = x.val1; } + dev->write((char *)&f, sizeof(double)); #else union { double val1; diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index afc16bc..ec4ba2f 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -84,10 +84,11 @@ public: Qt_4_3 = 9, Qt_4_4 = 10, Qt_4_5 = 11, - Qt_4_6 = 12 -#if QT_VERSION >= 0x040700 -#error Add the datastream version for this Qt version + Qt_4_6 = 12, Qt_4_7 = Qt_4_6 +#if QT_VERSION >= 0x040800 +#error Add the datastream version for this Qt version + Qt_4_8 = Qt_4_7 #endif }; diff --git a/src/corelib/io/qdataurl.cpp b/src/corelib/io/qdataurl.cpp new file mode 100644 index 0000000..9bb896e --- /dev/null +++ b/src/corelib/io/qdataurl.cpp @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplatformdefs.h" +#include "qurl.h" +#include "private/qdataurl_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \internal + + Decode a data: URL into its mimetype and payload. Returns a null string if + the URL could not be decoded. +*/ +Q_CORE_EXPORT QPair<QString, QByteArray> qDecodeDataUrl(const QUrl &uri) +{ + QString mimeType; + QByteArray payload; + + if (uri.scheme() == QLatin1String("data") && uri.host().isEmpty()) { + mimeType = QLatin1String("text/plain;charset=US-ASCII"); + + // the following would have been the correct thing, but + // reality often differs from the specification. People have + // data: URIs with ? and # + //QByteArray data = QByteArray::fromPercentEncoding(uri.encodedPath()); + QByteArray data = QByteArray::fromPercentEncoding(uri.toEncoded()); + + // remove the data: scheme + data.remove(0, 5); + + // parse it: + int pos = data.indexOf(','); + if (pos != -1) { + payload = data.mid(pos + 1); + data.truncate(pos); + data = data.trimmed(); + + // find out if the payload is encoded in Base64 + if (data.endsWith(";base64")) { + payload = QByteArray::fromBase64(payload); + data.chop(7); + } + + if (data.toLower().startsWith("charset")) { + int i = 7; // strlen("charset") + while (data.at(i) == ' ') + ++i; + if (data.at(i) == '=') + data.prepend("text/plain;"); + } + + if (!data.isEmpty()) + mimeType = QLatin1String(data.trimmed()); + + } + } + + return QPair<QString,QByteArray>(mimeType,payload); +} + +QT_END_NAMESPACE diff --git a/src/corelib/io/qdataurl_p.h b/src/corelib/io/qdataurl_p.h new file mode 100644 index 0000000..be5b10d --- /dev/null +++ b/src/corelib/io/qdataurl_p.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDATAURL_P_H +#define QDATAURL_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of qDecodeDataUrl. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "QtCore/qurl.h" +#include "QtCore/qbytearray.h" +#include "QtCore/qstring.h" +#include "QtCore/qpair.h" + +QT_BEGIN_NAMESPACE + +Q_CORE_EXPORT QPair<QString, QByteArray> qDecodeDataUrl(const QUrl &url); + +QT_END_NAMESPACE + +#endif // QDATAURL_P_H diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index dc7f17e..f5d803e 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -52,13 +52,13 @@ #include "qregexp.h" #include "qvector.h" #include "qalgorithms.h" +#include "qvarlengtharray.h" + #ifdef QT_BUILD_CORE_LIB -# include "qresource.h" +# include "qresource.h" +# include "private/qcoreglobaldata_p.h" #endif -#include "qvarlengtharray.h" - -#include "private/qcoreglobaldata_p.h" #include <stdlib.h> QT_BEGIN_NAMESPACE @@ -83,12 +83,10 @@ static QString driveSpec(const QString &path) //************* QDirPrivate class QDirPrivate { - QDir *q_ptr; - Q_DECLARE_PUBLIC(QDir) - friend struct QScopedPointerDeleter<QDirPrivate>; -protected: - QDirPrivate(QDir*, const QDir *copy=0); + +public: + QDirPrivate(const QDir *copy = 0); ~QDirPrivate(); QString initFileEngine(const QString &file); @@ -96,7 +94,6 @@ protected: void updateFileLists() const; void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *) const; -private: #ifdef QT3_SUPPORT QChar filterSepChar; bool matchAllDirs; @@ -109,28 +106,30 @@ private: sep = QChar(QLatin1Char(' ')); return sep; } - static inline QStringList splitFilters(const QString &nameFilter, QChar sep=0) { - if(sep == 0) + static inline QStringList splitFilters(const QString &nameFilter, QChar sep = 0) { + if (sep == 0) sep = getFilterSepChar(nameFilter); QStringList ret = nameFilter.split(sep); - for(int i = 0; i < ret.count(); i++) + for (int i = 0; i < ret.count(); ++i) ret[i] = ret[i].trimmed(); return ret; } struct Data { inline Data() - : ref(1), fileEngine(0) - { clear(); } + : ref(1), fileEngine(0), listsDirty(1) + {} inline Data(const Data ©) : ref(1), path(copy.path), nameFilters(copy.nameFilters), sort(copy.sort), - filters(copy.filters), fileEngine(0) - { clear(); } + filters(copy.filters), fileEngine(0), listsDirty(1) + {} inline ~Data() { delete fileEngine; } inline void clear() { listsDirty = 1; + files.clear(); + fileInfos.clear(); } mutable QAtomicInt ref; @@ -147,7 +146,6 @@ private: } *data; inline void setPath(const QString &p) { - detach(false); QString path = p; if ((path.endsWith(QLatin1Char('/')) || path.endsWith(QLatin1Char('\\'))) && path.length() > 1) { @@ -156,12 +154,9 @@ private: #endif path.truncate(path.length() - 1); } - if(!data->fileEngine || !QDir::isRelativePath(path)) - path = initFileEngine(path); - data->fileEngine->setFileName(path); + // set the path to be the qt friendly version so then we can operate on it using just / - data->path = data->fileEngine->fileName(QAbstractFileEngine::DefaultName); - data->clear(); + data->path = initFileEngine(path); } inline void reset() { detach(); @@ -170,18 +165,16 @@ private: void detach(bool createFileEngine = true); }; -QDirPrivate::QDirPrivate(QDir *qq, const QDir *copy) : q_ptr(qq) +QDirPrivate::QDirPrivate(const QDir *copy) #ifdef QT3_SUPPORT - , filterSepChar(0) - , matchAllDirs(false) + : filterSepChar(0), matchAllDirs(false) #endif { - if(copy) { + if (copy) { copy->d_func()->data->ref.ref(); data = copy->d_func()->data; } else { data = new QDirPrivate::Data; - data->clear(); } } @@ -190,18 +183,19 @@ QDirPrivate::~QDirPrivate() if (!data->ref.deref()) delete data; data = 0; - q_ptr = 0; } /* For sorting */ -struct QDirSortItem { +struct QDirSortItem +{ mutable QString filename_cache; mutable QString suffix_cache; QFileInfo item; }; -class QDirSortItemComparator { +class QDirSortItemComparator +{ int qt_cmp_si_sort_flags; public: QDirSortItemComparator(int flags) : qt_cmp_si_sort_flags(flags) {} @@ -240,7 +234,7 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt f2->suffix_cache = ic ? f2->item.suffix().toLower() : f2->item.suffix(); - r = qt_cmp_si_sort_flags & QDir::LocaleAware + r = qt_cmp_si_sort_flags & QDir::LocaleAware ? f1->suffix_cache.localeAwareCompare(f2->suffix_cache) : f1->suffix_cache.compare(f2->suffix_cache); } @@ -260,7 +254,7 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt f2->filename_cache = ic ? f2->item.fileName().toLower() : f2->item.fileName(); - r = qt_cmp_si_sort_flags & QDir::LocaleAware + r = qt_cmp_si_sort_flags & QDir::LocaleAware ? f1->filename_cache.localeAwareCompare(f2->filename_cache) : f1->filename_cache.compare(f2->filename_cache); } @@ -274,16 +268,13 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, QStringList *names, QFileInfoList *infos) const { - if(names) - names->clear(); - if(infos) - infos->clear(); + // names and infos are always empty lists or 0 here int n = l.size(); - if(n > 0) { + if (n > 0) { if (n == 1 || (sort & QDir::SortByMask) == QDir::Unsorted) { - if(infos) + if (infos) *infos = l; - if(names) { + if (names) { for (int i = 0; i < n; ++i) names->append(l.at(i).fileName()); } @@ -291,13 +282,13 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, QScopedArrayPointer<QDirSortItem> si(new QDirSortItem[n]); for (int i = 0; i < n; ++i) si[i].item = l.at(i); - qSort(si.data(), si.data()+n, QDirSortItemComparator(sort)); + qSort(si.data(), si.data() + n, QDirSortItemComparator(sort)); // put them back in the list(s) - if(infos) { + if (infos) { for (int i = 0; i < n; ++i) infos->append(si[i].item); } - if(names) { + if (names) { for (int i = 0; i < n; ++i) names->append(si[i].item.fileName()); } @@ -307,7 +298,7 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, QFileInfoList &l, inline void QDirPrivate::updateFileLists() const { - if(data->listsDirty) { + if (data->listsDirty) { QFileInfoList l; QDirIterator it(data->path, data->nameFilters, data->filters); while (it.hasNext()) { @@ -319,12 +310,11 @@ inline void QDirPrivate::updateFileLists() const } } -QString QDirPrivate::initFileEngine(const QString &path) +inline QString QDirPrivate::initFileEngine(const QString &path) { detach(false); - delete data->fileEngine; - data->fileEngine = 0; data->clear(); + delete data->fileEngine; data->fileEngine = QAbstractFileEngine::create(path); return data->fileEngine->fileName(QAbstractFileEngine::DefaultName); } @@ -520,8 +510,7 @@ void QDirPrivate::detach(bool createFileEngine) \sa currentPath() */ - -QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(this)) +QDir::QDir(const QString &path) : d_ptr(new QDirPrivate) { Q_D(QDir); d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path); @@ -548,18 +537,17 @@ QDir::QDir(const QString &path) : d_ptr(new QDirPrivate(this)) \sa exists(), setPath(), setNameFilter(), setFilter(), setSorting() */ - QDir::QDir(const QString &path, const QString &nameFilter, - SortFlags sort, Filters filters) : d_ptr(new QDirPrivate(this)) + SortFlags sort, Filters filters) : d_ptr(new QDirPrivate) { Q_D(QDir); d->setPath(path.isEmpty() ? QString::fromLatin1(".") : path); d->data->nameFilters = QDir::nameFiltersFromString(nameFilter); bool empty = d->data->nameFilters.isEmpty(); - if(!empty) { + if (!empty) { empty = true; - for(int i = 0; i < d->data->nameFilters.size(); ++i) { - if(!d->data->nameFilters.at(i).isEmpty()) { + for (int i = 0; i < d->data->nameFilters.size(); ++i) { + if (!d->data->nameFilters.at(i).isEmpty()) { empty = false; break; } @@ -577,8 +565,7 @@ QDir::QDir(const QString &path, const QString &nameFilter, \sa operator=() */ - -QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(this, &dir)) +QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(&dir)) { } @@ -586,7 +573,6 @@ QDir::QDir(const QDir &dir) : d_ptr(new QDirPrivate(this, &dir)) Destroys the QDir object frees up its resources. This has no effect on the underlying directory in the file system. */ - QDir::~QDir() { } @@ -607,7 +593,6 @@ QDir::~QDir() \sa path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), isRelative(), makeAbsolute() */ - void QDir::setPath(const QString &path) { Q_D(QDir); @@ -624,7 +609,6 @@ void QDir::setPath(const QString &path) \sa setPath(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), toNativeSeparators(), makeAbsolute() */ - QString QDir::path() const { Q_D(const QDir); @@ -639,7 +623,6 @@ QString QDir::path() const \sa setPath(), canonicalPath(), exists(), cleanPath(), dirName(), absoluteFilePath() */ - QString QDir::absolutePath() const { Q_D(const QDir); @@ -649,7 +632,6 @@ QString QDir::absolutePath() const return cleanPath(ret); } - /*! Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements. @@ -666,12 +648,11 @@ QString QDir::absolutePath() const \sa path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath() */ - QString QDir::canonicalPath() const { Q_D(const QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return cleanPath(d->data->fileEngine->fileName(QAbstractFileEngine::CanonicalName)); } @@ -687,7 +668,6 @@ QString QDir::canonicalPath() const \sa path(), filePath(), absolutePath(), absoluteFilePath() */ - QString QDir::dirName() const { Q_D(const QDir); @@ -706,7 +686,6 @@ QString QDir::dirName() const \sa dirName() absoluteFilePath(), isRelative(), canonicalPath() */ - QString QDir::filePath(const QString &fileName) const { Q_D(const QDir); @@ -714,7 +693,7 @@ QString QDir::filePath(const QString &fileName) const return QString(fileName); QString ret = d->data->path; - if(!fileName.isEmpty()) { + if (!fileName.isEmpty()) { if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/')) ret += QLatin1Char('/'); ret += fileName; @@ -730,13 +709,12 @@ QString QDir::filePath(const QString &fileName) const \sa relativeFilePath() filePath() canonicalPath() */ - QString QDir::absoluteFilePath(const QString &fileName) const { Q_D(const QDir); if (isAbsolutePath(fileName)) return fileName; - if(!d->data->fileEngine) + if (!d->data->fileEngine) return fileName; QString ret; @@ -744,7 +722,7 @@ QString QDir::absoluteFilePath(const QString &fileName) const if (isRelativePath(d->data->path)) //get pwd ret = QFSFileEngine::currentPath(fileName); #endif - if(!d->data->path.isEmpty() && d->data->path != QLatin1String(".")) { + if (!d->data->path.isEmpty() && d->data->path != QLatin1String(".")) { if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) ret += QLatin1Char('/'); ret += d->data->path; @@ -764,7 +742,6 @@ QString QDir::absoluteFilePath(const QString &fileName) const \sa absoluteFilePath() filePath() canonicalPath() */ - QString QDir::relativeFilePath(const QString &fileName) const { QString dir = absolutePath(); @@ -851,7 +828,7 @@ QString QDir::toNativeSeparators(const QString &pathName) { QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i=0; i<(int)n.length(); i++) { + for (int i = 0; i < (int)n.length(); ++i) { if (n[i] == QLatin1Char('/')) n[i] = QLatin1Char('\\'); } @@ -875,7 +852,7 @@ QString QDir::fromNativeSeparators(const QString &pathName) { QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i=0; i<(int)n.length(); i++) { + for (int i = 0; i < (int)n.length(); ++i) { if (n[i] == QLatin1Char('\\')) n[i] = QLatin1Char('/'); } @@ -894,7 +871,6 @@ QString QDir::fromNativeSeparators(const QString &pathName) \sa cdUp(), isReadable(), exists(), path() */ - bool QDir::cd(const QString &dirName) { Q_D(QDir); @@ -930,14 +906,13 @@ bool QDir::cd(const QString &dirName) } } } - { - QFileInfo fi(newPath); - if (!(fi.exists() && fi.isDir())) - return false; - } - d->setPath(newPath); - refresh(); + QDir dir(*this); + dir.setPath(newPath); + if (!dir.exists()) + return false; + + *this = dir; return true; } @@ -951,7 +926,6 @@ bool QDir::cd(const QString &dirName) \sa cd(), isReadable(), exists(), path() */ - bool QDir::cdUp() { return cd(QString::fromLatin1("..")); @@ -960,7 +934,6 @@ bool QDir::cdUp() /*! Returns the string list set by setNameFilters() */ - QStringList QDir::nameFilters() const { Q_D(const QDir); @@ -983,11 +956,11 @@ QStringList QDir::nameFilters() const \sa nameFilters(), setFilter() */ - void QDir::setNameFilters(const QStringList &nameFilters) { Q_D(QDir); - d->detach(); + + d->reset(); d->data->nameFilters = nameFilters; } @@ -1001,7 +974,6 @@ void QDir::setNameFilters(const QStringList &nameFilters) \sa {The Qt Resource System}, QResource::addSearchPath() */ - void QDir::addResourceSearchPath(const QString &path) { #ifdef QT_BUILD_CORE_LIB @@ -1039,7 +1011,7 @@ void QDir::setSearchPaths(const QString &prefix, const QStringList &searchPaths) return; } - for (int i = 0; i < prefix.count(); i++) { + for (int i = 0; i < prefix.count(); ++i) { if (!prefix.at(i).isLetterOrNumber()) { qWarning("QDir::setSearchPaths: Prefix can only contain letters or numbers"); return; @@ -1089,7 +1061,6 @@ QStringList QDir::searchPaths(const QString &prefix) /*! Returns the value set by setFilter() */ - QDir::Filters QDir::filter() const { Q_D(const QDir); @@ -1171,12 +1142,11 @@ QDir::Filters QDir::filter() const \sa filter(), setNameFilters() */ - void QDir::setFilter(Filters filters) { Q_D(QDir); - d->detach(); + d->reset(); d->data->filters = filters; } @@ -1185,7 +1155,6 @@ void QDir::setFilter(Filters filters) \sa setSorting() SortFlag */ - QDir::SortFlags QDir::sorting() const { Q_D(const QDir); @@ -1231,16 +1200,14 @@ QDir::SortFlags QDir::sorting() const \sa sorting() SortFlag */ - void QDir::setSorting(SortFlags sort) { Q_D(QDir); - d->detach(); + d->reset(); d->data->sort = sort; } - /*! Returns the total number of directories and files in the directory. @@ -1248,7 +1215,6 @@ void QDir::setSorting(SortFlags sort) \sa operator[](), entryList() */ - uint QDir::count() const { Q_D(const QDir); @@ -1260,13 +1226,10 @@ uint QDir::count() const /*! Returns the file name at position \a pos in the list of file names. Equivalent to entryList().at(index). - - Returns an empty string if \a pos is out of range or if the - entryList() function failed. + \a pos must be a valid index position in the list (i.e., 0 <= pos < count()). \sa count(), entryList() */ - QString QDir::operator[](int pos) const { Q_D(const QDir); @@ -1294,7 +1257,6 @@ QString QDir::operator[](int pos) const \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() */ - QStringList QDir::entryList(Filters filters, SortFlags sort) const { Q_D(const QDir); @@ -1342,7 +1304,6 @@ QFileInfoList QDir::entryInfoList(Filters filters, SortFlags sort) const \sa entryInfoList(), setNameFilters(), setSorting(), setFilter() */ - QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, SortFlags sort) const { @@ -1356,10 +1317,12 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, #endif if (sort == NoSort) sort = d->data->sort; - if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) { + + if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) { d->updateFileLists(); return d->data->files; } + QFileInfoList l; QDirIterator it(d->data->path, nameFilters, filters); while (it.hasNext()) { @@ -1387,7 +1350,6 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters, \sa entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), exists() */ - QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filters, SortFlags sort) const { @@ -1401,10 +1363,12 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter #endif if (sort == NoSort) sort = d->data->sort; - if (filters == NoFilter && sort == NoSort && nameFilters == d->data->nameFilters) { + + if (filters == d->data->filters && sort == d->data->sort && nameFilters == d->data->nameFilters) { d->updateFileLists(); return d->data->fileInfos; } + QFileInfoList l; QDirIterator it(d->data->path, nameFilters, filters); while (it.hasNext()) { @@ -1423,7 +1387,6 @@ QFileInfoList QDir::entryInfoList(const QStringList &nameFilters, Filters filter \sa rmdir() */ - bool QDir::mkdir(const QString &dirName) const { Q_D(const QDir); @@ -1432,7 +1395,7 @@ bool QDir::mkdir(const QString &dirName) const qWarning("QDir::mkdir: Empty or null file name(s)"); return false; } - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QString fn = filePath(dirName); @@ -1448,7 +1411,6 @@ bool QDir::mkdir(const QString &dirName) const \sa mkdir() */ - bool QDir::rmdir(const QString &dirName) const { Q_D(const QDir); @@ -1457,7 +1419,7 @@ bool QDir::rmdir(const QString &dirName) const qWarning("QDir::rmdir: Empty or null file name(s)"); return false; } - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QString fn = filePath(dirName); @@ -1474,7 +1436,6 @@ bool QDir::rmdir(const QString &dirName) const \sa rmpath() */ - bool QDir::mkpath(const QString &dirPath) const { Q_D(const QDir); @@ -1483,7 +1444,7 @@ bool QDir::mkpath(const QString &dirPath) const qWarning("QDir::mkpath: Empty or null file name(s)"); return false; } - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QString fn = filePath(dirPath); @@ -1509,7 +1470,7 @@ bool QDir::rmpath(const QString &dirPath) const qWarning("QDir::rmpath: Empty or null file name(s)"); return false; } - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QString fn = filePath(dirPath); @@ -1525,17 +1486,16 @@ bool QDir::rmpath(const QString &dirPath) const \sa QFileInfo::isReadable() */ - - bool QDir::isReadable() const { Q_D(const QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; - const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType - |QAbstractFileEngine::PermsMask); - if(!(info & QAbstractFileEngine::DirectoryType)) + const QAbstractFileEngine::FileFlags info = + d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType + | QAbstractFileEngine::PermsMask); + if (!(info & QAbstractFileEngine::DirectoryType)) return false; return info & QAbstractFileEngine::ReadUserPerm; } @@ -1551,19 +1511,17 @@ bool QDir::isReadable() const \sa QFileInfo::exists(), QFile::exists() */ - bool QDir::exists() const { Q_D(const QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; const QAbstractFileEngine::FileFlags info = - d->data->fileEngine->fileFlags( - QAbstractFileEngine::DirectoryType - | QAbstractFileEngine::ExistsFlag - | QAbstractFileEngine::Refresh); - if(!(info & QAbstractFileEngine::DirectoryType)) + d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType + | QAbstractFileEngine::ExistsFlag + | QAbstractFileEngine::Refresh); + if (!(info & QAbstractFileEngine::DirectoryType)) return false; return info & QAbstractFileEngine::ExistsFlag; } @@ -1580,12 +1538,11 @@ bool QDir::exists() const \sa root(), rootPath() */ - bool QDir::isRoot() const { Q_D(const QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return true; return d->data->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag; } @@ -1615,12 +1572,11 @@ bool QDir::isRoot() const \sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath() */ - bool QDir::isRelative() const { Q_D(const QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->data->fileEngine->isRelativePath(); } @@ -1633,20 +1589,19 @@ bool QDir::isRelative() const \sa isAbsolute() isAbsolutePath() isRelative() cleanPath() */ - bool QDir::makeAbsolute() // ### What do the return values signify? { Q_D(QDir); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QString absolutePath = d->data->fileEngine->fileName(QAbstractFileEngine::AbsoluteName); - if(QDir::isRelativePath(absolutePath)) + if (QDir::isRelativePath(absolutePath)) return false; d->detach(); d->data->path = absolutePath; d->data->fileEngine->setFileName(absolutePath); - if(!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType)) + if (!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType)) return false; return true; } @@ -1660,22 +1615,21 @@ bool QDir::makeAbsolute() // ### What do the return values signify? \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 10 */ - bool QDir::operator==(const QDir &dir) const { const QDirPrivate *d = d_func(); const QDirPrivate *other = dir.d_func(); - if(d->data == other->data) + if (d->data == other->data) return true; Q_ASSERT(d->data->fileEngine && other->data->fileEngine); - if(d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive()) + if (d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive()) return false; - if(d->data->filters == other->data->filters + if (d->data->filters == other->data->filters && d->data->sort == other->data->sort && d->data->nameFilters == other->data->nameFilters) { QString dir1 = absolutePath(), dir2 = dir.absolutePath(); - if(!other->data->fileEngine->caseSensitive()) + if (!other->data->fileEngine->caseSensitive()) return (dir1.toLower() == dir2.toLower()); return (dir1 == dir2); @@ -1688,7 +1642,6 @@ bool QDir::operator==(const QDir &dir) const Makes a copy of the \a dir object and assigns it to this QDir object. */ - QDir &QDir::operator=(const QDir &dir) { if (this == &dir) @@ -1707,7 +1660,6 @@ QDir &QDir::operator=(const QDir &dir) Use setPath() instead. */ - QDir &QDir::operator=(const QString &path) { Q_D(QDir); @@ -1728,22 +1680,19 @@ QDir &QDir::operator=(const QString &path) \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 11 */ - /*! Removes the file, \a fileName. Returns true if the file is removed successfully; otherwise returns false. */ - bool QDir::remove(const QString &fileName) { if (fileName.isEmpty()) { qWarning("QDir::remove: Empty or null file name"); return false; } - QString p = filePath(fileName); - return QFile::remove(p); + return QFile::remove(filePath(fileName)); } /*! @@ -1757,7 +1706,6 @@ bool QDir::remove(const QString &fileName) fail. For example, on at least one file system rename() fails if \a newName points to an open file. */ - bool QDir::rename(const QString &oldName, const QString &newName) { Q_D(QDir); @@ -1766,11 +1714,11 @@ bool QDir::rename(const QString &oldName, const QString &newName) qWarning("QDir::rename: Empty or null file name(s)"); return false; } - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; QFile file(filePath(oldName)); - if(!file.exists()) + if (!file.exists()) return false; return file.rename(filePath(newName)); } @@ -1785,15 +1733,13 @@ bool QDir::rename(const QString &oldName, const QString &newName) \sa QFileInfo::exists(), QFile::exists() */ - bool QDir::exists(const QString &name) const { if (name.isEmpty()) { qWarning("QDir::exists: Empty or null file name"); return false; } - QString tmp = filePath(name); - return QFile::exists(tmp); + return QFile::exists(filePath(name)); } /*! @@ -1805,7 +1751,6 @@ bool QDir::exists(const QString &name) const \sa root(), rootPath() */ - QFileInfoList QDir::drives() { #ifdef QT_NO_FSFILEENGINE @@ -1825,7 +1770,6 @@ QFileInfoList QDir::drives() user using their operating system's separator use toNativeSeparators(). */ - QChar QDir::separator() { #if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) @@ -1844,9 +1788,8 @@ QChar QDir::separator() Returns true if the directory was successfully changed; otherwise returns false. - \sa current() currentPath() home() root() temp() + \sa current(), currentPath(), home(), root(), temp() */ - bool QDir::setCurrent(const QString &path) { #ifdef QT_NO_FSFILEENGINE @@ -1865,13 +1808,13 @@ bool QDir::setCurrent(const QString &path) The directory is constructed using the absolute path of the current directory, ensuring that its path() will be the same as its absolutePath(). - \sa currentPath(), home(), root(), temp() + \sa currentPath(), setCurrent(), home(), root(), temp() */ /*! Returns the absolute path of the application's current directory. - \sa current(), homePath(), rootPath(), tempPath() + \sa current(), setCurrent(), homePath(), rootPath(), tempPath() */ QString QDir::currentPath() { @@ -1888,7 +1831,7 @@ QString QDir::currentPath() Use currentPath() instead. - \sa currentPath() + \sa currentPath(), setCurrent() */ /*! @@ -1945,14 +1888,14 @@ QString QDir::homePath() } /*! - \fn QString QDir::homeDirPath() + \fn QString QDir::homeDirPath() - Returns the absolute path of the user's home directory. + Returns the absolute path of the user's home directory. - Use homePath() instead. + Use homePath() instead. - \sa homePath() - */ + \sa homePath() +*/ /*! \fn QDir QDir::temp() @@ -2018,13 +1961,13 @@ QString QDir::rootPath() } /*! - \fn QString QDir::rootDirPath() + \fn QString QDir::rootDirPath() - Returns the absolute path of the root directory. + Returns the absolute path of the root directory. - Use rootPath() instead. + Use rootPath() instead. - \sa rootPath() + \sa rootPath() */ #ifndef QT_NO_REGEXP @@ -2037,11 +1980,9 @@ QString QDir::rootPath() \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() */ - - bool QDir::match(const QStringList &filters, const QString &fileName) { - for(QStringList::ConstIterator sit = filters.begin(); sit != filters.end(); ++sit) { + for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) { QRegExp rx(*sit, Qt::CaseInsensitive, QRegExp::Wildcard); if (rx.exactMatch(fileName)) return true; @@ -2057,12 +1998,11 @@ bool QDir::match(const QStringList &filters, const QString &fileName) \sa {QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList() */ - bool QDir::match(const QString &filter, const QString &fileName) { return match(nameFiltersFromString(filter), fileName); } -#endif +#endif // QT_NO_REGEXP /*! Removes all multiple directory separators "/" and resolves any @@ -2075,15 +2015,14 @@ bool QDir::match(const QString &filter, const QString &fileName) \sa absolutePath() canonicalPath() */ - QString QDir::cleanPath(const QString &path) { if (path.isEmpty()) return path; QString name = path; QChar dir_separator = separator(); - if(dir_separator != QLatin1Char('/')) - name.replace(dir_separator, QLatin1Char('/')); + if (dir_separator != QLatin1Char('/')) + name.replace(dir_separator, QLatin1Char('/')); int used = 0, levels = 0; const int len = name.length(); @@ -2091,27 +2030,27 @@ QString QDir::cleanPath(const QString &path) QChar *out = outVector.data(); const QChar *p = name.unicode(); - for(int i = 0, last = -1, iwrite = 0; i < len; i++) { - if(p[i] == QLatin1Char('/')) { - while(i < len-1 && p[i+1] == QLatin1Char('/')) { + for (int i = 0, last = -1, iwrite = 0; i < len; ++i) { + if (p[i] == QLatin1Char('/')) { + while (i < len-1 && p[i+1] == QLatin1Char('/')) { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths - if(!i) + if (!i) break; #endif i++; } bool eaten = false; - if(i < len - 1 && p[i+1] == QLatin1Char('.')) { + if (i < len - 1 && p[i+1] == QLatin1Char('.')) { int dotcount = 1; - if(i < len - 2 && p[i+2] == QLatin1Char('.')) + if (i < len - 2 && p[i+2] == QLatin1Char('.')) dotcount++; - if(i == len - dotcount - 1) { - if(dotcount == 1) { + if (i == len - dotcount - 1) { + if (dotcount == 1) { break; - } else if(levels) { - if(last == -1) { - for(int i2 = iwrite-1; i2 >= 0; i2--) { - if(out[i2] == QLatin1Char('/')) { + } else if (levels) { + if (last == -1) { + for (int i2 = iwrite-1; i2 >= 0; i2--) { + if (out[i2] == QLatin1Char('/')) { last = i2; break; } @@ -2120,11 +2059,11 @@ QString QDir::cleanPath(const QString &path) used -= iwrite - last - 1; break; } - } else if(p[i+dotcount+1] == QLatin1Char('/')) { - if(dotcount == 2 && levels) { - if(last == -1 || iwrite - last == 1) { - for(int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) { - if(out[i2] == QLatin1Char('/')) { + } else if (p[i+dotcount+1] == QLatin1Char('/')) { + if (dotcount == 2 && levels) { + if (last == -1 || iwrite - last == 1) { + for (int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) { + if (out[i2] == QLatin1Char('/')) { eaten = true; last = i2; break; @@ -2133,7 +2072,7 @@ QString QDir::cleanPath(const QString &path) } else { eaten = true; } - if(eaten) { + if (eaten) { levels--; used -= iwrite - last; iwrite = last; @@ -2145,38 +2084,38 @@ QString QDir::cleanPath(const QString &path) iwrite = qMax(0, last); last = -1; ++i; - } else if(dotcount == 1) { + } else if (dotcount == 1) { eaten = true; } - if(eaten) + if (eaten) i += dotcount; } else { levels++; } - } else if(last != -1 && iwrite - last == 1) { + } else if (last != -1 && iwrite - last == 1) { #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) eaten = (iwrite > 2); #else eaten = true; #endif last = -1; - } else if(last != -1 && i == len-1) { + } else if (last != -1 && i == len-1) { eaten = true; } else { levels++; } - if(!eaten) + if (!eaten) last = i - (i - iwrite); else continue; - } else if(!i && p[i] == QLatin1Char('.')) { + } else if (!i && p[i] == QLatin1Char('.')) { int dotcount = 1; - if(len >= 1 && p[1] == QLatin1Char('.')) + if (len >= 1 && p[1] == QLatin1Char('.')) dotcount++; - if(len >= dotcount && p[dotcount] == QLatin1Char('/')) { - if(dotcount == 1) { + if (len >= dotcount && p[dotcount] == QLatin1Char('/')) { + if (dotcount == 1) { i++; - while(i+1 < len-1 && p[i+1] == QLatin1Char('/')) + while (i+1 < len-1 && p[i+1] == QLatin1Char('/')) i++; continue; } @@ -2185,16 +2124,15 @@ QString QDir::cleanPath(const QString &path) out[iwrite++] = p[i]; used++; } - QString ret; - if(used == len) - ret = name; - else - ret = QString(out, used); + QString ret = (used == len ? name : QString(out, used)); // Strip away last slash except for root directories - if (ret.endsWith(QLatin1Char('/')) - && !(ret.size() == 1 || (ret.size() == 3 && ret.at(1) == QLatin1Char(':')))) - ret = ret.left(ret.length() - 1); + if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) { +#ifdef Q_OS_WIN + if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':'))) +#endif + ret.chop(1); + } return ret; } @@ -2205,7 +2143,6 @@ QString QDir::cleanPath(const QString &path) \sa isRelative() isAbsolutePath() makeAbsolute() */ - bool QDir::isRelativePath(const QString &path) { return QFileInfo(path).isRelative(); @@ -2214,12 +2151,11 @@ bool QDir::isRelativePath(const QString &path) /*! Refreshes the directory information. */ - void QDir::refresh() const { Q_D(const QDir); - d->data->clear(); + const_cast<QDirPrivate *>(d)->reset(); } /*! @@ -2229,7 +2165,6 @@ void QDir::refresh() const there is more than one filter, each pair of filters is separated by a space or by a semicolon.) */ - QStringList QDir::nameFiltersFromString(const QString &nameFilter) { return QDirPrivate::splitFilters(nameFilter); @@ -2309,6 +2244,8 @@ bool QDir::matchAllDirs() const void QDir::setMatchAllDirs(bool on) { Q_D(QDir); + + d->reset(); d->matchAllDirs = on; } @@ -2421,7 +2358,8 @@ void QDir::setNameFilter(const QString &nameFilter) Use QDir::SortFlags instead. */ -#endif +#endif // QT3_SUPPORT + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, QDir::Filters filters) { @@ -2484,9 +2422,6 @@ QDebug operator<<(QDebug debug, const QDir &dir) << ')'; return debug.space(); } - - - -#endif +#endif // QT_NO_DEBUG_STREAM QT_END_NAMESPACE diff --git a/src/corelib/io/qdir.h b/src/corelib/io/qdir.h index 6be4922..186dd2f 100644 --- a/src/corelib/io/qdir.h +++ b/src/corelib/io/qdir.h @@ -83,7 +83,7 @@ public: Modified = 0x080, Hidden = 0x100, System = 0x200, - + AccessMask = 0x3F0, AllDirs = 0x400, @@ -215,6 +215,7 @@ public: static bool match(const QStringList &filters, const QString &fileName); static bool match(const QString &filter, const QString &fileName); #endif + static QString cleanPath(const QString &path); void refresh() const; @@ -246,7 +247,7 @@ public: inline QT3_SUPPORT static QString homeDirPath() { return homePath(); } inline QT3_SUPPORT static QString rootDirPath() { return rootPath(); } inline QT3_SUPPORT static QString cleanDirPath(const QString &name) { return cleanPath(name); } -#endif +#endif // QT3_SUPPORT }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDir::Filters) diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index e90529e..625098e 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -41,12 +41,8 @@ #include "qplatformdefs.h" #include "qfileinfo.h" -#include "qdatetime.h" -#include "qabstractfileengine.h" #include "qfsfileengine_p.h" #include "qglobal.h" -#include "qatomic.h" -#include "qhash.h" #include "qdir.h" #include "qfileinfo_p.h" @@ -54,7 +50,7 @@ QT_BEGIN_NAMESPACE QFileInfoPrivate::QFileInfoPrivate(const QFileInfo *copy) { - if(copy) { + if (copy) { copy->d_func()->data->ref.ref(); data = copy->d_func()->data; } else { @@ -81,7 +77,8 @@ void QFileInfoPrivate::initFileEngine(const QString &file) bool QFileInfoPrivate::hasAccess(Access access) const { - if (!(getFileFlags(QAbstractFileEngine::FileInfoAll) & QAbstractFileEngine::LocalDiskFlag)) { + if (!(getFileFlags(QAbstractFileEngine::PermsMask + | QAbstractFileEngine::LocalDiskFlag) & QAbstractFileEngine::LocalDiskFlag)) { switch (access) { case ReadAccess: return getFileFlags(QAbstractFileEngine::ReadUserPerm); @@ -129,86 +126,104 @@ void QFileInfoPrivate::detach() QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const { - if(data->cache_enabled && !data->fileNames[(int)name].isNull()) + if (data->cache_enabled && !data->fileNames[(int)name].isNull()) return data->fileNames[(int)name]; QString ret = data->fileEngine->fileName(name); - if(data->cache_enabled) + if (ret.isNull()) + ret = QLatin1String(""); + if (data->cache_enabled) data->fileNames[(int)name] = ret; return ret; } +QString QFileInfoPrivate::getFileOwner(QAbstractFileEngine::FileOwner own) const +{ + if (data->cache_enabled && !data->fileOwners[(int)own].isNull()) + return data->fileOwners[(int)own]; + QString ret = data->fileEngine->owner(own); + if (ret.isNull()) + ret = QLatin1String(""); + if (data->cache_enabled) + data->fileOwners[(int)own] = ret; + return ret; +} + uint QFileInfoPrivate::getFileFlags(QAbstractFileEngine::FileFlags request) const { - // We split the testing into tests for for LinkType, BundleType and the rest. + // We split the testing into tests for for LinkType, BundleType, PermsMask + // and the rest. + // Tests for file permissions on Windows can be slow, expecially on network + // paths and NTFS drives. // In order to determine if a file is a symlink or not, we have to lstat(). // If we're not interested in that information, we might as well avoid one // extra syscall. Bundle detecton on Mac can be slow, expecially on network // paths, so we separate out that as well. - QAbstractFileEngine::FileFlags flags; - if (!data->getCachedFlag(CachedFileFlags)) { - QAbstractFileEngine::FileFlags req = QAbstractFileEngine::FileInfoAll; - req &= (~QAbstractFileEngine::LinkType); - req &= (~QAbstractFileEngine::BundleType); + QAbstractFileEngine::FileFlags req = 0; + uint cachedFlags = 0; - flags = data->fileEngine->fileFlags(req); - data->setCachedFlag(CachedFileFlags); - data->fileFlags |= uint(flags); - } else { - flags = QAbstractFileEngine::FileFlags(data->fileFlags & request); - } + if (request & (QAbstractFileEngine::FlagsMask | QAbstractFileEngine::TypesMask)) { + if (!data->getCachedFlag(CachedFileFlags)) { + req |= QAbstractFileEngine::FlagsMask; + req |= QAbstractFileEngine::TypesMask; + req &= (~QAbstractFileEngine::LinkType); + req &= (~QAbstractFileEngine::BundleType); - if (request & QAbstractFileEngine::LinkType) { - if (!data->getCachedFlag(CachedLinkTypeFlag)) { - QAbstractFileEngine::FileFlags linkflag; - linkflag = data->fileEngine->fileFlags(QAbstractFileEngine::LinkType); + cachedFlags |= CachedFileFlags; + } - data->setCachedFlag(CachedLinkTypeFlag); - data->fileFlags |= uint(linkflag); - flags |= linkflag; + if (request & QAbstractFileEngine::LinkType) { + if (!data->getCachedFlag(CachedLinkTypeFlag)) { + req |= QAbstractFileEngine::LinkType; + cachedFlags |= CachedLinkTypeFlag; + } } - } - if (request & QAbstractFileEngine::BundleType) { - if (!data->getCachedFlag(CachedBundleTypeFlag)) { - QAbstractFileEngine::FileFlags bundleflag; - bundleflag = data->fileEngine->fileFlags(QAbstractFileEngine::BundleType); + if (request & QAbstractFileEngine::BundleType) { + if (!data->getCachedFlag(CachedBundleTypeFlag)) { + req |= QAbstractFileEngine::BundleType; + cachedFlags |= CachedBundleTypeFlag; + } + } + } - data->setCachedFlag(CachedBundleTypeFlag); - data->fileFlags |= uint(bundleflag); - flags |= bundleflag; + if (request & QAbstractFileEngine::PermsMask) { + if (!data->getCachedFlag(CachedPerms)) { + req |= QAbstractFileEngine::PermsMask; + cachedFlags |= CachedPerms; } } - // no else branch - // if we had it cached, it was caught in the previous else branch + if (req) { + if (data->cache_enabled) + req &= (~QAbstractFileEngine::Refresh); + else + req |= QAbstractFileEngine::Refresh; - return flags & request; + QAbstractFileEngine::FileFlags flags = data->fileEngine->fileFlags(req); + data->fileFlags |= uint(flags); + data->setCachedFlag(cachedFlags); + } + + return data->fileFlags & request; } QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) const { if (!data->cache_enabled) data->clearFlags(); - if(request == QAbstractFileEngine::CreationTime) { - if(data->getCachedFlag(CachedCTime)) - return data->fileTimes[request]; - data->setCachedFlag(CachedCTime); - return (data->fileTimes[request] = data->fileEngine->fileTime(request)); + uint cf; + if (request == QAbstractFileEngine::CreationTime) + cf = CachedCTime; + else if (request == QAbstractFileEngine::ModificationTime) + cf = CachedMTime; + else + cf = CachedATime; + if (!data->getCachedFlag(cf)) { + data->fileTimes[request] = data->fileEngine->fileTime(request); + data->setCachedFlag(cf); } - if(request == QAbstractFileEngine::ModificationTime) { - if(data->getCachedFlag(CachedMTime)) - return data->fileTimes[request]; - data->setCachedFlag(CachedMTime); - return (data->fileTimes[request] = data->fileEngine->fileTime(request)); - } - if(request == QAbstractFileEngine::AccessTime) { - if(data->getCachedFlag(CachedATime)) - return data->fileTimes[request]; - data->setCachedFlag(CachedATime); - return (data->fileTimes[request] = data->fileEngine->fileTime(request)); - } - return data->fileTimes[0]; //cannot really happen + return data->fileTimes[request]; } //************* QFileInfo @@ -305,7 +320,6 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) \sa setFile() */ - QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate()) { } @@ -316,7 +330,6 @@ QFileInfo::QFileInfo() : d_ptr(new QFileInfoPrivate()) \sa setFile(), isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ - QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate()) { d_ptr->initFileEngine(file); @@ -331,7 +344,6 @@ QFileInfo::QFileInfo(const QString &file) : d_ptr(new QFileInfoPrivate()) \sa isRelative() */ - QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate()) { d_ptr->initFileEngine(file.fileName()); @@ -349,7 +361,6 @@ QFileInfo::QFileInfo(const QFile &file) : d_ptr(new QFileInfoPrivate()) \sa isRelative() */ - QFileInfo::QFileInfo(const QDir &dir, const QString &file) : d_ptr(new QFileInfoPrivate()) { d_ptr->initFileEngine(dir.filePath(file)); @@ -358,7 +369,6 @@ QFileInfo::QFileInfo(const QDir &dir, const QString &file) : d_ptr(new QFileInfo /*! Constructs a new QFileInfo that is a copy of the given \a fileinfo. */ - QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fileinfo)) { @@ -368,7 +378,6 @@ QFileInfo::QFileInfo(const QFileInfo &fileinfo) : d_ptr(new QFileInfoPrivate(&fi Destroys the QFileInfo and frees its resources. */ - QFileInfo::~QFileInfo() { } @@ -395,19 +404,19 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const Q_D(const QFileInfo); // ### Qt 5: understand long and short file names on Windows // ### (GetFullPathName()). - if(fileinfo.d_func()->data == d->data) + if (fileinfo.d_func()->data == d->data) return true; - if(!d->data->fileEngine || !fileinfo.d_func()->data->fileEngine) + if (!d->data->fileEngine || !fileinfo.d_func()->data->fileEngine) return false; - if(d->data->fileEngine->caseSensitive() != fileinfo.d_func()->data->fileEngine->caseSensitive()) + if (d->data->fileEngine->caseSensitive() != fileinfo.d_func()->data->fileEngine->caseSensitive()) return false; - if(fileinfo.size() == size()) { //if the size isn't the same... + if (fileinfo.size() == size()) { //if the size isn't the same... QString file1 = canonicalFilePath(), file2 = fileinfo.canonicalFilePath(); - if(file1.length() == file2.length()) { - if(!fileinfo.d_func()->data->fileEngine->caseSensitive()) { - for(int i = 0; i < file1.length(); i++) { - if(file1.at(i).toLower() != file2.at(i).toLower()) + if (file1.length() == file2.length()) { + if (!fileinfo.d_func()->data->fileEngine->caseSensitive()) { + for (int i = 0; i < file1.length(); i++) { + if (file1.at(i).toLower() != file2.at(i).toLower()) return false; } return true; @@ -441,7 +450,6 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) /*! Makes a copy of the given \a fileinfo and assigns it to this QFileInfo. */ - QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) { Q_D(QFileInfo); @@ -464,7 +472,6 @@ QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo) \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath() */ - void QFileInfo::setFile(const QString &file) { *this = QFileInfo(file); @@ -481,7 +488,6 @@ void QFileInfo::setFile(const QString &file) \sa isRelative() */ - void QFileInfo::setFile(const QFile &file) { *this = QFileInfo(file.fileName()); @@ -498,7 +504,6 @@ void QFileInfo::setFile(const QFile &file) \sa isRelative() */ - void QFileInfo::setFile(const QDir &dir, const QString &file) { *this = QFileInfo(dir.filePath(file)); @@ -528,25 +533,24 @@ void QFileInfo::setFile(const QDir &dir, const QString &file) QString QFileInfo::absoluteFilePath() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::AbsoluteName); } /*! - Returns the canonical path including the file name, i.e. an absolute - path without symbolic links or redundant "." or ".." elements. + Returns the canonical path including the file name, i.e. an absolute + path without symbolic links or redundant "." or ".." elements. - If the file does not exist, canonicalFilePath() returns an empty - string. + If the file does not exist, canonicalFilePath() returns an empty + string. - \sa filePath(), absoluteFilePath(), dir() + \sa filePath(), absoluteFilePath(), dir() */ - QString QFileInfo::canonicalFilePath() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::CanonicalName); } @@ -569,7 +573,6 @@ QString QFileInfo::canonicalFilePath() const \sa absoluteFilePath(), path(), canonicalPath(), fileName(), isRelative() */ - QString QFileInfo::absolutePath() const { Q_D(const QFileInfo); @@ -591,16 +594,14 @@ QString QFileInfo::absolutePath() const \sa path(), absolutePath() */ - QString QFileInfo::canonicalPath() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::CanonicalPathName); } - /*! Returns the file's path. This doesn't include the file name. @@ -610,11 +611,10 @@ QString QFileInfo::canonicalPath() const \sa filePath(), absolutePath(), canonicalPath(), dir(), fileName(), isRelative() */ - QString QFileInfo::path() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::PathName); } @@ -635,16 +635,14 @@ QString QFileInfo::path() const \sa isAbsolute() */ - bool QFileInfo::isRelative() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return true; return d->data->fileEngine->isRelativePath(); } - /*! Converts the file's path to an absolute path if it is not already in that form. Returns true to indicate that the path was converted; otherwise returns false @@ -652,11 +650,10 @@ bool QFileInfo::isRelative() const \sa filePath(), isRelative() */ - bool QFileInfo::makeAbsolute() { Q_D(QFileInfo); - if(!d->data->fileEngine || !d->data->fileEngine->isRelativePath()) + if (!d->data->fileEngine || !d->data->fileEngine->isRelativePath()) return false; QString absFileName = d->getFileName(QAbstractFileEngine::AbsoluteName); d->initFileEngine(absFileName); @@ -669,11 +666,10 @@ bool QFileInfo::makeAbsolute() \note If the file is a symlink that points to a non existing file, false is returned. */ - bool QFileInfo::exists() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::ExistsFlag); } @@ -685,7 +681,6 @@ bool QFileInfo::exists() const \note On Windows CE, there might be a delay for the file system driver to detect changes on the file. */ - void QFileInfo::refresh() { Q_D(QFileInfo); @@ -698,11 +693,10 @@ void QFileInfo::refresh() \sa absoluteFilePath(), canonicalFilePath(), isRelative() */ - QString QFileInfo::filePath() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::DefaultName); } @@ -718,11 +712,10 @@ QString QFileInfo::filePath() const \sa isRelative(), filePath(), baseName(), extension() */ - QString QFileInfo::fileName() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::BaseName); } @@ -739,11 +732,10 @@ QString QFileInfo::fileName() const \sa isBundle(), filePath(), baseName(), extension() */ - QString QFileInfo::bundleName() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::BundleName); } @@ -764,11 +756,10 @@ QString QFileInfo::bundleName() const \sa fileName(), suffix(), completeSuffix(), completeBaseName() */ - QString QFileInfo::baseName() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::BaseName).section(QLatin1Char('.'), 0, 0); } @@ -784,11 +775,10 @@ QString QFileInfo::baseName() const \sa fileName(), suffix(), completeSuffix(), baseName() */ - QString QFileInfo::completeBaseName() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); QString name = d->getFileName(QAbstractFileEngine::BaseName); int index = name.lastIndexOf(QLatin1Char('.')); @@ -806,11 +796,10 @@ QString QFileInfo::completeBaseName() const \sa fileName(), suffix(), baseName(), completeBaseName() */ - QString QFileInfo::completeSuffix() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); QString fileName = d->getFileName(QAbstractFileEngine::BaseName); int firstDot = fileName.indexOf(QLatin1Char('.')); @@ -834,11 +823,10 @@ QString QFileInfo::completeSuffix() const \sa fileName(), completeSuffix(), baseName(), completeBaseName() */ - QString QFileInfo::suffix() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); QString fileName = d->getFileName(QAbstractFileEngine::BaseName); int lastDot = fileName.lastIndexOf(QLatin1Char('.')); @@ -849,24 +837,23 @@ QString QFileInfo::suffix() const /*! - Returns the path of the object's parent directory as a QDir object. + Returns the path of the object's parent directory as a QDir object. - \bold{Note:} The QDir returned always corresponds to the object's - parent directory, even if the QFileInfo represents a directory. + \bold{Note:} The QDir returned always corresponds to the object's + parent directory, even if the QFileInfo represents a directory. - For each of the follwing, dir() returns a QDir for - \c{"~/examples/191697"}. + For each of the follwing, dir() returns a QDir for + \c{"~/examples/191697"}. - \snippet doc/src/snippets/fileinfo/main.cpp 0 + \snippet doc/src/snippets/fileinfo/main.cpp 0 - For each of the follwing, dir() returns a QDir for - \c{"."}. + For each of the follwing, dir() returns a QDir for + \c{"."}. - \snippet doc/src/snippets/fileinfo/main.cpp 1 + \snippet doc/src/snippets/fileinfo/main.cpp 1 - \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir() + \sa absolutePath(), filePath(), fileName(), isRelative(), absoluteDir() */ - QDir QFileInfo::dir() const { // ### Qt5: Maybe rename this to parentDirectory(), considering what it actually do? @@ -878,7 +865,6 @@ QDir QFileInfo::dir() const \sa dir(), filePath(), fileName(), isRelative() */ - QDir QFileInfo::absoluteDir() const { return QDir(absolutePath()); @@ -891,7 +877,7 @@ QDir QFileInfo::absoluteDir() const */ QDir QFileInfo::dir(bool absPath) const { - if(absPath) + if (absPath) return absoluteDir(); return dir(); } @@ -902,11 +888,10 @@ QDir QFileInfo::dir(bool absPath) const \sa isWritable(), isExecutable(), permission() */ - bool QFileInfo::isReadable() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->hasAccess(QFileInfoPrivate::ReadAccess); } @@ -916,11 +901,10 @@ bool QFileInfo::isReadable() const \sa isReadable(), isExecutable(), permission() */ - bool QFileInfo::isWritable() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->hasAccess(QFileInfoPrivate::WriteAccess); } @@ -930,11 +914,10 @@ bool QFileInfo::isWritable() const \sa isReadable(), isWritable(), permission() */ - bool QFileInfo::isExecutable() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->hasAccess(QFileInfoPrivate::ExecuteAccess); } @@ -948,7 +931,7 @@ bool QFileInfo::isExecutable() const bool QFileInfo::isHidden() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::HiddenFlag); } @@ -960,11 +943,10 @@ bool QFileInfo::isHidden() const \sa isDir(), isSymLink(), isBundle() */ - bool QFileInfo::isFile() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::FileType); } @@ -975,11 +957,10 @@ bool QFileInfo::isFile() const \sa isFile(), isSymLink(), isBundle() */ - bool QFileInfo::isDir() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::DirectoryType); } @@ -992,11 +973,10 @@ bool QFileInfo::isDir() const \sa isDir(), isSymLink(), isFile() */ - bool QFileInfo::isBundle() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::BundleType); } @@ -1018,21 +998,19 @@ bool QFileInfo::isBundle() const \sa isFile(), isDir(), symLinkTarget() */ - bool QFileInfo::isSymLink() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::LinkType); } /*! - Returns true if the object points to a directory or to a symbolic - link to a directory, and that directory is the root directory; otherwise - returns false. + Returns true if the object points to a directory or to a symbolic + link to a directory, and that directory is the root directory; otherwise + returns false. */ - bool QFileInfo::isRoot() const { Q_D(const QFileInfo); @@ -1064,7 +1042,7 @@ bool QFileInfo::isRoot() const QString QFileInfo::readLink() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::LinkName); } @@ -1079,13 +1057,12 @@ QString QFileInfo::readLink() const \sa ownerId(), group(), groupId() */ - QString QFileInfo::owner() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); - return d->data->fileEngine->owner(QAbstractFileEngine::OwnerUser); + return d->getFileOwner(QAbstractFileEngine::OwnerUser); } /*! @@ -1096,11 +1073,10 @@ QString QFileInfo::owner() const \sa owner(), group(), groupId() */ - uint QFileInfo::ownerId() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return 0; return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerUser); } @@ -1115,13 +1091,12 @@ uint QFileInfo::ownerId() const \sa groupId(), owner(), ownerId() */ - QString QFileInfo::group() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QLatin1String(""); - return d->data->fileEngine->owner(QAbstractFileEngine::OwnerGroup); + return d->getFileOwner(QAbstractFileEngine::OwnerGroup); } /*! @@ -1132,11 +1107,10 @@ QString QFileInfo::group() const \sa group(), owner(), ownerId() */ - uint QFileInfo::groupId() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return 0; return d->data->fileEngine->ownerId(QAbstractFileEngine::OwnerGroup); } @@ -1154,11 +1128,10 @@ uint QFileInfo::groupId() const \sa isReadable(), isWritable(), isExecutable() */ - bool QFileInfo::permission(QFile::Permissions permissions) const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::FileFlags((int)permissions)) == (uint)permissions; } @@ -1167,11 +1140,10 @@ bool QFileInfo::permission(QFile::Permissions permissions) const Returns the complete OR-ed together combination of QFile::Permissions for the file. */ - QFile::Permissions QFileInfo::permissions() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return 0; return QFile::Permissions(d->getFileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask); } @@ -1183,13 +1155,12 @@ QFile::Permissions QFileInfo::permissions() const \sa exists() */ - qint64 QFileInfo::size() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return 0; - if(!d->data->getCachedFlag(QFileInfoPrivate::CachedSize)) { + if (!d->data->getCachedFlag(QFileInfoPrivate::CachedSize)) { d->data->setCachedFlag(QFileInfoPrivate::CachedSize); d->data->fileSize = d->data->fileEngine->size(); } @@ -1209,11 +1180,10 @@ qint64 QFileInfo::size() const \sa lastModified() lastRead() */ - QDateTime QFileInfo::created() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QDateTime(); return d->getFileTime(QAbstractFileEngine::CreationTime); } @@ -1223,11 +1193,10 @@ QDateTime QFileInfo::created() const \sa created() lastRead() */ - QDateTime QFileInfo::lastModified() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QDateTime(); return d->getFileTime(QAbstractFileEngine::ModificationTime); } @@ -1240,11 +1209,10 @@ QDateTime QFileInfo::lastModified() const \sa created() lastModified() */ - QDateTime QFileInfo::lastRead() const { Q_D(const QFileInfo); - if(!d->data->fileEngine) + if (!d->data->fileEngine) return QDateTime(); return d->getFileTime(QAbstractFileEngine::AccessTime); } @@ -1252,7 +1220,6 @@ QDateTime QFileInfo::lastRead() const /*! \internal Detaches all internal data. */ - void QFileInfo::detach() { Q_D(QFileInfo); @@ -1264,7 +1231,6 @@ void QFileInfo::detach() \sa setCaching(), refresh() */ - bool QFileInfo::caching() const { Q_D(const QFileInfo); @@ -1283,7 +1249,6 @@ bool QFileInfo::caching() const \sa refresh(), caching() */ - void QFileInfo::setCaching(bool enable) { Q_D(QFileInfo); diff --git a/src/corelib/io/qfileinfo_p.h b/src/corelib/io/qfileinfo_p.h index 065f860..d97a0cf 100644 --- a/src/corelib/io/qfileinfo_p.h +++ b/src/corelib/io/qfileinfo_p.h @@ -54,6 +54,9 @@ // #include "qfileinfo.h" +#include "qabstractfileengine.h" +#include "qdatetime.h" +#include "qatomic.h" QT_BEGIN_NAMESPACE @@ -75,35 +78,41 @@ public: uint getFileFlags(QAbstractFileEngine::FileFlags) const; QDateTime &getFileTime(QAbstractFileEngine::FileTime) const; QString getFileName(QAbstractFileEngine::FileName) const; + QString getFileOwner(QAbstractFileEngine::FileOwner own) const; enum { CachedFileFlags=0x01, CachedLinkTypeFlag=0x02, CachedBundleTypeFlag=0x04, CachedMTime=0x10, CachedCTime=0x20, CachedATime=0x40, - CachedSize =0x08 }; + CachedSize =0x08, CachedPerms=0x80 }; struct Data { inline Data() - : ref(1), fileEngine(0), cache_enabled(1), fileSize(0) - { clear(); } + : ref(1), fileEngine(0), + cachedFlags(0), cache_enabled(1), fileFlags(0), fileSize(0) + {} inline Data(const Data ©) : ref(1), fileEngine(QAbstractFileEngine::create(copy.fileName)), - fileName(copy.fileName), cache_enabled(copy.cache_enabled), fileSize(copy.fileSize) - { clear(); } + fileName(copy.fileName), + cachedFlags(0), cache_enabled(copy.cache_enabled), fileFlags(0), fileSize(0) + {} inline ~Data() { delete fileEngine; } inline void clearFlags() { fileFlags = 0; cachedFlags = 0; if (fileEngine) - (void)fileEngine->fileFlags(QFSFileEngine::Refresh); + (void)fileEngine->fileFlags(QAbstractFileEngine::Refresh); } inline void clear() { clearFlags(); for (int i = QAbstractFileEngine::NFileNames - 1 ; i >= 0 ; --i) fileNames[i].clear(); + fileOwners[1].clear(); + fileOwners[0].clear(); } mutable QAtomicInt ref; QAbstractFileEngine *fileEngine; mutable QString fileName; mutable QString fileNames[QAbstractFileEngine::NFileNames]; + mutable QString fileOwners[2]; mutable uint cachedFlags : 31; mutable uint cache_enabled : 1; diff --git a/src/corelib/io/qfilesystemwatcher.cpp b/src/corelib/io/qfilesystemwatcher.cpp index 451fbd4..7223e49 100644 --- a/src/corelib/io/qfilesystemwatcher.cpp +++ b/src/corelib/io/qfilesystemwatcher.cpp @@ -248,7 +248,7 @@ QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine() eng = QDnotifyFileSystemWatcherEngine::create(); return eng; #elif defined(Q_OS_FREEBSD) || defined(Q_OS_MAC) -# if 0 && (defined Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) +# if defined(Q_OS_MAC) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) return QFSEventsFileSystemWatcherEngine::create(); else diff --git a/src/corelib/io/qfilesystemwatcher_dnotify.cpp b/src/corelib/io/qfilesystemwatcher_dnotify.cpp index 1a218c7..82470c8 100644 --- a/src/corelib/io/qfilesystemwatcher_dnotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_dnotify.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include "qplatformdefs.h" #include "qfilesystemwatcher.h" #include "qfilesystemwatcher_dnotify_p.h" @@ -255,16 +256,16 @@ QStringList QDnotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, if(fd == 0) { - DIR *d = ::opendir(path.toUtf8().constData()); + QT_DIR *d = QT_OPENDIR(path.toUtf8().constData()); if(!d) continue; // Could not open directory - DIR *parent = 0; + QT_DIR *parent = 0; QDir parentDir(path); if(!parentDir.isRoot()) { parentDir.cdUp(); - parent = ::opendir(parentDir.path().toUtf8().constData()); + parent = QT_OPENDIR(parentDir.path().toUtf8().constData()); if(!parent) { - ::closedir(d); + QT_CLOSEDIR(d); continue; } } @@ -272,8 +273,8 @@ QStringList QDnotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, fd = qt_safe_dup(::dirfd(d)); int parentFd = parent ? qt_safe_dup(::dirfd(parent)) : 0; - ::closedir(d); - if(parent) ::closedir(parent); + QT_CLOSEDIR(d); + if(parent) QT_CLOSEDIR(parent); Q_ASSERT(fd); if(::fcntl(fd, F_SETSIG, SIGIO) || diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.cpp b/src/corelib/io/qfilesystemwatcher_fsevents.cpp index 046377e..54ae24e 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.cpp +++ b/src/corelib/io/qfilesystemwatcher_fsevents.cpp @@ -94,7 +94,7 @@ static void addPathToHash(PathHash &pathHash, const QString &key, const QFileInf { PathInfoList &list = pathHash[key]; list.push_back(PathInfo(path, - fileInfo.absoluteFilePath().normalized(QString::NormalizationForm_D).toUtf8())); + fileInfo.canonicalFilePath().normalized(QString::NormalizationForm_D).toUtf8())); pathHash.insert(key, list); } @@ -206,7 +206,7 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths, } else { directories->append(path); // Full file path for dirs. - QCFString cfpath(createFSStreamPath(fileInfo.absoluteFilePath())); + QCFString cfpath(createFSStreamPath(fileInfo.canonicalFilePath())); addPathToHash(dirPathInfoHash, cfpath, fileInfo, path); CFArrayAppendValue(tmpArray, cfpath); } @@ -216,7 +216,7 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths, continue; } else { // Just the absolute path (minus it's filename) for files. - QCFString cfpath(createFSStreamPath(fileInfo.absolutePath())); + QCFString cfpath(createFSStreamPath(fileInfo.canonicalPath())); files->append(path); addPathToHash(filePathInfoHash, cfpath, fileInfo, path); CFArrayAppendValue(tmpArray, cfpath); @@ -293,7 +293,7 @@ QStringList QFSEventsFileSystemWatcherEngine::removePaths(const QStringList &pat itemCount = CFArrayGetCount(tmpArray); const QString &path = paths.at(i); QFileInfo fi(path); - QCFString cfpath(createFSStreamPath(fi.absolutePath())); + QCFString cfpath(createFSStreamPath(fi.canonicalPath())); CFIndex index = CFArrayGetFirstIndexOfValue(tmpArray, CFRangeMake(0, itemCount), cfpath); if (index != -1) { @@ -302,7 +302,7 @@ QStringList QFSEventsFileSystemWatcherEngine::removePaths(const QStringList &pat removePathFromHash(filePathInfoHash, cfpath, path); } else { // Could be a directory we are watching instead. - QCFString cfdirpath(createFSStreamPath(fi.absoluteFilePath())); + QCFString cfdirpath(createFSStreamPath(fi.canonicalFilePath())); index = CFArrayGetFirstIndexOfValue(tmpArray, CFRangeMake(0, itemCount), cfdirpath); if (index != -1) { CFArrayRemoveValueAtIndex(tmpArray, index); diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index a7dc8fa..4740a89 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -235,7 +235,7 @@ QInotifyFileSystemWatcherEngine::QInotifyFileSystemWatcherEngine(int fd) QInotifyFileSystemWatcherEngine::~QInotifyFileSystemWatcherEngine() { - foreach (int id, pathToID.values()) + foreach (int id, pathToID) inotify_rm_watch(inotifyFd, id < 0 ? -id : id); ::close(inotifyFd); diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index f088ded..8396481 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -109,7 +109,7 @@ QKqueueFileSystemWatcherEngine::~QKqueueFileSystemWatcherEngine() close(kqpipe[0]); close(kqpipe[1]); - foreach (int id, pathToID.values()) + foreach (int id, pathToID) ::close(id < 0 ? -id : id); } diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index c842e49..1672dfc 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -56,6 +56,9 @@ #endif #include <stdio.h> #include <stdlib.h> +#if defined(Q_OS_MAC) +# include <private/qcore_mac_p.h> +#endif QT_BEGIN_NAMESPACE @@ -143,9 +146,27 @@ QString QFSFileEnginePrivate::canonicalized(const QString &path) if (path.size() == 1 && path.at(0) == QLatin1Char('/')) return path; #endif - // Mac OS X 10.5.x doesn't support the realpath(X,0) extenstion we use here. -#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN) - char *ret = realpath(path.toLocal8Bit().constData(), (char*)0); +#if defined(Q_OS_LINUX) || defined(Q_OS_SYMBIAN) || defined(Q_OS_MAC) + char *ret = 0; +#if defined(Q_OS_MAC) + // Mac OS X 10.5.x doesn't support the realpath(X,0) extension we use here. + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) { + ret = realpath(path.toLocal8Bit().constData(), (char*)0); + } else { + // on 10.5 we can use FSRef to resolve the file path. + FSRef fsref; + if (FSPathMakeRef((const UInt8 *)QDir::cleanPath(path).toUtf8().data(), &fsref, 0) == noErr) { + CFURLRef urlref = CFURLCreateFromFSRef(NULL, &fsref); + CFStringRef canonicalPath = CFURLCopyFileSystemPath(urlref, kCFURLPOSIXPathStyle); + QString ret = QCFString::toQString(canonicalPath); + CFRelease(canonicalPath); + CFRelease(urlref); + return ret; + } + } +#else + ret = realpath(path.toLocal8Bit().constData(), (char*)0); +#endif if (ret) { QString canonicalPath = QDir::cleanPath(QString::fromLocal8Bit(ret)); free(ret); diff --git a/src/corelib/io/qfsfileengine_iterator_unix.cpp b/src/corelib/io/qfsfileengine_iterator_unix.cpp index b68b1a1..bfdb03e 100644 --- a/src/corelib/io/qfsfileengine_iterator_unix.cpp +++ b/src/corelib/io/qfsfileengine_iterator_unix.cpp @@ -58,13 +58,13 @@ public: #endif {} - DIR *dir; - dirent *dirEntry; + QT_DIR *dir; + QT_DIRENT *dirEntry; bool done; #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN) // for readdir_r - dirent *mt_file; + QT_DIRENT *mt_file; #endif }; @@ -76,14 +76,14 @@ void QFSFileEngineIterator::advance() return; #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN) - if (::readdir_r(platform->dir, platform->mt_file, &platform->dirEntry) != 0) + if (QT_READDIR_R(platform->dir, platform->mt_file, &platform->dirEntry) != 0) platform->done = true; #else // ### add local lock to prevent breaking reentrancy - platform->dirEntry = ::readdir(platform->dir); + platform->dirEntry = QT_READDIR(platform->dir); #endif // _POSIX_THREAD_SAFE_FUNCTIONS if (!platform->dirEntry) { - ::closedir(platform->dir); + QT_CLOSEDIR(platform->dir); platform->dir = 0; platform->done = true; #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN) @@ -101,7 +101,7 @@ void QFSFileEngineIterator::newPlatformSpecifics() void QFSFileEngineIterator::deletePlatformSpecifics() { if (platform->dir) { - ::closedir(platform->dir); + QT_CLOSEDIR(platform->dir); #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN) delete [] platform->mt_file; platform->mt_file = 0; @@ -115,18 +115,18 @@ bool QFSFileEngineIterator::hasNext() const { if (!platform->done && !platform->dir) { QFSFileEngineIterator *that = const_cast<QFSFileEngineIterator *>(this); - if ((that->platform->dir = ::opendir(QFile::encodeName(path()).data())) == 0) { + if ((that->platform->dir = QT_OPENDIR(QFile::encodeName(path()).data())) == 0) { that->platform->done = true; } else { // ### Race condition; we should use fpathconf and dirfd(). long maxPathName = ::pathconf(QFile::encodeName(path()).data(), _PC_NAME_MAX); if ((int) maxPathName == -1) maxPathName = FILENAME_MAX; - maxPathName += sizeof(dirent) + 1; + maxPathName += sizeof(QT_DIRENT) + 1; #if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) && !defined(Q_OS_SYMBIAN) if (that->platform->mt_file) delete [] that->platform->mt_file; - that->platform->mt_file = (dirent *)new char[maxPathName]; + that->platform->mt_file = (QT_DIRENT *)new char[maxPathName]; #endif that->advance(); diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index bec0075..eb99f27 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -66,10 +66,6 @@ #include <ctype.h> #include <limits.h> #define SECURITY_WIN32 -#ifdef Q_CC_MINGW -// A workaround for a certain version of MinGW, the define UNICODE_STRING. -#include <subauth.h> -#endif #include <security.h> #ifndef _INTPTR_T_DEFINED @@ -181,7 +177,7 @@ void QFSFileEnginePrivate::resolveLibs() triedResolve = true; #if !defined(Q_OS_WINCE) - HINSTANCE advapiHnd = LoadLibraryW(L"advapi32"); + HINSTANCE advapiHnd = LoadLibrary(L"advapi32"); if (advapiHnd) { ptrGetNamedSecurityInfoW = (PtrGetNamedSecurityInfoW)GetProcAddress(advapiHnd, "GetNamedSecurityInfoW"); ptrLookupAccountSidW = (PtrLookupAccountSidW)GetProcAddress(advapiHnd, "LookupAccountSidW"); @@ -213,7 +209,7 @@ void QFSFileEnginePrivate::resolveLibs() ptrFreeSid(pWorld); } } - HINSTANCE userenvHnd = LoadLibraryW(L"userenv"); + HINSTANCE userenvHnd = LoadLibrary(L"userenv"); if (userenvHnd) ptrGetUserProfileDirectoryW = (PtrGetUserProfileDirectoryW)GetProcAddress(userenvHnd, "GetUserProfileDirectoryW"); #endif @@ -221,7 +217,6 @@ void QFSFileEnginePrivate::resolveLibs() } #endif // QT_NO_LIBRARY -// UNC functions NT typedef DWORD (WINAPI *PtrNetShareEnum)(LPWSTR, DWORD, LPBYTE*, DWORD, LPDWORD, LPDWORD, LPDWORD); static PtrNetShareEnum ptrNetShareEnum = 0; typedef DWORD (WINAPI *PtrNetApiBufferFree)(LPVOID); @@ -245,7 +240,7 @@ bool QFSFileEnginePrivate::resolveUNCLibs() #endif triedResolve = true; #if !defined(Q_OS_WINCE) - HINSTANCE hLib = LoadLibraryW(L"Netapi32"); + HINSTANCE hLib = LoadLibrary(L"netapi32"); if (hLib) { ptrNetShareEnum = (PtrNetShareEnum)GetProcAddress(hLib, "NetShareEnum"); if (ptrNetShareEnum) @@ -1042,11 +1037,11 @@ QString QFSFileEngine::homePath() if (ok) { DWORD dwBufferSize = 0; // First call, to determine size of the strings (with '\0'). - ok = ::ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize); + ok = ptrGetUserProfileDirectoryW(token, NULL, &dwBufferSize); if (!ok && dwBufferSize != 0) { // We got the required buffer size wchar_t *userDirectory = new wchar_t[dwBufferSize]; // Second call, now we can fill the allocated buffer. - ok = ::ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize); + ok = ptrGetUserProfileDirectoryW(token, userDirectory, &dwBufferSize); if (ok) ret = QString::fromWCharArray(userDirectory); @@ -1418,7 +1413,7 @@ QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions() const QAbstractFileEngine::FileFlags ret = 0; #if !defined(QT_NO_LIBRARY) - if((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) { + if((qt_ntfs_permission_lookup > 0) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)) { resolveLibs(); if(ptrGetNamedSecurityInfoW && ptrBuildTrusteeWithSidW && ptrGetEffectiveRightsFromAclW) { enum { ReadMask = 0x00000001, WriteMask = 0x00000002, ExecMask = 0x00000020 }; @@ -1721,8 +1716,7 @@ QString QFSFileEngine::owner(FileOwner own) const QString name; #if !defined(QT_NO_LIBRARY) Q_D(const QFSFileEngine); - - if ((qt_ntfs_permission_lookup > 0) && ((QSysInfo::WindowsVersion&QSysInfo::WV_NT_based) > QSysInfo::WV_NT)) { + if((qt_ntfs_permission_lookup > 0) && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)) { QFSFileEnginePrivate::resolveLibs(); if (ptrGetNamedSecurityInfoW && ptrLookupAccountSidW) { PSID pOwner = 0; diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index 0aa534a..906979c 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -46,6 +46,7 @@ #include <QtCore/qobjectdefs.h> #include <QtCore/qpair.h> #include <QtCore/qstring.h> +#include <QtCore/qhash.h> QT_BEGIN_HEADER @@ -75,6 +76,7 @@ public: RemovePath = 0x20, RemoveQuery = 0x40, RemoveFragment = 0x80, + // 0x100: private: normalized StripTrailingSlash = 0x10000 }; @@ -268,6 +270,11 @@ public: inline DataPtr &data_ptr() { return d; } }; +inline uint qHash(const QUrl &uri) +{ + return qHash(uri.toEncoded(QUrl::FormattingOption(0x100))); +} + Q_DECLARE_TYPEINFO(QUrl, Q_MOVABLE_TYPE); Q_DECLARE_SHARED(QUrl) Q_DECLARE_OPERATORS_FOR_FLAGS(QUrl::FormattingOptions) diff --git a/src/corelib/kernel/qabstractitemmodel.cpp b/src/corelib/kernel/qabstractitemmodel.cpp index 36e4af9..b0503be 100644 --- a/src/corelib/kernel/qabstractitemmodel.cpp +++ b/src/corelib/kernel/qabstractitemmodel.cpp @@ -1248,7 +1248,7 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, /*! \fn QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const = 0 - Returns the parent of the model item with the given \a index. If the model + Returns the parent of the model item with the given \a index. If the item has no parent, an invalid QModelIndex is returned. A common convention used in models that expose tree data structures is that diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 3500b63..d23ea4c 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -272,7 +272,6 @@ QT_BEGIN_NAMESPACE \omitvalue MacGLClearDrawable \omitvalue NetworkReplyUpdated \omitvalue FutureCallOut - \omitvalue CocoaRequestModal \omitvalue UpdateSoftKeys \omitvalue NativeGesture */ @@ -331,7 +330,7 @@ QEvent::~QEvent() equivalent of calling setAccepted(false). Clearing the accept parameter indicates that the event receiver - does not want the event. Unwanted events might be propgated to the + does not want the event. Unwanted events might be propagated to the parent widget. \sa accept() diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index c76e81b..a20d171 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -266,7 +266,6 @@ public: UngrabMouse = 187, GrabKeyboard = 188, UngrabKeyboard = 189, - CocoaRequestModal = 190, // Internal for requesting an application modal Cocoa Window MacGLClearDrawable = 191, // Internal Cocoa, the window has changed, so we must clear StateMachineSignal = 192, diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index cbc87f3..7c8fb3d 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -341,6 +341,9 @@ public: // for controlling when to send posted events QAtomicInt serialNumber; int lastSerialNumber; +#ifndef Q_OS_WINCE + int lastMessageTime; +#endif QAtomicInt wakeUps; // timers @@ -364,7 +367,12 @@ public: }; QEventDispatcherWin32Private::QEventDispatcherWin32Private() - : threadId(GetCurrentThreadId()), interrupt(false), internalHwnd(0), getMessageHook(0), serialNumber(0), lastSerialNumber(0), wakeUps(0) + : threadId(GetCurrentThreadId()), interrupt(false), internalHwnd(0), getMessageHook(0), + serialNumber(0), lastSerialNumber(0), +#ifndef Q_OS_WINCE + lastMessageTime(0), +#endif + wakeUps(0) { resolveTimerAPI(); } @@ -479,6 +487,9 @@ LRESULT CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp) int localSerialNumber = d->serialNumber; if (localSerialNumber != d->lastSerialNumber) { d->lastSerialNumber = localSerialNumber; +#ifndef Q_OS_WINCE + d->lastMessageTime = GetMessageTime(); +#endif QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); } return 0; @@ -495,9 +506,13 @@ LRESULT CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp) if (q) { QEventDispatcherWin32Private *d = q->d_func(); int localSerialNumber = d->serialNumber; - if (HIWORD(GetQueueStatus(QS_INPUT | QS_RAWINPUT | QS_TIMER)) == 0) { - // no more input or timer events in the message queue, we can allow posted events to be - // sent now + if (HIWORD(GetQueueStatus(QS_INPUT | QS_RAWINPUT | QS_TIMER)) == 0 +#ifndef Q_OS_WINCE + || GetMessageTime() - d->lastMessageTime >= 10 +#endif + ) { + // no more input or timer events in the message queue or more than 10ms has elapsed since + // we send posted events, we can allow posted events to be sent now (void) d->wakeUps.fetchAndStoreRelease(0); MSG *msg = (MSG *) lp; if (localSerialNumber != d->lastSerialNumber @@ -744,6 +759,8 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { if (seenWM_QT_SENDPOSTEDEVENTS) { + // when calling processEvents() "manually", we only want to send posted + // events once needWM_QT_SENDPOSTEDEVENTS = true; continue; } diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index cd7418a..be1b2ae 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -482,6 +482,46 @@ int QMetaObject::classInfoCount() const return n; } +/** \internal +* helper class for indexOf{Method,Slot,Signal}, returns the relative index of the method within +* the baseObject +* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything. +*/ +template<int MethodType> +static inline int indexOfMethodRelative(const QMetaObject **baseObject, + const char *method, + bool normalizeStringData) +{ + const QMetaObject *m; + for (m = *baseObject; m; m = *baseObject = m->d.superdata) { + const QMetaObject *const m = *baseObject; + int i = (MethodType == MethodSignal && priv(m->d.data)->revision >= 4) + ? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1); + if (i < 0) + continue; + + const int end = (MethodType == MethodSlot && priv(m->d.data)->revision >= 4) + ? (priv(m->d.data)->signalCount) : 0; + if (!normalizeStringData) { + for (; i >= end; --i) { + if ((MethodType == 0 || (m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodType) + && strcmp(method, m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) + return i; + } + } else if (priv(m->d.data)->revision < 5) { + const char *stringdata = (m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5 * i]); + const QByteArray normalizedSignature = QMetaObject::normalizedSignature(stringdata); + for (; i >= end; --i) { + if ((MethodType == 0|| (m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodType) + && normalizedSignature == method) + return i; + } + } + } + return -1; +} + + /*! \since 4.5 @@ -515,17 +555,14 @@ int QMetaObject::indexOfConstructor(const char *constructor) const */ int QMetaObject::indexOfMethod(const char *method) const { - int i = -1; const QMetaObject *m = this; - while (m && i < 0) { - for (i = priv(m->d.data)->methodCount-1; i >= 0; --i) - if (strcmp(method, m->d.stringdata - + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) { - i += m->methodOffset(); - break; - } - m = m->d.superdata; + int i = indexOfMethodRelative<0>(&m, method, false); + if (i < 0) { + m = this; + i = indexOfMethodRelative<0>(&m, method, true); } + if (i >= 0) + i += m->methodOffset(); return i; } @@ -543,7 +580,11 @@ int QMetaObject::indexOfMethod(const char *method) const int QMetaObject::indexOfSignal(const char *signal) const { const QMetaObject *m = this; - int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal); + int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, false); + if (i < 0) { + m = this; + i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, true); + } if (i >= 0) i += m->methodOffset(); return i; @@ -554,21 +595,11 @@ int QMetaObject::indexOfSignal(const char *signal) const \a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found */ -int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, const char *signal) +int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, + const char *signal, + bool normalizeStringData) { - int i = -1; - while (*baseObject) { - const QMetaObject *const m = *baseObject; - for (i = priv(m->d.data)->methodCount-1; i >= 0; --i) - if ((m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodSignal - && strcmp(signal, m->d.stringdata - + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) { - break; - } - if (i >= 0) - break; - *baseObject = m->d.superdata; - } + int i = indexOfMethodRelative<MethodSignal>(baseObject, signal, normalizeStringData); #ifndef QT_NO_DEBUG const QMetaObject *m = *baseObject; if (i >= 0 && m && m->d.superdata) { @@ -581,7 +612,6 @@ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, co return i; } - /*! Finds \a slot and returns its index; otherwise returns -1. @@ -592,18 +622,19 @@ int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, co */ int QMetaObject::indexOfSlot(const char *slot) const { - int i = -1; - const QMetaObject *m = this; - while (m && i < 0) { - for (i = priv(m->d.data)->methodCount-1; i >= 0; --i) - if ((m->d.data[priv(m->d.data)->methodData + 5*i + 4] & MethodTypeMask) == MethodSlot - && strcmp(slot, m->d.stringdata - + m->d.data[priv(m->d.data)->methodData + 5*i]) == 0) { - i += m->methodOffset(); - break; - } - m = m->d.superdata; - } + int i = QMetaObjectPrivate::indexOfSlot(this, slot, false); + if (i < 0) + i = QMetaObjectPrivate::indexOfSlot(this, slot, true); + return i; +} + +int QMetaObjectPrivate::indexOfSlot(const QMetaObject *m, + const char *slot, + bool normalizeStringData) +{ + int i = indexOfMethodRelative<MethodSlot>(&m, slot, normalizeStringData); + if (i >= 0) + i += m->methodOffset(); return i; } diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h index 3bbb050..a176149 100644 --- a/src/corelib/kernel/qmetaobject_p.h +++ b/src/corelib/kernel/qmetaobject_p.h @@ -115,11 +115,17 @@ struct QMetaObjectPrivate int constructorCount, constructorData; //since revision 2 int flags; //since revision 3 int signalCount; //since revision 4 + // revision 5 introduces changes in normalized signatures, no new members static inline const QMetaObjectPrivate *get(const QMetaObject *metaobject) { return reinterpret_cast<const QMetaObjectPrivate*>(metaobject->d.data); } - static int indexOfSignalRelative(const QMetaObject **baseObject, const char* name); + static int indexOfSignalRelative(const QMetaObject **baseObject, + const char* name, + bool normalizeStringData); + static int indexOfSlot(const QMetaObject *m, + const char *slot, + bool normalizeStringData); static int originalClone(const QMetaObject *obj, int local_method_index); #ifndef QT_NO_QOBJECT @@ -247,6 +253,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc } while (optional[++i].keyword != 0); } + bool star = false; while (t != e) { char c = *t++; if (fixScope && c == ':' && *t == ':' ) { @@ -257,6 +264,7 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc --i; result.resize(i + 1); } + star = star || c == '*'; result += c; if (c == '<') { //template recursion @@ -277,6 +285,23 @@ static QByteArray normalizeTypeInternal(const char *t, const char *e, bool fixSc } } } + + // cv qualifers can appear after the type as well + if (t != e && (e - t >= 5 && strncmp("const", t, 5) == 0)) { + t += 5; + while (t != e && is_space(*t)) + ++t; + if (adjustConst && t != e && *t == '&') { + // treat const ref as value + ++t; + } else if (!star) { + // move const to the front (but not if const comes after a *) + result.prepend("const "); + } else { + // keep const after a * + result += "const"; + } + } } return result; diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index e304290..870baab 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -361,7 +361,14 @@ void QMetaType::registerStreamOperators(const char *typeName, SaveOperator saveO int idx = type(typeName); if (!idx) return; + registerStreamOperators(idx, saveOp, loadOp); +} +/*! \internal +*/ +void QMetaType::registerStreamOperators(int idx, SaveOperator saveOp, + LoadOperator loadOp) +{ QVector<QCustomTypeInfo> *ct = customTypes(); if (!ct) return; diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index c0dd288..c23caed 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -108,6 +108,8 @@ public: typedef void (*LoadOperator)(QDataStream &, void *); static void registerStreamOperators(const char *typeName, SaveOperator saveOp, LoadOperator loadOp); + static void registerStreamOperators(int type, SaveOperator saveOp, + LoadOperator loadOp); #endif static int registerType(const char *typeName, Destructor destructor, Constructor constructor); @@ -224,6 +226,24 @@ inline int qRegisterMetaType( #endif } +#ifndef QT_NO_DATASTREAM +template <typename T> +inline int qRegisterMetaTypeStreamOperators() +{ + typedef void(*SavePtr)(QDataStream &, const T *); + typedef void(*LoadPtr)(QDataStream &, T *); + SavePtr sptr = qMetaTypeSaveHelper<T>; + LoadPtr lptr = qMetaTypeLoadHelper<T>; + + register int id = qMetaTypeId<T>(); + QMetaType::registerStreamOperators(id, + reinterpret_cast<QMetaType::SaveOperator>(sptr), + reinterpret_cast<QMetaType::LoadOperator>(lptr)); + + return id; +} +#endif + #define Q_DECLARE_METATYPE(TYPE) \ QT_BEGIN_NAMESPACE \ template <> \ diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 5298fff..761b31f 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -871,7 +871,7 @@ QObject::~QObject() // all the signal/slots connections are still in place - if we don't // quit now, we will crash pretty soon. qWarning("Detected an unexpected exception in ~QObject while emitting destroyed()."); -#if defined(Q_AUTOTEST_EXPORT) && !defined(QT_NO_EXCEPTIONS) +#if defined(Q_BUILD_INTERNAL) && !defined(QT_NO_EXCEPTIONS) struct AutotestException : public std::exception { const char *what() const throw() { return "autotest swallow"; } @@ -903,7 +903,8 @@ QObject::~QObject() // disconnect all receivers if (d->connectionLists) { ++d->connectionLists->inUse; - for (int signal = -1; signal < d->connectionLists->count(); ++signal) { + int connectionListsCount = d->connectionLists->count(); + for (int signal = -1; signal < connectionListsCount; ++signal) { QObjectPrivate::ConnectionList &connectionList = (*d->connectionLists)[signal]; @@ -940,16 +941,17 @@ QObject::~QObject() // disconnect all senders QObjectPrivate::Connection *node = d->senders; while (node) { - QMutex *m = signalSlotLock(node->sender); + QObject *sender = node->sender; + QMutex *m = signalSlotLock(sender); node->prev = &node; bool needToUnlock = QOrderedMutexLocker::relock(locker.mutex(), m); //the node has maybe been removed while the mutex was unlocked in relock? - if (!node || signalSlotLock(node->sender) != m) { + if (!node || node->sender != sender) { m->unlock(); continue; } node->receiver = 0; - QObjectConnectionListVector *senderLists = node->sender->d_func()->connectionLists; + QObjectConnectionListVector *senderLists = sender->d_func()->connectionLists; if (senderLists) senderLists->dirty = true; @@ -2510,20 +2512,25 @@ bool QObject::connect(const QObject *sender, const char *signal, const QMetaObject *smeta = sender->metaObject(); const char *signal_arg = signal; ++signal; //skip code - int signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); + int signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false); if (signal_index < 0) { // check for normalized signatures tmp_signal_name = QMetaObject::normalizedSignature(signal - 1); signal = tmp_signal_name.constData() + 1; smeta = sender->metaObject(); - signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false); + } + if (signal_index < 0) { + // re-use tmp_signal_name and signal from above - if (signal_index < 0) { - err_method_notfound(sender, signal_arg, "connect"); - err_info_about_objects("connect", sender, receiver); - return false; - } + smeta = sender->metaObject(); + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true); + } + if (signal_index < 0) { + err_method_notfound(sender, signal_arg, "connect"); + err_info_about_objects("connect", sender, receiver); + return false; } signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index); int signalOffset, methodOffset; @@ -2543,16 +2550,21 @@ bool QObject::connect(const QObject *sender, const char *signal, int method_index = -1; switch (membcode) { case QSLOT_CODE: - method_index = rmeta->indexOfSlot(method); + method_index = QMetaObjectPrivate::indexOfSlot(rmeta, method, false); break; case QSIGNAL_CODE: - method_index = rmeta->indexOfSignal(method); + method_index = QMetaObjectPrivate::indexOfSignalRelative(&rmeta, method, false); + if (method_index >= 0) + method_index += rmeta->methodOffset(); break; } if (method_index < 0) { // check for normalized methods tmp_method_name = QMetaObject::normalizedSignature(method); method = tmp_method_name.constData(); + + // rmeta may have been modified above + rmeta = receiver->metaObject(); switch (membcode) { case QSLOT_CODE: method_index = rmeta->indexOfSlot(method); @@ -2740,7 +2752,9 @@ bool QObject::disconnect(const QObject *sender, const char *signal, do { int signal_index = -1; if (signal) { - signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal); + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, false); + if (signal_index < 0) + signal_index = QMetaObjectPrivate::indexOfSignalRelative(&smeta, signal, true); if (signal_index < 0) break; signal_index = QMetaObjectPrivate::originalClone(smeta, signal_index); @@ -3360,7 +3374,9 @@ int QObjectPrivate::signalIndex(const char *signalName) const { Q_Q(const QObject); const QMetaObject *base = q->metaObject(); - int relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName); + int relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, false); + if (relative_index < 0) + relative_index = QMetaObjectPrivate::indexOfSignalRelative(&base, signalName, true); if (relative_index < 0) return relative_index; relative_index = QMetaObjectPrivate::originalClone(base, relative_index); diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 27ab105..cc5bf97 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -189,8 +189,8 @@ public: QList<QObject *> pendingChildInsertedEvents; #else // preserve binary compatibility with code compiled without Qt 3 support - // ### why? - QList<QObject *> unused; + // keeping the binary layout stable helps the Qt Creator debugger + void *unused; #endif QList<QPointer<QObject> > eventFilters; diff --git a/src/corelib/plugin/qlibrary.cpp b/src/corelib/plugin/qlibrary.cpp index f2c2384..a2c575a 100644 --- a/src/corelib/plugin/qlibrary.cpp +++ b/src/corelib/plugin/qlibrary.cpp @@ -630,6 +630,22 @@ bool QLibraryPrivate::isPlugin(QSettings *settings) .arg((QT_VERSION & 0xff00) >> 8) .arg(QLIBRARY_AS_DEBUG ? QLatin1String("debug") : QLatin1String("false")) .arg(fileName); +#ifdef Q_WS_MAC + // On Mac, add the application arch to the reg key in order to + // cache plugin information separately for each arch. This prevents + // Qt from wrongly caching plugin load failures when the archs + // don't match. +#if defined(__x86_64__) + regkey += QLatin1String("-x86_64"); +#elif defined(__i386__) + regkey += QLatin1String("-i386"); +#elif defined(__ppc64__) + regkey += QLatin1String("-ppc64"); +#elif defined(__ppc__) + regkey += QLatin1String("-ppc"); +#endif +#endif // Q_WS_MAC + QStringList reg; #ifndef QT_NO_SETTINGS if (!settings) { diff --git a/src/corelib/thread/qorderedmutexlocker_p.h b/src/corelib/thread/qorderedmutexlocker_p.h index 7d52a29..702125c 100644 --- a/src/corelib/thread/qorderedmutexlocker_p.h +++ b/src/corelib/thread/qorderedmutexlocker_p.h @@ -103,9 +103,11 @@ public: mtx2->lock(); return true; } - mtx1->unlock(); - mtx2->lock(); - mtx1->lock(); + if (!mtx2->tryLock()) { + mtx1->unlock(); + mtx2->lock(); + mtx1->lock(); + } return true; } diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 556093f..a27e488 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1061,6 +1061,11 @@ QByteArray &QByteArray::operator=(const char *str) \internal */ +/*! \fn bool QByteArray::isSharedWith(const QByteArray &other) const + + \internal +*/ + /*! \fn char QByteArray::at(int i) const Returns the character at index position \a i in the byte array. diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index ef97716..ec592f5f 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -164,6 +164,7 @@ public: inline const char *constData() const; inline void detach(); bool isDetached() const; + inline bool isSharedWith(const QByteArray &other) const { return d == other.d; } void clear(); #ifdef Q_COMPILER_MANGLES_RETURN_TYPE diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 6231471..285f4c9 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -847,6 +847,11 @@ void QHashData::checkSanity() \internal */ +/*! \fn bool QHash::isSharedWith(const QHash<Key, T> &other) const + + \internal +*/ + /*! \fn void QHash::clear() Removes all items from the hash. diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 5e93523..2832ca2 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -299,6 +299,7 @@ public: inline void detach() { if (d->ref != 1) detach_helper(); } inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + inline bool isSharedWith(const QHash<Key, T> &other) const { return d == other.d; } void clear(); diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index 5a53c32..909d940 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -197,6 +197,11 @@ QLinkedListData QLinkedListData::shared_null = { \internal */ +/*! \fn bool QLinkedList::isSharedWith(const QLinkedList<T> &other) const + + \internal +*/ + /*! \fn bool QLinkedList::isEmpty() const Returns true if the list contains no items; otherwise returns diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index f6de966..fe586a4 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -93,6 +93,7 @@ public: { if (d->ref != 1) detach_helper(); } inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + inline bool isSharedWith(const QLinkedList<T> &other) const { return d == other.d; } inline bool isEmpty() const { return d->size == 0; } diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp index c302857..ce62016 100644 --- a/src/corelib/tools/qlist.cpp +++ b/src/corelib/tools/qlist.cpp @@ -599,6 +599,11 @@ void **QListData::erase(void **xi) \internal */ +/*! \fn bool QList::isSharedWith(const QList<T> &other) const + + \internal +*/ + /*! \fn bool QList::isEmpty() const Returns true if the list contains no items; otherwise returns diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 120442d..1d08c41 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -130,6 +130,7 @@ public: inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + inline bool isSharedWith(const QList<T> &other) const { return d == other.d; } inline bool isEmpty() const { return p.isEmpty(); } diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 8d79cb3..ff10fa1 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -4293,6 +4293,7 @@ bool QLocalePrivate::validateChars(const QString &str, NumberMode numMode, QByte const bool scientific = numMode == DoubleScientificMode; bool lastWasE = false; + bool lastWasDigit = false; int eCnt = 0; int decPointCnt = 0; bool dec = false; @@ -4307,6 +4308,7 @@ bool QLocalePrivate::validateChars(const QString &str, NumberMode numMode, QByte if (dec && decDigits != -1 && decDigits < ++decDigitCnt) return false; } + lastWasDigit = true; } else { switch (c) { case '.': @@ -4344,7 +4346,10 @@ bool QLocalePrivate::validateChars(const QString &str, NumberMode numMode, QByte break; case ',': - return false; + //it can only be placed after a digit which is before the decimal point + if (!lastWasDigit || decPointCnt > 0) + return false; + break; case 'e': if (scientific) { @@ -4362,10 +4367,12 @@ bool QLocalePrivate::validateChars(const QString &str, NumberMode numMode, QByte // If it's not a valid digit, it shall be Invalid. return false; } + lastWasDigit = false; } lastWasE = c == 'e'; - buff->append(c); + if (c != ',') + buff->append(c); } return true; diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 82cbe78..3143ee4 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -473,6 +473,11 @@ void QMapData::dump() \internal */ +/*! \fn bool QMap::isSharedWith(const QMap<Key, T> &other) const + + \internal +*/ + /*! \fn void QMap::setInsertInOrder(bool sharable) \internal diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index e71064c..9ba9ca5 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -182,6 +182,7 @@ public: inline void detach() { if (d->ref != 1) detach_helper(); } inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + inline bool isSharedWith(const QMap<Key, T> &other) const { return d == other.d; } inline void setInsertInOrder(bool ordered) { d->insertInOrder = ordered; } void clear(); diff --git a/src/corelib/tools/qpoint.cpp b/src/corelib/tools/qpoint.cpp index d60087f..9850ee7 100644 --- a/src/corelib/tools/qpoint.cpp +++ b/src/corelib/tools/qpoint.cpp @@ -374,7 +374,7 @@ QDebug operator<<(QDebug dbg, const QPoint &p) { QDebug operator<<(QDebug d, const QPointF &p) { d.nospace() << "QPointF(" << p.x() << ", " << p.y() << ')'; - return d; + return d.space(); } #endif diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3ef0e66..dec59b7 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -55,6 +55,7 @@ #include "qtools_p.h" #include "qhash.h" #include "qdebug.h" +#include "qendian.h" #ifdef Q_OS_MAC #include <private/qcore_mac_p.h> @@ -1091,7 +1092,12 @@ QString::QString(QChar ch) \internal */ -/*! \fn void QString::isDetached() const +/*! \fn bool QString::isDetached() const + + \internal +*/ + +/*! \fn bool QString::isSharedWith(const QString &other) const \internal */ @@ -7317,7 +7323,7 @@ QDataStream &operator>>(QDataStream &in, QString &str) != (QSysInfo::ByteOrder == QSysInfo::BigEndian)) { ushort *data = reinterpret_cast<ushort *>(str.data()); while (len--) { - *data = (*data >> 8) | (*data << 8); + *data = qbswap(*data); ++data; } } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index c1def0f..5e3b0fd 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -122,6 +122,7 @@ public: inline void detach(); inline bool isDetached() const; + inline bool isSharedWith(const QString &other) const { return d == other.d; } void clear(); inline const QChar at(int i) const; diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index 4b0f488..e9bdf57 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -404,7 +404,17 @@ void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QRegExp &r */ QString QtPrivate::QStringList_join(const QStringList *that, const QString &sep) { + int totalLength = 0; + const int size = that->size(); + + for (int i = 0; i < size; ++i) + totalLength += that->at(i).size(); + + if(size > 0) + totalLength += sep.size() * (size - 1); + QString res; + res.reserve(totalLength); for (int i = 0; i < that->size(); ++i) { if (i) res += sep; diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 48b52d2..3a13540 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -392,6 +392,11 @@ int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive \internal */ +/*! \fn bool QVector::isSharedWith(const QVector<T> &other) const + + \internal +*/ + /*! \fn T *QVector::data() Returns a pointer to the data stored in the vector. The pointer diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 90b7442..61b22fd 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -134,6 +134,7 @@ public: inline void detach() { if (d->ref != 1) detach_helper(); } inline bool isDetached() const { return d->ref == 1; } inline void setSharable(bool sharable) { if (!sharable) detach(); d->sharable = sharable; } + inline bool isSharedWith(const QVector<T> &other) const { return d == other.d; } inline T *data() { detach(); return p->array; } inline const T *data() const { return p->array; } diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index 5717ca2..1bf00b8 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -3003,8 +3003,7 @@ QXmlStreamWriterPrivate::QXmlStreamWriterPrivate(QXmlStreamWriter *q) deleteDevice = false; #ifndef QT_NO_TEXTCODEC codec = QTextCodec::codecForMib(106); // utf8 - encoder = codec->makeEncoder(); - encoder->state.flags |= QTextCodec::IgnoreHeader; // no byte order mark for utf8 + encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8 #endif inStartElement = inEmptyElement = false; wroteSomething = false; @@ -3278,9 +3277,7 @@ void QXmlStreamWriter::setCodec(QTextCodec *codec) if (codec) { d->codec = codec; delete d->encoder; - d->encoder = codec->makeEncoder(); - if (codec->mibEnum() == 106) - d->encoder->state.flags |= QTextCodec::IgnoreHeader; // no byte order mark for utf8 + d->encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8 } } |