diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 10 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_fsevents.mm | 103 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_fsevents_p.h | 19 | ||||
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 19 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qsettings.h | 9 | ||||
-rw-r--r-- | src/corelib/io/qsettings_mac.cpp | 50 | ||||
-rw-r--r-- | src/corelib/io/qsettings_win.cpp | 13 | ||||
-rw-r--r-- | src/corelib/io/qsettings_winrt.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.mm | 37 | ||||
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qtldurl.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qtldurl_p.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qurl.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qurl.h | 2 |
16 files changed, 157 insertions, 129 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 6aaaa4c05a..c9f7672ac3 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -101,13 +101,13 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e if (suffix.length() > 0) { // First step: is the extension known ? - QCFType<CFStringRef> extensionRef = QCFString::toCFStringRef(suffix); + QCFType<CFStringRef> extensionRef = suffix.toCFString(); QCFType<CFStringRef> uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL); if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle)) return true; // Second step: check if an application knows the package type - QCFType<CFStringRef> path = QCFString::toCFStringRef(entry.filePath()); + QCFType<CFStringRef> path = entry.filePath().toCFString(); QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true); UInt32 type, creator; @@ -126,7 +126,7 @@ static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e if (application) { QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application); CFStringRef identifier = CFBundleGetIdentifier(bundle); - QString applicationId = QCFString::toQString(identifier); + QString applicationId = QString::fromCFString(identifier); if (applicationId != QLatin1String("com.apple.finder")) return true; } @@ -222,7 +222,7 @@ QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, if (!cfstr) return QFileSystemEntry(); - return QFileSystemEntry(QCFString::toQString(cfstr)); + return QFileSystemEntry(QString::fromCFString(cfstr)); } #endif return QFileSystemEntry(); @@ -412,7 +412,7 @@ QString QFileSystemEngine::bundleName(const QFileSystemEntry &entry) if (QCFType<CFDictionaryRef> dict = CFBundleCopyInfoDictionaryForURL(url)) { if (CFTypeRef name = (CFTypeRef)CFDictionaryGetValue(dict, kCFBundleNameKey)) { if (CFGetTypeID(name) == CFStringGetTypeID()) - return QCFString::toQString((CFStringRef)name); + return QString::fromCFString((CFStringRef)name); } } return QString(); diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index beb8acb05f..a5558b62e7 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.mm @@ -87,7 +87,7 @@ bool QFseventsFileSystemWatcherEngine::checkDir(DirsByName::iterator &it) if (res == -1) { needsRestart |= derefPath(info.watchedPath); emit emitDirectoryChanged(info.origPath, true); - it = watchedDirectories.erase(it); + it = watchingState.watchedDirectories.erase(it); } else if (st.st_ctimespec != info.ctime || st.st_mode != info.mode) { info.ctime = st.st_ctimespec; info.mode = st.st_mode; @@ -138,7 +138,8 @@ bool QFseventsFileSystemWatcherEngine::rescanDirs(const QString &path) { bool needsRestart = false; - for (DirsByName::iterator it = watchedDirectories.begin(); it != watchedDirectories.end(); ) { + for (DirsByName::iterator it = watchingState.watchedDirectories.begin(); + it != watchingState.watchedDirectories.end(); ) { if (it.key().startsWith(path)) needsRestart |= checkDir(it); else @@ -177,11 +178,12 @@ bool QFseventsFileSystemWatcherEngine::rescanFiles(const QString &path) { bool needsRestart = false; - for (FilesByPath::iterator i = watchedFiles.begin(); i != watchedFiles.end(); ) { + for (FilesByPath::iterator i = watchingState.watchedFiles.begin(); + i != watchingState.watchedFiles.end(); ) { if (i.key().startsWith(path)) { needsRestart |= rescanFiles(i.value()); if (i.value().isEmpty()) { - i = watchedFiles.erase(i); + i = watchingState.watchedFiles.erase(i); continue; } } @@ -232,8 +234,8 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream if (eFlags & kFSEventStreamEventFlagRootChanged) { // re-check everything: - DirsByName::iterator dirIt = watchedDirectories.find(path); - if (dirIt != watchedDirectories.end()) + DirsByName::iterator dirIt = watchingState.watchedDirectories.find(path); + if (dirIt != watchingState.watchedDirectories.end()) needsRestart |= checkDir(dirIt); needsRestart |= rescanFiles(path); continue; @@ -243,13 +245,13 @@ void QFseventsFileSystemWatcherEngine::processEvent(ConstFSEventStreamRef stream needsRestart |= rescanDirs(path); // check watched directories: - DirsByName::iterator dirIt = watchedDirectories.find(path); - if (dirIt != watchedDirectories.end()) + DirsByName::iterator dirIt = watchingState.watchedDirectories.find(path); + if (dirIt != watchingState.watchedDirectories.end()) needsRestart |= checkDir(dirIt); // check watched files: - FilesByPath::iterator pIt = watchedFiles.find(path); - if (pIt != watchedFiles.end()) + FilesByPath::iterator pIt = watchingState.watchedFiles.find(path); + if (pIt != watchingState.watchedFiles.end()) needsRestart |= rescanFiles(pIt.value()); } @@ -276,12 +278,11 @@ void QFseventsFileSystemWatcherEngine::doEmitDirectoryChanged(const QString &pat emit directoryChanged(path, removed); } -void QFseventsFileSystemWatcherEngine::restartStream() +bool QFseventsFileSystemWatcherEngine::restartStream() { - QMacAutoReleasePool pool; QMutexLocker locker(&lock); stopStream(); - startStream(); + return startStream(); } QFseventsFileSystemWatcherEngine *QFseventsFileSystemWatcherEngine::create(QObject *parent) @@ -311,6 +312,7 @@ QFseventsFileSystemWatcherEngine::~QFseventsFileSystemWatcherEngine() { QMacAutoReleasePool pool; + // Stop the stream in case we have to wait for the lock below to be acquired. if (stream) FSEventStreamStop(stream); @@ -334,8 +336,10 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, QMutexLocker locker(&lock); + bool wasRunning = stream != Q_NULLPTR; bool needsRestart = false; + WatchingState oldState = watchingState; QStringList p = paths; QMutableListIterator<QString> it(p); while (it.hasNext()) { @@ -356,7 +360,7 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, const bool isDir = S_ISDIR(st.st_mode); if (isDir) { - if (watchedDirectories.contains(realPath)) + if (watchingState.watchedDirectories.contains(realPath)) continue; directories->append(origPath); watchedPath = realPath; @@ -371,17 +375,18 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, parentPath = watchedPath; } - for (PathRefCounts::const_iterator i = watchedPaths.begin(), ei = watchedPaths.end(); i != ei; ++i) { + for (PathRefCounts::const_iterator i = watchingState.watchedPaths.begin(), + ei = watchingState.watchedPaths.end(); i != ei; ++i) { if (watchedPath.startsWith(i.key())) { watchedPath = i.key(); break; } } - PathRefCounts::iterator it = watchedPaths.find(watchedPath); - if (it == watchedPaths.end()) { + PathRefCounts::iterator it = watchingState.watchedPaths.find(watchedPath); + if (it == watchingState.watchedPaths.end()) { needsRestart = true; - watchedPaths.insert(watchedPath, 1); + watchingState.watchedPaths.insert(watchedPath, 1); DEBUG("Adding '%s' to watchedPaths", qPrintable(watchedPath)); } else { ++it.value(); @@ -392,18 +397,25 @@ QStringList QFseventsFileSystemWatcherEngine::addPaths(const QStringList &paths, DirInfo dirInfo; dirInfo.dirInfo = info; dirInfo.entries = scanForDirEntries(realPath); - watchedDirectories.insert(realPath, dirInfo); + watchingState.watchedDirectories.insert(realPath, dirInfo); DEBUG("-- Also adding '%s' to watchedDirectories", qPrintable(realPath)); } else { - watchedFiles[parentPath].insert(realPath, info); + watchingState.watchedFiles[parentPath].insert(realPath, info); DEBUG("-- Also adding '%s' to watchedFiles", qPrintable(realPath)); } } if (needsRestart) { stopStream(); - if (!startStream()) + if (!startStream()) { + // ok, something went wrong, let's try to restore the previous state + watchingState = qMove(oldState); + // and because we don't know which path caused the issue (if any), fail on all of them p = paths; + + if (wasRunning) + startStream(); + } } return p; @@ -419,6 +431,7 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat bool needsRestart = false; + WatchingState oldState = watchingState; QStringList p = paths; QMutableListIterator<QString> it(p); while (it.hasNext()) { @@ -431,10 +444,10 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat realPath = fi.canonicalFilePath(); if (fi.isDir()) { - DirsByName::iterator dirIt = watchedDirectories.find(realPath); - if (dirIt != watchedDirectories.end()) { + DirsByName::iterator dirIt = watchingState.watchedDirectories.find(realPath); + if (dirIt != watchingState.watchedDirectories.end()) { needsRestart |= derefPath(dirIt->dirInfo.watchedPath); - watchedDirectories.erase(dirIt); + watchingState.watchedDirectories.erase(dirIt); directories->removeAll(origPath); it.remove(); DEBUG("Removed directory '%s'", qPrintable(realPath)); @@ -442,15 +455,15 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat } else { QFileInfo fi(realPath); QString parentPath = fi.path(); - FilesByPath::iterator pIt = watchedFiles.find(parentPath); - if (pIt != watchedFiles.end()) { + FilesByPath::iterator pIt = watchingState.watchedFiles.find(parentPath); + if (pIt != watchingState.watchedFiles.end()) { InfoByName &filesInDir = pIt.value(); InfoByName::iterator fIt = filesInDir.find(realPath); if (fIt != filesInDir.end()) { needsRestart |= derefPath(fIt->watchedPath); filesInDir.erase(fIt); if (filesInDir.isEmpty()) - watchedFiles.erase(pIt); + watchingState.watchedFiles.erase(pIt); files->removeAll(origPath); it.remove(); DEBUG("Removed file '%s'", qPrintable(realPath)); @@ -461,26 +474,33 @@ QStringList QFseventsFileSystemWatcherEngine::removePaths(const QStringList &pat locker.unlock(); - if (needsRestart) - restartStream(); + if (needsRestart) { + if (!restartStream()) { + watchingState = qMove(oldState); + startStream(); + } + } return p; } +// Returns false if FSEventStream* calls failed for some mysterious reason, true if things got a +// thumbs-up. bool QFseventsFileSystemWatcherEngine::startStream() { Q_ASSERT(stream == 0); - QMacAutoReleasePool pool; - if (stream) // This shouldn't happen, but let's be nice and handle it. + if (stream) // Ok, this really shouldn't happen, esp. not after the assert. But let's be nice in release mode and still handle it. stopStream(); - if (watchedPaths.isEmpty()) - return false; + QMacAutoReleasePool pool; - DEBUG() << "Starting stream with paths" << watchedPaths.keys(); + if (watchingState.watchedPaths.isEmpty()) + return true; // we succeeded in doing nothing - NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchedPaths.size()]; - for (PathRefCounts::const_iterator i = watchedPaths.begin(), ei = watchedPaths.end(); i != ei; ++i) + DEBUG() << "Starting stream with paths" << watchingState.watchedPaths.keys(); + + NSMutableArray *pathsToWatch = [NSMutableArray arrayWithCapacity:watchingState.watchedPaths.size()]; + for (PathRefCounts::const_iterator i = watchingState.watchedPaths.begin(), ei = watchingState.watchedPaths.end(); i != ei; ++i) [pathsToWatch addObject:i.key().toNSString()]; struct FSEventStreamContext callBackInfo = { @@ -504,7 +524,7 @@ bool QFseventsFileSystemWatcherEngine::startStream() latency, FSEventStreamCreateFlags(0)); - if (!stream) { + if (!stream) { // nope, no way to know what went wrong, so just fail DEBUG() << "Failed to create stream!"; return false; } @@ -514,7 +534,7 @@ bool QFseventsFileSystemWatcherEngine::startStream() if (FSEventStreamStart(stream)) { DEBUG() << "Stream started successfully with sinceWhen =" << lastReceivedEvent; return true; - } else { + } else { // again, no way to know what went wrong, so just clean up and fail DEBUG() << "Stream failed to start!"; FSEventStreamInvalidate(stream); FSEventStreamRelease(stream); @@ -525,6 +545,7 @@ bool QFseventsFileSystemWatcherEngine::startStream() void QFseventsFileSystemWatcherEngine::stopStream(bool isStopped) { + QMacAutoReleasePool pool; if (stream) { if (!isStopped) FSEventStreamStop(stream); @@ -554,9 +575,9 @@ QFseventsFileSystemWatcherEngine::InfoByName QFseventsFileSystemWatcherEngine::s bool QFseventsFileSystemWatcherEngine::derefPath(const QString &watchedPath) { - PathRefCounts::iterator it = watchedPaths.find(watchedPath); - if (it != watchedPaths.end() && --it.value() < 1) { - watchedPaths.erase(it); + PathRefCounts::iterator it = watchingState.watchedPaths.find(watchedPath); + if (it != watchingState.watchedPaths.end() && --it.value() < 1) { + watchingState.watchedPaths.erase(it); DEBUG("Removing '%s' from watchedPaths.", qPrintable(watchedPath)); return true; } diff --git a/src/corelib/io/qfilesystemwatcher_fsevents_p.h b/src/corelib/io/qfilesystemwatcher_fsevents_p.h index dc4e5bf38b..1b0b8ae15c 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents_p.h +++ b/src/corelib/io/qfilesystemwatcher_fsevents_p.h @@ -87,7 +87,7 @@ Q_SIGNALS: private slots: void doEmitFileChanged(const QString &path, bool removed); void doEmitDirectoryChanged(const QString &path, bool removed); - void restartStream(); + bool restartStream(); private: struct Info { @@ -118,6 +118,19 @@ private: typedef QHash<QString, DirInfo> DirsByName; typedef QHash<QString, qint64> PathRefCounts; + struct WatchingState { + // These fields go hand-in-hand. FSEvents watches paths, and there is no use in watching + // the same path multiple times. So, the "refcount" on a path is the number of watched + // files that have the same path, plus the number of directories that have the same path. + // + // If the stream fails to start after adding files/directories, the watcher will try to + // keep watching files/directories that it was already watching. It does that by restoring + // the previous WatchingState and restarting the stream. + FilesByPath watchedFiles; + DirsByName watchedDirectories; + PathRefCounts watchedPaths; + }; + QFseventsFileSystemWatcherEngine(QObject *parent); bool startStream(); void stopStream(bool isStopped = false); @@ -131,10 +144,8 @@ private: QMutex lock; dispatch_queue_t queue; FSEventStreamRef stream; - FilesByPath watchedFiles; - DirsByName watchedDirectories; - PathRefCounts watchedPaths; FSEventStreamEventId lastReceivedEvent; + WatchingState watchingState; }; QT_END_NAMESPACE diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index c560bc7a03..52a78ad1c4 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -120,6 +120,14 @@ static void checkWarnMessage(const QIODevice *device, const char *function, cons } \ } while (0) +#define CHECK_MAXBYTEARRAYSIZE(function) \ + do { \ + if (maxSize >= MaxByteArraySize) { \ + checkWarnMessage(this, #function, "maxSize argument exceeds QByteArray size limit"); \ + maxSize = MaxByteArraySize - 1; \ + } \ + } while (0) + #define CHECK_WRITABLE(function, returnType) \ do { \ if ((d->openMode & WriteOnly) == 0) { \ @@ -1178,10 +1186,7 @@ QByteArray QIODevice::read(qint64 maxSize) } CHECK_MAXLEN(read, result); - if (maxSize >= MaxByteArraySize) { - checkWarnMessage(this, "read", "maxSize argument exceeds QByteArray size limit"); - maxSize = MaxByteArraySize - 1; - } + CHECK_MAXBYTEARRAYSIZE(read); result.resize(int(maxSize)); qint64 readBytes = read(result.data(), result.size()); @@ -1402,17 +1407,13 @@ QByteArray QIODevice::readLine(qint64 maxSize) QByteArray result; CHECK_MAXLEN(readLine, result); + CHECK_MAXBYTEARRAYSIZE(readLine); #if defined QIODEVICE_DEBUG printf("%p QIODevice::readLine(%lld), d->pos = %lld, d->buffer.size() = %lld\n", this, maxSize, d->pos, d->buffer.size()); #endif - if (maxSize >= MaxByteArraySize) { - qWarning("QIODevice::read: maxSize argument exceeds QByteArray size limit"); - maxSize = MaxByteArraySize - 1; - } - result.resize(int(maxSize)); qint64 readBytes = 0; if (!result.size()) { diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 1d425653a3..b39816dd7d 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -418,7 +418,7 @@ void QProcessPrivate::startProcess() } if (url) { const QCFString str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); - encodedProgramName += (QDir::separator() + QDir(program).relativeFilePath(QCFString::toQString(str))).toUtf8(); + encodedProgramName += (QDir::separator() + QDir(program).relativeFilePath(QString::fromCFString(str))).toUtf8(); } } #endif diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index b67afe0e0f..675b375b22 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -427,7 +427,9 @@ QString QSettingsPrivate::variantToString(const QVariant &v) case QVariant::Double: case QVariant::KeySequence: { result = v.toString(); - if (result.startsWith(QLatin1Char('@'))) + if (result.contains(QChar::Null)) + result = QLatin1String("@String(") + result + QLatin1Char(')'); + else if (result.startsWith(QLatin1Char('@'))) result.prepend(QLatin1Char('@')); break; } @@ -487,6 +489,8 @@ QVariant QSettingsPrivate::stringToVariant(const QString &s) if (s.endsWith(QLatin1Char(')'))) { if (s.startsWith(QLatin1String("@ByteArray("))) { return QVariant(s.midRef(11, s.size() - 12).toLatin1()); + } else if (s.startsWith(QLatin1String("@String("))) { + return QVariant(s.midRef(8, s.size() - 9).toString()); } else if (s.startsWith(QLatin1String("@Variant(")) || s.startsWith(QLatin1String("@DateTime("))) { #ifndef QT_NO_DATASTREAM diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index 21fb9519de..edd59026ed 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -80,6 +80,9 @@ public: AccessError, FormatError }; +#ifndef QT_NO_QOBJECT + Q_ENUM(Status) +#endif enum Format { NativeFormat, @@ -108,11 +111,17 @@ public: CustomFormat15, CustomFormat16 }; +#ifndef QT_NO_QOBJECT + Q_ENUM(Format) +#endif enum Scope { UserScope, SystemScope }; +#ifndef QT_NO_QOBJECT + Q_ENUM(Scope) +#endif #ifndef QT_NO_QOBJECT explicit QSettings(const QString &organization, diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index 4ad5a7b398..a31dfc5366 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -83,12 +83,12 @@ static QString rotateSlashesDotsAndMiddots(const QString &key, int shift) static QCFType<CFStringRef> macKey(const QString &key) { - return QCFString::toCFStringRef(rotateSlashesDotsAndMiddots(key, Macify)); + return rotateSlashesDotsAndMiddots(key, Macify).toCFString(); } static QString qtKey(CFStringRef cfkey) { - return rotateSlashesDotsAndMiddots(QCFString::toQString(cfkey), Qtify); + return rotateSlashesDotsAndMiddots(QString::fromCFString(cfkey), Qtify); } static QCFType<CFPropertyListRef> macValue(const QVariant &value); @@ -160,7 +160,7 @@ static QCFType<CFPropertyListRef> macValue(const QVariant &value) } } - cfkeys[numUniqueKeys] = QCFString::toCFStringRef(key); + cfkeys[numUniqueKeys] = key.toCFString(); cfvalues[numUniqueKeys] = singleton ? macValue(values.constFirst()) : macList(values); ++numUniqueKeys; } @@ -175,17 +175,12 @@ static QCFType<CFPropertyListRef> macValue(const QVariant &value) break; case QVariant::DateTime: { - /* - CFDate, unlike QDateTime, doesn't store timezone information. - */ - QDateTime dt = value.toDateTime(); - if (dt.timeSpec() == Qt::LocalTime) { - QDateTime reference; - reference.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970)); - result = CFDateCreate(kCFAllocatorDefault, CFAbsoluteTime(reference.secsTo(dt))); - } else { + QDateTime dateTime = value.toDateTime(); + // CFDate, unlike QDateTime, doesn't store timezone information + if (dateTime.timeSpec() == Qt::LocalTime) + result = dateTime.toCFDate(); + else goto string_case; - } } break; case QVariant::Bool: @@ -214,7 +209,11 @@ static QCFType<CFPropertyListRef> macValue(const QVariant &value) case QVariant::String: string_case: default: - result = QCFString::toCFStringRef(QSettingsPrivate::variantToString(value)); + QString string = QSettingsPrivate::variantToString(value); + if (string.contains(QChar::Null)) + result = string.toUtf8().toCFData(); + else + result = string.toCFString(); } return result; } @@ -230,7 +229,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue) Sorted grossly from most to least frequent type. */ if (typeId == CFStringGetTypeID()) { - return QSettingsPrivate::stringToVariant(QCFString::toQString(static_cast<CFStringRef>(cfvalue))); + return QSettingsPrivate::stringToVariant(QString::fromCFString(static_cast<CFStringRef>(cfvalue))); } else if (typeId == CFNumberGetTypeID()) { CFNumberRef cfnumber = static_cast<CFNumberRef>(cfvalue); if (CFNumberIsFloatType(cfnumber)) { @@ -266,9 +265,16 @@ static QVariant qtValue(CFPropertyListRef cfvalue) } else if (typeId == CFBooleanGetTypeID()) { return (bool)CFBooleanGetValue(static_cast<CFBooleanRef>(cfvalue)); } else if (typeId == CFDataGetTypeID()) { - CFDataRef cfdata = static_cast<CFDataRef>(cfvalue); - return QByteArray(reinterpret_cast<const char *>(CFDataGetBytePtr(cfdata)), - CFDataGetLength(cfdata)); + QByteArray byteArray = QByteArray::fromRawCFData(static_cast<CFDataRef>(cfvalue)); + + // Fast-path for QByteArray, so that we don't have to go + // though the expensive and lossy conversion via UTF-8. + if (!byteArray.startsWith('@')) + return byteArray; + + const QString str = QString::fromUtf8(byteArray.constData(), byteArray.size()); + return QSettingsPrivate::stringToVariant(str); + } else if (typeId == CFDictionaryGetTypeID()) { CFDictionaryRef cfdict = static_cast<CFDictionaryRef>(cfvalue); CFTypeID arrayTypeId = CFArrayGetTypeID(); @@ -279,7 +285,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue) QMultiMap<QString, QVariant> map; for (int i = 0; i < size; ++i) { - QString key = QCFString::toQString(static_cast<CFStringRef>(keys[i])); + QString key = QString::fromCFString(static_cast<CFStringRef>(keys[i])); if (CFGetTypeID(values[i]) == arrayTypeId) { CFArrayRef cfarray = static_cast<CFArrayRef>(values[i]); @@ -292,9 +298,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue) } return map; } else if (typeId == CFDateGetTypeID()) { - QDateTime dt; - dt.setSecsSinceEpoch(qint64(kCFAbsoluteTimeIntervalSince1970)); - return dt.addSecs((int)CFDateGetAbsoluteTime(static_cast<CFDateRef>(cfvalue))); + return QDateTime::fromCFDate(static_cast<CFDateRef>(cfvalue)); } return QVariant(); } @@ -571,7 +575,7 @@ QString QMacSettingsPrivate::fileName() const if (scope == QSettings::UserScope) result = QDir::homePath(); result += QLatin1String("/Library/Preferences/"); - result += QCFString::toQString(domains[0].applicationOrSuiteId); + result += QString::fromCFString(domains[0].applicationOrSuiteId); result += QLatin1String(".plist"); return result; } diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 3f06ab7043..1c10548cbc 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -667,15 +667,6 @@ void QWinSettingsPrivate::remove(const QString &uKey) } } -static bool stringContainsNullChar(const QString &s) -{ - for (int i = 0; i < s.length(); ++i) { - if (s.at(i).unicode() == 0) - return true; - } - return false; -} - void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) { if (writeHandle() == 0) { @@ -704,7 +695,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) QStringList l = variantListToStringList(value.toList()); QStringList::const_iterator it = l.constBegin(); for (; it != l.constEnd(); ++it) { - if ((*it).length() == 0 || stringContainsNullChar(*it)) { + if ((*it).length() == 0 || it->contains(QChar::Null)) { type = REG_BINARY; break; } @@ -748,7 +739,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) // If the string does not contain '\0', we can use REG_SZ, the native registry // string type. Otherwise we use REG_BINARY. QString s = variantToString(value); - type = stringContainsNullChar(s) ? REG_BINARY : REG_SZ; + type = s.contains(QChar::Null) ? REG_BINARY : REG_SZ; if (type == REG_BINARY) { regValueBuff = QByteArray((const char*)s.utf16(), s.length() * 2); } else { diff --git a/src/corelib/io/qsettings_winrt.cpp b/src/corelib/io/qsettings_winrt.cpp index 708287ce5e..209b56d920 100644 --- a/src/corelib/io/qsettings_winrt.cpp +++ b/src/corelib/io/qsettings_winrt.cpp @@ -402,7 +402,7 @@ void QWinRTSettingsPrivate::set(const QString &uKey, const QVariant &value) QStringList::const_iterator it = l.constBegin(); bool containsNull = false; for (; it != l.constEnd(); ++it) { - if ((*it).length() == 0 || it->indexOf(QChar::Null) != -1) { + if ((*it).length() == 0 || it->contains(QChar::Null)) { // We can only store as binary containsNull = true; break; @@ -445,7 +445,7 @@ void QWinRTSettingsPrivate::set(const QString &uKey, const QVariant &value) break; default: { const QString s = variantToString(value); - if (s.indexOf(QChar::Null) != -1) { + if (s.contains(QChar::Null)) { hr = valueStatics->CreateUInt8Array(s.length() * 2, (BYTE*) s.utf16(), &val); } else { HStringReference ref((const wchar_t*)s.utf16(), s.size()); diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index dc3d7737b6..a293d4862f 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -168,36 +168,11 @@ static QString baseWritableLocation(QStandardPaths::StandardLocation type, QString QStandardPaths::writableLocation(StandardLocation type) { - if (isTestModeEnabled()) { - const QString qttestDir = QDir::homePath() + QLatin1String("/.qttest"); - QString path; - switch (type) { - case GenericDataLocation: - case AppDataLocation: - case AppLocalDataLocation: - path = qttestDir + QLatin1String("/Application Support"); - if (type != GenericDataLocation) - appendOrganizationAndApp(path); - return path; - case GenericCacheLocation: - case CacheLocation: - path = qttestDir + QLatin1String("/Cache"); - if (type == CacheLocation) - appendOrganizationAndApp(path); - return path; - case GenericConfigLocation: - case ConfigLocation: - case AppConfigLocation: - path = qttestDir + QLatin1String("/Preferences"); - if (type == AppConfigLocation) - appendOrganizationAndApp(path); - return path; - default: - break; - } - } + QString location = baseWritableLocation(type, NSUserDomainMask, true); + if (isTestModeEnabled()) + location = location.replace(QDir::homePath(), QDir::homePath() + QLatin1String("/.qttest")); - return baseWritableLocation(type, NSUserDomainMask, true); + return location; } QStringList QStandardPaths::standardLocations(StandardLocation type) @@ -230,13 +205,13 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) if (mainBundle) { CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle); CFStringRef cfBundlePath = CFURLCopyPath(bundleUrl); - QString bundlePath = QCFString::toQString(cfBundlePath); + QString bundlePath = QString::fromCFString(cfBundlePath); CFRelease(cfBundlePath); CFRelease(bundleUrl); CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(mainBundle); CFStringRef cfResourcesPath = CFURLCopyPath(resourcesUrl); - QString resourcesPath = QCFString::toQString(cfResourcesPath); + QString resourcesPath = QString::fromCFString(cfResourcesPath); CFRelease(cfResourcesPath); CFRelease(resourcesUrl); diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index c430c7714a..7aae128796 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -665,7 +665,7 @@ QString QTemporaryFile::fileTemplate() const /*! Sets the static portion of the file name to \a name. If the file - template ends in XXXXXX that will automatically be replaced with + template contains XXXXXX that will automatically be replaced with the unique part of the filename, otherwise a filename will be determined automatically based on the static portion specified. diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp index dd0ee6068d..96543bbbfd 100644 --- a/src/corelib/io/qtldurl.cpp +++ b/src/corelib/io/qtldurl.cpp @@ -37,6 +37,10 @@ ** ****************************************************************************/ +#include <qglobal.h> + +#if QT_CONFIG(topleveldomain) + #include "qplatformdefs.h" #include "qurl.h" #include "private/qurltlds_p.h" @@ -125,3 +129,5 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain) } QT_END_NAMESPACE + +#endif diff --git a/src/corelib/io/qtldurl_p.h b/src/corelib/io/qtldurl_p.h index b9fbdebbc5..4636f18874 100644 --- a/src/corelib/io/qtldurl_p.h +++ b/src/corelib/io/qtldurl_p.h @@ -55,6 +55,8 @@ #include "QtCore/qurl.h" #include "QtCore/qstring.h" +QT_REQUIRE_CONFIG(topleveldomain); + QT_BEGIN_NAMESPACE Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain); diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 42a742213b..c165aef5a2 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3117,6 +3117,7 @@ bool QUrl::hasFragment() const return d->hasFragment(); } +#if QT_CONFIG(topleveldomain) /*! \since 4.8 @@ -3151,6 +3152,7 @@ QString QUrl::topLevelDomain(ComponentFormattingOptions options) const } return tld; } +#endif /*! Returns the result of the merge of this URL with \a relative. This diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index bce271fcb1..a554a3b07e 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -235,7 +235,9 @@ public: void setHost(const QString &host, ParsingMode mode = DecodedMode); QString host(ComponentFormattingOptions = FullyDecoded) const; +#if QT_CONFIG(topleveldomain) QString topLevelDomain(ComponentFormattingOptions options = FullyDecoded) const; +#endif void setPort(int port); int port(int defaultPort = -1) const; |