180QUrl QFileSelector::select(
const QUrl &filePath)
const
182 Q_D(
const QFileSelector);
183 if (!isLocalScheme(filePath.scheme()) && !filePath.isLocalFile())
186 if (isLocalScheme(filePath.scheme())) {
187 auto scheme =
":"_L1;
190 if (filePath.scheme() ==
"assets"_L1)
191 scheme =
"assets:"_L1;
194 QString equivalentPath = scheme + filePath.path();
195 QString selectedPath = d->select(equivalentPath);
196 ret.setPath(selectedPath.remove(0, scheme.size()));
200 if (ret.hasFragment())
201 frag = ret.fragment();
205 ret = QUrl::fromLocalFile(d->select(ret.toLocalFile()));
207 ret.setFragment(frag);
214QString QFileSelectorPrivate::selectionHelper(
const QString &path,
const QString &fileName,
215 const QStringList &selectors, QChar indicator)
218
219
220
221 Q_ASSERT(path.isEmpty() || path.endsWith(u'/'));
223 for (
const QString &s : selectors) {
224 QString prospectiveBase = path;
225 if (!indicator.isNull())
226 prospectiveBase += indicator;
227 prospectiveBase += s + u'/';
228 QStringList remainingSelectors = selectors;
229 remainingSelectors.removeAll(s);
230 if (!QDir(prospectiveBase).exists())
232 QString prospectiveFile = selectionHelper(prospectiveBase, fileName, remainingSelectors, indicator);
233 if (!prospectiveFile.isEmpty())
234 return prospectiveFile;
239 if (!QFile::exists(path + fileName))
241 return path + fileName;
244QString QFileSelectorPrivate::select(
const QString &filePath)
const
246 Q_Q(
const QFileSelector);
247 QFileInfo fi(filePath);
250 if (
auto path = fi.path(); !path.isEmpty())
251 pathString = path.endsWith(u'/') ? path : path + u'/';
252 QString ret = selectionHelper(pathString,
253 fi.fileName(), q->allSelectors());
291void QFileSelectorPrivate::updateSelectors()
293 if (!sharedData->staticSelectors.isEmpty())
296 QLatin1Char pathSep(
',');
297 QStringList envSelectors = QString::fromLatin1(qgetenv(
"QT_FILE_SELECTORS"))
298 .split(pathSep, Qt::SkipEmptyParts);
299 if (envSelectors.size())
300 sharedData->staticSelectors << envSelectors;
302 if (!qEnvironmentVariableIsEmpty(env_override))
305 sharedData->staticSelectors << sharedData->preloadedStatics;
308 sharedData->staticSelectors << QLocale().name();
310 sharedData->staticSelectors << platformSelectors();
341qsizetype QFileSelectorPrivate::removeStatics(
const QStringList &statics)
343 const auto locker = qt_scoped_lock(sharedDataMutex);
345 sharedData->staticSelectors.clear();
346 return sharedData->preloadedStatics.removeIf([statics](
auto &s) {
return statics.contains(s, Qt::CaseSensitive);});