| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/mimetypes/qmimeprovider.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2015 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com> | - | ||||||||||||||||||||||||
| 5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 26 | ** | - | ||||||||||||||||||||||||
| 27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 30 | ** | - | ||||||||||||||||||||||||
| 31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 32 | ** | - | ||||||||||||||||||||||||
| 33 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | #include "qmimeprovider_p.h" | - | ||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||
| 37 | #ifndef QT_NO_MIMETYPE | - | ||||||||||||||||||||||||
| 38 | - | |||||||||||||||||||||||||
| 39 | #include "qmimetypeparser_p.h" | - | ||||||||||||||||||||||||
| 40 | #include <qstandardpaths.h> | - | ||||||||||||||||||||||||
| 41 | #include "qmimemagicrulematcher_p.h" | - | ||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||
| 43 | #include <QXmlStreamReader> | - | ||||||||||||||||||||||||
| 44 | #include <QDir> | - | ||||||||||||||||||||||||
| 45 | #include <QFile> | - | ||||||||||||||||||||||||
| 46 | #include <QByteArrayMatcher> | - | ||||||||||||||||||||||||
| 47 | #include <QDebug> | - | ||||||||||||||||||||||||
| 48 | #include <QDateTime> | - | ||||||||||||||||||||||||
| 49 | #include <QtEndian> | - | ||||||||||||||||||||||||
| 50 | - | |||||||||||||||||||||||||
| 51 | static void initResources() | - | ||||||||||||||||||||||||
| 52 | { | - | ||||||||||||||||||||||||
| 53 | Q_INIT_RESOURCE(mimetypes); | - | ||||||||||||||||||||||||
| 54 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 55 | - | |||||||||||||||||||||||||
| 56 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | static QString fallbackParent(const QString &mimeTypeName) | - | ||||||||||||||||||||||||
| 59 | { | - | ||||||||||||||||||||||||
| 60 | const QString myGroup = mimeTypeName.left(mimeTypeName.indexOf(QLatin1Char('/'))); | - | ||||||||||||||||||||||||
| 61 | // All text/* types are subclasses of text/plain. | - | ||||||||||||||||||||||||
| 62 | if (myGroup == QLatin1String("text") && mimeTypeName != QLatin1String("text/plain"))
| 8-40 | ||||||||||||||||||||||||
| 63 | return QLatin1String("text/plain"); executed 8 times by 1 test: return QLatin1String("text/plain");Executed by:
| 8 | ||||||||||||||||||||||||
| 64 | // All real-file mimetypes implicitly derive from application/octet-stream | - | ||||||||||||||||||||||||
| 65 | if (myGroup != QLatin1String("inode") &&
| 8-52 | ||||||||||||||||||||||||
| 66 | // ignore non-file extensions | - | ||||||||||||||||||||||||
| 67 | myGroup != QLatin1String("all") && myGroup != QLatin1String("fonts") && myGroup != QLatin1String("print") && myGroup != QLatin1String("uri")
| 0-52 | ||||||||||||||||||||||||
| 68 | && mimeTypeName != QLatin1String("application/octet-stream")) {
| 16-36 | ||||||||||||||||||||||||
| 69 | return QLatin1String("application/octet-stream"); executed 36 times by 1 test: return QLatin1String("application/octet-stream");Executed by:
| 36 | ||||||||||||||||||||||||
| 70 | } | - | ||||||||||||||||||||||||
| 71 | return QString(); executed 24 times by 1 test: return QString();Executed by:
| 24 | ||||||||||||||||||||||||
| 72 | } | - | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | QMimeProviderBase::QMimeProviderBase(QMimeDatabasePrivate *db) | - | ||||||||||||||||||||||||
| 75 | : m_db(db) | - | ||||||||||||||||||||||||
| 76 | { | - | ||||||||||||||||||||||||
| 77 | } executed 6 times by 3 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | Q_CORE_EXPORT int qmime_secondsBetweenChecks = 5; // exported for the unit test | - | ||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | bool QMimeProviderBase::shouldCheck() | - | ||||||||||||||||||||||||
| 82 | { | - | ||||||||||||||||||||||||
| 83 | if (m_lastCheck.isValid() && m_lastCheck.elapsed() < qmime_secondsBetweenChecks * 1000)
| 4-9085 | ||||||||||||||||||||||||
| 84 | return false; executed 8977 times by 2 tests: return false;Executed by:
| 8977 | ||||||||||||||||||||||||
| 85 | m_lastCheck.start(); | - | ||||||||||||||||||||||||
| 86 | return true; executed 112 times by 3 tests: return true;Executed by:
| 112 | ||||||||||||||||||||||||
| 87 | } | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | QMimeBinaryProvider::QMimeBinaryProvider(QMimeDatabasePrivate *db) | - | ||||||||||||||||||||||||
| 90 | : QMimeProviderBase(db), m_mimetypeListLoaded(false) | - | ||||||||||||||||||||||||
| 91 | { | - | ||||||||||||||||||||||||
| 92 | } executed 4 times by 3 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||
| 94 | #if defined(Q_OS_UNIX) && !defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
| 95 | #define QT_USE_MMAP | - | ||||||||||||||||||||||||
| 96 | #endif | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | struct QMimeBinaryProvider::CacheFile | - | ||||||||||||||||||||||||
| 99 | { | - | ||||||||||||||||||||||||
| 100 | CacheFile(const QString &fileName); | - | ||||||||||||||||||||||||
| 101 | ~CacheFile(); | - | ||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||
| 103 | bool isValid() const { return m_valid; } executed 3 times by 2 tests: return m_valid;Executed by:
| 3 | ||||||||||||||||||||||||
| 104 | inline quint16 getUint16(int offset) const | - | ||||||||||||||||||||||||
| 105 | { | - | ||||||||||||||||||||||||
| 106 | return qFromBigEndian(*reinterpret_cast<quint16 *>(data + offset)); executed 12 times by 2 tests: return qFromBigEndian(*reinterpret_cast<quint16 *>(data + offset));Executed by:
| 12 | ||||||||||||||||||||||||
| 107 | } | - | ||||||||||||||||||||||||
| 108 | inline quint32 getUint32(int offset) const | - | ||||||||||||||||||||||||
| 109 | { | - | ||||||||||||||||||||||||
| 110 | return qFromBigEndian(*reinterpret_cast<quint32 *>(data + offset)); executed 92955 times by 2 tests: return qFromBigEndian(*reinterpret_cast<quint32 *>(data + offset));Executed by:
| 92955 | ||||||||||||||||||||||||
| 111 | } | - | ||||||||||||||||||||||||
| 112 | inline const char *getCharStar(int offset) const | - | ||||||||||||||||||||||||
| 113 | { | - | ||||||||||||||||||||||||
| 114 | return reinterpret_cast<const char *>(data + offset); executed 31519 times by 2 tests: return reinterpret_cast<const char *>(data + offset);Executed by:
| 31519 | ||||||||||||||||||||||||
| 115 | } | - | ||||||||||||||||||||||||
| 116 | bool load(); | - | ||||||||||||||||||||||||
| 117 | bool reload(); | - | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | QFile file; | - | ||||||||||||||||||||||||
| 120 | uchar *data; | - | ||||||||||||||||||||||||
| 121 | QDateTime m_mtime; | - | ||||||||||||||||||||||||
| 122 | bool m_valid; | - | ||||||||||||||||||||||||
| 123 | }; | - | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | QMimeBinaryProvider::CacheFile::CacheFile(const QString &fileName) | - | ||||||||||||||||||||||||
| 126 | : file(fileName), m_valid(false) | - | ||||||||||||||||||||||||
| 127 | { | - | ||||||||||||||||||||||||
| 128 | load(); | - | ||||||||||||||||||||||||
| 129 | } executed 3 times by 2 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | QMimeBinaryProvider::CacheFile::~CacheFile() | - | ||||||||||||||||||||||||
| 132 | { | - | ||||||||||||||||||||||||
| 133 | } | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | bool QMimeBinaryProvider::CacheFile::load() | - | ||||||||||||||||||||||||
| 136 | { | - | ||||||||||||||||||||||||
| 137 | if (!file.open(QIODevice::ReadOnly))
| 0-6 | ||||||||||||||||||||||||
| 138 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 139 | data = file.map(0, file.size()); | - | ||||||||||||||||||||||||
| 140 | if (data) {
| 0-6 | ||||||||||||||||||||||||
| 141 | const int major = getUint16(0); | - | ||||||||||||||||||||||||
| 142 | const int minor = getUint16(2); | - | ||||||||||||||||||||||||
| 143 | m_valid = (major == 1 && minor >= 1 && minor <= 2);
| 0-6 | ||||||||||||||||||||||||
| 144 | } executed 6 times by 2 tests: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 145 | m_mtime = QFileInfo(file).lastModified(); | - | ||||||||||||||||||||||||
| 146 | return m_valid; executed 6 times by 2 tests: return m_valid;Executed by:
| 6 | ||||||||||||||||||||||||
| 147 | } | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | bool QMimeBinaryProvider::CacheFile::reload() | - | ||||||||||||||||||||||||
| 150 | { | - | ||||||||||||||||||||||||
| 151 | //qDebug() << "reload!" << file->fileName(); | - | ||||||||||||||||||||||||
| 152 | m_valid = false; | - | ||||||||||||||||||||||||
| 153 | if (file.isOpen()) {
| 0-3 | ||||||||||||||||||||||||
| 154 | file.close(); | - | ||||||||||||||||||||||||
| 155 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 156 | data = 0; | - | ||||||||||||||||||||||||
| 157 | return load(); executed 3 times by 1 test: return load();Executed by:
| 3 | ||||||||||||||||||||||||
| 158 | } | - | ||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||
| 160 | QMimeBinaryProvider::CacheFile *QMimeBinaryProvider::CacheFileList::findCacheFile(const QString &fileName) const | - | ||||||||||||||||||||||||
| 161 | { | - | ||||||||||||||||||||||||
| 162 | for (const_iterator it = begin(); it != end(); ++it) {
| 3 | ||||||||||||||||||||||||
| 163 | if ((*it)->file.fileName() == fileName)
| 1-2 | ||||||||||||||||||||||||
| 164 | return *it; executed 2 times by 1 test: return *it;Executed by:
| 2 | ||||||||||||||||||||||||
| 165 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 166 | return 0; executed 3 times by 2 tests: return 0;Executed by:
| 3 | ||||||||||||||||||||||||
| 167 | } | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | QMimeBinaryProvider::~QMimeBinaryProvider() | - | ||||||||||||||||||||||||
| 170 | { | - | ||||||||||||||||||||||||
| 171 | qDeleteAll(m_cacheFiles); | - | ||||||||||||||||||||||||
| 172 | } executed 4 times by 4 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | // Position of the "list offsets" values, at the beginning of the mime.cache file | - | ||||||||||||||||||||||||
| 175 | enum { | - | ||||||||||||||||||||||||
| 176 | PosAliasListOffset = 4, | - | ||||||||||||||||||||||||
| 177 | PosParentListOffset = 8, | - | ||||||||||||||||||||||||
| 178 | PosLiteralListOffset = 12, | - | ||||||||||||||||||||||||
| 179 | PosReverseSuffixTreeOffset = 16, | - | ||||||||||||||||||||||||
| 180 | PosGlobListOffset = 20, | - | ||||||||||||||||||||||||
| 181 | PosMagicListOffset = 24, | - | ||||||||||||||||||||||||
| 182 | // PosNamespaceListOffset = 28, | - | ||||||||||||||||||||||||
| 183 | PosIconsListOffset = 32, | - | ||||||||||||||||||||||||
| 184 | PosGenericIconsListOffset = 36 | - | ||||||||||||||||||||||||
| 185 | }; | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | bool QMimeBinaryProvider::isValid() | - | ||||||||||||||||||||||||
| 188 | { | - | ||||||||||||||||||||||||
| 189 | #if defined(QT_USE_MMAP) | - | ||||||||||||||||||||||||
| 190 | if (!qEnvironmentVariableIsEmpty("QT_NO_MIME_CACHE"))
| 1-3 | ||||||||||||||||||||||||
| 191 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | Q_ASSERT(m_cacheFiles.isEmpty()); // this method is only ever called once | - | ||||||||||||||||||||||||
| 194 | checkCache(); | - | ||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | if (m_cacheFiles.count() > 1)
| 0-3 | ||||||||||||||||||||||||
| 197 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 198 | if (m_cacheFiles.isEmpty())
| 1-2 | ||||||||||||||||||||||||
| 199 | return false; executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | // We found exactly one file; is it the user-modified mimes, or a system file? | - | ||||||||||||||||||||||||
| 202 | const QString foundFile = m_cacheFiles.first()->file.fileName(); | - | ||||||||||||||||||||||||
| 203 | const QString localCacheFile = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1String("/mime/mime.cache"); | - | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | return foundFile != localCacheFile; executed 2 times by 2 tests: return foundFile != localCacheFile;Executed by:
| 2 | ||||||||||||||||||||||||
| 206 | #else | - | ||||||||||||||||||||||||
| 207 | return false; | - | ||||||||||||||||||||||||
| 208 | #endif | - | ||||||||||||||||||||||||
| 209 | } | - | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | bool QMimeBinaryProvider::CacheFileList::checkCacheChanged() | - | ||||||||||||||||||||||||
| 212 | { | - | ||||||||||||||||||||||||
| 213 | bool somethingChanged = false; | - | ||||||||||||||||||||||||
| 214 | QMutableListIterator<CacheFile *> it(*this); | - | ||||||||||||||||||||||||
| 215 | while (it.hasNext()) {
| 56-78 | ||||||||||||||||||||||||
| 216 | CacheFile *cacheFile = it.next(); | - | ||||||||||||||||||||||||
| 217 | QFileInfo fileInfo(cacheFile->file); | - | ||||||||||||||||||||||||
| 218 | if (!fileInfo.exists()) { // This can't happen by just running update-mime-database. But the user could use rm -rf :-)
| 1-77 | ||||||||||||||||||||||||
| 219 | delete cacheFile; | - | ||||||||||||||||||||||||
| 220 | it.remove(); | - | ||||||||||||||||||||||||
| 221 | somethingChanged = true; | - | ||||||||||||||||||||||||
| 222 | } else if (fileInfo.lastModified() > cacheFile->m_mtime) { executed 1 time by 1 test: end of blockExecuted by:
| 1-74 | ||||||||||||||||||||||||
| 223 | if (!cacheFile->reload()) {
| 0-3 | ||||||||||||||||||||||||
| 224 | delete cacheFile; | - | ||||||||||||||||||||||||
| 225 | it.remove(); | - | ||||||||||||||||||||||||
| 226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 227 | somethingChanged = true; | - | ||||||||||||||||||||||||
| 228 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||
| 229 | } executed 78 times by 1 test: end of blockExecuted by:
| 78 | ||||||||||||||||||||||||
| 230 | return somethingChanged; executed 56 times by 3 tests: return somethingChanged;Executed by:
| 56 | ||||||||||||||||||||||||
| 231 | } | - | ||||||||||||||||||||||||
| 232 | - | |||||||||||||||||||||||||
| 233 | void QMimeBinaryProvider::checkCache() | - | ||||||||||||||||||||||||
| 234 | { | - | ||||||||||||||||||||||||
| 235 | if (!shouldCheck())
| 56-4477 | ||||||||||||||||||||||||
| 236 | return; executed 4477 times by 2 tests: return;Executed by:
| 4477 | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | // First iterate over existing known cache files and check for uptodate | - | ||||||||||||||||||||||||
| 239 | if (m_cacheFiles.checkCacheChanged())
| 4-52 | ||||||||||||||||||||||||
| 240 | m_mimetypeListLoaded = false; executed 4 times by 1 test: m_mimetypeListLoaded = false;Executed by:
| 4 | ||||||||||||||||||||||||
| 241 | - | |||||||||||||||||||||||||
| 242 | // Then check if new cache files appeared | - | ||||||||||||||||||||||||
| 243 | const QStringList cacheFileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/mime.cache")); | - | ||||||||||||||||||||||||
| 244 | if (cacheFileNames != m_cacheFileNames) {
| 4-52 | ||||||||||||||||||||||||
| 245 | foreach (const QString &cacheFileName, cacheFileNames) { | - | ||||||||||||||||||||||||
| 246 | CacheFile *cacheFile = m_cacheFiles.findCacheFile(cacheFileName); | - | ||||||||||||||||||||||||
| 247 | if (!cacheFile) {
| 2-3 | ||||||||||||||||||||||||
| 248 | //qDebug() << "new file:" << cacheFileName; | - | ||||||||||||||||||||||||
| 249 | cacheFile = new CacheFile(cacheFileName); | - | ||||||||||||||||||||||||
| 250 | if (cacheFile->isValid()) // verify version
| 0-3 | ||||||||||||||||||||||||
| 251 | m_cacheFiles.append(cacheFile); executed 3 times by 2 tests: m_cacheFiles.append(cacheFile);Executed by:
| 3 | ||||||||||||||||||||||||
| 252 | else | - | ||||||||||||||||||||||||
| 253 | delete cacheFile; never executed: delete cacheFile; | 0 | ||||||||||||||||||||||||
| 254 | } | - | ||||||||||||||||||||||||
| 255 | } executed 5 times by 2 tests: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 256 | m_cacheFileNames = cacheFileNames; | - | ||||||||||||||||||||||||
| 257 | m_mimetypeListLoaded = false; | - | ||||||||||||||||||||||||
| 258 | } executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 259 | } executed 56 times by 3 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | static QMimeType mimeTypeForNameUnchecked(const QString &name) | - | ||||||||||||||||||||||||
| 262 | { | - | ||||||||||||||||||||||||
| 263 | QMimeTypePrivate data; | - | ||||||||||||||||||||||||
| 264 | data.name = name; | - | ||||||||||||||||||||||||
| 265 | // The rest is retrieved on demand. | - | ||||||||||||||||||||||||
| 266 | // comment and globPatterns: in loadMimeTypePrivate | - | ||||||||||||||||||||||||
| 267 | // iconName: in loadIcon | - | ||||||||||||||||||||||||
| 268 | // genericIconName: in loadGenericIcon | - | ||||||||||||||||||||||||
| 269 | return QMimeType(data); executed 5482 times by 2 tests: return QMimeType(data);Executed by:
| 5482 | ||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | QMimeType QMimeBinaryProvider::mimeTypeForName(const QString &name) | - | ||||||||||||||||||||||||
| 273 | { | - | ||||||||||||||||||||||||
| 274 | checkCache(); | - | ||||||||||||||||||||||||
| 275 | if (!m_mimetypeListLoaded)
| 7-2145 | ||||||||||||||||||||||||
| 276 | loadMimeTypeList(); executed 7 times by 2 tests: loadMimeTypeList();Executed by:
| 7 | ||||||||||||||||||||||||
| 277 | if (!m_mimetypeNames.contains(name))
| 8-2144 | ||||||||||||||||||||||||
| 278 | return QMimeType(); // unknown mimetype executed 8 times by 1 test: return QMimeType();Executed by:
| 8 | ||||||||||||||||||||||||
| 279 | return mimeTypeForNameUnchecked(name); executed 2144 times by 2 tests: return mimeTypeForNameUnchecked(name);Executed by:
| 2144 | ||||||||||||||||||||||||
| 280 | } | - | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString *foundSuffix) | - | ||||||||||||||||||||||||
| 283 | { | - | ||||||||||||||||||||||||
| 284 | checkCache(); | - | ||||||||||||||||||||||||
| 285 | if (fileName.isEmpty())
| 2-94 | ||||||||||||||||||||||||
| 286 | return QStringList(); executed 2 times by 1 test: return QStringList();Executed by:
| 2 | ||||||||||||||||||||||||
| 287 | const QString lowerFileName = fileName.toLower(); | - | ||||||||||||||||||||||||
| 288 | QMimeGlobMatchResult result; | - | ||||||||||||||||||||||||
| 289 | // TODO this parses in the order (local, global). Check that it handles "NOGLOBS" correctly. | - | ||||||||||||||||||||||||
| 290 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 291 | matchGlobList(result, cacheFile, cacheFile->getUint32(PosLiteralListOffset), fileName); | - | ||||||||||||||||||||||||
| 292 | matchGlobList(result, cacheFile, cacheFile->getUint32(PosGlobListOffset), fileName); | - | ||||||||||||||||||||||||
| 293 | const int reverseSuffixTreeOffset = cacheFile->getUint32(PosReverseSuffixTreeOffset); | - | ||||||||||||||||||||||||
| 294 | const int numRoots = cacheFile->getUint32(reverseSuffixTreeOffset); | - | ||||||||||||||||||||||||
| 295 | const int firstRootOffset = cacheFile->getUint32(reverseSuffixTreeOffset + 4); | - | ||||||||||||||||||||||||
| 296 | matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, lowerFileName, fileName.length() - 1, false); | - | ||||||||||||||||||||||||
| 297 | if (result.m_matchingMimeTypes.isEmpty())
| 32-65 | ||||||||||||||||||||||||
| 298 | matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true); executed 32 times by 1 test: matchSuffixTree(result, cacheFile, numRoots, firstRootOffset, fileName, fileName.length() - 1, true);Executed by:
| 32 | ||||||||||||||||||||||||
| 299 | } executed 97 times by 1 test: end of blockExecuted by:
| 97 | ||||||||||||||||||||||||
| 300 | if (foundSuffix)
| 8-86 | ||||||||||||||||||||||||
| 301 | *foundSuffix = result.m_foundSuffix; executed 8 times by 1 test: *foundSuffix = result.m_foundSuffix;Executed by:
| 8 | ||||||||||||||||||||||||
| 302 | return result.m_matchingMimeTypes; executed 94 times by 1 test: return result.m_matchingMimeTypes;Executed by:
| 94 | ||||||||||||||||||||||||
| 303 | } | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName) | - | ||||||||||||||||||||||||
| 306 | { | - | ||||||||||||||||||||||||
| 307 | const int numGlobs = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 308 | //qDebug() << "Loading" << numGlobs << "globs from" << cacheFile->file.fileName() << "at offset" << cacheFile->globListOffset; | - | ||||||||||||||||||||||||
| 309 | for (int i = 0; i < numGlobs; ++i) {
| 194-1602 | ||||||||||||||||||||||||
| 310 | const int globOffset = cacheFile->getUint32(off + 4 + 12 * i); | - | ||||||||||||||||||||||||
| 311 | const int mimeTypeOffset = cacheFile->getUint32(off + 4 + 12 * i + 4); | - | ||||||||||||||||||||||||
| 312 | const int flagsAndWeight = cacheFile->getUint32(off + 4 + 12 * i + 8); | - | ||||||||||||||||||||||||
| 313 | const int weight = flagsAndWeight & 0xff; | - | ||||||||||||||||||||||||
| 314 | const bool caseSensitive = flagsAndWeight & 0x100; | - | ||||||||||||||||||||||||
| 315 | const Qt::CaseSensitivity qtCaseSensitive = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
| 94-1508 | ||||||||||||||||||||||||
| 316 | const QString pattern = QLatin1String(cacheFile->getCharStar(globOffset)); | - | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||||||||
| 319 | //qDebug() << pattern << mimeType << weight << caseSensitive; | - | ||||||||||||||||||||||||
| 320 | QMimeGlobPattern glob(pattern, QString() /*unused*/, weight, qtCaseSensitive); | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | // TODO: this could be done faster for literals where a simple == would do. | - | ||||||||||||||||||||||||
| 323 | if (glob.matchFileName(fileName))
| 16-1586 | ||||||||||||||||||||||||
| 324 | result.addMatch(QLatin1String(mimeType), weight, pattern); executed 16 times by 1 test: result.addMatch(QLatin1String(mimeType), weight, pattern);Executed by:
| 16 | ||||||||||||||||||||||||
| 325 | } executed 1602 times by 1 test: end of blockExecuted by:
| 1602 | ||||||||||||||||||||||||
| 326 | } executed 194 times by 1 test: end of blockExecuted by:
| 194 | ||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck) | - | ||||||||||||||||||||||||
| 329 | { | - | ||||||||||||||||||||||||
| 330 | QChar fileChar = fileName[charPos]; | - | ||||||||||||||||||||||||
| 331 | int min = 0; | - | ||||||||||||||||||||||||
| 332 | int max = numEntries - 1; | - | ||||||||||||||||||||||||
| 333 | while (min <= max) {
| 123-1309 | ||||||||||||||||||||||||
| 334 | const int mid = (min + max) / 2; | - | ||||||||||||||||||||||||
| 335 | const int off = firstOffset + 12 * mid; | - | ||||||||||||||||||||||||
| 336 | const QChar ch = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 337 | if (ch < fileChar)
| 586-723 | ||||||||||||||||||||||||
| 338 | min = mid + 1; executed 586 times by 1 test: min = mid + 1;Executed by:
| 586 | ||||||||||||||||||||||||
| 339 | else if (ch > fileChar)
| 339-384 | ||||||||||||||||||||||||
| 340 | max = mid - 1; executed 339 times by 1 test: max = mid - 1;Executed by:
| 339 | ||||||||||||||||||||||||
| 341 | else { | - | ||||||||||||||||||||||||
| 342 | --charPos; | - | ||||||||||||||||||||||||
| 343 | int numChildren = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 344 | int childrenOffset = cacheFile->getUint32(off + 8); | - | ||||||||||||||||||||||||
| 345 | bool success = false; | - | ||||||||||||||||||||||||
| 346 | if (charPos > 0)
| 6-378 | ||||||||||||||||||||||||
| 347 | success = matchSuffixTree(result, cacheFile, numChildren, childrenOffset, fileName, charPos, caseSensitiveCheck); executed 378 times by 1 test: success = matchSuffixTree(result, cacheFile, numChildren, childrenOffset, fileName, charPos, caseSensitiveCheck);Executed by:
| 378 | ||||||||||||||||||||||||
| 348 | if (!success) {
| 181-203 | ||||||||||||||||||||||||
| 349 | for (int i = 0; i < numChildren; ++i) {
| 57-190 | ||||||||||||||||||||||||
| 350 | const int childOff = childrenOffset + 12 * i; | - | ||||||||||||||||||||||||
| 351 | const int mch = cacheFile->getUint32(childOff); | - | ||||||||||||||||||||||||
| 352 | if (mch != 0)
| 66-124 | ||||||||||||||||||||||||
| 353 | break; executed 124 times by 1 test: break;Executed by:
| 124 | ||||||||||||||||||||||||
| 354 | const int mimeTypeOffset = cacheFile->getUint32(childOff + 4); | - | ||||||||||||||||||||||||
| 355 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||||||||
| 356 | const int flagsAndWeight = cacheFile->getUint32(childOff + 8); | - | ||||||||||||||||||||||||
| 357 | const int weight = flagsAndWeight & 0xff; | - | ||||||||||||||||||||||||
| 358 | const bool caseSensitive = flagsAndWeight & 0x100; | - | ||||||||||||||||||||||||
| 359 | if (caseSensitiveCheck || !caseSensitive) {
| 4-62 | ||||||||||||||||||||||||
| 360 | result.addMatch(QLatin1String(mimeType), weight, QLatin1Char('*') + fileName.mid(charPos+1)); | - | ||||||||||||||||||||||||
| 361 | success = true; | - | ||||||||||||||||||||||||
| 362 | } executed 62 times by 1 test: end of blockExecuted by:
| 62 | ||||||||||||||||||||||||
| 363 | } executed 66 times by 1 test: end of blockExecuted by:
| 66 | ||||||||||||||||||||||||
| 364 | } executed 181 times by 1 test: end of blockExecuted by:
| 181 | ||||||||||||||||||||||||
| 365 | return success; executed 384 times by 1 test: return success;Executed by:
| 384 | ||||||||||||||||||||||||
| 366 | } | - | ||||||||||||||||||||||||
| 367 | } | - | ||||||||||||||||||||||||
| 368 | return false; executed 123 times by 1 test: return false;Executed by:
| 123 | ||||||||||||||||||||||||
| 369 | } | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data) | - | ||||||||||||||||||||||||
| 372 | { | - | ||||||||||||||||||||||||
| 373 | const char *dataPtr = data.constData(); | - | ||||||||||||||||||||||||
| 374 | const int dataSize = data.size(); | - | ||||||||||||||||||||||||
| 375 | for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) {
| 5890-10116 | ||||||||||||||||||||||||
| 376 | const int off = firstOffset + matchlet * 32; | - | ||||||||||||||||||||||||
| 377 | const int rangeStart = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 378 | const int rangeLength = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 379 | //const int wordSize = cacheFile->getUint32(off + 8); | - | ||||||||||||||||||||||||
| 380 | const int valueLength = cacheFile->getUint32(off + 12); | - | ||||||||||||||||||||||||
| 381 | const int valueOffset = cacheFile->getUint32(off + 16); | - | ||||||||||||||||||||||||
| 382 | const int maskOffset = cacheFile->getUint32(off + 20); | - | ||||||||||||||||||||||||
| 383 | const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : NULL;
| 215-9901 | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | if (!QMimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask))
| 45-10071 | ||||||||||||||||||||||||
| 386 | continue; executed 10071 times by 1 test: continue;Executed by:
| 10071 | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | const int numChildren = cacheFile->getUint32(off + 24); | - | ||||||||||||||||||||||||
| 389 | const int firstChildOffset = cacheFile->getUint32(off + 28); | - | ||||||||||||||||||||||||
| 390 | if (numChildren == 0) // No submatch? Then we are done.
| 22-23 | ||||||||||||||||||||||||
| 391 | return true; executed 23 times by 1 test: return true;Executed by:
| 23 | ||||||||||||||||||||||||
| 392 | // Check that one of the submatches matches too | - | ||||||||||||||||||||||||
| 393 | if (matchMagicRule(cacheFile, numChildren, firstChildOffset, data))
| 4-18 | ||||||||||||||||||||||||
| 394 | return true; executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||
| 395 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 396 | return false; executed 5890 times by 1 test: return false;Executed by:
| 5890 | ||||||||||||||||||||||||
| 397 | } | - | ||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||
| 399 | QMimeType QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracyPtr) | - | ||||||||||||||||||||||||
| 400 | { | - | ||||||||||||||||||||||||
| 401 | checkCache(); | - | ||||||||||||||||||||||||
| 402 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 403 | const int magicListOffset = cacheFile->getUint32(PosMagicListOffset); | - | ||||||||||||||||||||||||
| 404 | const int numMatches = cacheFile->getUint32(magicListOffset); | - | ||||||||||||||||||||||||
| 405 | //const int maxExtent = cacheFile->getUint32(magicListOffset + 4); | - | ||||||||||||||||||||||||
| 406 | const int firstMatchOffset = cacheFile->getUint32(magicListOffset + 8); | - | ||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | for (int i = 0; i < numMatches; ++i) {
| 9-5895 | ||||||||||||||||||||||||
| 409 | const int off = firstMatchOffset + i * 16; | - | ||||||||||||||||||||||||
| 410 | const int numMatchlets = cacheFile->getUint32(off + 8); | - | ||||||||||||||||||||||||
| 411 | const int firstMatchletOffset = cacheFile->getUint32(off + 12); | - | ||||||||||||||||||||||||
| 412 | if (matchMagicRule(cacheFile, numMatchlets, firstMatchletOffset, data)) {
| 23-5872 | ||||||||||||||||||||||||
| 413 | const int mimeTypeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 414 | const char *mimeType = cacheFile->getCharStar(mimeTypeOffset); | - | ||||||||||||||||||||||||
| 415 | *accuracyPtr = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 416 | // Return the first match. We have no rules for conflicting magic data... | - | ||||||||||||||||||||||||
| 417 | // (mime.cache itself is sorted, but what about local overrides with a lower prio?) | - | ||||||||||||||||||||||||
| 418 | return mimeTypeForNameUnchecked(QLatin1String(mimeType)); executed 23 times by 1 test: return mimeTypeForNameUnchecked(QLatin1String(mimeType));Executed by:
| 23 | ||||||||||||||||||||||||
| 419 | } | - | ||||||||||||||||||||||||
| 420 | } executed 5872 times by 1 test: end of blockExecuted by:
| 5872 | ||||||||||||||||||||||||
| 421 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 422 | return QMimeType(); executed 9 times by 1 test: return QMimeType();Executed by:
| 9 | ||||||||||||||||||||||||
| 423 | } | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | QStringList QMimeBinaryProvider::parents(const QString &mime) | - | ||||||||||||||||||||||||
| 426 | { | - | ||||||||||||||||||||||||
| 427 | checkCache(); | - | ||||||||||||||||||||||||
| 428 | const QByteArray mimeStr = mime.toLatin1(); | - | ||||||||||||||||||||||||
| 429 | QStringList result; | - | ||||||||||||||||||||||||
| 430 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 431 | const int parentListOffset = cacheFile->getUint32(PosParentListOffset); | - | ||||||||||||||||||||||||
| 432 | const int numEntries = cacheFile->getUint32(parentListOffset); | - | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | int begin = 0; | - | ||||||||||||||||||||||||
| 435 | int end = numEntries - 1; | - | ||||||||||||||||||||||||
| 436 | while (begin <= end) {
| 34-466 | ||||||||||||||||||||||||
| 437 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||||||||
| 438 | const int off = parentListOffset + 4 + 8 * medium; | - | ||||||||||||||||||||||||
| 439 | const int mimeOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 440 | const char *aMime = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||||||||
| 441 | const int cmp = qstrcmp(aMime, mimeStr); | - | ||||||||||||||||||||||||
| 442 | if (cmp < 0) {
| 230-236 | ||||||||||||||||||||||||
| 443 | begin = medium + 1; | - | ||||||||||||||||||||||||
| 444 | } else if (cmp > 0) { executed 230 times by 1 test: end of blockExecuted by:
| 26-230 | ||||||||||||||||||||||||
| 445 | end = medium - 1; | - | ||||||||||||||||||||||||
| 446 | } else { executed 210 times by 1 test: end of blockExecuted by:
| 210 | ||||||||||||||||||||||||
| 447 | const int parentsOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 448 | const int numParents = cacheFile->getUint32(parentsOffset); | - | ||||||||||||||||||||||||
| 449 | for (int i = 0; i < numParents; ++i) {
| 26-34 | ||||||||||||||||||||||||
| 450 | const int parentOffset = cacheFile->getUint32(parentsOffset + 4 + 4 * i); | - | ||||||||||||||||||||||||
| 451 | const char *aParent = cacheFile->getCharStar(parentOffset); | - | ||||||||||||||||||||||||
| 452 | result.append(QString::fromLatin1(aParent)); | - | ||||||||||||||||||||||||
| 453 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 454 | break; executed 26 times by 1 test: break;Executed by:
| 26 | ||||||||||||||||||||||||
| 455 | } | - | ||||||||||||||||||||||||
| 456 | } | - | ||||||||||||||||||||||||
| 457 | } executed 60 times by 1 test: end of blockExecuted by:
| 60 | ||||||||||||||||||||||||
| 458 | if (result.isEmpty()) {
| 26-34 | ||||||||||||||||||||||||
| 459 | const QString parent = fallbackParent(mime); | - | ||||||||||||||||||||||||
| 460 | if (!parent.isEmpty())
| 12-22 | ||||||||||||||||||||||||
| 461 | result.append(parent); executed 22 times by 1 test: result.append(parent);Executed by:
| 22 | ||||||||||||||||||||||||
| 462 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 463 | return result; executed 60 times by 1 test: return result;Executed by:
| 60 | ||||||||||||||||||||||||
| 464 | } | - | ||||||||||||||||||||||||
| 465 | - | |||||||||||||||||||||||||
| 466 | QString QMimeBinaryProvider::resolveAlias(const QString &name) | - | ||||||||||||||||||||||||
| 467 | { | - | ||||||||||||||||||||||||
| 468 | checkCache(); | - | ||||||||||||||||||||||||
| 469 | const QByteArray input = name.toLatin1(); | - | ||||||||||||||||||||||||
| 470 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 471 | const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset); | - | ||||||||||||||||||||||||
| 472 | const int numEntries = cacheFile->getUint32(aliasListOffset); | - | ||||||||||||||||||||||||
| 473 | int begin = 0; | - | ||||||||||||||||||||||||
| 474 | int end = numEntries - 1; | - | ||||||||||||||||||||||||
| 475 | while (begin <= end) {
| 2180-16570 | ||||||||||||||||||||||||
| 476 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||||||||
| 477 | const int off = aliasListOffset + 4 + 8 * medium; | - | ||||||||||||||||||||||||
| 478 | const int aliasOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 479 | const char *alias = cacheFile->getCharStar(aliasOffset); | - | ||||||||||||||||||||||||
| 480 | const int cmp = qstrcmp(alias, input); | - | ||||||||||||||||||||||||
| 481 | if (cmp < 0) {
| 8004-8566 | ||||||||||||||||||||||||
| 482 | begin = medium + 1; | - | ||||||||||||||||||||||||
| 483 | } else if (cmp > 0) { executed 8566 times by 2 tests: end of blockExecuted by:
| 9-8566 | ||||||||||||||||||||||||
| 484 | end = medium - 1; | - | ||||||||||||||||||||||||
| 485 | } else { executed 7995 times by 2 tests: end of blockExecuted by:
| 7995 | ||||||||||||||||||||||||
| 486 | const int mimeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 487 | const char *mimeType = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||||||||
| 488 | return QLatin1String(mimeType); executed 9 times by 1 test: return QLatin1String(mimeType);Executed by:
| 9 | ||||||||||||||||||||||||
| 489 | } | - | ||||||||||||||||||||||||
| 490 | } | - | ||||||||||||||||||||||||
| 491 | } executed 2180 times by 2 tests: end of blockExecuted by:
| 2180 | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | return name; executed 2169 times by 2 tests: return name;Executed by:
| 2169 | ||||||||||||||||||||||||
| 494 | } | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | QStringList QMimeBinaryProvider::listAliases(const QString &name) | - | ||||||||||||||||||||||||
| 497 | { | - | ||||||||||||||||||||||||
| 498 | checkCache(); | - | ||||||||||||||||||||||||
| 499 | QStringList result; | - | ||||||||||||||||||||||||
| 500 | const QByteArray input = name.toLatin1(); | - | ||||||||||||||||||||||||
| 501 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 502 | const int aliasListOffset = cacheFile->getUint32(PosAliasListOffset); | - | ||||||||||||||||||||||||
| 503 | const int numEntries = cacheFile->getUint32(aliasListOffset); | - | ||||||||||||||||||||||||
| 504 | for (int pos = 0; pos < numEntries; ++pos) {
| 4-776 | ||||||||||||||||||||||||
| 505 | const int off = aliasListOffset + 4 + 8 * pos; | - | ||||||||||||||||||||||||
| 506 | const int mimeOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 507 | const char *mimeType = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||||||||
| 508 | - | |||||||||||||||||||||||||
| 509 | if (input == mimeType) {
| 4-772 | ||||||||||||||||||||||||
| 510 | const int aliasOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 511 | const char *alias = cacheFile->getCharStar(aliasOffset); | - | ||||||||||||||||||||||||
| 512 | result.append(QString::fromLatin1(alias)); | - | ||||||||||||||||||||||||
| 513 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 514 | } executed 776 times by 1 test: end of blockExecuted by:
| 776 | ||||||||||||||||||||||||
| 515 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 516 | return result; executed 4 times by 1 test: return result;Executed by:
| 4 | ||||||||||||||||||||||||
| 517 | } | - | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | void QMimeBinaryProvider::loadMimeTypeList() | - | ||||||||||||||||||||||||
| 520 | { | - | ||||||||||||||||||||||||
| 521 | if (!m_mimetypeListLoaded) {
| 5-7 | ||||||||||||||||||||||||
| 522 | m_mimetypeListLoaded = true; | - | ||||||||||||||||||||||||
| 523 | m_mimetypeNames.clear(); | - | ||||||||||||||||||||||||
| 524 | // Unfortunately mime.cache doesn't have a full list of all mimetypes. | - | ||||||||||||||||||||||||
| 525 | // So we have to parse the plain-text files called "types". | - | ||||||||||||||||||||||||
| 526 | const QStringList typesFilenames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/types")); | - | ||||||||||||||||||||||||
| 527 | foreach (const QString &typeFilename, typesFilenames) { | - | ||||||||||||||||||||||||
| 528 | QFile file(typeFilename); | - | ||||||||||||||||||||||||
| 529 | if (file.open(QIODevice::ReadOnly)) {
| 0-10 | ||||||||||||||||||||||||
| 530 | while (!file.atEnd()) {
| 10-4698 | ||||||||||||||||||||||||
| 531 | QByteArray line = file.readLine(); | - | ||||||||||||||||||||||||
| 532 | line.chop(1); | - | ||||||||||||||||||||||||
| 533 | m_mimetypeNames.insert(QString::fromLatin1(line.constData(), line.size())); | - | ||||||||||||||||||||||||
| 534 | } executed 4698 times by 2 tests: end of blockExecuted by:
| 4698 | ||||||||||||||||||||||||
| 535 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 536 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 537 | } executed 7 times by 2 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||
| 538 | } executed 12 times by 2 tests: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | QList<QMimeType> QMimeBinaryProvider::allMimeTypes() | - | ||||||||||||||||||||||||
| 541 | { | - | ||||||||||||||||||||||||
| 542 | QList<QMimeType> result; | - | ||||||||||||||||||||||||
| 543 | loadMimeTypeList(); | - | ||||||||||||||||||||||||
| 544 | result.reserve(m_mimetypeNames.count()); | - | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | for (QSet<QString>::const_iterator it = m_mimetypeNames.constBegin(); | - | ||||||||||||||||||||||||
| 547 | it != m_mimetypeNames.constEnd(); ++it)
| 5-3315 | ||||||||||||||||||||||||
| 548 | result.append(mimeTypeForNameUnchecked(*it)); executed 3315 times by 1 test: result.append(mimeTypeForNameUnchecked(*it));Executed by:
| 3315 | ||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||
| 550 | return result; executed 5 times by 1 test: return result;Executed by:
| 5 | ||||||||||||||||||||||||
| 551 | } | - | ||||||||||||||||||||||||
| 552 | - | |||||||||||||||||||||||||
| 553 | void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data) | - | ||||||||||||||||||||||||
| 554 | { | - | ||||||||||||||||||||||||
| 555 | #ifdef QT_NO_XMLSTREAMREADER | - | ||||||||||||||||||||||||
| 556 | qWarning() << "Cannot load mime type since QXmlStreamReader is not available."; | - | ||||||||||||||||||||||||
| 557 | return; | - | ||||||||||||||||||||||||
| 558 | #else | - | ||||||||||||||||||||||||
| 559 | if (data.loaded)
| 10-18 | ||||||||||||||||||||||||
| 560 | return; executed 10 times by 1 test: return;Executed by:
| 10 | ||||||||||||||||||||||||
| 561 | data.loaded = true; | - | ||||||||||||||||||||||||
| 562 | // load comment and globPatterns | - | ||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||
| 564 | const QString file = data.name + QLatin1String(".xml"); | - | ||||||||||||||||||||||||
| 565 | // shared-mime-info since 1.3 lowercases the xml files | - | ||||||||||||||||||||||||
| 566 | QStringList mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file.toLower()); | - | ||||||||||||||||||||||||
| 567 | if (mimeFiles.isEmpty()) {
| 0-18 | ||||||||||||||||||||||||
| 568 | mimeFiles = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QString::fromLatin1("mime/") + file); // pre-1.3 | - | ||||||||||||||||||||||||
| 569 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 570 | if (mimeFiles.isEmpty()) {
| 0-18 | ||||||||||||||||||||||||
| 571 | qWarning() << "No file found for" << file << ", even though update-mime-info said it would exist.\n" | - | ||||||||||||||||||||||||
| 572 | "Either it was just removed, or the directory doesn't have executable permission..." | - | ||||||||||||||||||||||||
| 573 | << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime"), QStandardPaths::LocateDirectory); | - | ||||||||||||||||||||||||
| 574 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 575 | } | - | ||||||||||||||||||||||||
| 576 | - | |||||||||||||||||||||||||
| 577 | QString comment; | - | ||||||||||||||||||||||||
| 578 | QString mainPattern; | - | ||||||||||||||||||||||||
| 579 | const QString preferredLanguage = QLocale().name(); | - | ||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||
| 581 | for (QStringList::const_reverse_iterator it = mimeFiles.crbegin(), end = mimeFiles.crend(); it != end; ++it) { // global first, then local.
| 18 | ||||||||||||||||||||||||
| 582 | QFile qfile(*it); | - | ||||||||||||||||||||||||
| 583 | if (!qfile.open(QFile::ReadOnly))
| 0-18 | ||||||||||||||||||||||||
| 584 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | QXmlStreamReader xml(&qfile); | - | ||||||||||||||||||||||||
| 587 | if (xml.readNextStartElement()) {
| 0-18 | ||||||||||||||||||||||||
| 588 | if (xml.name() != QLatin1String("mime-type")) {
| 0-18 | ||||||||||||||||||||||||
| 589 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 590 | } | - | ||||||||||||||||||||||||
| 591 | const QStringRef name = xml.attributes().value(QLatin1String("type")); | - | ||||||||||||||||||||||||
| 592 | if (name.isEmpty())
| 0-18 | ||||||||||||||||||||||||
| 593 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 594 | if (name.compare(data.name, Qt::CaseInsensitive))
| 0-18 | ||||||||||||||||||||||||
| 595 | qWarning() << "Got name" << name << "in file" << file << "expected" << data.name; never executed: QMessageLogger(__FILE__, 595, __PRETTY_FUNCTION__).warning() << "Got name" << name << "in file" << file << "expected" << data.name; | 0 | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | while (xml.readNextStartElement()) {
| 18-812 | ||||||||||||||||||||||||
| 598 | const QStringRef tag = xml.name(); | - | ||||||||||||||||||||||||
| 599 | if (tag == QLatin1String("comment")) {
| 66-746 | ||||||||||||||||||||||||
| 600 | QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString(); | - | ||||||||||||||||||||||||
| 601 | const QString text = xml.readElementText(); | - | ||||||||||||||||||||||||
| 602 | if (lang.isEmpty()) {
| 18-728 | ||||||||||||||||||||||||
| 603 | lang = QLatin1String("en_US"); | - | ||||||||||||||||||||||||
| 604 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 605 | data.localeComments.insert(lang, text); | - | ||||||||||||||||||||||||
| 606 | continue; // we called readElementText, so we're at the EndElement already. executed 746 times by 1 test: continue;Executed by:
| 746 | ||||||||||||||||||||||||
| 607 | } else if (tag == QLatin1String("icon")) { // as written out by shared-mime-info >= 0.40
| 0-66 | ||||||||||||||||||||||||
| 608 | data.iconName = xml.attributes().value(QLatin1String("name")).toString(); | - | ||||||||||||||||||||||||
| 609 | } else if (tag == QLatin1String("glob-deleteall")) { // as written out by shared-mime-info >= 0.70 never executed: end of block
| 0-65 | ||||||||||||||||||||||||
| 610 | data.globPatterns.clear(); | - | ||||||||||||||||||||||||
| 611 | } else if (tag == QLatin1String("glob")) { // as written out by shared-mime-info >= 0.70 executed 1 time by 1 test: end of blockExecuted by:
| 1-35 | ||||||||||||||||||||||||
| 612 | const QString pattern = xml.attributes().value(QLatin1String("pattern")).toString(); | - | ||||||||||||||||||||||||
| 613 | if (mainPattern.isEmpty() && pattern.startsWith(QLatin1Char('*'))) {
| 1-16 | ||||||||||||||||||||||||
| 614 | mainPattern = pattern; | - | ||||||||||||||||||||||||
| 615 | } executed 13 times by 1 test: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||
| 616 | if (!data.globPatterns.contains(pattern))
| 0-30 | ||||||||||||||||||||||||
| 617 | data.globPatterns.append(pattern); executed 30 times by 1 test: data.globPatterns.append(pattern);Executed by:
| 30 | ||||||||||||||||||||||||
| 618 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||||||||||||||
| 619 | xml.skipCurrentElement(); | - | ||||||||||||||||||||||||
| 620 | } executed 66 times by 1 test: end of blockExecuted by:
| 66 | ||||||||||||||||||||||||
| 621 | Q_ASSERT(xml.name() == QLatin1String("mime-type")); | - | ||||||||||||||||||||||||
| 622 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 623 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 624 | - | |||||||||||||||||||||||||
| 625 | // Let's assume that shared-mime-info is at least version 0.70 | - | ||||||||||||||||||||||||
| 626 | // Otherwise we would need 1) a version check, and 2) code for parsing patterns from the globs file. | - | ||||||||||||||||||||||||
| 627 | #if 1 | - | ||||||||||||||||||||||||
| 628 | if (!mainPattern.isEmpty() && (data.globPatterns.isEmpty() || data.globPatterns.first() != mainPattern)) {
| 0-13 | ||||||||||||||||||||||||
| 629 | // ensure it's first in the list of patterns | - | ||||||||||||||||||||||||
| 630 | data.globPatterns.removeAll(mainPattern); | - | ||||||||||||||||||||||||
| 631 | data.globPatterns.prepend(mainPattern); | - | ||||||||||||||||||||||||
| 632 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 633 | #else | - | ||||||||||||||||||||||||
| 634 | const bool globsInXml = sharedMimeInfoVersion() >= QT_VERSION_CHECK(0, 70, 0); | - | ||||||||||||||||||||||||
| 635 | if (globsInXml) { | - | ||||||||||||||||||||||||
| 636 | if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) { | - | ||||||||||||||||||||||||
| 637 | // ensure it's first in the list of patterns | - | ||||||||||||||||||||||||
| 638 | data.globPatterns.removeAll(mainPattern); | - | ||||||||||||||||||||||||
| 639 | data.globPatterns.prepend(mainPattern); | - | ||||||||||||||||||||||||
| 640 | } | - | ||||||||||||||||||||||||
| 641 | } else { | - | ||||||||||||||||||||||||
| 642 | // Fallback: get the patterns from the globs file | - | ||||||||||||||||||||||||
| 643 | // TODO: This would be the only way to support shared-mime-info < 0.70 | - | ||||||||||||||||||||||||
| 644 | // But is this really worth the effort? | - | ||||||||||||||||||||||||
| 645 | } | - | ||||||||||||||||||||||||
| 646 | #endif | - | ||||||||||||||||||||||||
| 647 | #endif //QT_NO_XMLSTREAMREADER | - | ||||||||||||||||||||||||
| 648 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||||||||
| 649 | - | |||||||||||||||||||||||||
| 650 | // Binary search in the icons or generic-icons list | - | ||||||||||||||||||||||||
| 651 | QString QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime) | - | ||||||||||||||||||||||||
| 652 | { | - | ||||||||||||||||||||||||
| 653 | const int iconsListOffset = cacheFile->getUint32(posListOffset); | - | ||||||||||||||||||||||||
| 654 | const int numIcons = cacheFile->getUint32(iconsListOffset); | - | ||||||||||||||||||||||||
| 655 | int begin = 0; | - | ||||||||||||||||||||||||
| 656 | int end = numIcons - 1; | - | ||||||||||||||||||||||||
| 657 | while (begin <= end) {
| 6-34 | ||||||||||||||||||||||||
| 658 | const int medium = (begin + end) / 2; | - | ||||||||||||||||||||||||
| 659 | const int off = iconsListOffset + 4 + 8 * medium; | - | ||||||||||||||||||||||||
| 660 | const int mimeOffset = cacheFile->getUint32(off); | - | ||||||||||||||||||||||||
| 661 | const char *mime = cacheFile->getCharStar(mimeOffset); | - | ||||||||||||||||||||||||
| 662 | const int cmp = qstrcmp(mime, inputMime); | - | ||||||||||||||||||||||||
| 663 | if (cmp < 0)
| 16-18 | ||||||||||||||||||||||||
| 664 | begin = medium + 1; executed 18 times by 1 test: begin = medium + 1;Executed by:
| 18 | ||||||||||||||||||||||||
| 665 | else if (cmp > 0)
| 2-14 | ||||||||||||||||||||||||
| 666 | end = medium - 1; executed 14 times by 1 test: end = medium - 1;Executed by:
| 14 | ||||||||||||||||||||||||
| 667 | else { | - | ||||||||||||||||||||||||
| 668 | const int iconOffset = cacheFile->getUint32(off + 4); | - | ||||||||||||||||||||||||
| 669 | return QLatin1String(cacheFile->getCharStar(iconOffset)); executed 2 times by 1 test: return QLatin1String(cacheFile->getCharStar(iconOffset));Executed by:
| 2 | ||||||||||||||||||||||||
| 670 | } | - | ||||||||||||||||||||||||
| 671 | } | - | ||||||||||||||||||||||||
| 672 | return QString(); executed 6 times by 1 test: return QString();Executed by:
| 6 | ||||||||||||||||||||||||
| 673 | } | - | ||||||||||||||||||||||||
| 674 | - | |||||||||||||||||||||||||
| 675 | void QMimeBinaryProvider::loadIcon(QMimeTypePrivate &data) | - | ||||||||||||||||||||||||
| 676 | { | - | ||||||||||||||||||||||||
| 677 | checkCache(); | - | ||||||||||||||||||||||||
| 678 | const QByteArray inputMime = data.name.toLatin1(); | - | ||||||||||||||||||||||||
| 679 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 680 | const QString icon = iconForMime(cacheFile, PosIconsListOffset, inputMime); | - | ||||||||||||||||||||||||
| 681 | if (!icon.isEmpty()) {
| 0-4 | ||||||||||||||||||||||||
| 682 | data.iconName = icon; | - | ||||||||||||||||||||||||
| 683 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 684 | } | - | ||||||||||||||||||||||||
| 685 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 686 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 687 | - | |||||||||||||||||||||||||
| 688 | void QMimeBinaryProvider::loadGenericIcon(QMimeTypePrivate &data) | - | ||||||||||||||||||||||||
| 689 | { | - | ||||||||||||||||||||||||
| 690 | checkCache(); | - | ||||||||||||||||||||||||
| 691 | const QByteArray inputMime = data.name.toLatin1(); | - | ||||||||||||||||||||||||
| 692 | foreach (CacheFile *cacheFile, m_cacheFiles) { | - | ||||||||||||||||||||||||
| 693 | const QString icon = iconForMime(cacheFile, PosGenericIconsListOffset, inputMime); | - | ||||||||||||||||||||||||
| 694 | if (!icon.isEmpty()) {
| 2 | ||||||||||||||||||||||||
| 695 | data.genericIconName = icon; | - | ||||||||||||||||||||||||
| 696 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 697 | } | - | ||||||||||||||||||||||||
| 698 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 699 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | //// | - | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | QMimeXMLProvider::QMimeXMLProvider(QMimeDatabasePrivate *db) | - | ||||||||||||||||||||||||
| 704 | : QMimeProviderBase(db), m_loaded(false) | - | ||||||||||||||||||||||||
| 705 | { | - | ||||||||||||||||||||||||
| 706 | initResources(); | - | ||||||||||||||||||||||||
| 707 | } executed 2 times by 2 tests: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 708 | - | |||||||||||||||||||||||||
| 709 | QMimeXMLProvider::~QMimeXMLProvider() | - | ||||||||||||||||||||||||
| 710 | { | - | ||||||||||||||||||||||||
| 711 | } | - | ||||||||||||||||||||||||
| 712 | - | |||||||||||||||||||||||||
| 713 | bool QMimeXMLProvider::isValid() | - | ||||||||||||||||||||||||
| 714 | { | - | ||||||||||||||||||||||||
| 715 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 716 | } | - | ||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | QMimeType QMimeXMLProvider::mimeTypeForName(const QString &name) | - | ||||||||||||||||||||||||
| 719 | { | - | ||||||||||||||||||||||||
| 720 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||
| 722 | return m_nameMimeTypeMap.value(name); executed 2183 times by 1 test: return m_nameMimeTypeMap.value(name);Executed by:
| 2183 | ||||||||||||||||||||||||
| 723 | } | - | ||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | QStringList QMimeXMLProvider::findByFileName(const QString &fileName, QString *foundSuffix) | - | ||||||||||||||||||||||||
| 726 | { | - | ||||||||||||||||||||||||
| 727 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 728 | - | |||||||||||||||||||||||||
| 729 | const QStringList matchingMimeTypes = m_mimeTypeGlobs.matchingGlobs(fileName, foundSuffix); | - | ||||||||||||||||||||||||
| 730 | return matchingMimeTypes; executed 96 times by 1 test: return matchingMimeTypes;Executed by:
| 96 | ||||||||||||||||||||||||
| 731 | } | - | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | QMimeType QMimeXMLProvider::findByMagic(const QByteArray &data, int *accuracyPtr) | - | ||||||||||||||||||||||||
| 734 | { | - | ||||||||||||||||||||||||
| 735 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||
| 737 | QString candidate; | - | ||||||||||||||||||||||||
| 738 | - | |||||||||||||||||||||||||
| 739 | foreach (const QMimeMagicRuleMatcher &matcher, m_magicMatchers) { | - | ||||||||||||||||||||||||
| 740 | if (matcher.matches(data)) {
| 37-11003 | ||||||||||||||||||||||||
| 741 | const int priority = matcher.priority(); | - | ||||||||||||||||||||||||
| 742 | if (priority > *accuracyPtr) {
| 14-23 | ||||||||||||||||||||||||
| 743 | *accuracyPtr = priority; | - | ||||||||||||||||||||||||
| 744 | candidate = matcher.mimetype(); | - | ||||||||||||||||||||||||
| 745 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||||||||
| 746 | } executed 37 times by 1 test: end of blockExecuted by:
| 37 | ||||||||||||||||||||||||
| 747 | } executed 11040 times by 1 test: end of blockExecuted by:
| 11040 | ||||||||||||||||||||||||
| 748 | return mimeTypeForName(candidate); executed 32 times by 1 test: return mimeTypeForName(candidate);Executed by:
| 32 | ||||||||||||||||||||||||
| 749 | } | - | ||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||
| 751 | void QMimeXMLProvider::ensureLoaded() | - | ||||||||||||||||||||||||
| 752 | { | - | ||||||||||||||||||||||||
| 753 | if (!m_loaded || shouldCheck()) {
| 1-4556 | ||||||||||||||||||||||||
| 754 | bool fdoXmlFound = false; | - | ||||||||||||||||||||||||
| 755 | QStringList allFiles; | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | const QStringList packageDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/packages"), QStandardPaths::LocateDirectory); | - | ||||||||||||||||||||||||
| 758 | //qDebug() << "packageDirs=" << packageDirs; | - | ||||||||||||||||||||||||
| 759 | foreach (const QString &packageDir, packageDirs) { | - | ||||||||||||||||||||||||
| 760 | QDir dir(packageDir); | - | ||||||||||||||||||||||||
| 761 | const QStringList files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot); | - | ||||||||||||||||||||||||
| 762 | //qDebug() << static_cast<const void *>(this) << packageDir << files; | - | ||||||||||||||||||||||||
| 763 | if (!fdoXmlFound)
| 0-88 | ||||||||||||||||||||||||
| 764 | fdoXmlFound = files.contains(QLatin1String("freedesktop.org.xml")); executed 88 times by 1 test: fdoXmlFound = files.contains(QLatin1String("freedesktop.org.xml"));Executed by:
| 88 | ||||||||||||||||||||||||
| 765 | QStringList::const_iterator endIt(files.constEnd()); | - | ||||||||||||||||||||||||
| 766 | for (QStringList::const_iterator it(files.constBegin()); it != endIt; ++it) {
| 88-261 | ||||||||||||||||||||||||
| 767 | allFiles.append(packageDir + QLatin1Char('/') + *it); | - | ||||||||||||||||||||||||
| 768 | } executed 261 times by 1 test: end of blockExecuted by:
| 261 | ||||||||||||||||||||||||
| 769 | } executed 88 times by 1 test: end of blockExecuted by:
| 88 | ||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||
| 771 | if (!fdoXmlFound) {
| 0-57 | ||||||||||||||||||||||||
| 772 | // We could instead install the file as part of installing Qt? | - | ||||||||||||||||||||||||
| 773 | allFiles.prepend(QLatin1String(":/qt-project.org/qmime/freedesktop.org.xml")); | - | ||||||||||||||||||||||||
| 774 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 775 | - | |||||||||||||||||||||||||
| 776 | if (m_allFiles == allFiles)
| 5-52 | ||||||||||||||||||||||||
| 777 | return; executed 52 times by 1 test: return;Executed by:
| 52 | ||||||||||||||||||||||||
| 778 | m_allFiles = allFiles; | - | ||||||||||||||||||||||||
| 779 | - | |||||||||||||||||||||||||
| 780 | m_nameMimeTypeMap.clear(); | - | ||||||||||||||||||||||||
| 781 | m_aliases.clear(); | - | ||||||||||||||||||||||||
| 782 | m_parents.clear(); | - | ||||||||||||||||||||||||
| 783 | m_mimeTypeGlobs.clear(); | - | ||||||||||||||||||||||||
| 784 | m_magicMatchers.clear(); | - | ||||||||||||||||||||||||
| 785 | - | |||||||||||||||||||||||||
| 786 | //qDebug() << "Loading" << m_allFiles; | - | ||||||||||||||||||||||||
| 787 | - | |||||||||||||||||||||||||
| 788 | foreach (const QString &file, allFiles) | - | ||||||||||||||||||||||||
| 789 | load(file); executed 17 times by 1 test: load(file);Executed by:
| 17 | ||||||||||||||||||||||||
| 790 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 791 | } executed 4505 times by 1 test: end of blockExecuted by:
| 4505 | ||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||
| 793 | void QMimeXMLProvider::load(const QString &fileName) | - | ||||||||||||||||||||||||
| 794 | { | - | ||||||||||||||||||||||||
| 795 | QString errorMessage; | - | ||||||||||||||||||||||||
| 796 | if (!load(fileName, &errorMessage))
| 0-17 | ||||||||||||||||||||||||
| 797 | qWarning("QMimeDatabase: Error loading %s\n%s", qPrintable(fileName), qPrintable(errorMessage)); never executed: QMessageLogger(__FILE__, 797, __PRETTY_FUNCTION__).warning("QMimeDatabase: Error loading %s\n%s", QString(fileName).toLocal8Bit().constData(), QString(errorMessage).toLocal8Bit().constData()); | 0 | ||||||||||||||||||||||||
| 798 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||
| 800 | bool QMimeXMLProvider::load(const QString &fileName, QString *errorMessage) | - | ||||||||||||||||||||||||
| 801 | { | - | ||||||||||||||||||||||||
| 802 | m_loaded = true; | - | ||||||||||||||||||||||||
| 803 | - | |||||||||||||||||||||||||
| 804 | QFile file(fileName); | - | ||||||||||||||||||||||||
| 805 | if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
| 0-17 | ||||||||||||||||||||||||
| 806 | if (errorMessage)
| 0 | ||||||||||||||||||||||||
| 807 | *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 | ||||||||||||||||||||||||
| 808 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 809 | } | - | ||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | if (errorMessage)
| 0-17 | ||||||||||||||||||||||||
| 812 | errorMessage->clear(); executed 17 times by 1 test: errorMessage->clear();Executed by:
| 17 | ||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||
| 814 | QMimeTypeParser parser(*this); | - | ||||||||||||||||||||||||
| 815 | return parser.parse(&file, fileName, errorMessage); executed 17 times by 1 test: return parser.parse(&file, fileName, errorMessage);Executed by:
| 17 | ||||||||||||||||||||||||
| 816 | } | - | ||||||||||||||||||||||||
| 817 | - | |||||||||||||||||||||||||
| 818 | void QMimeXMLProvider::addGlobPattern(const QMimeGlobPattern &glob) | - | ||||||||||||||||||||||||
| 819 | { | - | ||||||||||||||||||||||||
| 820 | m_mimeTypeGlobs.addGlob(glob); | - | ||||||||||||||||||||||||
| 821 | } executed 4136 times by 1 test: end of blockExecuted by:
| 4136 | ||||||||||||||||||||||||
| 822 | - | |||||||||||||||||||||||||
| 823 | void QMimeXMLProvider::addMimeType(const QMimeType &mt) | - | ||||||||||||||||||||||||
| 824 | { | - | ||||||||||||||||||||||||
| 825 | m_nameMimeTypeMap.insert(mt.name(), mt); | - | ||||||||||||||||||||||||
| 826 | } executed 3319 times by 1 test: end of blockExecuted by:
| 3319 | ||||||||||||||||||||||||
| 827 | - | |||||||||||||||||||||||||
| 828 | QStringList QMimeXMLProvider::parents(const QString &mime) | - | ||||||||||||||||||||||||
| 829 | { | - | ||||||||||||||||||||||||
| 830 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 831 | QStringList result = m_parents.value(mime); | - | ||||||||||||||||||||||||
| 832 | if (result.isEmpty()) {
| 26-34 | ||||||||||||||||||||||||
| 833 | const QString parent = fallbackParent(mime); | - | ||||||||||||||||||||||||
| 834 | if (!parent.isEmpty())
| 12-22 | ||||||||||||||||||||||||
| 835 | result.append(parent); executed 22 times by 1 test: result.append(parent);Executed by:
| 22 | ||||||||||||||||||||||||
| 836 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 837 | return result; executed 60 times by 1 test: return result;Executed by:
| 60 | ||||||||||||||||||||||||
| 838 | } | - | ||||||||||||||||||||||||
| 839 | - | |||||||||||||||||||||||||
| 840 | void QMimeXMLProvider::addParent(const QString &child, const QString &parent) | - | ||||||||||||||||||||||||
| 841 | { | - | ||||||||||||||||||||||||
| 842 | m_parents[child].append(parent); | - | ||||||||||||||||||||||||
| 843 | } executed 1560 times by 1 test: end of blockExecuted by:
| 1560 | ||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||
| 845 | QStringList QMimeXMLProvider::listAliases(const QString &name) | - | ||||||||||||||||||||||||
| 846 | { | - | ||||||||||||||||||||||||
| 847 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 848 | // Iterate through the whole hash. This method is rarely used. | - | ||||||||||||||||||||||||
| 849 | return m_aliases.keys(name); executed 4 times by 1 test: return m_aliases.keys(name);Executed by:
| 4 | ||||||||||||||||||||||||
| 850 | } | - | ||||||||||||||||||||||||
| 851 | - | |||||||||||||||||||||||||
| 852 | QString QMimeXMLProvider::resolveAlias(const QString &name) | - | ||||||||||||||||||||||||
| 853 | { | - | ||||||||||||||||||||||||
| 854 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 855 | return m_aliases.value(name, name); executed 2177 times by 1 test: return m_aliases.value(name, name);Executed by:
| 2177 | ||||||||||||||||||||||||
| 856 | } | - | ||||||||||||||||||||||||
| 857 | - | |||||||||||||||||||||||||
| 858 | void QMimeXMLProvider::addAlias(const QString &alias, const QString &name) | - | ||||||||||||||||||||||||
| 859 | { | - | ||||||||||||||||||||||||
| 860 | m_aliases.insert(alias, name); | - | ||||||||||||||||||||||||
| 861 | } executed 975 times by 1 test: end of blockExecuted by:
| 975 | ||||||||||||||||||||||||
| 862 | - | |||||||||||||||||||||||||
| 863 | QList<QMimeType> QMimeXMLProvider::allMimeTypes() | - | ||||||||||||||||||||||||
| 864 | { | - | ||||||||||||||||||||||||
| 865 | ensureLoaded(); | - | ||||||||||||||||||||||||
| 866 | return m_nameMimeTypeMap.values(); executed 5 times by 1 test: return m_nameMimeTypeMap.values();Executed by:
| 5 | ||||||||||||||||||||||||
| 867 | } | - | ||||||||||||||||||||||||
| 868 | - | |||||||||||||||||||||||||
| 869 | void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher) | - | ||||||||||||||||||||||||
| 870 | { | - | ||||||||||||||||||||||||
| 871 | m_magicMatchers.append(matcher); | - | ||||||||||||||||||||||||
| 872 | } executed 1733 times by 1 test: end of blockExecuted by:
| 1733 | ||||||||||||||||||||||||
| 873 | - | |||||||||||||||||||||||||
| 874 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 875 | - | |||||||||||||||||||||||||
| 876 | #endif // QT_NO_MIMETYPE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |