| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimeprovider.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | static void initResources() | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | do { extern int qInitResources_mimetypes (); qInitResources_mimetypes (); } while (0); | - | ||||||||||||||||||
| 9 | } | - | ||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | static QString fallbackParent(const QString &mimeTypeName) | - | ||||||||||||||||||
| 14 | { | - | ||||||||||||||||||
| 15 | const QString myGroup = mimeTypeName.left(mimeTypeName.indexOf(QLatin1Char('/'))); | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | if (myGroup == QLatin1String("text") && mimeTypeName != QLatin1String("text/plain")) | - | ||||||||||||||||||
| 18 | return QLatin1String("text/plain"); | - | ||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | if (myGroup != QLatin1String("inode") && | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | myGroup != QLatin1String("all") && myGroup != QLatin1String("fonts") && myGroup != QLatin1String("print") && myGroup != QLatin1String("uri") | - | ||||||||||||||||||
| 23 | && mimeTypeName != QLatin1String("application/octet-stream")) { | - | ||||||||||||||||||
| 24 | return QLatin1String("application/octet-stream"); | - | ||||||||||||||||||
| 25 | } | - | ||||||||||||||||||
| 26 | return QString(); | - | ||||||||||||||||||
| 27 | } | - | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | QMimeProviderBase::QMimeProviderBase(QMimeDatabasePrivate *db) | - | ||||||||||||||||||
| 30 | : m_db(db) | - | ||||||||||||||||||
| 31 | { | - | ||||||||||||||||||
| 32 | } | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | __attribute__((visibility("default"))) int qmime_secondsBetweenChecks = 5; | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | bool QMimeProviderBase::shouldCheck() | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | if (m_lastCheck.isValid() && m_lastCheck.elapsed() < qmime_secondsBetweenChecks * 1000) | - | ||||||||||||||||||
| 39 | return false; | - | ||||||||||||||||||
| 40 | m_lastCheck.start(); | - | ||||||||||||||||||
| 41 | return true; | - | ||||||||||||||||||
| 42 | } | - | ||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | QMimeBinaryProvider::QMimeBinaryProvider(QMimeDatabasePrivate *db) | - | ||||||||||||||||||
| 45 | : QMimeProviderBase(db), m_mimetypeListLoaded(false) | - | ||||||||||||||||||
| 46 | { | - | ||||||||||||||||||
| 47 | } | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | struct QMimeBinaryProvider::CacheFile | - | ||||||||||||||||||
| 54 | { | - | ||||||||||||||||||
| 55 | CacheFile(const QString &fileName); | - | ||||||||||||||||||
| 56 | ~CacheFile(); | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | bool isValid() const { return m_valid; } | - | ||||||||||||||||||
| 59 | inline quint16 getUint16(int offset) const | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | return qFromBigEndian(*reinterpret_cast<quint16 *>(data + offset)); | - | ||||||||||||||||||
| 62 | } | - | ||||||||||||||||||
| 63 | inline quint32 getUint32(int offset) const | - | ||||||||||||||||||
| 64 | { | - | ||||||||||||||||||
| 65 | return qFromBigEndian(*reinterpret_cast<quint32 *>(data + offset)); | - | ||||||||||||||||||
| 66 | } | - | ||||||||||||||||||
| 67 | inline const char *getCharStar(int offset) const | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | return reinterpret_cast<const char *>(data + offset); | - | ||||||||||||||||||
| 70 | } | - | ||||||||||||||||||
| 71 | bool load(); | - | ||||||||||||||||||
| 72 | bool reload(); | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | QFile file; | - | ||||||||||||||||||
| 75 | uchar *data; | - | ||||||||||||||||||
| 76 | QDateTime m_mtime; | - | ||||||||||||||||||
| 77 | bool m_valid; | - | ||||||||||||||||||
| 78 | }; | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | QMimeBinaryProvider::CacheFile::CacheFile(const QString &fileName) | - | ||||||||||||||||||
| 81 | : file(fileName), m_valid(false) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | load(); | - | ||||||||||||||||||
| 84 | } | - | ||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | QMimeBinaryProvider::CacheFile::~CacheFile() | - | ||||||||||||||||||
| 87 | { | - | ||||||||||||||||||
| 88 | } | - | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | bool QMimeBinaryProvider::CacheFile::load() | - | ||||||||||||||||||
| 91 | { | - | ||||||||||||||||||
| 92 | if (!file.open(QIODevice::ReadOnly)) | - | ||||||||||||||||||
| 93 | return false; | - | ||||||||||||||||||
| 94 | data = file.map(0, file.size()); | - | ||||||||||||||||||
| 95 | if (data) { | - | ||||||||||||||||||
| 96 | const int major = getUint16(0); | - | ||||||||||||||||||
| 97 | const int minor = getUint16(2); | - | ||||||||||||||||||
| 98 | m_valid = (major == 1 && minor >= 1 && minor <= 2); | - | ||||||||||||||||||
| 99 | } | - | ||||||||||||||||||
| 100 | m_mtime = QFileInfo(file).lastModified(); | - | ||||||||||||||||||
| 101 | return m_valid; | - | ||||||||||||||||||
| 102 | } | - | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | bool QMimeBinaryProvider::CacheFile::reload() | - | ||||||||||||||||||
| 105 | { | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | m_valid = false; | - | ||||||||||||||||||
| 108 | if (file.isOpen()) { | - | ||||||||||||||||||
| 109 | file.close(); | - | ||||||||||||||||||
| 110 | } | - | ||||||||||||||||||
| 111 | data = 0; | - | ||||||||||||||||||
| 112 | return load(); | - | ||||||||||||||||||
| 113 | } | - | ||||||||||||||||||
| 114 | - | |||||||||||||||||||
| 115 | QMimeBinaryProvider::CacheFile *QMimeBinaryProvider::CacheFileList::findCacheFile(const QString &fileName) const | - | ||||||||||||||||||
| 116 | { | - | ||||||||||||||||||
| 117 | for (const_iterator it = begin(); it != end(); ++it) { | - | ||||||||||||||||||
| 118 | if ((*it)->file.fileName() == fileName) | - | ||||||||||||||||||
| 119 | return *it; | - | ||||||||||||||||||
| 120 | } | - | ||||||||||||||||||
| 121 | return 0; | - | ||||||||||||||||||
| 122 | } | - | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | QMimeBinaryProvider::~QMimeBinaryProvider() | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | qDeleteAll(m_cacheFiles); | - | ||||||||||||||||||
| 127 | } | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | enum { | - | ||||||||||||||||||
| 131 | PosAliasListOffset = 4, | - | ||||||||||||||||||
| 132 | PosParentListOffset = 8, | - | ||||||||||||||||||
| 133 | PosLiteralListOffset = 12, | - | ||||||||||||||||||
| 134 | PosReverseSuffixTreeOffset = 16, | - | ||||||||||||||||||
| 135 | PosGlobListOffset = 20, | - | ||||||||||||||||||
| 136 | PosMagicListOffset = 24, | - | ||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | PosIconsListOffset = 32, | - | ||||||||||||||||||
| 139 | PosGenericIconsListOffset = 36 | - | ||||||||||||||||||
| 140 | }; | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | bool QMimeBinaryProvider::isValid() | - | ||||||||||||||||||
| 143 | { | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | if (!qEnvironmentVariableIsEmpty("QT_NO_MIME_CACHE")
| 1-24 | ||||||||||||||||||
| 146 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 147 | - | |||||||||||||||||||
| 148 | ((!(m_cacheFiles.isEmpty())) ? qt_assert("m_cacheFiles.isEmpty()",__FILE__,193199) : qt_noop()); | - | ||||||||||||||||||
| 149 | checkCache(); | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | if (m_cacheFiles.count() > 1
| 0-24 | ||||||||||||||||||
| 152 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||
| 153 | if (m_cacheFiles.isEmpty()
| 1-23 | ||||||||||||||||||
| 154 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||
| 155 | - | |||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | const QString foundFile = m_cacheFiles.firstconstFirst()->file.fileName(); | - | ||||||||||||||||||
| 158 | const QString localCacheFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/mime/mime.cache"); | - | ||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | return executed 23 times by 23 tests: foundFile != localCacheFile;return foundFile != localCacheFile;Executed by:
executed 23 times by 23 tests: return foundFile != localCacheFile;Executed by:
| 23 | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | } | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | bool QMimeBinaryProvider::CacheFileList::checkCacheChanged() | - | ||||||||||||||||||
| 167 | { | - | ||||||||||||||||||
| 168 | bool somethingChanged = false; | - | ||||||||||||||||||
| 169 | QMutableListIterator<CacheFile *> it(*this); | - | ||||||||||||||||||
| 170 | while (it.hasNext()) { | - | ||||||||||||||||||
| 171 | CacheFile *cacheFile = it.next(); | - | ||||||||||||||||||
| 172 | QFileInfo fileInfo(cacheFile->file); | - | ||||||||||||||||||
| 173 | if (!fileInfo.exists()) { | - | ||||||||||||||||||
| 174 | delete cacheFile; | - | ||||||||||||||||||
| 175 | it.remove(); | - | ||||||||||||||||||
| 176 | somethingChanged = true; | - | ||||||||||||||||||
| 177 | } else if (fileInfo.lastModified() > cacheFile->m_mtime) { | - | ||||||||||||||||||
| 178 | if (!cacheFile->reload()) { | - | ||||||||||||||||||
| 179 | delete cacheFile; | - | ||||||||||||||||||
| 180 | it.remove(); | - | ||||||||||||||||||
| 181 | } | - | ||||||||||||||||||
| 182 | somethingChanged = true; | - | ||||||||||||||||||
| 183 | } | - | ||||||||||||||||||
| 184 | } | - | ||||||||||||||||||
| 185 | return somethingChanged; | - | ||||||||||||||||||
| 186 | } | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | void QMimeBinaryProvider::checkCache() | - | ||||||||||||||||||
| 189 | { | - | ||||||||||||||||||
| 190 | if (!shouldCheck()
| 96-11745 | ||||||||||||||||||
| 191 | return; executed 11745 times by 23 tests: return;Executed by:
| 11745 | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | if (m_cacheFiles.checkCacheChanged()
| 4-92 | ||||||||||||||||||
| 195 | m_mimetypeListLoaded = false; executed 4 times by 1 test: m_mimetypeListLoaded = false;Executed by:
| 4 | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | const QStringList cacheFileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/mime.cache")); | - | ||||||||||||||||||
| 199 | if (cacheFileNames != m_cacheFileNames
| 25-71 | ||||||||||||||||||
| 200 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cacheFileNames)>::type> _container_((cacheFileNames)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &cacheFileName = *_container_.i; _container_.control; _container_.control = 0: cacheFileNames) { | - | ||||||||||||||||||
| 201 | CacheFile *cacheFile = m_cacheFiles.findCacheFile(cacheFileName); | - | ||||||||||||||||||
| 202 | if (!cacheFile
| 2-24 | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | cacheFile = new CacheFile(cacheFileName); | - | ||||||||||||||||||
| 205 | if (cacheFile->isValid()
| 0-24 | ||||||||||||||||||
| 206 | m_cacheFiles.append(cacheFile); executed 24 times by 23 tests: m_cacheFiles.append(cacheFile);Executed by:
| 24 | ||||||||||||||||||
| 207 | else | - | ||||||||||||||||||
| 208 | delete cacheFile; never executed: delete cacheFile; | 0 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | } executed 26 times by 23 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 211 | m_cacheFileNames = cacheFileNames; | - | ||||||||||||||||||
| 212 | m_mimetypeListLoaded = false; | - | ||||||||||||||||||
| 213 | } executed 25 times by 23 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 214 | } executed 96 times by 24 tests: end of blockExecuted by:
| 96 | ||||||||||||||||||
| 215 | - | |||||||||||||||||||
| 216 | static QMimeType mimeTypeForNameUnchecked(const QString &name) | - | ||||||||||||||||||
| 217 | { | - | ||||||||||||||||||
| 218 | QMimeTypePrivate data; | - | ||||||||||||||||||
| 219 | data.name = name; | - | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | return QMimeType(data); | - | ||||||||||||||||||
| 225 | } | - | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | QMimeType QMimeBinaryProvider::mimeTypeForName(const QString &name) | - | ||||||||||||||||||
| 228 | { | - | ||||||||||||||||||
| 229 | checkCache(); | - | ||||||||||||||||||
| 230 | if (!m_mimetypeListLoaded) | - | ||||||||||||||||||
| 231 | loadMimeTypeList(); | - | ||||||||||||||||||
| 232 | if (!m_mimetypeNames.contains(name)) | - | ||||||||||||||||||
| 233 | return QMimeType(); | - | ||||||||||||||||||
| 234 | return mimeTypeForNameUnchecked(name); | - | ||||||||||||||||||
| 235 | } | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString *foundSuffix) | - | ||||||||||||||||||
| 238 | { | - | ||||||||||||||||||
| 239 | checkCache(); | - | ||||||||||||||||||
| 240 | if (fileName.isEmpty()
| 2-2523 | ||||||||||||||||||
| 241 | return executed 2 times by 1 test: QStringList();return QStringList();Executed by:
executed 2 times by 1 test: return QStringList();Executed by:
| 2 | ||||||||||||||||||
| 242 | const QString lowerFileName = fileName.toLower(); | - | ||||||||||||||||||
| 243 | QMimeGlobMatchResult result; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 246 | matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName); | - | ||||||||||||||||||
| 247 | matchGlobList(result, cacheFile, cacheFile->getUint32(PosGlobListOffset), fileName); | - | ||||||||||||||||||
| 248 | const int reverseSuffixTreeOffset = cacheFile->getUint32(PosReverseSuffixTreeOffset); | - | ||||||||||||||||||
| 249 | const int numRoots = cacheFile->getUint32(reverseSuffixTreeOffset); | - | ||||||||||||||||||
| 250 | const int firstRootOffset = cacheFile->getUint32(reverseSuffixTreeOffset + 4); | - | ||||||||||||||||||
| 251 | matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, lowerFileName, fileName.length() - 1, false); | - | ||||||||||||||||||
| 252 | if (result.m_matchingMimeTypes.isEmpty()
| 34-2492 | ||||||||||||||||||
| 253 | matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true); executed 34 times by 3 tests: matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true);Executed by:
| 34 | ||||||||||||||||||
| 254 | } executed 2526 times by 22 tests: end of blockExecuted by:
| 2526 | ||||||||||||||||||
| 255 | if (foundSuffix
| 8-2515 | ||||||||||||||||||
| 256 | * executed 8 times by 1 test: foundSuffix = result.m_foundSuffix;*foundSuffix = result.m_foundSuffix;Executed by:
executed 8 times by 1 test: *foundSuffix = result.m_foundSuffix;Executed by:
| 8 | ||||||||||||||||||
| 257 | return executed 2523 times by 22 tests: result.m_matchingMimeTypes;return result.m_matchingMimeTypes;Executed by:
executed 2523 times by 22 tests: return result.m_matchingMimeTypes;Executed by:
| 2523 | ||||||||||||||||||
| 258 | } | - | ||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName) | - | ||||||||||||||||||
| 261 | { | - | ||||||||||||||||||
| 262 | const int numGlobs = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | for (int i = 0; i < numGlobs; ++i) { | - | ||||||||||||||||||
| 265 | const int globOffset = cacheFile->getUint32(off + 4 + 12 * i); | - | ||||||||||||||||||
| 266 | const int mimeTypeOffset = cacheFile->getUint32(off + 4 + 12 * i + 4); | - | ||||||||||||||||||
| 267 | const int flagsAndWeight = cacheFile->getUint32(off + 4 + 12 * i + 8); | - | ||||||||||||||||||
| 268 | const int weight = flagsAndWeight & 0xff; | - | ||||||||||||||||||
| 269 | const bool caseSensitive = flagsAndWeight & 0x100; | - | ||||||||||||||||||
| 270 | const Qt::CaseSensitivity qtCaseSensitive = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; | - | ||||||||||||||||||
| 271 | const QString pattern = QLatin1String(cacheFile->getCharStar(globOffset)); | - | ||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | QMimeGlobPattern glob(pattern, QString() , weight, qtCaseSensitive); | - | ||||||||||||||||||
| 276 | - | |||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | if (glob.matchFileName(fileName)) | - | ||||||||||||||||||
| 279 | result.addMatch(QLatin1String(mimeType), weight, pattern); | - | ||||||||||||||||||
| 280 | } | - | ||||||||||||||||||
| 281 | } | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck) | - | ||||||||||||||||||
| 284 | { | - | ||||||||||||||||||
| 285 | QChar fileChar = fileName[charPos]; | - | ||||||||||||||||||
| 286 | int min = 0; | - | ||||||||||||||||||
| 287 | int max = numEntries - 1; | - | ||||||||||||||||||
| 288 | while (min <= max) { | - | ||||||||||||||||||
| 289 | const int mid = (min + max) / 2; | - | ||||||||||||||||||
| 290 | const int off = firstOffset + 12 * mid; | - | ||||||||||||||||||
| 291 | const QChar ch = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 292 | if (ch < fileChar) | - | ||||||||||||||||||
| 293 | min = mid + 1; | - | ||||||||||||||||||
| 294 | else if (ch > fileChar) | - | ||||||||||||||||||
| 295 | max = mid - 1; | - | ||||||||||||||||||
| 296 | else { | - | ||||||||||||||||||
| 297 | --charPos; | - | ||||||||||||||||||
| 298 | int numChildren = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 299 | int childrenOffset = cacheFile->getUint32(off + 8); | - | ||||||||||||||||||
| 300 | bool success = false; | - | ||||||||||||||||||
| 301 | if (charPos > 0) | - | ||||||||||||||||||
| 302 | success = matchSuffixTree(result, cacheFile, numChildren, childrenOffset, fileName, charPos, caseSensitiveCheck); | - | ||||||||||||||||||
| 303 | if (!success) { | - | ||||||||||||||||||
| 304 | for (int i = 0; i < numChildren; ++i) { | - | ||||||||||||||||||
| 305 | const int childOff = childrenOffset + 12 * i; | - | ||||||||||||||||||
| 306 | const int mch = cacheFile->getUint32(childOff); | - | ||||||||||||||||||
| 307 | if (mch != 0) | - | ||||||||||||||||||
| 308 | break; | - | ||||||||||||||||||
| 309 | const int mimeTypeOffset = cacheFile->getUint32(childOff + 4); | - | ||||||||||||||||||
| 310 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||
| 311 | const int flagsAndWeight = cacheFile->getUint32(childOff + 8); | - | ||||||||||||||||||
| 312 | const int weight = flagsAndWeight & 0xff; | - | ||||||||||||||||||
| 313 | const bool caseSensitive = flagsAndWeight & 0x100; | - | ||||||||||||||||||
| 314 | if (caseSensitiveCheck || !caseSensitive) { | - | ||||||||||||||||||
| 315 | result.addMatch(QLatin1String(mimeType), weight, QLatin1Char('*') + fileName.mid(charPos+1)); | - | ||||||||||||||||||
| 316 | success = true; | - | ||||||||||||||||||
| 317 | } | - | ||||||||||||||||||
| 318 | } | - | ||||||||||||||||||
| 319 | } | - | ||||||||||||||||||
| 320 | return success; | - | ||||||||||||||||||
| 321 | } | - | ||||||||||||||||||
| 322 | } | - | ||||||||||||||||||
| 323 | return false; | - | ||||||||||||||||||
| 324 | } | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data) | - | ||||||||||||||||||
| 327 | { | - | ||||||||||||||||||
| 328 | const char *dataPtr = data.constData(); | - | ||||||||||||||||||
| 329 | const int dataSize = data.size(); | - | ||||||||||||||||||
| 330 | for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) { | - | ||||||||||||||||||
| 331 | const int off = firstOffset + matchlet * 32; | - | ||||||||||||||||||
| 332 | const int rangeStart = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 333 | const int rangeLength = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | const int valueLength = cacheFile->getUint32(off + 12); | - | ||||||||||||||||||
| 336 | const int valueOffset = cacheFile->getUint32(off + 16); | - | ||||||||||||||||||
| 337 | const int maskOffset = cacheFile->getUint32(off + 20); | - | ||||||||||||||||||
| 338 | const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : __null; | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | if (!QMimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask)) | - | ||||||||||||||||||
| 341 | continue; | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | const int numChildren = cacheFile->getUint32(off + 24); | - | ||||||||||||||||||
| 344 | const int firstChildOffset = cacheFile->getUint32(off + 28); | - | ||||||||||||||||||
| 345 | if (numChildren == 0) | - | ||||||||||||||||||
| 346 | return true; | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | if (matchMagicRule(cacheFile, numChildren, firstChildOffset, data)) | - | ||||||||||||||||||
| 349 | return true; | - | ||||||||||||||||||
| 350 | } | - | ||||||||||||||||||
| 351 | return false; | - | ||||||||||||||||||
| 352 | } | - | ||||||||||||||||||
| 353 | - | |||||||||||||||||||
| 354 | QMimeType QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr) | - | ||||||||||||||||||
| 355 | { | - | ||||||||||||||||||
| 356 | checkCache(); | - | ||||||||||||||||||
| 357 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 358 | const int magicListOffset = cacheFile->getUint32(PosMagicListOffset); | - | ||||||||||||||||||
| 359 | const int numMatches = cacheFile->getUint32(magicListOffset); | - | ||||||||||||||||||
| 360 | - | |||||||||||||||||||
| 361 | const int firstMatchOffset = cacheFile->getUint32(magicListOffset + 8); | - | ||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | for (int i = 0; i < numMatches
| 9-5895 | ||||||||||||||||||
| 364 | const int off = firstMatchOffset + i * 16; | - | ||||||||||||||||||
| 365 | const int numMatchlets = cacheFile->getUint32(off + 8); | - | ||||||||||||||||||
| 366 | const int firstMatchletOffset = cacheFile->getUint32(off + 12); | - | ||||||||||||||||||
| 367 | if (matchMagicRule(cacheFile, numMatchlets, firstMatchletOffset, data)
| 23-5872 | ||||||||||||||||||
| 368 | const int mimeTypeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 369 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||
| 370 | *accuracyPtr = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | - | |||||||||||||||||||
| 373 | return executed 23 times by 1 test: mimeTypeForNameUnchecked(QLatin1String(mimeType));return mimeTypeForNameUnchecked(QLatin1String(mimeType));Executed by:
executed 23 times by 1 test: return mimeTypeForNameUnchecked(QLatin1String(mimeType));Executed by:
| 23 | ||||||||||||||||||
| 374 | } | - | ||||||||||||||||||
| 375 | } executed 5872 times by 1 test: end of blockExecuted by:
| 5872 | ||||||||||||||||||
| 376 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 377 | return executed 9 times by 1 test: QMimeType();return QMimeType();Executed by:
executed 9 times by 1 test: return QMimeType();Executed by:
| 9 | ||||||||||||||||||
| 378 | } | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | QStringList QMimeBinaryProvider::parents(const QString &mime) | - | ||||||||||||||||||
| 381 | { | - | ||||||||||||||||||
| 382 | checkCache(); | - | ||||||||||||||||||
| 383 | const QByteArray mimeStr = mime.toLatin1(); | - | ||||||||||||||||||
| 384 | QStringList result; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||
| 385 | ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 386 | const int parentListOffset = cacheFile->getUint32(PosParentListOffset); | - | ||||||||||||||||||
| 387 | const int numEntries = cacheFile->getUint32(parentListOffset); | - | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | int begin = 0; | - | ||||||||||||||||||
| 390 | int end = numEntries - 1; | - | ||||||||||||||||||
| 391 | while (begin <= end
| 34-466 | ||||||||||||||||||
| 392 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||
| 393 | const int off = parentListOffset + 4 + 8 * medium; | - | ||||||||||||||||||
| 394 | const int mimeOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 395 | const char *aMime = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||
| 396 | const int cmp = qstrcmp(aMime, mimeStr); | - | ||||||||||||||||||
| 397 | if (cmp < 0
| 230-236 | ||||||||||||||||||
| 398 | begin = medium + 1; | - | ||||||||||||||||||
| 399 | } executed 230 times by 1 test: else if (cmp > 0end of blockExecuted by:
| 26-230 | ||||||||||||||||||
| 400 | end = medium - 1; | - | ||||||||||||||||||
| 401 | } executed 210 times by 1 test: else {end of blockExecuted by:
| 210 | ||||||||||||||||||
| 402 | const int parentsOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 403 | const int numParents = cacheFile->getUint32(parentsOffset); | - | ||||||||||||||||||
| 404 | for (int i = 0; i < numParents
| 26-34 | ||||||||||||||||||
| 405 | const int parentOffset = cacheFile->getUint32(parentsOffset + 4 + 4 * i); | - | ||||||||||||||||||
| 406 | const char *aParent = cacheFile->getCharStar(parentOffset); | - | ||||||||||||||||||
| 407 | result.append(QString::fromLatin1(aParent)); | - | ||||||||||||||||||
| 408 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 409 | break; executed 26 times by 1 test: break;Executed by:
| 26 | ||||||||||||||||||
| 410 | } | - | ||||||||||||||||||
| 411 | } | - | ||||||||||||||||||
| 412 | } executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||
| 413 | if (result.isEmpty()
| 26-34 | ||||||||||||||||||
| 414 | const QString parent = fallbackParent(mime); | - | ||||||||||||||||||
| 415 | if (!parent.isEmpty()
| 12-22 | ||||||||||||||||||
| 416 | result.append(parent); executed 22 times by 1 test: result.append(parent);Executed by:
| 22 | ||||||||||||||||||
| 417 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||
| 418 | return executed 60 times by 1 test: result;return result;Executed by:
executed 60 times by 1 test: return result;Executed by:
| 60 | ||||||||||||||||||
| 419 | } | - | ||||||||||||||||||
| 420 | - | |||||||||||||||||||
| 421 | QString QMimeBinaryProvider::resolveAlias(const QString &name) | - | ||||||||||||||||||
| 422 | { | - | ||||||||||||||||||
| 423 | checkCache(); | - | ||||||||||||||||||
| 424 | const QByteArray input = name.toLatin1(); | - | ||||||||||||||||||
| 425 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 426 | const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset); | - | ||||||||||||||||||
| 427 | const int numEntries = cacheFile->getUint32(aliasListOffset); | - | ||||||||||||||||||
| 428 | int begin = 0; | - | ||||||||||||||||||
| 429 | int end = numEntries - 1; | - | ||||||||||||||||||
| 430 | while (begin <= end
| 4609-36002 | ||||||||||||||||||
| 431 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||
| 432 | const int off = aliasListOffset + 4 + 8 * medium; | - | ||||||||||||||||||
| 433 | const int aliasOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 434 | const char *alias = cacheFile->getCharStar(aliasOffset); | - | ||||||||||||||||||
| 435 | const int cmp = qstrcmp(alias, input); | - | ||||||||||||||||||
| 436 | if (cmp < 0
| 17721-18281 | ||||||||||||||||||
| 437 | begin = medium + 1; | - | ||||||||||||||||||
| 438 | } executed 18281 times by 23 tests: else if (cmp > 0end of blockExecuted by:
| 9-18281 | ||||||||||||||||||
| 439 | end = medium - 1; | - | ||||||||||||||||||
| 440 | } executed 17712 times by 23 tests: else {end of blockExecuted by:
| 17712 | ||||||||||||||||||
| 441 | const int mimeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 442 | const char *mimeType = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||
| 443 | return executed 9 times by 1 test: QLatin1String(mimeType);return QLatin1String(mimeType);Executed by:
executed 9 times by 1 test: return QLatin1String(mimeType);Executed by:
| 9 | ||||||||||||||||||
| 444 | } | - | ||||||||||||||||||
| 445 | } | - | ||||||||||||||||||
| 446 | } executed 4609 times by 23 tests: end of blockExecuted by:
| 4609 | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | return executed 4598 times by 23 tests: name;return name;Executed by:
executed 4598 times by 23 tests: return name;Executed by:
| 4598 | ||||||||||||||||||
| 449 | } | - | ||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | QStringList QMimeBinaryProvider::listAliases(const QString &name) | - | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | checkCache(); | - | ||||||||||||||||||
| 454 | QStringList result; | - | ||||||||||||||||||
| 455 | const QByteArray input = name.toLatin1(); | - | ||||||||||||||||||
| 456 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 457 | const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset); | - | ||||||||||||||||||
| 458 | const int numEntries = cacheFile->getUint32(aliasListOffset); | - | ||||||||||||||||||
| 459 | for (int pos = 0; pos < numEntries
| 4-776 | ||||||||||||||||||
| 460 | const int off = aliasListOffset + 4 + 8 * pos; | - | ||||||||||||||||||
| 461 | const int mimeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 462 | const char *mimeType = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||
| 463 | - | |||||||||||||||||||
| 464 | if (input == mimeType
| 4-772 | ||||||||||||||||||
| 465 | const int aliasOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 466 | const char *alias = cacheFile->getCharStar(aliasOffset); | - | ||||||||||||||||||
| 467 | result.append(QString::fromLatin1(alias)); | - | ||||||||||||||||||
| 468 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 469 | } executed 776 times by 1 test: end of blockExecuted by:
| 776 | ||||||||||||||||||
| 470 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 471 | return executed 4 times by 1 test: result;return result;Executed by:
executed 4 times by 1 test: return result;Executed by:
| 4 | ||||||||||||||||||
| 472 | } | - | ||||||||||||||||||
| 473 | - | |||||||||||||||||||
| 474 | void QMimeBinaryProvider::loadMimeTypeList() | - | ||||||||||||||||||
| 475 | { | - | ||||||||||||||||||
| 476 | if (!m_mimetypeListLoaded
| 5-28 | ||||||||||||||||||
| 477 | m_mimetypeListLoaded = true; | - | ||||||||||||||||||
| 478 | m_mimetypeNames.clear(); | - | ||||||||||||||||||
| 479 | - | |||||||||||||||||||
| 480 | - | |||||||||||||||||||
| 481 | const QStringList typesFilenames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/types")); | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(typesFilenames)>::type> _container_((typesFilenames)); | ||||||||||||||||||||
| 482 | _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &typeFilename = *_container_.i; _container_.control; _container_.control = 0: typesFilenames) { | - | ||||||||||||||||||
| 483 | QFile file(typeFilename); | - | ||||||||||||||||||
| 484 | if (file.open(QIODevice::ReadOnly)
| 0-31 | ||||||||||||||||||
| 485 | while (!file.atEnd()
| 31-19818 | ||||||||||||||||||
| 486 | QByteArray line = file.readLine(); | - | ||||||||||||||||||
| 487 | line.chop(1); | - | ||||||||||||||||||
| 488 | m_mimetypeNames.insert(QString::fromLatin1(line.constData(), line.size())); | - | ||||||||||||||||||
| 489 | } executed 19818 times by 23 tests: end of blockExecuted by:
| 19818 | ||||||||||||||||||
| 490 | } executed 31 times by 23 tests: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 491 | } executed 31 times by 23 tests: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 492 | } executed 28 times by 23 tests: end of blockExecuted by:
| 28 | ||||||||||||||||||
| 493 | } executed 33 times by 23 tests: end of blockExecuted by:
| 33 | ||||||||||||||||||
| 494 | - | |||||||||||||||||||
| 495 | QList<QMimeType> QMimeBinaryProvider::allMimeTypes() | - | ||||||||||||||||||
| 496 | { | - | ||||||||||||||||||
| 497 | QList<QMimeType> result; | - | ||||||||||||||||||
| 498 | loadMimeTypeList(); | - | ||||||||||||||||||
| 499 | result.reserve(m_mimetypeNames.count()); | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | for (QSet<QString>::const_iterator it = m_mimetypeNames.constBegin(); | - | ||||||||||||||||||
| 502 | it != m_mimetypeNames.constEnd(); ++it) | - | ||||||||||||||||||
| 503 | result.append(mimeTypeForNameUnchecked(*it)); | - | ||||||||||||||||||
| 504 | - | |||||||||||||||||||
| 505 | return result; | - | ||||||||||||||||||
| 506 | } | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) | - | ||||||||||||||||||
| 509 | { | - | ||||||||||||||||||
| 510 | - | |||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | - | |||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | if (data.loaded
| 10-2447 | ||||||||||||||||||
| 515 | return; executed 10 times by 1 test: return;Executed by:
| 10 | ||||||||||||||||||
| 516 | data.loaded = true; | - | ||||||||||||||||||
| 517 | - | |||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | const QString file = data.name + QLatin1String(".xml"); | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file.toLower()); | - | ||||||||||||||||||
| 522 | if (mimeFiles.isEmpty()
| 0-2447 | ||||||||||||||||||
| 523 | mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); | - | ||||||||||||||||||
| 524 | } never executed: end of block | 0 | ||||||||||||||||||
| 525 | if (mimeFiles.isEmpty()
| 0-2447 | ||||||||||||||||||
| 526 | QMessageLogger(__FILE__, 571577, __PRETTY_FUNCTION__).warning() << "No file found for" << file << ", even though update-mime-info said it would exist.\n" | - | ||||||||||||||||||
| 527 | "Either it was just removed, or the directory doesn't have executable permission..." | - | ||||||||||||||||||
| 528 | << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime"), QStandardPaths::LocateDirectory); | - | ||||||||||||||||||
| 529 | return; never executed: return; | 0 | ||||||||||||||||||
| 530 | } | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | QString comment;QString mainPattern; | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | const QString preferredLanguage = QLocale().name();for (QStringList::const_reverse_iterator it = mimeFiles.crbegin(), end = mimeFiles.crend(); it != end
| 2447 | ||||||||||||||||||
| 535 | QFile qfile(*it); | - | ||||||||||||||||||
| 536 | if (!qfile.open(QFile::ReadOnly)
| 0-2447 | ||||||||||||||||||
| 537 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 538 | - | |||||||||||||||||||
| 539 | QXmlStreamReader xml(&qfile); | - | ||||||||||||||||||
| 540 | if (xml.readNextStartElement()
| 0-2447 | ||||||||||||||||||
| 541 | if (xml.name() != QLatin1String("mime-type")
| 0-2447 | ||||||||||||||||||
| 542 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 543 | } | - | ||||||||||||||||||
| 544 | const QStringRef name = xml.attributes().value(QLatin1String("type")); | - | ||||||||||||||||||
| 545 | if (name.isEmpty()
| 0-2447 | ||||||||||||||||||
| 546 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 547 | if (name.compare(data.name, Qt::CaseInsensitive)
| 0-2447 | ||||||||||||||||||
| 548 | QMessageLogger(__FILE__, 595599, __PRETTY_FUNCTION__).warning() << "Got name" << name << "in file" << file << "expected" << data.name; never executed: QMessageLogger(__FILE__, 599, __PRETTY_FUNCTION__).warning() << "Got name" << name << "in file" << file << "expected" << data.name; | 0 | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | while (xml.readNextStartElement()
| 2447-117409 | ||||||||||||||||||
| 551 | const QStringRef tag = xml.name(); | - | ||||||||||||||||||
| 552 | if (tag == QLatin1String("comment")
| 2500-114909 | ||||||||||||||||||
| 553 | QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString(); | - | ||||||||||||||||||
| 554 | const QString text = xml.readElementText(); | - | ||||||||||||||||||
| 555 | if (lang.isEmpty()
| 2447-112462 | ||||||||||||||||||
| 556 | lang = QLatin1String("en_US"); | - | ||||||||||||||||||
| 557 | } executed 2447 times by 22 tests: end of blockExecuted by:
| 2447 | ||||||||||||||||||
| 558 | data.localeComments.insert(lang, text); | - | ||||||||||||||||||
| 559 | continue; executed 114909 times by 22 tests: continue;Executed by:
| 114909 | ||||||||||||||||||
| 560 | } else if (tag == QLatin1String("icon")
| 0-2500 | ||||||||||||||||||
| 561 | data.iconName = xml.attributes().value(QLatin1String("name")).toString(); | - | ||||||||||||||||||
| 562 | } never executed: else if (tag == QLatin1String("glob-deleteall")end of block
| 0-2499 | ||||||||||||||||||
| 563 | data.globPatterns.clear(); | - | ||||||||||||||||||
| 564 | } executed 1 time by 1 test: else if (tag == QLatin1String("glob")end of blockExecuted by:
| 1-2463 | ||||||||||||||||||
| 565 | const QString pattern = xml.attributes().value(QLatin1String("pattern")).toString(); | - | ||||||||||||||||||
| 566 | if (mainPattern.isEmpty()
| 1-2443 | ||||||||||||||||||
| 567 | mainPattern = pattern; | - | ||||||||||||||||||
| 568 | } executed 2442 times by 22 tests: end of blockExecuted by:
| 2442 | ||||||||||||||||||
| 569 | if (!data.globPatterns.contains(pattern)
| 0-2463 | ||||||||||||||||||
| 570 | data.globPatterns.append(pattern); executed 2463 times by 22 tests: data.globPatterns.append(pattern);Executed by:
| 2463 | ||||||||||||||||||
| 571 | } executed 2463 times by 22 tests: end of blockExecuted by:
| 2463 | ||||||||||||||||||
| 572 | xml.skipCurrentElement(); | - | ||||||||||||||||||
| 573 | } executed 2500 times by 22 tests: end of blockExecuted by:
| 2500 | ||||||||||||||||||
| 574 | ((!(xml.name() == QLatin1String("mime-type"))) ? qt_assert("xml.name() == QLatin1String(\"mime-type\")",__FILE__,621625) : qt_noop()); | - | ||||||||||||||||||
| 575 | } executed 2447 times by 22 tests: end of blockExecuted by:
| 2447 | ||||||||||||||||||
| 576 | } executed 2447 times by 22 tests: end of blockExecuted by:
| 2447 | ||||||||||||||||||
| 577 | - | |||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | if (!mainPattern.isEmpty()
| 0-2442 | ||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | data.globPatterns.removeAll(mainPattern); | - | ||||||||||||||||||
| 584 | data.globPatterns.prepend(mainPattern); | - | ||||||||||||||||||
| 585 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||
| 586 | } executed 2447 times by 22 tests: end of blockExecuted by:
| 2447 | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | - | |||||||||||||||||||
| 589 | QString QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime) | - | ||||||||||||||||||
| 590 | { | - | ||||||||||||||||||
| 591 | const int iconsListOffset = cacheFile->getUint32(posListOffset); | - | ||||||||||||||||||
| 592 | const int numIcons = cacheFile->getUint32(iconsListOffset); | - | ||||||||||||||||||
| 593 | int begin = 0; | - | ||||||||||||||||||
| 594 | int end = numIcons - 1; | - | ||||||||||||||||||
| 595 | while (begin <= end) { | - | ||||||||||||||||||
| 596 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||
| 597 | const int off = iconsListOffset + 4 + 8 * medium; | - | ||||||||||||||||||
| 598 | const int mimeOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||
| 599 | const char *mime = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||
| 600 | const int cmp = qstrcmp(mime, inputMime); | - | ||||||||||||||||||
| 601 | if (cmp < 0) | - | ||||||||||||||||||
| 602 | begin = medium + 1; | - | ||||||||||||||||||
| 603 | else if (cmp > 0) | - | ||||||||||||||||||
| 604 | end = medium - 1; | - | ||||||||||||||||||
| 605 | else { | - | ||||||||||||||||||
| 606 | const int iconOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||
| 607 | return QLatin1String(cacheFile->getCharStar(iconOffset)); | - | ||||||||||||||||||
| 608 | } | - | ||||||||||||||||||
| 609 | } | - | ||||||||||||||||||
| 610 | return QString(); | - | ||||||||||||||||||
| 611 | } | - | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data) | - | ||||||||||||||||||
| 614 | { | - | ||||||||||||||||||
| 615 | checkCache(); | - | ||||||||||||||||||
| 616 | const QByteArray inputMime = data.name.toLatin1(); | - | ||||||||||||||||||
| 617 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 618 | const QString icon = iconForMime(cacheFile, PosIconsListOffset, inputMime); | - | ||||||||||||||||||
| 619 | if (!icon.isEmpty()
| 0-4 | ||||||||||||||||||
| 620 | data.iconName = icon; | - | ||||||||||||||||||
| 621 | return; never executed: return; | 0 | ||||||||||||||||||
| 622 | } | - | ||||||||||||||||||
| 623 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 624 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data) | - | ||||||||||||||||||
| 627 | { | - | ||||||||||||||||||
| 628 | checkCache(); | - | ||||||||||||||||||
| 629 | const QByteArray inputMime = data.name.toLatin1(); | - | ||||||||||||||||||
| 630 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_cacheFiles)>::type> _container_((m_cacheFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (CacheFile *cacheFile = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_cacheFiles)) { | - | ||||||||||||||||||
| 631 | const QString icon = iconForMime(cacheFile, PosGenericIconsListOffset, inputMime); | - | ||||||||||||||||||
| 632 | if (!icon.isEmpty()
| 2 | ||||||||||||||||||
| 633 | data.genericIconName = icon; | - | ||||||||||||||||||
| 634 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||
| 635 | } | - | ||||||||||||||||||
| 636 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 637 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | QMimeXMLProvider::QMimeXMLProvider(QMimeDatabasePrivate *db) | - | ||||||||||||||||||
| 642 | : QMimeProviderBase(db), m_loaded(false) | - | ||||||||||||||||||
| 643 | { | - | ||||||||||||||||||
| 644 | initResources(); | - | ||||||||||||||||||
| 645 | } | - | ||||||||||||||||||
| 646 | - | |||||||||||||||||||
| 647 | QMimeXMLProvider::~QMimeXMLProvider() | - | ||||||||||||||||||
| 648 | { | - | ||||||||||||||||||
| 649 | } | - | ||||||||||||||||||
| 650 | - | |||||||||||||||||||
| 651 | bool QMimeXMLProvider::isValid() | - | ||||||||||||||||||
| 652 | { | - | ||||||||||||||||||
| 653 | return true; | - | ||||||||||||||||||
| 654 | } | - | ||||||||||||||||||
| 655 | - | |||||||||||||||||||
| 656 | QMimeType QMimeXMLProvider::mimeTypeForName(const QString &name) | - | ||||||||||||||||||
| 657 | { | - | ||||||||||||||||||
| 658 | ensureLoaded(); | - | ||||||||||||||||||
| 659 | - | |||||||||||||||||||
| 660 | return m_nameMimeTypeMap.value(name); | - | ||||||||||||||||||
| 661 | } | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | QStringList QMimeXMLProvider::findByFileName(const QString &fileName, QString *foundSuffix) | - | ||||||||||||||||||
| 664 | { | - | ||||||||||||||||||
| 665 | ensureLoaded(); | - | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | const QStringList matchingMimeTypes = m_mimeTypeGlobs.matchingGlobs(fileName, foundSuffix); | - | ||||||||||||||||||
| 668 | return matchingMimeTypes; | - | ||||||||||||||||||
| 669 | } | - | ||||||||||||||||||
| 670 | - | |||||||||||||||||||
| 671 | QMimeType QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr) | - | ||||||||||||||||||
| 672 | { | - | ||||||||||||||||||
| 673 | ensureLoaded(); | - | ||||||||||||||||||
| 674 | - | |||||||||||||||||||
| 675 | QString candidate; | - | ||||||||||||||||||
| for (QForeachContainer<typename QtPrivate::remove_reference<decltype(m_magicMatchers)>::type> _container_((m_magicMatchers)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||
| 676 | - | |||||||||||||||||||
| 677 | ++_container_.i, _container_.control ^= 1)for (const QMimeMagicRuleMatcher &matcher = *_container_.i; _container_.control; _container_.control = 0): qAsConst(m_magicMatchers)) { | - | ||||||||||||||||||
| 678 | if (matcher.matches(data)
| 37-11003 | ||||||||||||||||||
| 679 | const int priority = matcher.priority(); | - | ||||||||||||||||||
| 680 | if (priority > *accuracyPtr
| 14-23 | ||||||||||||||||||
| 681 | *accuracyPtr = priority; | - | ||||||||||||||||||
| 682 | candidate = matcher.mimetype(); | - | ||||||||||||||||||
| 683 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||
| 684 | } executed 37 times by 1 test: end of blockExecuted by:
| 37 | ||||||||||||||||||
| 685 | } executed 11040 times by 1 test: end of blockExecuted by:
| 11040 | ||||||||||||||||||
| 686 | return executed 32 times by 1 test: mimeTypeForName(candidate);return mimeTypeForName(candidate);Executed by:
executed 32 times by 1 test: return mimeTypeForName(candidate);Executed by:
| 32 | ||||||||||||||||||
| 687 | } | - | ||||||||||||||||||
| 688 | - | |||||||||||||||||||
| 689 | void QMimeXMLProvider::ensureLoaded() | - | ||||||||||||||||||
| 690 | { | - | ||||||||||||||||||
| 691 | if (!m_loaded
| 1-4556 | ||||||||||||||||||
| 692 | bool fdoXmlFound = false; | - | ||||||||||||||||||
| 693 | QStringList allFiles; | - | ||||||||||||||||||
| 694 | - | |||||||||||||||||||
| 695 | const QStringList packageDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/packages"), QStandardPaths::LocateDirectory); | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(packageDirs)>::type> _container_((packageDirs)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &packageDir = *_container_.i; _container_.control; _container_.control = 0: packageDirs) { | - | ||||||||||||||||||
| 698 | QDir dir(packageDir); | - | ||||||||||||||||||
| 699 | const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | if (!fdoXmlFound
| 0-88 | ||||||||||||||||||
| 702 | fdoXmlFound = files.contains(QLatin1String("freedesktop.org.xml")); executed 88 times by 1 test: fdoXmlFound = files.contains(QLatin1String("freedesktop.org.xml"));Executed by:
| 88 | ||||||||||||||||||
| 703 | QStringList::const_iterator endIt(files.constEnd()); | - | ||||||||||||||||||
| 704 | for (QStringList::const_iterator it(files.constBegin()); it != endIt
| 88-261 | ||||||||||||||||||
| 705 | allFiles.append(packageDir + QLatin1Char('/') + *it); | - | ||||||||||||||||||
| 706 | } executed 261 times by 1 test: end of blockExecuted by:
| 261 | ||||||||||||||||||
| 707 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||
| 708 | - | |||||||||||||||||||
| 709 | if (!fdoXmlFound
| 0-57 | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | allFiles.prepend(QLatin1String(":/qt-project.org/qmime/freedesktop.org.xml")); | - | ||||||||||||||||||
| 712 | } never executed: end of block | 0 | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | if (m_allFiles == allFiles
| 5-52 | ||||||||||||||||||
| 715 | return; executed 52 times by 1 test: return;Executed by:
| 52 | ||||||||||||||||||
| 716 | m_allFiles = allFiles; | - | ||||||||||||||||||
| 717 | - | |||||||||||||||||||
| 718 | m_nameMimeTypeMap.clear(); | - | ||||||||||||||||||
| 719 | m_aliases.clear(); | - | ||||||||||||||||||
| 720 | m_parents.clear(); | - | ||||||||||||||||||
| 721 | m_mimeTypeGlobs.clear(); | - | ||||||||||||||||||
| 722 | m_magicMatchers.clear(); | - | ||||||||||||||||||
| 723 | - | |||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | - | |||||||||||||||||||
| 726 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(allFiles)>::type> _container_((allFiles)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QString &file = *_container_.i; _container_.control; _container_.control = 0): qAsConst(allFiles)) | - | ||||||||||||||||||
| 727 | load(file); executed 17 times by 1 test: load(file);Executed by:
| 17 | ||||||||||||||||||
| 728 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||
| 729 | } executed 4505 times by 1 test: end of blockExecuted by:
| 4505 | ||||||||||||||||||
| 730 | - | |||||||||||||||||||
| 731 | void QMimeXMLProvider::load(const QString &fileName) | - | ||||||||||||||||||
| 732 | { | - | ||||||||||||||||||
| 733 | QString errorMessage; | - | ||||||||||||||||||
| 734 | if (!load(fileName, &errorMessage)) | - | ||||||||||||||||||
| 735 | QMessageLogger(__FILE__, 797801, __PRETTY_FUNCTION__).warning("QMimeDatabase: Error loading %s\n%s", QString(fileName).toLocal8Bit().constData(), QString(errorMessage).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 736 | } | - | ||||||||||||||||||
| 737 | - | |||||||||||||||||||
| 738 | bool QMimeXMLProvider::load(const QString &fileName, QString *errorMessage) | - | ||||||||||||||||||
| 739 | { | - | ||||||||||||||||||
| 740 | m_loaded = true; | - | ||||||||||||||||||
| 741 | - | |||||||||||||||||||
| 742 | QFile file(fileName); | - | ||||||||||||||||||
| 743 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { | - | ||||||||||||||||||
| 744 | if (errorMessage) | - | ||||||||||||||||||
| 745 | *errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(fileName, file.errorString()); | - | ||||||||||||||||||
| 746 | return false; | - | ||||||||||||||||||
| 747 | } | - | ||||||||||||||||||
| 748 | - | |||||||||||||||||||
| 749 | if (errorMessage) | - | ||||||||||||||||||
| 750 | errorMessage->clear(); | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | QMimeTypeParser parser(*this); | - | ||||||||||||||||||
| 753 | return parser.parse(&file, fileName, errorMessage); | - | ||||||||||||||||||
| 754 | } | - | ||||||||||||||||||
| 755 | - | |||||||||||||||||||
| 756 | void QMimeXMLProvider::addGlobPattern(const QMimeGlobPattern &glob) | - | ||||||||||||||||||
| 757 | { | - | ||||||||||||||||||
| 758 | m_mimeTypeGlobs.addGlob(glob); | - | ||||||||||||||||||
| 759 | } | - | ||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | void QMimeXMLProvider::addMimeType(const QMimeType &mt) | - | ||||||||||||||||||
| 762 | { | - | ||||||||||||||||||
| 763 | m_nameMimeTypeMap.insert(mt.name(), mt); | - | ||||||||||||||||||
| 764 | } | - | ||||||||||||||||||
| 765 | - | |||||||||||||||||||
| 766 | QStringList QMimeXMLProvider::parents(const QString &mime) | - | ||||||||||||||||||
| 767 | { | - | ||||||||||||||||||
| 768 | ensureLoaded(); | - | ||||||||||||||||||
| 769 | QStringList result = m_parents.value(mime); | - | ||||||||||||||||||
| 770 | if (result.isEmpty()) { | - | ||||||||||||||||||
| 771 | const QString parent = fallbackParent(mime); | - | ||||||||||||||||||
| 772 | if (!parent.isEmpty()) | - | ||||||||||||||||||
| 773 | result.append(parent); | - | ||||||||||||||||||
| 774 | } | - | ||||||||||||||||||
| 775 | return result; | - | ||||||||||||||||||
| 776 | } | - | ||||||||||||||||||
| 777 | - | |||||||||||||||||||
| 778 | void QMimeXMLProvider::addParent(const QString &child, const QString &parent) | - | ||||||||||||||||||
| 779 | { | - | ||||||||||||||||||
| 780 | m_parents[child].append(parent); | - | ||||||||||||||||||
| 781 | } | - | ||||||||||||||||||
| 782 | - | |||||||||||||||||||
| 783 | QStringList QMimeXMLProvider::listAliases(const QString &name) | - | ||||||||||||||||||
| 784 | { | - | ||||||||||||||||||
| 785 | ensureLoaded(); | - | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | return m_aliases.keys(name); | - | ||||||||||||||||||
| 788 | } | - | ||||||||||||||||||
| 789 | - | |||||||||||||||||||
| 790 | QString QMimeXMLProvider::resolveAlias(const QString &name) | - | ||||||||||||||||||
| 791 | { | - | ||||||||||||||||||
| 792 | ensureLoaded(); | - | ||||||||||||||||||
| 793 | return m_aliases.value(name, name); | - | ||||||||||||||||||
| 794 | } | - | ||||||||||||||||||
| 795 | - | |||||||||||||||||||
| 796 | void QMimeXMLProvider::addAlias(const QString &alias, const QString &name) | - | ||||||||||||||||||
| 797 | { | - | ||||||||||||||||||
| 798 | m_aliases.insert(alias, name); | - | ||||||||||||||||||
| 799 | } | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | QList<QMimeType> QMimeXMLProvider::allMimeTypes() | - | ||||||||||||||||||
| 802 | { | - | ||||||||||||||||||
| 803 | ensureLoaded(); | - | ||||||||||||||||||
| 804 | return m_nameMimeTypeMap.values(); | - | ||||||||||||||||||
| 805 | } | - | ||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher) | - | ||||||||||||||||||
| 808 | { | - | ||||||||||||||||||
| 809 | m_magicMatchers.append(matcher); | - | ||||||||||||||||||
| 810 | } | - | ||||||||||||||||||
| 811 | - | |||||||||||||||||||
| 812 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |