| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfileselector.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | static const char env_override[] = "QT_NO_BUILTIN_SELECTORS"; | - | ||||||
| 7 | - | |||||||
| 8 | static const ushort selectorIndicator = '+'; | - | ||||||
| 9 | - | |||||||
| 10 | namespace { namespace Q_QGS_sharedData { typedef QFileSelectorSharedData Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QFileSelectorSharedData, Q_QGS_sharedData::innerFunction, Q_QGS_sharedData::guard> sharedData;; | - | ||||||
| 11 | static QBasicMutex sharedDataMutex; | - | ||||||
| 12 | - | |||||||
| 13 | QFileSelectorPrivate::QFileSelectorPrivate() | - | ||||||
| 14 | : QObjectPrivate() | - | ||||||
| 15 | { | - | ||||||
| 16 | } | - | ||||||
| 17 | QFileSelector::QFileSelector(QObject *parent) | - | ||||||
| 18 | : QObject(*(new QFileSelectorPrivate()), parent) | - | ||||||
| 19 | { | - | ||||||
| 20 | } | - | ||||||
| 21 | - | |||||||
| 22 | - | |||||||
| 23 | - | |||||||
| 24 | - | |||||||
| 25 | QFileSelector::~QFileSelector() | - | ||||||
| 26 | { | - | ||||||
| 27 | } | - | ||||||
| 28 | QString QFileSelector::select(const QString &filePath) const | - | ||||||
| 29 | { | - | ||||||
| 30 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||
| 31 | return d->select(filePath); | - | ||||||
| 32 | } | - | ||||||
| 33 | - | |||||||
| 34 | static bool isLocalScheme(const QString &file) | - | ||||||
| 35 | { | - | ||||||
| 36 | bool local = file == QLatin1String("qrc"); | - | ||||||
| 37 | - | |||||||
| 38 | - | |||||||
| 39 | - | |||||||
| 40 | return local; | - | ||||||
| 41 | } | - | ||||||
| 42 | QUrl QFileSelector::select(const QUrl &filePath) const | - | ||||||
| 43 | { | - | ||||||
| 44 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||
| 45 | if (!isLocalScheme(filePath.scheme()) && !filePath.isLocalFile()) | - | ||||||
| 46 | return filePath; | - | ||||||
| 47 | QUrl ret(filePath); | - | ||||||
| 48 | if (isLocalScheme(filePath.scheme())) { | - | ||||||
| 49 | QLatin1String scheme(":"); | - | ||||||
| 50 | - | |||||||
| 51 | - | |||||||
| 52 | - | |||||||
| 53 | - | |||||||
| 54 | - | |||||||
| 55 | - | |||||||
| 56 | QString equivalentPath = scheme + filePath.path(); | - | ||||||
| 57 | QString selectedPath = d->select(equivalentPath); | - | ||||||
| 58 | ret.setPath(selectedPath.remove(0, scheme.size())); | - | ||||||
| 59 | } else { | - | ||||||
| 60 | ret = QUrl::fromLocalFile(d->select(ret.toLocalFile())); | - | ||||||
| 61 | } | - | ||||||
| 62 | return ret; | - | ||||||
| 63 | } | - | ||||||
| 64 | - | |||||||
| 65 | static QString selectionHelper(const QString &path, const QString &fileName, const QStringList &selectors) | - | ||||||
| 66 | { | - | ||||||
| 67 | - | |||||||
| 68 | - | |||||||
| 69 | - | |||||||
| 70 | - | |||||||
| 71 | ((!(path.isEmpty() || path.endsWith(QLatin1Char('/')))) ? qt_assert("path.isEmpty() || path.endsWith(QLatin1Char('/'))",__FILE__,273276) : qt_noop()); | - | ||||||
| 72 | - | |||||||
| 73 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(selectors)>::type> _container_((selectors)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &s = *_container_.i; _container_.control; _container_.control = 0: selectors) { | - | ||||||
| 74 | QString prospectiveBase = path + QLatin1Char(selectorIndicator) + s + QLatin1Char('/'); | - | ||||||
| 75 | QStringList remainingSelectors = selectors; | - | ||||||
| 76 | remainingSelectors.removeAll(s); | - | ||||||
| 77 | if (!QDir(prospectiveBase).exists() 
 | 23-95 | ||||||
| 78 | continue; executed 95 times by 1 test:  continue;Executed by: 
 | 95 | ||||||
| 79 | QString prospectiveFile = selectionHelper(prospectiveBase, fileName, remainingSelectors); | - | ||||||
| 80 | if (!prospectiveFile.isEmpty() 
 | 4-19 | ||||||
| 81 | return executed 19 times by 1 test: prospectiveFile; return prospectiveFile;Executed by: 
 executed 19 times by 1 test:  return prospectiveFile;Executed by: 
 | 19 | ||||||
| 82 | } executed 4 times by 1 test:  end of blockExecuted by: 
 | 4 | ||||||
| 83 | - | |||||||
| 84 | - | |||||||
| 85 | - | |||||||
| 86 | if (!QFile::exists(path + fileName) 
 | 4-20 | ||||||
| 87 | return executed 4 times by 1 test: QString(); return QString();Executed by: 
 executed 4 times by 1 test:  return QString();Executed by: 
 | 4 | ||||||
| 88 | return executed 20 times by 1 test: path + fileName; return path + fileName;Executed by: 
 executed 20 times by 1 test:  return path + fileName;Executed by: 
 | 20 | ||||||
| 89 | } | - | ||||||
| 90 | - | |||||||
| 91 | QString QFileSelectorPrivate::select(const QString &filePath) const | - | ||||||
| 92 | { | - | ||||||
| 93 | const QFileSelector * const q = q_func(); | - | ||||||
| 94 | QFileInfo fi(filePath); | - | ||||||
| 95 | - | |||||||
| 96 | if (!fi.exists()) | - | ||||||
| 97 | return filePath; | - | ||||||
| 98 | - | |||||||
| 99 | QString ret = selectionHelper(fi.path().isEmpty() ? QString() : fi.path() + QLatin1Char('/'), | - | ||||||
| 100 | fi.fileName(), q->allSelectors()); | - | ||||||
| 101 | - | |||||||
| 102 | if (!ret.isEmpty()) | - | ||||||
| 103 | return ret; | - | ||||||
| 104 | return filePath; | - | ||||||
| 105 | } | - | ||||||
| 106 | - | |||||||
| 107 | - | |||||||
| 108 | - | |||||||
| 109 | - | |||||||
| 110 | QStringList QFileSelector::extraSelectors() const | - | ||||||
| 111 | { | - | ||||||
| 112 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||
| 113 | return d->extras; | - | ||||||
| 114 | } | - | ||||||
| 115 | - | |||||||
| 116 | - | |||||||
| 117 | - | |||||||
| 118 | - | |||||||
| 119 | - | |||||||
| 120 | - | |||||||
| 121 | void QFileSelector::setExtraSelectors(const QStringList &list) | - | ||||||
| 122 | { | - | ||||||
| 123 | QFileSelectorPrivate * const d = d_func(); | - | ||||||
| 124 | d->extras = list; | - | ||||||
| 125 | } | - | ||||||
| 126 | - | |||||||
| 127 | - | |||||||
| 128 | - | |||||||
| 129 | - | |||||||
| 130 | QStringList QFileSelector::allSelectors() const | - | ||||||
| 131 | { | - | ||||||
| 132 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||
| 133 | QMutexLocker locker(&sharedDataMutex); | - | ||||||
| 134 | QFileSelectorPrivate::updateSelectors(); | - | ||||||
| 135 | return d->extras + sharedData->staticSelectors; | - | ||||||
| 136 | } | - | ||||||
| 137 | - | |||||||
| 138 | void QFileSelectorPrivate::updateSelectors() | - | ||||||
| 139 | { | - | ||||||
| 140 | if (!sharedData->staticSelectors.isEmpty()) | - | ||||||
| 141 | return; | - | ||||||
| 142 | - | |||||||
| 143 | QLatin1Char pathSep(','); | - | ||||||
| 144 | QStringList envSelectors = QString::fromLatin1(qgetenv("QT_FILE_SELECTORS")) | - | ||||||
| 145 | .split(pathSep, QString::SkipEmptyParts); | - | ||||||
| 146 | if (envSelectors.count()) | - | ||||||
| 147 | sharedData->staticSelectors << envSelectors; | - | ||||||
| 148 | - | |||||||
| 149 | if (!qEnvironmentVariableIsEmpty(env_override)) | - | ||||||
| 150 | return; | - | ||||||
| 151 | - | |||||||
| 152 | sharedData->staticSelectors << sharedData->preloadedStatics; | - | ||||||
| 153 | - | |||||||
| 154 | - | |||||||
| 155 | sharedData->staticSelectors << QLocale().name(); | - | ||||||
| 156 | - | |||||||
| 157 | sharedData->staticSelectors << platformSelectors(); | - | ||||||
| 158 | } | - | ||||||
| 159 | - | |||||||
| 160 | QStringList QFileSelectorPrivate::platformSelectors() | - | ||||||
| 161 | { | - | ||||||
| 162 | - | |||||||
| 163 | QStringList ret; | - | ||||||
| 164 | ret << ([]() -> QString { enum { Size = sizeof(u"" "unix")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "unix" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()); | - | ||||||
| 165 | - | |||||||
| 166 | - | |||||||
| 167 | ret << QSysInfo::kernelType(); | - | ||||||
| 168 | - | |||||||
| 169 | - | |||||||
| 170 | - | |||||||
| 171 | - | |||||||
| 172 | QString productName = QSysInfo::productType(); | - | ||||||
| 173 | - | |||||||
| 174 | - | |||||||
| 175 | - | |||||||
| 176 | - | |||||||
| 177 | if (productName != QLatin1String("unknown") 
 | 0-3 | ||||||
| 178 | ret << productName; executed 3 times by 1 test:  ret << productName;Executed by: 
 | 3 | ||||||
| 179 | - | |||||||
| 180 | return executed 3 times by 1 test: ret; return ret;Executed by: 
 executed 3 times by 1 test:  return ret;Executed by: 
 | 3 | ||||||
| 181 | } | - | ||||||
| 182 | - | |||||||
| 183 | void QFileSelectorPrivate::addStatics(const QStringList &statics) | - | ||||||
| 184 | { | - | ||||||
| 185 | QMutexLocker locker(&sharedDataMutex); | - | ||||||
| 186 | sharedData->preloadedStatics << statics; | - | ||||||
| 187 | sharedData->staticSelectors.clear(); | - | ||||||
| 188 | } executed 1 time by 1 test:  end of blockExecuted by: 
 | 1 | ||||||
| 189 | - | |||||||
| 190 | - | |||||||
| 191 | - | |||||||
| Switch to Source code | Preprocessed file |