diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/io.pri | 5 | ||||
-rw-r--r-- | src/corelib/io/qdebug.cpp | 10 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemengine_unix.cpp | 20 | ||||
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 33 | ||||
-rw-r--r-- | src/corelib/io/qiodevice_p.h | 4 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_haiku.cpp | 222 |
6 files changed, 268 insertions, 26 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index 77788e3cca..4749444c11 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -165,6 +165,11 @@ win32 { SOURCES += \ io/qstandardpaths_android.cpp \ io/qstorageinfo_unix.cpp + } else:haiku { + SOURCES += \ + io/qstandardpaths_haiku.cpp \ + io/qstorageinfo_unix.cpp + LIBS += -lbe } else { SOURCES += \ io/qstandardpaths_unix.cpp \ diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 9ed29c38af..ad61621a93 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies). ** Copyright (C) 2014 Intel Corporation. ** Contact: http://www.qt-project.org/legal ** @@ -263,12 +263,8 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, in // improperly-paired surrogates, fall through } buf[1] = 'u'; - if (sizeof(Char) == 1) { - buf[2] = buf[3] = '0'; - } else { - buf[2] = toHexUpper(*p >> 12); - buf[3] = toHexUpper(*p >> 8); - } + buf[2] = toHexUpper(ushort(*p) >> 12); + buf[3] = toHexUpper(ushort(*p) >> 8); buf[4] = toHexUpper(*p >> 4); buf[5] = toHexUpper(*p); buflen = 6; diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp index 11d421591a..feb86d2895 100644 --- a/src/corelib/io/qfilesystemengine_unix.cpp +++ b/src/corelib/io/qfilesystemengine_unix.cpp @@ -250,6 +250,26 @@ QFileSystemEntry QFileSystemEngine::canonicalName(const QFileSystemEntry &entry, return QFileSystemEntry(ret); } } + +# elif defined(Q_OS_ANDROID) + // On some Android versions, realpath() will return a path even if it does not exist + // To work around this, we check existence in advance. + if (!data.hasFlags(QFileSystemMetaData::ExistsAttribute)) + fillMetaData(entry, data, QFileSystemMetaData::ExistsAttribute); + + if (!data.exists()) { + ret = 0; + errno = ENOENT; + } else { + ret = (char*)malloc(PATH_MAX + 1); + if (realpath(entry.nativeFilePath().constData(), (char*)ret) == 0) { + const int savedErrno = errno; // errno is checked below, and free() might change it + free(ret); + errno = savedErrno; + ret = 0; + } + } + # else # if _POSIX_VERSION >= 200801L ret = realpath(entry.nativeFilePath().constData(), (char*)0); diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index b1f164ab1b..388c623bcb 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -117,8 +117,7 @@ void debugBinaryString(const char *data, qint64 maxlen) */ QIODevicePrivate::QIODevicePrivate() : openMode(QIODevice::NotOpen), buffer(QIODEVICE_BUFFERSIZE), - pos(0), devicePos(0), seqDumpPos(0) - , pPos(&pos), pDevicePos(&devicePos) + pos(0), devicePos(0) , baseReadLineDataCalled(false) , firstRead(true) , accessMode(Unset) @@ -566,7 +565,6 @@ void QIODevice::close() d->openMode = NotOpen; d->errorString.clear(); d->pos = 0; - d->seqDumpPos = 0; d->buffer.clear(); d->firstRead = true; } @@ -755,11 +753,14 @@ qint64 QIODevice::read(char *data, qint64 maxSize) this, data, int(maxSize), int(d->pos), int(d->buffer.size())); #endif + const bool sequential = d->isSequential(); + // Short circuit for getChar() if (maxSize == 1) { int chint; while ((chint = d->buffer.getChar()) != -1) { - ++(*d->pPos); + if (!sequential) + ++d->pos; char c = char(uchar(chint)); if (c == '\r' && (d->openMode & Text)) @@ -784,7 +785,8 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // Try reading from the buffer. qint64 bufferReadChunkSize = d->buffer.read(data, maxSize); if (bufferReadChunkSize > 0) { - *d->pPos += bufferReadChunkSize; + if (!sequential) + d->pos += bufferReadChunkSize; readSoFar += bufferReadChunkSize; data += bufferReadChunkSize; maxSize -= bufferReadChunkSize; @@ -798,17 +800,13 @@ qint64 QIODevice::read(char *data, qint64 maxSize) // for fast pos updates. CHECK_READABLE(read, qint64(-1)); d->firstRead = false; - if (d->isSequential()) { - d->pPos = &d->seqDumpPos; - d->pDevicePos = &d->seqDumpPos; - } } } if (maxSize > 0 && !deviceAtEof) { qint64 readFromDevice = 0; // Make sure the device is positioned correctly. - if (d->pos == d->devicePos || d->isSequential() || seek(d->pos)) { + if (sequential || d->pos == d->devicePos || seek(d->pos)) { madeBufferReadsOnly = false; // fix readData attempt if (maxSize >= QIODEVICE_BUFFERSIZE || (d->openMode & Unbuffered)) { // Read big chunk directly to output buffer @@ -822,8 +820,10 @@ qint64 QIODevice::read(char *data, qint64 maxSize) readSoFar += readFromDevice; data += readFromDevice; maxSize -= readFromDevice; - *d->pPos += readFromDevice; - *d->pDevicePos += readFromDevice; + if (!sequential) { + d->pos += readFromDevice; + d->devicePos += readFromDevice; + } } } else { const int bytesToBuffer = QIODEVICE_BUFFERSIZE; @@ -832,7 +832,8 @@ qint64 QIODevice::read(char *data, qint64 maxSize) deviceAtEof = (readFromDevice != bytesToBuffer); d->buffer.chop(bytesToBuffer - qMax(0, int(readFromDevice))); if (readFromDevice > 0) { - *d->pDevicePos += readFromDevice; + if (!sequential) + d->devicePos += readFromDevice; #if defined QIODEVICE_DEBUG printf("%p \treading %d from device into buffer\n", this, int(readFromDevice)); @@ -1414,7 +1415,8 @@ qint64 QIODevicePrivate::peek(char *data, qint64 maxSize) return readBytes; buffer.ungetBlock(data, readBytes); - *pPos -= readBytes; + if (!isSequential()) + pos -= readBytes; return readBytes; } @@ -1429,7 +1431,8 @@ QByteArray QIODevicePrivate::peek(qint64 maxSize) return result; buffer.ungetBlock(result.constData(), result.size()); - *pPos -= result.size(); + if (!isSequential()) + pos -= result.size(); return result; } diff --git a/src/corelib/io/qiodevice_p.h b/src/corelib/io/qiodevice_p.h index d764cb0fbb..ac76f8ded8 100644 --- a/src/corelib/io/qiodevice_p.h +++ b/src/corelib/io/qiodevice_p.h @@ -209,10 +209,6 @@ public: QIODevicePrivateLinearBuffer buffer; qint64 pos; qint64 devicePos; - // these three are for fast position updates during read, avoiding isSequential test - qint64 seqDumpPos; - qint64 *pPos; - qint64 *pDevicePos; bool baseReadLineDataCalled; bool firstRead; diff --git a/src/corelib/io/qstandardpaths_haiku.cpp b/src/corelib/io/qstandardpaths_haiku.cpp new file mode 100644 index 0000000000..ac57686126 --- /dev/null +++ b/src/corelib/io/qstandardpaths_haiku.cpp @@ -0,0 +1,222 @@ +/*************************************************************************** +** +** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Tobias Koenig <tobias.koenig@kdab.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** 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, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qstandardpaths.h" + +#ifndef QT_NO_STANDARDPATHS + +#ifndef QT_BOOTSTRAPPED +#include <qcoreapplication.h> +#endif + +#include <qfile.h> + +#include <FindDirectory.h> +#include <Path.h> +#include <PathFinder.h> +#include <StringList.h> + +QT_BEGIN_NAMESPACE + +namespace { + +void appendOrganizationAndApp(QString &path) +{ +#ifndef QT_BOOTSTRAPPED + const QString org = QCoreApplication::organizationName(); + if (!org.isEmpty()) + path += QLatin1Char('/') + org; + const QString appName = QCoreApplication::applicationName(); + if (!appName.isEmpty()) + path += QLatin1Char('/') + appName; +#else + Q_UNUSED(path); +#endif +} + +/* + * Returns the generic standard path for given directory type. + */ +QString haikuStandardPath(directory_which which) +{ + BPath standardPath; + + if (find_directory(which, &standardPath, false) != B_OK) + return QString(); + + return QFile::decodeName(standardPath.Path()); +} + +/* + * Returns the generic standard paths for given path type. + */ +QStringList haikuStandardPaths(path_base_directory baseDirectory) +{ + BStringList paths; + + if (BPathFinder::FindPaths(baseDirectory, paths) != B_OK) + return QStringList(); + + QStringList standardPaths; + for (int i = 0; i < paths.CountStrings(); ++i) { + standardPaths << QFile::decodeName(paths.StringAt(i).String()); + } + + return standardPaths; +} + +/* + * Returns the application specific standard path for given directory type. + */ +QString haikuAppStandardPath(directory_which which) +{ + QString path = haikuStandardPath(which); + if (!path.isEmpty()) + appendOrganizationAndApp(path); + + return path; +} + +/* + * Returns the application specific standard paths for given path type. + */ +QStringList haikuAppStandardPaths(path_base_directory baseDirectory) +{ + QStringList paths = haikuStandardPaths(baseDirectory); + for (int i = 0; i < paths.count(); ++i) + appendOrganizationAndApp(paths[i]); + + return paths; +} + +} // namespace + +QString QStandardPaths::writableLocation(StandardLocation type) +{ + switch (type) { + case DesktopLocation: + return haikuStandardPath(B_DESKTOP_DIRECTORY); + case DocumentsLocation: // fall through + case PicturesLocation: + case MusicLocation: + case MoviesLocation: + case DownloadLocation: + case HomeLocation: + return haikuStandardPath(B_USER_DIRECTORY); + case FontsLocation: + return haikuStandardPath(B_USER_NONPACKAGED_FONTS_DIRECTORY); + case ApplicationsLocation: + return haikuStandardPath(B_USER_NONPACKAGED_BIN_DIRECTORY); + case TempLocation: + return haikuStandardPath(B_SYSTEM_TEMP_DIRECTORY); + case AppDataLocation: // fall through + case AppLocalDataLocation: + return haikuAppStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY); + case GenericDataLocation: + return haikuStandardPath(B_USER_NONPACKAGED_DATA_DIRECTORY); + case CacheLocation: + return haikuAppStandardPath(B_USER_CACHE_DIRECTORY); + case GenericCacheLocation: + return haikuStandardPath(B_USER_CACHE_DIRECTORY); + case ConfigLocation: // fall through + case AppConfigLocation: + return haikuAppStandardPath(B_USER_SETTINGS_DIRECTORY); + case GenericConfigLocation: + return haikuStandardPath(B_USER_SETTINGS_DIRECTORY); + default: + return QString(); + } +} + +QStringList QStandardPaths::standardLocations(StandardLocation type) +{ + QStringList paths; + + const QString writablePath = writableLocation(type); + if (!writablePath.isEmpty()) + paths += writablePath; + + switch (type) { + case DocumentsLocation: // fall through + case PicturesLocation: + case MusicLocation: + case MoviesLocation: + case DownloadLocation: + case HomeLocation: + paths += haikuStandardPath(B_USER_NONPACKAGED_DIRECTORY); + break; + case FontsLocation: + paths += haikuStandardPaths(B_FIND_PATH_FONTS_DIRECTORY); + break; + case ApplicationsLocation: + paths += haikuStandardPaths(B_FIND_PATH_BIN_DIRECTORY); + paths += haikuStandardPaths(B_FIND_PATH_APPS_DIRECTORY); + break; + case AppDataLocation: // fall through + case AppLocalDataLocation: + paths += haikuAppStandardPaths(B_FIND_PATH_DATA_DIRECTORY); + break; + case GenericDataLocation: + paths += haikuStandardPaths(B_FIND_PATH_DATA_DIRECTORY); + break; + case CacheLocation: + paths += haikuAppStandardPath(B_SYSTEM_CACHE_DIRECTORY); + break; + case GenericCacheLocation: + paths += haikuStandardPath(B_SYSTEM_CACHE_DIRECTORY); + break; + case ConfigLocation: // fall through + case AppConfigLocation: + paths += haikuAppStandardPath(B_SYSTEM_SETTINGS_DIRECTORY); + break; + case GenericConfigLocation: + paths += haikuStandardPath(B_SYSTEM_SETTINGS_DIRECTORY); + break; + default: + break; + } + + return paths; +} + +QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS |