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