diff options
Diffstat (limited to 'src/corelib/io/qfileselector.cpp')
-rw-r--r-- | src/corelib/io/qfileselector.cpp | 72 |
1 files changed, 21 insertions, 51 deletions
diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp index 1a58da1e18..7f5480c274 100644 --- a/src/corelib/io/qfileselector.cpp +++ b/src/corelib/io/qfileselector.cpp @@ -1,42 +1,6 @@ -/*************************************************************************** -** -** Copyright (C) 2013 BlackBerry Limited. All rights reserved. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2013 BlackBerry Limited. All rights reserved. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qfileselector.h" #include "qfileselector_p.h" @@ -52,11 +16,13 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + //Environment variable to allow tooling full control of file selectors static const char env_override[] = "QT_NO_BUILTIN_SELECTORS"; Q_GLOBAL_STATIC(QFileSelectorSharedData, sharedData); -static QBasicMutex sharedDataMutex; +Q_CONSTINIT static QBasicMutex sharedDataMutex; QFileSelectorPrivate::QFileSelectorPrivate() : QObjectPrivate() @@ -196,9 +162,9 @@ QString QFileSelector::select(const QString &filePath) const static bool isLocalScheme(const QString &file) { - bool local = file == QLatin1String("qrc"); + bool local = file == "qrc"_L1; #ifdef Q_OS_ANDROID - local |= file == QLatin1String("assets"); + local |= file == "assets"_L1; #endif return local; } @@ -217,11 +183,11 @@ QUrl QFileSelector::select(const QUrl &filePath) const return filePath; QUrl ret(filePath); if (isLocalScheme(filePath.scheme())) { - QLatin1String scheme(":"); + auto scheme = ":"_L1; #ifdef Q_OS_ANDROID // use other scheme because ":" means "qrc" here - if (filePath.scheme() == QLatin1String("assets")) - scheme = QLatin1String("assets:"); + if (filePath.scheme() == "assets"_L1) + scheme = "assets:"_L1; #endif QString equivalentPath = scheme + filePath.path(); @@ -244,19 +210,20 @@ QUrl QFileSelector::select(const QUrl &filePath) const return ret; } -QString QFileSelectorPrivate::selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors, const QChar &indicator) +QString QFileSelectorPrivate::selectionHelper(const QString &path, const QString &fileName, + const QStringList &selectors, QChar indicator) { /* selectionHelper does a depth-first search of possible selected files. Because there is strict selector ordering in the API, we can stop checking as soon as we find the file in a directory which does not contain any other valid selector directories. */ - Q_ASSERT(path.isEmpty() || path.endsWith(QLatin1Char('/'))); + Q_ASSERT(path.isEmpty() || path.endsWith(u'/')); for (const QString &s : selectors) { QString prospectiveBase = path; if (!indicator.isNull()) prospectiveBase += indicator; - prospectiveBase += s + QLatin1Char('/'); + prospectiveBase += s + u'/'; QStringList remainingSelectors = selectors; remainingSelectors.removeAll(s); if (!QDir(prospectiveBase).exists()) @@ -278,7 +245,10 @@ QString QFileSelectorPrivate::select(const QString &filePath) const Q_Q(const QFileSelector); QFileInfo fi(filePath); - QString ret = selectionHelper(fi.path().isEmpty() ? QString() : fi.path() + QLatin1Char('/'), + QString pathString; + if (auto path = fi.path(); !path.isEmpty()) + pathString = path.endsWith(u'/') ? path : path + u'/'; + QString ret = selectionHelper(pathString, fi.fileName(), q->allSelectors()); if (!ret.isEmpty()) @@ -325,7 +295,7 @@ void QFileSelectorPrivate::updateSelectors() QLatin1Char pathSep(','); QStringList envSelectors = QString::fromLatin1(qgetenv("QT_FILE_SELECTORS")) .split(pathSep, Qt::SkipEmptyParts); - if (envSelectors.count()) + if (envSelectors.size()) sharedData->staticSelectors << envSelectors; if (!qEnvironmentVariableIsEmpty(env_override)) @@ -353,7 +323,7 @@ QStringList QFileSelectorPrivate::platformSelectors() ret << QSysInfo::kernelType(); # endif QString productName = QSysInfo::productType(); - if (productName != QLatin1String("unknown")) + if (productName != "unknown"_L1) ret << productName; // "opensuse", "fedora", "osx", "ios", "android" #endif return ret; |