mimetypes/qmimeprovider.cpp

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

Generated by Squish Coco Non-Commercial