| 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
executed 1 time by 1 test: }guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 1 time by 1 test: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of blockExecuted by:
executed 50 times by 1 test: &holder.value;return &holder.value;Executed by:
executed 50 times by 1 test: } } } static QGlobalStatic<QFileSelectorSharedData, Q_QGS_sharedData::innerFunction, Q_QGS_sharedData::guard> sharedData;;return &holder.value;Executed by:
| 0-50 | ||||||||||||
| 11 | static QBasicMutex sharedDataMutex; | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | QFileSelectorPrivate::QFileSelectorPrivate() | - | ||||||||||||
| 14 | : QObjectPrivate() | - | ||||||||||||
| 15 | { | - | ||||||||||||
| 16 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||
| 17 | QFileSelector::QFileSelector(QObject *parent) | - | ||||||||||||
| 18 | : QObject(*(new QFileSelectorPrivate()), parent) | - | ||||||||||||
| 19 | { | - | ||||||||||||
| 20 | } executed 19 times by 1 test: end of blockExecuted by:
| 19 | ||||||||||||
| 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 executed 17 times by 1 test: d->select(filePath);return d->select(filePath);Executed by:
executed 17 times by 1 test: return d->select(filePath);Executed by:
| 17 | ||||||||||||
| 32 | } | - | ||||||||||||
| 33 | - | |||||||||||||
| 34 | static bool isLocalScheme(const QString &file) | - | ||||||||||||
| 35 | { | - | ||||||||||||
| 36 | bool local = file == QLatin1String("qrc"); | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | - | |||||||||||||
| 39 | - | |||||||||||||
| 40 | return executed 10 times by 1 test: local;return local;Executed by:
executed 10 times by 1 test: return local;Executed by:
| 10 | ||||||||||||
| 41 | } | - | ||||||||||||
| 42 | QUrl QFileSelector::select(const QUrl &filePath) const | - | ||||||||||||
| 43 | { | - | ||||||||||||
| 44 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||||||||
| 45 | if (!isLocalScheme(filePath.scheme())
| 2-4 | ||||||||||||
| 46 | return executed 2 times by 1 test: filePath;return filePath;Executed by:
executed 2 times by 1 test: return filePath;Executed by:
| 2 | ||||||||||||
| 47 | QUrl ret(filePath); | - | ||||||||||||
| 48 | if (isLocalScheme(filePath.scheme())
| 2 | ||||||||||||
| 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 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||
| 60 | ret = QUrl::fromLocalFile(d->select(ret.toLocalFile())); | - | ||||||||||||
| 61 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 62 | return executed 4 times by 1 test: ret;return ret;Executed by:
executed 4 times by 1 test: return ret;Executed by:
| 4 | ||||||||||||
| 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__,276) : qt_noop()); | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | for (const QString &s : 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()
| 1-20 | ||||||||||||
| 97 | return executed 1 time by 1 test: filePath;return filePath;Executed by:
executed 1 time by 1 test: return filePath;Executed by:
| 1 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | QString ret = selectionHelper(fi.path().isEmpty() ? QString() : fi.path() + QLatin1Char('/'), | - | ||||||||||||
| 100 | fi.fileName(), q->allSelectors()); | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | if (!ret.isEmpty()
| 0-20 | ||||||||||||
| 103 | return executed 20 times by 1 test: ret;return ret;Executed by:
executed 20 times by 1 test: return ret;Executed by:
| 20 | ||||||||||||
| 104 | return never executed: filePath;return filePath;never executed: return filePath; | 0 | ||||||||||||
| 105 | } | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | - | |||||||||||||
| 110 | QStringList QFileSelector::extraSelectors() const | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | const QFileSelectorPrivate * const d = d_func(); | - | ||||||||||||
| 113 | return never executed: d->extras;return d->extras;never executed: return d->extras; | 0 | ||||||||||||
| 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 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||
| 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 executed 20 times by 1 test: d->extras + sharedData->staticSelectors;return d->extras + sharedData->staticSelectors;Executed by:
executed 20 times by 1 test: return d->extras + sharedData->staticSelectors;Executed by:
| 20 | ||||||||||||
| 136 | } | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | void QFileSelectorPrivate::updateSelectors() | - | ||||||||||||
| 139 | { | - | ||||||||||||
| 140 | if (!sharedData->staticSelectors.isEmpty()
| 2-18 | ||||||||||||
| 141 | return; executed 18 times by 1 test: return;Executed by:
| 18 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | QLatin1Char pathSep(','); | - | ||||||||||||
| 144 | QStringList envSelectors = QString::fromLatin1(qgetenv("QT_FILE_SELECTORS")) | - | ||||||||||||
| 145 | .split(pathSep, QString::SkipEmptyParts); | - | ||||||||||||
| 146 | if (envSelectors.count()
| 0-2 | ||||||||||||
| 147 | sharedData->staticSelectors << envSelectors; never executed: sharedData->staticSelectors << envSelectors; | 0 | ||||||||||||
| 148 | - | |||||||||||||
| 149 | if (!qEnvironmentVariableIsEmpty(env_override)
| 0-2 | ||||||||||||
| 150 | return; never executed: return; | 0 | ||||||||||||
| 151 | - | |||||||||||||
| 152 | sharedData->staticSelectors << sharedData->preloadedStatics; | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | - | |||||||||||||
| 155 | sharedData->staticSelectors << QLocale().name(); | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | sharedData->staticSelectors << platformSelectors(); | - | ||||||||||||
| 158 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||
| 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 executed 3 times by 1 test: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 3 times by 1 test: }());return qstring_literal_temp;Executed by:
| 3 | ||||||||||||
| 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 |