| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qstandardpaths.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | - | |||||||||||||
| 8 | - | |||||||||||||
| 9 | static bool existsAsSpecified(const QString &path, QStandardPaths::LocateOptions options) | - | ||||||||||||
| 10 | { | - | ||||||||||||
| 11 | if (options & QStandardPaths::LocateDirectory) | - | ||||||||||||
| 12 | return QDir(path).exists(); | - | ||||||||||||
| 13 | return QFileInfo(path).isFile(); | - | ||||||||||||
| 14 | } | - | ||||||||||||
| 15 | QString QStandardPaths::locate(StandardLocation type, const QString &fileName, LocateOptions options) | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | const QStringList &dirs = standardLocations(type); | - | ||||||||||||
| 18 | for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) { | - | ||||||||||||
| 19 | const QString path = *dir + QLatin1Char('/') + fileName; | - | ||||||||||||
| 20 | if (existsAsSpecified(path, options)) | - | ||||||||||||
| 21 | return path; | - | ||||||||||||
| 22 | } | - | ||||||||||||
| 23 | return QString(); | - | ||||||||||||
| 24 | } | - | ||||||||||||
| 25 | QStringList QStandardPaths::locateAll(StandardLocation type, const QString &fileName, LocateOptions options) | - | ||||||||||||
| 26 | { | - | ||||||||||||
| 27 | const QStringList &dirs = standardLocations(type); | - | ||||||||||||
| 28 | QStringList result; | - | ||||||||||||
| 29 | for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) { | - | ||||||||||||
| 30 | const QString path = *dir + QLatin1Char('/') + fileName; | - | ||||||||||||
| 31 | if (existsAsSpecified(path, options)) | - | ||||||||||||
| 32 | result.append(path); | - | ||||||||||||
| 33 | } | - | ||||||||||||
| 34 | return result; | - | ||||||||||||
| 35 | } | - | ||||||||||||
| 36 | static QString checkExecutable(const QString &path) | - | ||||||||||||
| 37 | { | - | ||||||||||||
| 38 | const QFileInfo info(path); | - | ||||||||||||
| 39 | if (info.isBundle()) | - | ||||||||||||
| 40 | return info.bundleName(); | - | ||||||||||||
| 41 | if (info.isFile() && info.isExecutable()) | - | ||||||||||||
| 42 | return QDir::cleanPath(path); | - | ||||||||||||
| 43 | return QString(); | - | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | static inline QString searchExecutable(const QStringList &searchPaths, | - | ||||||||||||
| 47 | const QString &executableName) | - | ||||||||||||
| 48 | { | - | ||||||||||||
| 49 | const QDir currentDir = QDir::current(); | - | ||||||||||||
| 50 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(searchPaths)>::type> _container_((searchPaths)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QString &searchPath = *_container_.i; _container_.control; _container_.control = 0: searchPaths) { | - | ||||||||||||
| 51 | const QString candidate = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName); | - | ||||||||||||
| 52 | const QString absPath = checkExecutable(candidate); | - | ||||||||||||
| 53 | if (!absPath.isEmpty()
| 12-225 | ||||||||||||
| 54 | return executed 12 times by 3 tests: absPath;return absPath;Executed by:
executed 12 times by 3 tests: return absPath;Executed by:
| 12 | ||||||||||||
| 55 | } executed 225 times by 4 tests: end of blockExecuted by:
| 225 | ||||||||||||
| 56 | return executed 3 times by 2 tests: QString();return QString();Executed by:
executed 3 times by 2 tests: return QString();Executed by:
| 3 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | QString QStandardPaths::findExecutable(const QString &executableName, const QStringList &paths) | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | if (QFileInfo(executableName).isAbsolute()
| 2-15 | ||||||||||||
| 61 | return executed 2 times by 1 test: checkExecutable(executableName);return checkExecutable(executableName);Executed by:
executed 2 times by 1 test: return checkExecutable(executableName);Executed by:
| 2 | ||||||||||||
| 62 | - | |||||||||||||
| 63 | QStringList searchPaths = paths; | - | ||||||||||||
| 64 | if (paths.isEmpty()
| 0-15 | ||||||||||||
| 65 | QByteArray pEnv = qgetenv("PATH"); | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(QDir::listSeparator(), QString::SkipEmptyParts); | - | ||||||||||||
| 68 | searchPaths.reserve(rawPaths.size()); | - | ||||||||||||
| 69 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(rawPaths)>::type> _container_((rawPaths)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &rawPath = *_container_.i; _container_.control; _container_.control = 0: rawPaths) { | - | ||||||||||||
| 70 | QString cleanPath = QDir::cleanPath(rawPath); | - | ||||||||||||
| 71 | if (cleanPath.size() > 1
| 0-255 | ||||||||||||
| 72 | cleanPath.truncate(cleanPath.size() - 1); never executed: cleanPath.truncate(cleanPath.size() - 1); | 0 | ||||||||||||
| 73 | searchPaths.push_back(cleanPath); | - | ||||||||||||
| 74 | } executed 255 times by 4 tests: end of blockExecuted by:
| 255 | ||||||||||||
| 75 | } executed 15 times by 4 tests: end of blockExecuted by:
| 15 | ||||||||||||
| 76 | return executed 15 times by 4 tests: searchExecutable(searchPaths, executableName);return searchExecutable(searchPaths, executableName);Executed by:
executed 15 times by 4 tests: return searchExecutable(searchPaths, executableName);Executed by:
| 15 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | QString QStandardPaths::displayName(StandardLocation type) | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | switch (type) { | - | ||||||||||||
| 81 | case DesktopLocation: | - | ||||||||||||
| 82 | return QCoreApplication::translate("QStandardPaths", "Desktop"); | - | ||||||||||||
| 83 | case DocumentsLocation: | - | ||||||||||||
| 84 | return QCoreApplication::translate("QStandardPaths", "Documents"); | - | ||||||||||||
| 85 | case FontsLocation: | - | ||||||||||||
| 86 | return QCoreApplication::translate("QStandardPaths", "Fonts"); | - | ||||||||||||
| 87 | case ApplicationsLocation: | - | ||||||||||||
| 88 | return QCoreApplication::translate("QStandardPaths", "Applications"); | - | ||||||||||||
| 89 | case MusicLocation: | - | ||||||||||||
| 90 | return QCoreApplication::translate("QStandardPaths", "Music"); | - | ||||||||||||
| 91 | case MoviesLocation: | - | ||||||||||||
| 92 | return QCoreApplication::translate("QStandardPaths", "Movies"); | - | ||||||||||||
| 93 | case PicturesLocation: | - | ||||||||||||
| 94 | return QCoreApplication::translate("QStandardPaths", "Pictures"); | - | ||||||||||||
| 95 | case TempLocation: | - | ||||||||||||
| 96 | return QCoreApplication::translate("QStandardPaths", "Temporary Directory"); | - | ||||||||||||
| 97 | case HomeLocation: | - | ||||||||||||
| 98 | return QCoreApplication::translate("QStandardPaths", "Home"); | - | ||||||||||||
| 99 | case CacheLocation: | - | ||||||||||||
| 100 | return QCoreApplication::translate("QStandardPaths", "Cache"); | - | ||||||||||||
| 101 | case GenericDataLocation: | - | ||||||||||||
| 102 | return QCoreApplication::translate("QStandardPaths", "Shared Data"); | - | ||||||||||||
| 103 | case RuntimeLocation: | - | ||||||||||||
| 104 | return QCoreApplication::translate("QStandardPaths", "Runtime"); | - | ||||||||||||
| 105 | case ConfigLocation: | - | ||||||||||||
| 106 | return QCoreApplication::translate("QStandardPaths", "Configuration"); | - | ||||||||||||
| 107 | case GenericConfigLocation: | - | ||||||||||||
| 108 | return QCoreApplication::translate("QStandardPaths", "Shared Configuration"); | - | ||||||||||||
| 109 | case GenericCacheLocation: | - | ||||||||||||
| 110 | return QCoreApplication::translate("QStandardPaths", "Shared Cache"); | - | ||||||||||||
| 111 | case DownloadLocation: | - | ||||||||||||
| 112 | return QCoreApplication::translate("QStandardPaths", "Download"); | - | ||||||||||||
| 113 | case AppDataLocation: | - | ||||||||||||
| 114 | case AppLocalDataLocation: | - | ||||||||||||
| 115 | return QCoreApplication::translate("QStandardPaths", "Application Data"); | - | ||||||||||||
| 116 | case AppConfigLocation: | - | ||||||||||||
| 117 | return QCoreApplication::translate("QStandardPaths", "Application Configuration"); | - | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | return QString(); | - | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | static bool qsp_testMode = false; | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | - | |||||||||||||
| 125 | void QStandardPaths::enableTestMode(bool testMode) | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | qsp_testMode = testMode; | - | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | - | |||||||||||||
| 131 | void QStandardPaths::setTestModeEnabled(bool testMode) | - | ||||||||||||
| 132 | { | - | ||||||||||||
| 133 | qsp_testMode = testMode; | - | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | bool QStandardPaths::isTestModeEnabled() | - | ||||||||||||
| 136 | { | - | ||||||||||||
| 137 | return qsp_testMode; | - | ||||||||||||
| 138 | } | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | - | |||||||||||||
| 141 | - | |||||||||||||
| Switch to Source code | Preprocessed file |