diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/io.pri | 10 | ||||
-rw-r--r-- | src/corelib/io/qdatastream.cpp | 1 | ||||
-rw-r--r-- | src/corelib/io/qdatastream.h | 5 | ||||
-rw-r--r-- | src/corelib/io/qprocess.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 25 | ||||
-rw-r--r-- | src/corelib/io/qsettings.cpp | 26 | ||||
-rw-r--r-- | src/corelib/io/qsettings.h | 5 | ||||
-rw-r--r-- | src/corelib/io/qsettings_win.cpp | 120 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths.cpp | 16 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_ios.mm | 133 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.mm | 204 |
11 files changed, 251 insertions, 296 deletions
diff --git a/src/corelib/io/io.pri b/src/corelib/io/io.pri index b2bcbdf727..7be1e5883e 100644 --- a/src/corelib/io/io.pri +++ b/src/corelib/io/io.pri @@ -149,20 +149,14 @@ win32 { } freebsd: LIBS_PRIVATE += -lutil # qlockfile_unix.cpp requires this mac { + SOURCES += io/qstorageinfo_mac.cpp + OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm osx { OBJECTIVE_SOURCES += io/qfilesystemwatcher_fsevents.mm HEADERS += io/qfilesystemwatcher_fsevents_p.h - } - macx { - SOURCES += io/qstorageinfo_mac.cpp - OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm LIBS += -framework DiskArbitration -framework IOKit } else:ios { - OBJECTIVE_SOURCES += io/qstandardpaths_ios.mm - SOURCES += io/qstorageinfo_mac.cpp LIBS += -framework MobileCoreServices - } else { - SOURCES += io/qstandardpaths_unix.cpp } } else:blackberry { SOURCES += \ diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index 675178ea80..c32df4c8a6 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -527,6 +527,7 @@ void QDataStream::setByteOrder(ByteOrder bo) \value Qt_5_4 Version 16 (Qt 5.4) \value Qt_5_5 Same as Qt_5_4 \value Qt_5_6 Version 17 (Qt 5.6) + \value Qt_5_7 Same as Qt_5_6 \omitvalue Qt_DefaultCompiledVersion \sa setVersion(), version() diff --git a/src/corelib/io/qdatastream.h b/src/corelib/io/qdatastream.h index 5730c12907..744829c659 100644 --- a/src/corelib/io/qdatastream.h +++ b/src/corelib/io/qdatastream.h @@ -84,10 +84,11 @@ public: Qt_5_4 = 16, Qt_5_5 = Qt_5_4, Qt_5_6 = 17, -#if QT_VERSION >= 0x050700 + Qt_5_7 = Qt_5_6, +#if QT_VERSION >= 0x050800 #error Add the datastream version for this Qt version and update Qt_DefaultCompiledVersion #endif - Qt_DefaultCompiledVersion = Qt_5_6 + Qt_DefaultCompiledVersion = Qt_5_7 }; enum ByteOrder { diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 8ee8d0b703..ecda86a91d 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1194,7 +1194,7 @@ bool QProcessPrivate::_q_startupNotification() } q->setProcessState(QProcess::NotRunning); - setErrorAndEmit(QProcess::FailedToStart); + setErrorAndEmit(QProcess::FailedToStart, errorString); // the error string was already set #ifdef Q_OS_UNIX // make sure the process manager removes this entry waitForDeadChild(); diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 63480dfc6b..a958aa4322 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -672,6 +672,7 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv qt_safe_close(childStartedPipe[0]); // enter the working directory + const char *callthatfailed = "chdir: "; if (workingDir && QT_CHDIR(workingDir) == -1) { // failed, stop the process goto report_errno; @@ -683,6 +684,7 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv // execute the process if (!envp) { qt_safe_execvp(argv[0], argv); + callthatfailed = "execvp: "; } else { if (path) { char **arg = path; @@ -700,15 +702,19 @@ void QProcessPrivate::execChild(const char *workingDir, char **path, char **argv #endif qt_safe_execve(argv[0], argv, envp); } + callthatfailed = "execve: "; } // notify failure + // we're running in the child process, so we don't need to be thread-safe; + // we can use strerror report_errno: - QString error = qt_error_string(errno); + const char *msg = strerror(errno); #if defined (QPROCESS_DEBUG) - fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", qPrintable(error)); + fprintf(stderr, "QProcessPrivate::execChild() failed (%s), notifying parent process\n", msg); #endif - qt_safe_write(childStartedPipe[1], error.data(), error.length() * sizeof(QChar)); + qt_safe_write(childStartedPipe[1], callthatfailed, strlen(callthatfailed)); + qt_safe_write(childStartedPipe[1], msg, strlen(msg)); qt_safe_close(childStartedPipe[1]); childStartedPipe[1] = -1; } @@ -716,8 +722,15 @@ report_errno: bool QProcessPrivate::processStarted() { - ushort buf[errorBufferMax]; - int i = qt_safe_read(childStartedPipe[0], &buf, sizeof buf); + char buf[errorBufferMax]; + int i = 0; + int ret; + do { + ret = qt_safe_read(childStartedPipe[0], buf + i, sizeof buf - i); + if (ret > 0) + i += ret; + } while (ret > 0 && i < int(sizeof buf)); + if (startupSocketNotifier) { startupSocketNotifier->setEnabled(false); startupSocketNotifier->deleteLater(); @@ -732,7 +745,7 @@ bool QProcessPrivate::processStarted() // did we read an error message? if (i > 0) - q_func()->setErrorString(QString((const QChar *)buf, i / sizeof(QChar))); + q_func()->setErrorString(QString::fromLocal8Bit(buf, i)); return i <= 0; } diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index b9993c454e..654d688c53 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -2412,14 +2412,24 @@ void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, This enum type specifies the storage format used by QSettings. - \value NativeFormat Store the settings using the most - appropriate storage format for the platform. - On Windows, this means the system registry; - on OS X and iOS, this means the CFPreferences - API; on Unix, this means textual - configuration files in INI format. - \value IniFormat Store the settings in INI files. - \value InvalidFormat Special value returned by registerFormat(). + \value NativeFormat Store the settings using the most + appropriate storage format for the platform. + On Windows, this means the system registry; + on OS X and iOS, this means the CFPreferences + API; on Unix, this means textual + configuration files in INI format. + \value Registry32Format Windows only: Explicitly access the 32-bit system registry + from a 64-bit application running on 64-bit Windows. + On 32-bit Windows or from a 32-bit application on 64-bit Windows, + this works the same as specifying NativeFormat. + This enum value was added in Qt 5.7. + \value Registry64Format Windows only: Explicitly access the 64-bit system registry + from a 32-bit application running on 64-bit Windows. + On 32-bit Windows or from a 64-bit application on 64-bit Windows, + this works the same as specifying NativeFormat. + This enum value was added in Qt 5.7. + \value IniFormat Store the settings in INI files. + \value InvalidFormat Special value returned by registerFormat(). \omitvalue CustomFormat1 \omitvalue CustomFormat2 \omitvalue CustomFormat3 diff --git a/src/corelib/io/qsettings.h b/src/corelib/io/qsettings.h index 8f41273ffa..dd0c4a9bfb 100644 --- a/src/corelib/io/qsettings.h +++ b/src/corelib/io/qsettings.h @@ -79,6 +79,11 @@ public: NativeFormat, IniFormat, +#ifdef Q_OS_WIN + Registry32Format, + Registry64Format, +#endif + InvalidFormat = 16, CustomFormat1, CustomFormat2, diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 1546219c3b..88f58422a8 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -41,6 +41,18 @@ #include "qdebug.h" #include <qt_windows.h> +// See "Accessing an Alternate Registry View" at: +// http://msdn.microsoft.com/en-us/library/aa384129%28VS.85%29.aspx +#ifndef KEY_WOW64_64KEY + // Access a 32-bit key from either a 32-bit or 64-bit application. +# define KEY_WOW64_64KEY 0x0100 +#endif + +#ifndef KEY_WOW64_32KEY + // Access a 64-bit key from either a 32-bit or 64-bit application. +# define KEY_WOW64_32KEY 0x0200 +#endif + QT_BEGIN_NAMESPACE /* Keys are stored in QStrings. If the variable name starts with 'u', this is a "user" @@ -135,12 +147,13 @@ static QString errorCodeToString(DWORD errorCode) return result; } -// Open a key with the specified perms -static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) +// Open a key with the specified "perms". +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access = 0) { HKEY resultHandle = 0; LONG res = RegOpenKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), - 0, perms, &resultHandle); + 0, perms | access, &resultHandle); if (res == ERROR_SUCCESS) return resultHandle; @@ -148,17 +161,18 @@ static HKEY openKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) return 0; } -// Open a key with the specified perms, create it if it does not exist -static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey) +// Open a key with the specified "perms", create it if it does not exist. +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSubKey, REGSAM access = 0) { // try to open it - HKEY resultHandle = openKey(parentHandle, perms, rSubKey); + HKEY resultHandle = openKey(parentHandle, perms, rSubKey, access); if (resultHandle != 0) return resultHandle; // try to create it LONG res = RegCreateKeyEx(parentHandle, reinterpret_cast<const wchar_t *>(rSubKey.utf16()), 0, 0, - REG_OPTION_NON_VOLATILE, perms, 0, &resultHandle, 0); + REG_OPTION_NON_VOLATILE, perms | access, 0, &resultHandle, 0); if (res == ERROR_SUCCESS) return resultHandle; @@ -169,11 +183,12 @@ static HKEY createOrOpenKey(HKEY parentHandle, REGSAM perms, const QString &rSub return 0; } -// Open or create a key in read-write mode if possible, otherwise read-only -static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *readOnly) +// Open or create a key in read-write mode if possible, otherwise read-only. +// "access" is to explicitly use the 32- or 64-bit branch. +static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *readOnly, REGSAM access = 0) { // try to open or create it read/write - HKEY resultHandle = createOrOpenKey(parentHandle, registryPermissions, rSubKey); + HKEY resultHandle = createOrOpenKey(parentHandle, registryPermissions, rSubKey, access); if (resultHandle != 0) { if (readOnly != 0) *readOnly = false; @@ -181,7 +196,7 @@ static HKEY createOrOpenKey(HKEY parentHandle, const QString &rSubKey, bool *rea } // try to open or create it read/only - resultHandle = createOrOpenKey(parentHandle, KEY_READ, rSubKey); + resultHandle = createOrOpenKey(parentHandle, KEY_READ, rSubKey, access); if (resultHandle != 0) { if (readOnly != 0) *readOnly = true; @@ -247,9 +262,9 @@ static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildS return result; } -static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result) +static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result, REGSAM access = 0) { - HKEY handle = openKey(parentHandle, KEY_READ, rSubKey); + HKEY handle = openKey(parentHandle, KEY_READ, rSubKey, access); if (handle == 0) return; @@ -270,11 +285,11 @@ static void allKeys(HKEY parentHandle, const QString &rSubKey, NameSet *result) if (!s.isEmpty()) s += QLatin1Char('\\'); s += childGroups.at(i); - allKeys(parentHandle, s, result); + allKeys(parentHandle, s, result, access); } } -static void deleteChildGroups(HKEY parentHandle) +static void deleteChildGroups(HKEY parentHandle, REGSAM access = 0) { QStringList childGroups = childKeysOrGroups(parentHandle, QSettingsPrivate::ChildGroups); @@ -282,10 +297,10 @@ static void deleteChildGroups(HKEY parentHandle) QString group = childGroups.at(i); // delete subgroups in group - HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group); + HKEY childGroupHandle = openKey(parentHandle, registryPermissions, group, access); if (childGroupHandle == 0) continue; - deleteChildGroups(childGroupHandle); + deleteChildGroups(childGroupHandle, access); RegCloseKey(childGroupHandle); // delete group itself @@ -305,7 +320,7 @@ static void deleteChildGroups(HKEY parentHandle) class RegistryKey { public: - RegistryKey(HKEY parent_handle = 0, const QString &key = QString(), bool read_only = true); + RegistryKey(HKEY parent_handle = 0, const QString &key = QString(), bool read_only = true, REGSAM access = 0); QString key() const; HKEY handle() const; HKEY parentHandle() const; @@ -316,13 +331,15 @@ private: mutable HKEY m_handle; QString m_key; mutable bool m_read_only; + REGSAM m_access; }; -RegistryKey::RegistryKey(HKEY parent_handle, const QString &key, bool read_only) +RegistryKey::RegistryKey(HKEY parent_handle, const QString &key, bool read_only, REGSAM access) : m_parent_handle(parent_handle), m_handle(0), m_key(key), - m_read_only(read_only) + m_read_only(read_only), + m_access(access) { } @@ -337,9 +354,9 @@ HKEY RegistryKey::handle() const return m_handle; if (m_read_only) - m_handle = openKey(m_parent_handle, KEY_READ, m_key); + m_handle = openKey(m_parent_handle, KEY_READ, m_key, m_access); else - m_handle = createOrOpenKey(m_parent_handle, m_key, &m_read_only); + m_handle = createOrOpenKey(m_parent_handle, m_key, &m_read_only, m_access); return m_handle; } @@ -371,8 +388,8 @@ class QWinSettingsPrivate : public QSettingsPrivate { public: QWinSettingsPrivate(QSettings::Scope scope, const QString &organization, - const QString &application); - QWinSettingsPrivate(QString rKey); + const QString &application, REGSAM access = 0); + QWinSettingsPrivate(QString rKey, REGSAM access = 0); ~QWinSettingsPrivate(); void remove(const QString &uKey); @@ -390,11 +407,13 @@ public: private: RegistryKeyList regList; // list of registry locations to search for keys bool deleteWriteHandleOnExit; + REGSAM access; }; QWinSettingsPrivate::QWinSettingsPrivate(QSettings::Scope scope, const QString &organization, - const QString &application) - : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application) + const QString &application, REGSAM access) + : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application), + access(access) { deleteWriteHandleOnExit = false; @@ -405,23 +424,24 @@ QWinSettingsPrivate::QWinSettingsPrivate(QSettings::Scope scope, const QString & if (scope == QSettings::UserScope) { if (!application.isEmpty()) - regList.append(RegistryKey(HKEY_CURRENT_USER, appPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_CURRENT_USER, appPrefix, !regList.isEmpty(), access)); - regList.append(RegistryKey(HKEY_CURRENT_USER, orgPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_CURRENT_USER, orgPrefix, !regList.isEmpty(), access)); } if (!application.isEmpty()) - regList.append(RegistryKey(HKEY_LOCAL_MACHINE, appPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_LOCAL_MACHINE, appPrefix, !regList.isEmpty(), access)); - regList.append(RegistryKey(HKEY_LOCAL_MACHINE, orgPrefix, !regList.isEmpty())); + regList.append(RegistryKey(HKEY_LOCAL_MACHINE, orgPrefix, !regList.isEmpty(), access)); } if (regList.isEmpty()) setStatus(QSettings::AccessError); } -QWinSettingsPrivate::QWinSettingsPrivate(QString rPath) - : QSettingsPrivate(QSettings::NativeFormat) +QWinSettingsPrivate::QWinSettingsPrivate(QString rPath, REGSAM access) + : QSettingsPrivate(QSettings::NativeFormat), + access(access) { deleteWriteHandleOnExit = false; @@ -460,9 +480,9 @@ QWinSettingsPrivate::QWinSettingsPrivate(QString rPath) } if (rPath.length() == keyLength) - regList.append(RegistryKey(keyName, QString(), false)); + regList.append(RegistryKey(keyName, QString(), false, access)); else if (rPath[keyLength] == QLatin1Char('\\')) - regList.append(RegistryKey(keyName, rPath.mid(keyLength+1), false)); + regList.append(RegistryKey(keyName, rPath.mid(keyLength+1), false, access)); } bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVariant *value) const @@ -471,7 +491,7 @@ bool QWinSettingsPrivate::readKey(HKEY parentHandle, const QString &rSubKey, QVa QString rSubkeyPath = keyPath(rSubKey); // open a handle on the subkey - HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath); + HKEY handle = openKey(parentHandle, KEY_READ, rSubkeyPath, access); if (handle == 0) return false; @@ -604,16 +624,16 @@ void QWinSettingsPrivate::remove(const QString &uKey) // try to delete value bar in key foo LONG res; - HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey)); + HKEY handle = openKey(writeHandle(), registryPermissions, keyPath(rKey), access); if (handle != 0) { res = RegDeleteValue(handle, reinterpret_cast<const wchar_t *>(keyName(rKey).utf16())); RegCloseKey(handle); } // try to delete key foo/bar and all subkeys - handle = openKey(writeHandle(), registryPermissions, rKey); + handle = openKey(writeHandle(), registryPermissions, rKey, access); if (handle != 0) { - deleteChildGroups(handle); + deleteChildGroups(handle, access); if (rKey.isEmpty()) { QStringList childKeys = childKeysOrGroups(handle, QSettingsPrivate::ChildKeys); @@ -661,7 +681,7 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) QString rKey = escapedKey(uKey); - HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey)); + HKEY handle = createOrOpenKey(writeHandle(), registryPermissions, keyPath(rKey), access); if (handle == 0) { setStatus(QSettings::AccessError); return; @@ -775,13 +795,13 @@ QStringList QWinSettingsPrivate::children(const QString &uKey, ChildSpec spec) c HKEY parent_handle = regList.at(i).handle(); if (parent_handle == 0) continue; - HKEY handle = openKey(parent_handle, KEY_READ, rKey); + HKEY handle = openKey(parent_handle, KEY_READ, rKey, access); if (handle == 0) continue; if (spec == AllKeys) { NameSet keys; - allKeys(handle, QLatin1String(""), &keys); + allKeys(handle, QLatin1String(""), &keys, access); mergeKeySets(&result, keys); } else { // ChildGroups or ChildKeys QStringList names = childKeysOrGroups(handle, spec); @@ -836,20 +856,26 @@ bool QWinSettingsPrivate::isWritable() const QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, const QString &organization, const QString &application) { - if (format == QSettings::NativeFormat) { + if (format == QSettings::NativeFormat) return new QWinSettingsPrivate(scope, organization, application); - } else { + else if (format == QSettings::Registry32Format) + return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_32KEY); + else if (format == QSettings::Registry64Format) + return new QWinSettingsPrivate(scope, organization, application, KEY_WOW64_64KEY); + else return new QConfFileSettingsPrivate(format, scope, organization, application); - } } QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format) { - if (format == QSettings::NativeFormat) { + if (format == QSettings::NativeFormat) return new QWinSettingsPrivate(fileName); - } else { + else if (format == QSettings::Registry32Format) + return new QWinSettingsPrivate(fileName, KEY_WOW64_32KEY); + else if (format == QSettings::Registry64Format) + return new QWinSettingsPrivate(fileName, KEY_WOW64_64KEY); + else return new QConfFileSettingsPrivate(fileName, format); - } } QT_END_NAMESPACE diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 8828e09e8f..0137e859e7 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -277,13 +277,13 @@ QT_BEGIN_NAMESPACE \header \li Path type \li Android \li iOS \row \li DesktopLocation \li "<APPROOT>/files" - \li "<APPROOT>/<APPDIR>" (not writable) + \li "<APPROOT>/Documents/Desktop" \row \li DocumentsLocation \li "<USER>/Documents", "<USER>/<APPNAME>/Documents" \li "<APPROOT>/Documents" \row \li FontsLocation \li "/system/fonts" (not writable) - \li "<APPROOT>/Documents/.fonts" + \li "<APPROOT>/Library/Fonts" \row \li ApplicationsLocation \li not supported (directory not readable) \li not supported @@ -301,7 +301,7 @@ QT_BEGIN_NAMESPACE \li "<APPROOT>/tmp" \row \li HomeLocation \li "<APPROOT>/files" - \li "<APPROOT>/<APPDIR>" (not writable) + \li "<APPROOT>" (not writable) \row \li DataLocation \li "<APPROOT>/files", "<USER>/<APPNAME>/files" \li "<APPROOT>/Library/Application Support" @@ -316,13 +316,13 @@ QT_BEGIN_NAMESPACE \li not supported \row \li ConfigLocation \li "<APPROOT>/files/settings" - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences" \row \li GenericConfigLocation \li "<APPROOT>/files/settings" (there is no shared settings) - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences" \row \li DownloadLocation \li "<USER>/Downloads", "<USER>/<APPNAME>/Downloads" - \li "<APPROOT>/Documents/Download" + \li "<APPROOT>/Documents/Downloads" \row \li GenericCacheLocation \li "<APPROOT>/cache" (there is no shared cache) \li "<APPROOT>/Library/Caches" @@ -331,7 +331,7 @@ QT_BEGIN_NAMESPACE \li "<APPROOT>/Library/Application Support" \row \li AppConfigLocation \li "<APPROOT>/files/settings" - \li "<APPROOT>/Documents" + \li "<APPROOT>/Library/Preferences/<APPNAME>" \row \li AppLocalDataLocation \li "<APPROOT>/files", "<USER>/<APPNAME>/files" \li "<APPROOT>/Library/Application Support" @@ -555,7 +555,7 @@ QString QStandardPaths::findExecutable(const QString &executableName, const QStr an empty QString if no relevant location can be found. */ -#if !defined(Q_OS_OSX) && !defined(QT_BOOTSTRAPPED) +#if !defined(Q_OS_MAC) && !defined(QT_BOOTSTRAPPED) QString QStandardPaths::displayName(StandardLocation type) { switch (type) { diff --git a/src/corelib/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm deleted file mode 100644 index eb85e2fd23..0000000000 --- a/src/corelib/io/qstandardpaths_ios.mm +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL21$ -** 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 The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#import <UIKit/UIKit.h> - -#include "qstandardpaths.h" - -#ifndef QT_NO_STANDARDPATHS - -QT_BEGIN_NAMESPACE - -static QString pathForDirectory(NSSearchPathDirectory directory) -{ - return QString::fromNSString( - [NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES) lastObject]); -} - -static QString bundlePath() -{ - return QString::fromNSString([[NSBundle mainBundle] bundlePath]); -} - -QString QStandardPaths::writableLocation(StandardLocation type) -{ - QString location; - - switch (type) { - case DocumentsLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case FontsLocation: - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/.fonts"); - break; - case ApplicationsLocation: - // NSApplicationDirectory points to a non-existing write-protected path. - break; - case MusicLocation: - // NSMusicDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Music"); - break; - case MoviesLocation: - // NSMoviesDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Movies"); - break; - case PicturesLocation: - // NSPicturesDirectory points to a non-existing write-protected path. Use sensible fallback. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Pictures"); - break; - case TempLocation: - location = QString::fromNSString(NSTemporaryDirectory()); - break; - case DesktopLocation: - case HomeLocation: - location = bundlePath(); - break; - case AppDataLocation: - case AppLocalDataLocation: - location = pathForDirectory(NSApplicationSupportDirectory); - break; - case GenericDataLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case CacheLocation: - case GenericCacheLocation: - location = pathForDirectory(NSCachesDirectory); - break; - case ConfigLocation: - case GenericConfigLocation: - case AppConfigLocation: - location = pathForDirectory(NSDocumentDirectory); - break; - case DownloadLocation: - // NSDownloadsDirectory points to a non-existing write-protected path. - location = pathForDirectory(NSDocumentDirectory) + QLatin1String("/Download"); - break; - case RuntimeLocation: - break; - default: - break; - } - - return location; -} - -QStringList QStandardPaths::standardLocations(StandardLocation type) -{ - QStringList dirs; - - switch (type) { - case PicturesLocation: - dirs << writableLocation(PicturesLocation) << QLatin1String("assets-library://"); - break; - default: - dirs << writableLocation(type); - break; - } - - return dirs; -} - -QT_END_NAMESPACE - -#endif // QT_NO_STANDARDPATHS diff --git a/src/corelib/io/qstandardpaths_mac.mm b/src/corelib/io/qstandardpaths_mac.mm index d6126ce1c3..57d365e916 100644 --- a/src/corelib/io/qstandardpaths_mac.mm +++ b/src/corelib/io/qstandardpaths_mac.mm @@ -32,6 +32,9 @@ ****************************************************************************/ #include "qstandardpaths.h" + +#ifndef QT_NO_STANDARDPATHS + #include <qdir.h> #include <qurl.h> #include <private/qcore_mac_p.h> @@ -40,63 +43,47 @@ #include <qcoreapplication.h> #endif -#include <CoreFoundation/CoreFoundation.h> -#include <ApplicationServices/ApplicationServices.h> +#import <Foundation/Foundation.h> QT_BEGIN_NAMESPACE -/* - Translates a QStandardPaths::StandardLocation into the mac equivalent. -*/ -OSType translateLocation(QStandardPaths::StandardLocation type) +static QString pathForDirectory(NSSearchPathDirectory directory, + NSSearchPathDomainMask mask) +{ + return QString::fromNSString( + [NSSearchPathForDirectoriesInDomains(directory, mask, YES) lastObject]); +} + +static NSSearchPathDirectory searchPathDirectory(QStandardPaths::StandardLocation type) { switch (type) { - case QStandardPaths::ConfigLocation: - case QStandardPaths::GenericConfigLocation: - case QStandardPaths::AppConfigLocation: - return kPreferencesFolderType; case QStandardPaths::DesktopLocation: - return kDesktopFolderType; + return NSDesktopDirectory; case QStandardPaths::DocumentsLocation: - return kDocumentsFolderType; - case QStandardPaths::FontsLocation: - // There are at least two different font directories on the mac: /Library/Fonts and ~/Library/Fonts. - // To select a specific one we have to specify a different first parameter when calling FSFindFolder. - return kFontsFolderType; + return NSDocumentDirectory; case QStandardPaths::ApplicationsLocation: - return kApplicationsFolderType; + return NSApplicationDirectory; case QStandardPaths::MusicLocation: - return kMusicDocumentsFolderType; + return NSMusicDirectory; case QStandardPaths::MoviesLocation: - return kMovieDocumentsFolderType; + return NSMoviesDirectory; case QStandardPaths::PicturesLocation: - return kPictureDocumentsFolderType; - case QStandardPaths::TempLocation: - return kTemporaryFolderType; + return NSPicturesDirectory; case QStandardPaths::GenericDataLocation: case QStandardPaths::RuntimeLocation: case QStandardPaths::AppDataLocation: case QStandardPaths::AppLocalDataLocation: - return kApplicationSupportFolderType; + return NSApplicationSupportDirectory; case QStandardPaths::GenericCacheLocation: case QStandardPaths::CacheLocation: - return kCachedDataFolderType; + return NSCachesDirectory; + case QStandardPaths::DownloadLocation: + return NSDownloadsDirectory; default: - return kDesktopFolderType; + return (NSSearchPathDirectory)0; } } -/* - Constructs a full unicode path from a FSRef. -*/ -static QString getFullPath(const FSRef &ref) -{ - QByteArray ba(2048, 0); - if (FSRefMakePath(&ref, reinterpret_cast<UInt8 *>(ba.data()), ba.size()) == noErr) - return QString::fromUtf8(ba.constData()).normalized(QString::NormalizationForm_C); - return QString(); -} - static void appendOrganizationAndApp(QString &path) { #ifndef QT_BOOTSTRAPPED @@ -111,28 +98,65 @@ static void appendOrganizationAndApp(QString &path) #endif } -static QString macLocation(QStandardPaths::StandardLocation type, short domain) +static QString baseWritableLocation(QStandardPaths::StandardLocation type, + NSSearchPathDomainMask mask = NSUserDomainMask, + bool appendOrgAndApp = false) { - // https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/index.html - if (type == QStandardPaths::DownloadLocation) { - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSURL *url = [fileManager URLForDirectory:NSDownloadsDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil]; - if (!url) - return QString(); - return QString::fromNSString([url path]); + QString path; + const NSSearchPathDirectory dir = searchPathDirectory(type); + switch (type) { + case QStandardPaths::HomeLocation: + path = QDir::homePath(); + break; + case QStandardPaths::TempLocation: + path = QDir::tempPath(); + break; +#ifdef Q_OS_IOS + // These locations point to non-existing write-protected paths. Use sensible fallbacks. + case QStandardPaths::MusicLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Music"); + break; + case QStandardPaths::MoviesLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Movies"); + break; + case QStandardPaths::PicturesLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Pictures"); + break; + case QStandardPaths::DownloadLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Downloads"); + break; + case QStandardPaths::DesktopLocation: + path = pathForDirectory(NSDocumentDirectory, mask) + QLatin1String("/Desktop"); + break; + case QStandardPaths::ApplicationsLocation: + break; +#endif + case QStandardPaths::FontsLocation: + path = pathForDirectory(NSLibraryDirectory, mask) + QLatin1String("/Fonts"); + break; + case QStandardPaths::ConfigLocation: + case QStandardPaths::GenericConfigLocation: + case QStandardPaths::AppConfigLocation: + path = pathForDirectory(NSLibraryDirectory, mask) + QLatin1String("/Preferences"); + break; + default: + path = pathForDirectory(dir, mask); + break; } - // http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/Reference/reference.html - FSRef ref; - OSErr err = FSFindFolder(domain, translateLocation(type), false, &ref); - if (err) - return QString(); - - QString path = getFullPath(ref); + if (appendOrgAndApp) { + switch (type) { + case QStandardPaths::AppDataLocation: + case QStandardPaths::AppLocalDataLocation: + case QStandardPaths::AppConfigLocation: + case QStandardPaths::CacheLocation: + appendOrganizationAndApp(path); + break; + default: + break; + } + } - if (type == QStandardPaths::AppDataLocation || type == QStandardPaths::AppLocalDataLocation || - type == QStandardPaths::CacheLocation || type == QStandardPaths::AppConfigLocation) - appendOrganizationAndApp(path); return path; } @@ -167,31 +191,32 @@ QString QStandardPaths::writableLocation(StandardLocation type) } } - switch (type) { - case HomeLocation: - return QDir::homePath(); - case TempLocation: - return QDir::tempPath(); - case GenericDataLocation: - case AppDataLocation: - case AppLocalDataLocation: - case GenericCacheLocation: - case CacheLocation: - case RuntimeLocation: - return macLocation(type, kUserDomain); - default: - return macLocation(type, kOnAppropriateDisk); - } + return baseWritableLocation(type, NSUserDomainMask, true); } QStringList QStandardPaths::standardLocations(StandardLocation type) { QStringList dirs; - if (type == GenericDataLocation || type == AppDataLocation || type == AppLocalDataLocation || type == GenericCacheLocation || type == CacheLocation) { - const QString path = macLocation(type, kOnAppropriateDisk); - if (!path.isEmpty()) - dirs.append(path); +#ifdef Q_OS_IOS + if (type == PicturesLocation) + dirs << writableLocation(PicturesLocation) << QLatin1String("assets-library://"); +#endif + + if (type == GenericDataLocation || type == FontsLocation || type == ApplicationsLocation + || type == AppDataLocation || type == AppLocalDataLocation + || type == GenericCacheLocation || type == CacheLocation) { + QList<NSSearchPathDomainMask> masks; + masks << NSLocalDomainMask; + if (type == FontsLocation || type == GenericCacheLocation) + masks << NSSystemDomainMask; + + for (QList<NSSearchPathDomainMask>::const_iterator it = masks.begin(); + it != masks.end(); ++it) { + const QString path = baseWritableLocation(type, *it, true); + if (!path.isEmpty() && !dirs.contains(path)) + dirs.append(path); + } } if (type == AppDataLocation || type == AppLocalDataLocation) { @@ -219,28 +244,41 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) } } const QString localDir = writableLocation(type); - dirs.prepend(localDir); + if (!localDir.isEmpty()) + dirs.prepend(localDir); return dirs; } #ifndef QT_BOOTSTRAPPED QString QStandardPaths::displayName(StandardLocation type) { + // Use "Home" instead of the user's Unix username if (QStandardPaths::HomeLocation == type) return QCoreApplication::translate("QStandardPaths", "Home"); - FSRef ref; - OSErr err = FSFindFolder(kOnAppropriateDisk, translateLocation(type), false, &ref); - if (err) - return QString(); + // The temporary directory returned by the old Carbon APIs is ~/Library/Caches/TemporaryItems, + // the display name of which ("TemporaryItems") isn't translated by the system. The standard + // temporary directory has no reasonable display name either, so use something more sensible. + if (QStandardPaths::TempLocation == type) + return QCoreApplication::translate("QStandardPaths", "Temporary Items"); - QCFString displayName; - err = LSCopyDisplayNameForRef(&ref, &displayName); - if (err) - return QString(); + // standardLocations() may return an empty list on some platforms + if (QStandardPaths::ApplicationsLocation == type) + return QCoreApplication::translate("QStandardPaths", "Applications"); - return static_cast<QString>(displayName); + if (QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, + standardLocations(type).first().toCFString(), + kCFURLPOSIXPathStyle, true)) { + QCFString name; + CFURLCopyResourcePropertyForKey(url, kCFURLLocalizedNameKey, &name, NULL); + if (name && CFStringGetLength(name)) + return QString::fromCFString(name); + } + + return QFileInfo(baseWritableLocation(type)).fileName(); } #endif QT_END_NAMESPACE + +#endif // QT_NO_STANDARDPATHS |