summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimedatabase_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QMimeDatabase: collect glob patterns from all locationsDavid Faure2023-09-131-4/+5
| | | | | | | | | | | | | | | | | | | A QMimeTypePrivate used to belong to a single provider, which would provide the complete data for it. But since the redesign in commit 7a5644d6481a3c1a741677, each provider represents is a single mime directory, and the merging happens at the QMimeDatabase level. So we need a QMimeType[Private] to be just a name (a "request" for information about this mimetype) and the information for that mimetype is retrieved on demand by querying the providers and either stopping at the first one (e.g. for icons) or merging the data from all of them (e.g. for glob patterns). The XML provider was using QMimeTypePrivate as data storage, give it its own struct QMimeTypeXMLData for that purpose instead. Task-number: QTBUG-116905 Change-Id: Ia0e0d94aa899720dc0b908f40c25317473005af4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: don't stat() something that isn't a local fileThiago Macieira2023-02-021-1/+1
| | | | | | | | | | | | | | | | We must check that the path is an actual file on the filesystem before using native APIs. This regression was introduced by commit 047d8f36de45ebb318726167f941b0dbc64754ba. [ChangeLog][QtCore][QMimeDatabase] Fixed a regression from 6.4.0 that made certain QMimeDatabase functions that inspected file contents to fail on Unix systems, if the file was not a native file (e.g., a Qt resource). Fixes: QTBUG-110707 Pick-to: 6.4 6.5 Change-Id: I570832c9ac8b4e03bde8fffd173f7b4c6b164192 Reviewed-by: Igor Kushnir <igorkuo@gmail.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Use SPDX license identifiersLucie Gérard2022-05-161-39/+3
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* QMimeDatabasePrivate: deduplicate QStringLiteralIgor Kushnir2021-12-211-2/+3
| | | | | | | | | | | | | | | | | | | | defaultMimeType() cannot be moved out of the class and defined in qmimedatabase.cpp, because it is called from QMimeType::isDefault() in qmimetype.cpp. Return m_defaultMimeType constant by reference rather than by value from the inline helper function. This eliminates useless copying of QString when calling code needs only a reference, and so improves performance. Even though m_defaultMimeType is initialized with a QStringLiteral and its QArrayDataPointer has d == nullptr, QArrayDataPointer's ref() and deref() still have to compare d with nullptr to decide that no reference count manipulation is needed. Compilers might be unable to reorder these checks with surrounding code because they guard reference count manipulation. Branch misprediction could further harm performance. Optimizing these checks out can be difficult for compilers. Change-Id: I3ffa0fdc5ad948452301dd9688073b5323a7983b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabasePrivate: remove unused output parameterIgor Kushnir2021-12-211-1/+1
| | | | | | | | | mimeTypeForFileNameAndData()'s output parameter int *priorityPtr (named differently "accuracyPtr" in the definition) is never used by its callers. Remove it to shorten the code and slightly improve performance. Change-Id: Ibc3d169501e89584b4318074ccb780580dc70fb6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase::mimeTypeForFile: don't create QFileInfo on UNIXIgor Kushnir2021-12-201-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When mode != MatchExtension is passed to QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const a QFileInfo object is always created and used to check QFileInfo::isDir(). Replace this expensive approach with a very cheap (bitmask) S_ISDIR check under Q_OS_UNIX. QT_STAT is already called for other reasons, so we just reuse its result in the S_ISDIR check. Extract almost all code from QMimeDatabase::mimeTypeForFile(const QString &, MatchMode) const; QMimeDatabase::mimeTypeForData(QIODevice *) const; QMimeDatabase::mimeTypeForFile(const QFileInfo &, MatchMode) const into QMimeDatabasePrivate::mimeTypeForFileExtension(const QString &); QMimeDatabasePrivate::mimeTypeForData(QIODevice *); QMimeDatabasePrivate::mimeTypeForFile(const QString &, const QFileInfo *, QMimeDatabase::MatchMode) respectively. This refactoring is a less convoluted and more efficient alternative to adding more mutex-unlocking hacks. The existing QMutexLocker::unlock() calls are thereby eliminated. The following table contains the average results of the benchmark tst_QMimeDatabase::benchMimeTypeForFile() on my GNU/Linux system before and at this commit. The numbers denote milliseconds per iteration. This commit does not measurably affect performance when mode == MatchExtension, therefore the MatchExtension section contains a single column with results common to both commits (it is interesting to compare benchmark results across match modes). data row tag before at MatchDefault: archive 0.012 0.010 OpenDocument Text 0.012 0.010 existent archive with extension 0.022 0.018 existent C with extension 0.016 0.012 existent text file with extension 0.017 0.012 existent C w/o extension 0.072 0.067 existent patch w/o extension 0.10 0.10 existent archive w/o extension 0.064 0.060 MatchExtension: archive 0.0081 OpenDocument Text 0.0076 existent archive with extension 0.012 existent C with extension 0.0075 existent text file with extension 0.0076 existent C w/o extension 0.0122 existent patch w/o extension 0.0091 existent archive w/o extension 0.0091 MatchContent: archive 0.0098 0.0078 OpenDocument Text 0.0098 0.0078 existent archive with extension 0.051 0.047 existent C with extension 0.051 0.047 existent text file with extension 0.053 0.049 existent C w/o extension 0.058 0.054 existent patch w/o extension 0.099 0.095 existent archive w/o extension 0.054 0.050 Change-Id: I01b37c9645f0d8d35fd1a6ea1c7a99be2faeeb73 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: David Faure <david.faure@kdab.com>
* Use QList instead of QVector in corelibJarek Kobus2020-06-251-1/+1
| | | | | | | | | | Applied to headers only. Source file to be changed separately. Omitted statemachine for now to avoid conflicts. Omitted qmetatype.h for now - to be handled later. Task-number: QTBUG-84469 Change-Id: I317376037a62467c313467d92955ad0b7473aa97 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Bump version to Qt 6Lars Knoll2019-05-141-0/+1
| | | | | | | | | | | | | | | | | | Needed to disable QT_NO_UNSHARABLE_CONTAINERS, as this triggers asserts. QMetaType also has some Qt 6 specific code disabled to get things to compile. Fix various details in autotests to accommodate for the changes with Qt 6. Add a workaround for black lists on macos, where QSysInfo::productType() now returns 'macos' and not 'osx' anymore. Change-Id: Ie26afb12a2aac36521472715934a7e34639ea4d0 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Use Q_DISABLE_COPY_MOVE for private classesFriedemann Kleint2018-12-121-1/+1
| | | | | Change-Id: I3cfcfba892ff4a0ab4e31f308620b445162bb17b Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* Merge remote-tracking branch 'origin/5.12' into devLiang Qi2018-10-251-2/+1
|\ | | | | | | | | | | | | | | | | Conflicts: src/corelib/animation/qpropertyanimation.cpp src/gui/image/qicon.cpp tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp Change-Id: I3698172b7b44ebb487cb38f50fd2c4a9f8a35b21
| * Modernize the "mimetype" featureLiang Qi2018-10-121-2/+1
| | | | | | | | | | | | Change-Id: I9b67c2cbc0891a38ece18d521c86fbc7344dce7a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* | Use std::unique_ptr for memory management in QMimeDataBasePrivateIvan Komissarov2018-10-221-1/+3
| | | | | | | | | | | | | | | | This change simplifies memory management as long as it doesn't requires manuall calls to qDeleteAll and manual deleting/nulling pointers. Change-Id: Id0dc563d0b1e74ae33939d90d4b39999020cd7ce Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* | Use a std::vector instead of a QVector in QMimeDatabasePrivateIvan Komissarov2018-09-291-2/+3
|/ | | | | | | | | | Using std::vector saves a bit c++ code when using range-for loop over the vector. Besides, no shared copies created anymore which is a bit faster. Change-Id: I564306ed9ac907e9f32f59b33ed15c027a59b4eb Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeDatabase: redesign to use both binary and XML providersDavid Faure2017-11-301-5/+8
| | | | | | | | | | | | | | | | | | | | | | Previously, we would use mime.cache in all mime directories if at least one of them had such a file (other than the most-local one), otherwise the "source" XML would be used in all directories. Now it's possible to use mime.cache in those directories which have one, and XML in those directories that don't. Not only is this more correct, it will allow in a subsequent commit to bundle the binary cache in QtCore's qrc rather than the very big XML file. The design change to allow this is that now every provider only deals with a single directory, and QMimeDatabasePrivate takes care of creating multiple providers, one for each dir. This required to move most of the loops from the binary provider up to QMimeDatabasePrivate itself. Change-Id: Iac82d5f5836b80d45076e586b903d16fa2525b34 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: move recheck test up from the mime providersDavid Faure2017-11-301-0/+3
| | | | | | | | | | This is actually simpler (two calls to ensureLoaded are enough, rather than one in every implementation method) and is necessary for further refactoring steps (which will instanciate more provider instances). Change-Id: I9fb8acf3556515babecb88ba88e25af43937af5a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: ensure mutex is locked in provider()David Faure2017-11-301-3/+14
| | | | | | | | This wasn't the case when called from QMimeType, or some QMimeDatabase methods. Now fixed. Change-Id: Ifd515c1520482e4a23c399f1f773269659c92359 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: fix handling of conflicting globsDavid Faure2016-12-271-1/+1
| | | | | | | | | | | | | | | | | | | This code always intended to follow the recommended checking order from the spec, which says "if multiple globs match, use file contents". But if the globs had different weights, it would discard globs with lower weights, and then wrongly conclude, if there is only one glob left, that there was no ambiguity. The correct way is rather: remember that multiple globs matched, do determination from contents, and if that didn't work, *then* use (one of) the highest-weight glob(s). This fixes PGP-encrypted *.asc files being detected as text/plain rather than application/pgp-encrypted. (https://bugs.kde.org/show_bug.cgi?id=346754) Change-Id: I734459daf9f502baa95ebb89432819964e0ce304 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.5' into 5.6Liang Qi2015-10-021-0/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: qmake/doc/src/qmake-manual.qdoc src/corelib/tools/qstring.h src/gui/image/qimagereader.cpp src/network/access/qnetworkaccessmanager.cpp src/tools/qdoc/doc/examples/examples.qdoc src/widgets/accessible/qaccessiblewidgetfactory_p.h src/widgets/doc/qtwidgets.qdocconf Change-Id: I8fae62283aebefe24e5ca4b4abd97386560c0fcb
| * QMimeType: add KDAB copyright to the code I contributed a lot to.David Faure2015-09-041-0/+1
| | | | | | | | | | Change-Id: I794259f28c7adbaad3cfb40f92a0ad2dc512e5b4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Remove <qhash.h> where it's not usedMarc Mutz2015-04-201-1/+0
|/ | | | | | | | To avoid source-incompatibilites, wrap in QT_DEPRECATED_SINCE(5, 5) in public headers. Change-Id: I6117e8a6b11200d2f1a0a94a0e87d5c27538218e Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Introduce QT_NO_MIMETYPESérgio Martins2015-02-171-4/+8
| | | | | | | | | | | | | The mime type stuff generates one of the biggest translation units in QtCore due to the compressed 1.7MB freedesktop.org.xml resource. With QT_NO_MIMETYPE, libQt5Core.so is almost 400Kb smaller (4.8MB->4.4MB gcc 4.9 stripped release build) Change-Id: I5339090994034355724ff4deddb64720e81baeaf Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Fix build error without precompiled headersThiago Macieira2014-12-201-0/+1
| | | | | | | | qstringlist.h no longer includes qiodevice.h Change-Id: I08b83400316cb0b43bde0b390a9430e589e79e10 Reviewed-by: Robin Burchell <robin.burchell@viroteck.net> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* Add missing private headers warningSamuel Gaist2014-09-041-0/+11
| | | | | Change-Id: I7a4dd22ea3bcebf4c3ec3ad731628fd8f3c247e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Rename QMimeDatabase method for consistency.David Faure2012-05-151-1/+1
| | | | | | | | Name is about mimetype names, while FileName is about, well, file names. Task-number: QTBUG-25748 Change-Id: I34a9ac1a5fc06dc3e3855365e19c4dc7a1aa2671 Reviewed-by: Wolf-Michael Bolle <wolf-michael.bolle@nokia.com>
* Remove extra lines in mimetypesABBAPOH2012-04-011-1/+0
| | | | | Change-Id: Ic7ec295b2a0b23a21f44f880f29df13503f8ef3a Reviewed-by: David Faure <faure@kde.org>
* Import QMimeType / QMimeDatabase into QtCore.David Faure2012-02-181-0/+90
History of the development before the import: ssh://codereview.qt-project.org/playground/mimetypes.git Mimetype definitions come from shared-mime-info where available (UNIX systems), loaded using a mmap'ed binary cache generated by update-mime-database. As a fallback if no cache is found, we parse the raw XML files otherwise. This makes the MIME type support fast and with very low memory usage on UNIX, and it makes it easy to use on Windows (no dependency on shared-mime-info, Qt even includes a freedesktop.xml file to use if none are found on the system). Change-Id: I27b05008216ff936dc463bd80d3893422bfb940e Reviewed-by: Richard J. Moore <rich@kde.org>