summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes/qmimeprovider_p.h
Commit message (Collapse)AuthorAgeFilesLines
* QMimeBinaryProvider: cut out the QMap middle-manMarc Mutz2024-02-091-2/+3
| | | | | | | | | | | | | | | | | | | | | | In Qt 6, QMap is just a shared pointer to a std::map. QMimeBinaryProvider::m_mimetypeExtra is never copied, though, so the implicit sharing that QMap adds on top of std::map is useless. Use the underlying std::map directly. Yes, the std::map API is a bit raw around the edges (std::pair value_type), but we're professionals here. Saves more than 1.7KiB in TEXT size on optimized AMD64 GCC 11 C++20 Linux builds. As a drive-by, cut out the insertIt temporary, too, and assign directly to `it`. Change-Id: If3fd98a7e7017909d00b8725f8c252b19459d5b6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeDatabase: introduce QMimeMagicResult to accumulate magic resultsDavid Faure2023-09-131-3/+11
| | | | | | | | | | Better than two pointer parameters. However it can't be a return value as we initially thought, it's an in/out parameter, in order to compare the results in the current directory with those found in earlier directories. Change-Id: Ic6137f2627703f8d6930c3f7dd1a1102187eef30 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: fix glob-deleteall support for the binary providersDavid Faure2023-09-131-30/+6
| | | | | | | | | | | This fixes the recently added QEXPECT_FAIL about glob-deleteall in a local directory (with a binary cache). Before adding a glob match we ask the more-local (higher-precedence) directories if they have a glob-deleteall for that mimetype, and skip it then. This "asking" is a virtual method, implemented for both XML and binary providers. Change-Id: I6e4baf0120749f3331fd2d9254bea750a322b72d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeDatabase: collect glob patterns from all locationsDavid Faure2023-09-131-21/+35
| | | | | | | | | | | | | | | | | | | 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: fix detection of pattern conflict in different prefixesDavid Faure2023-09-011-1/+2
| | | | | | | | | | Installing a second mimetype with *.txt as glob had a different effect depending on whether it was installed into the same prefix or a different prefix as the one where text/plain is installed. Pick-to: 6.6 Change-Id: I7f54b8efe22f620eb57257745c48fe5402c87626 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeProvider: fix a clazy warningAhmad Samir2023-05-071-0/+2
| | | | | | | | Polymorphic class QMimeXMLProvider is copyable. Potential slicing. [-Wclazy-copyable-polymorphic]. Change-Id: I1eff1389140ce9426db32a37df89935a7b3db3a5 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* QMimeBinaryProvider: manage m_cacheFile with a std::unique_ptrAhmad Samir2023-05-071-1/+1
| | | | | Change-Id: Ic68772a75c255a3a2880fa49b2456c34e3153493 Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeDatabase: handle glob-deleteall tagsAhmad Samir2023-05-071-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | According to the Freedesktop spec[1], a mimetype that has glob-deleteall overwrites other glob-pattern definitions for a mimetype if it is in a higher precedence dir, the default order is (from high to low) ~/.local/share/mime, /usr/local/share/mime, /usr/share/mime. Or if the XDG_DATA_DIRS env var is set, then it takes precedence. The QMime*ProviderS in m_providers are constructed/stored in that same order, high to low). For QMimeXMLProvider, we can just clear the glob patterns associated with those mimetypes from the lists/maps. For the QMimeBinaryProvider however, we can't change the binary (mmap'ed) cache file, instead check mimetype names against the exclusion list before modifying a QMimeGlobMatchResult. [1] https://specifications.freedesktop.org/shared-mime-info-spec/latest/ar01s02.html This test uses XDG_DATA_DIRS so only viable when USE_XDG_DATA_DIRS is defined. Fixes: QTBUG-101755 Pick-to: 6.5 Change-Id: Icadbdf1027155296377c5a6ab3be8e41b6668325 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Faure <david.faure@kdab.com>
* mimetypes/: port to qsizetypeAhmad Samir2023-04-151-1/+3
| | | | | | | | | | | | | | | Fixes compiler warnings about narrowing conversions. Found by compiling with clang and -Wshorten-64-to-32. Drive-by changes: - use range-for instead of an iterator based loop - use strlen("*.") instead of magic number 2 Pick-to: 6.5 Task-number: QTBUG-102461 Change-Id: I0bf2299049c0411ed496468238ca30b69946ffc2 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>
* QtCore: Replace remaining uses of QLatin1String with QLatin1StringViewSona Kurazyan2022-03-261-1/+1
| | | | | | | Task-number: QTBUG-98434 Change-Id: Ib7c5fc0aaca6ef33b93c7486e99502c555bf20bc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Core: Do not depend on transitive includesFabian Kosmale2022-03-171-0/+1
| | | | | Change-Id: I2c71188a4d27692a2d6ef1aa447b329627214b17 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* MIME providers: Make provider implementations finalEike Ziller2022-03-021-2/+2
| | | | | | | | | We do not derive from them, and making QMimeXMLProvider final avoids a warning about calling a virtual function from the constructor. Change-Id: I565c63eb555fabb3c98e7d284b54037b7a7194da Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeBinaryProvider: cache comments and globPatternsAlexander Volkov2021-06-171-1/+8
| | | | | | | | Avoid multiple re-reads of xml files, for example in dolphin, which displays MIME type comments as file types. Change-Id: Ia124930e2a1fdc99d8a4d160f2288a00f55e0e8e Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeDatabase: fix performance regression when using the internal XMLDavid Faure2020-09-181-0/+3
| | | | | | | | | That XML was parsed over and over again, because the QMimeXMLProvider was re-created instead of re-used. Pick-to: 5.15 Change-Id: I07ff005d3f238afc1490b69a58cf4815e67d418c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QMimeXMLProvider: fix another issue with -no-mimetype-databaseThiago Macieira2020-03-031-4/+1
| | | | | | | | | | | The compiler must emit the destructor for the members of a class in an inline constructor, in case the constructor throws. This won't work in Qt 5.15 due to QList requiring knowing whether QMimeMagicRuleMatcher is trivial or not. Another solution would be to use QVector. Fixes: QTBUG-82547 Change-Id: Ia8b65350cd5d49debca9fffd15f79db872ed7c0c Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeXMLProvider: add missing semi-colon in the #else caseThiago Macieira2020-02-271-1/+1
| | | | | | Fixes: QTBUG-82547 Change-Id: Ia8b65350cd5d49debca9fffd15f74e22c0536805 Reviewed-by: David Faure <david.faure@kdab.com>
* MIME: Make the internal database direct content, not a Qt resourceThiago Macieira2019-12-101-0/+11
| | | | | | | | | | | | | | | | | | | | | | This saves us from having to bootstrap rcc in regular (non-cross) compilations, as it can now link to QtCore. Actually un-bootstrapping rcc is left as an exercise for the reader. This commit discovered that MSVC cannot handle constexpr arrays bigger than 256 kB, at which point it simply starts claiming that the constant expressions using it are not constexpr. ICC has a similar problem at 64 kB, but it tells you why ("note: type "const unsigned char [65537]" too large for constant-expression evaluation"). Note also that this requires gzip or zstd to be in PATH for compression to happen. RCC linked to zlib, which is always present due to the bundled copy. gzip's presence is not likely to be a problem on Unix systems, but could be for Windows users, especially MSVC ones. If gzip is not present, QtCore's size will increase by about 1910 kB of read-only (sharable) data. Change-Id: I2b1955a995ad40f3b89afffd15a3e65a94670242 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* 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>
* | Fix a few overrides in Qt CoreAlessandro Portale2018-09-251-8/+8
|/ | | | | | | | | | | | | | | | This change removes redundant 'virtual' from function declarations. Clang Tidy's modernize-use-override check reports: warning: 'virtual' is redundant since the function is already declared 'override' CppCoreGuidelines say: C.128: Virtual functions should specify exactly one of virtual, override, or final Change-Id: I9a4bdd6cc041d46ae64b25597ba4f7268ac4c2b7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Kevin Funk <kevin.funk@kdab.com>
* QMimeDatabase: redesign to use both binary and XML providersDavid Faure2017-11-301-27/+24
| | | | | | | | | | | | | | | | | | | | | | 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-8/+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>
* Replace Q_DECL_OVERRIDE with override where possibleKevin Funk2017-09-191-19/+19
| | | | | | | | | | | | | | | | Remaining uses of Q_DECL_OVERRIDE are in: src/corelib/global/qcompilerdetection.h src/corelib/global/qglobal.cpp doc/global/qt-cpp-defines.qdocconf (definition and documentation of Q_DECL_OVERRIDE) tests/manual/qcursor/qcursorhighdpi/main.cpp (a test executable compilable both under Qt4 and Qt5) Change-Id: Ib9b05d829add69e98a86238274b6a1fcb19b49ba Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QMimeBinaryProvider: avoid QString creation just to check for isEmpty()Marc Mutz2017-03-031-1/+1
| | | | | | | | | | | Return a QLatin1String instead and only if that is not empty, convert it into a QString. Also saves 320B in text size on optimized GCC 6.1 AMD64 Linux builds. Change-Id: I5432d213a6200e45414626bedb9f216bafaf1108 Reviewed-by: David Faure <david.faure@kdab.com>
* QMimeDatabase: fix handling of conflicting globsDavid Faure2016-12-271-3/+4
| | | | | | | | | | | | | | | | | | | 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>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-10-171-0/+1
|\ | | | | | | | | | | | | | | Conflicts: mkspecs/macx-ios-clang/features/resolve_config.prf src/testlib/qtestcase.qdoc Change-Id: Icefa63056ffb37106f35299a8f19165535571799
| * QMimeXMLProvider: add missing out-of-line destructorJ-P Nurmi2016-10-131-0/+1
| | | | | | | | | | | | | | | | Fixes build with the latest GCC 7. Change-Id: I4900a256ed1c6cb177d7f94d54e5b07c06ddad08 Task-number: QTBUG-56514 Reviewed-by: Marc Mutz <marc.mutz@kdab.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>
* 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>
* QMimeDatabase: use QElapsedTimer instead of QDateTime::currentDateTime()David Faure2015-08-121-1/+2
| | | | | | | | This reduces the number of syscalls greatly, by avoiding the timezone conversion every time. Change-Id: I39a54def4b45f25c6e037ced6943b05ddc749c9d Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
* Introduce QT_NO_MIMETYPESérgio Martins2015-02-171-1/+5
| | | | | | | | | | | | | 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>
* Add Q_DECL_OVERRIDE in the src subdirectoryOlivier Goffart2014-12-031-19/+19
| | | | | | | | | | Done automatically with clang-modernize on linux (But does not add Q_DECL_OVERRIDE to the function that are marked as inline because it a compilation error with MSVC2010) Change-Id: I2196ee26e3e6fe20816834ecea5ea389eeab3171 Reviewed-by: Thiago Macieira <thiago.macieira@intel.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>
* Add QMimeType::aliases().David Faure2012-11-221-0/+3
| | | | | | | | | Requested by Allan Sandfeld Jensen for QWebkit, which needs to register upfront all the mimetypes that a given plugin can handle. Change-Id: I64b8d39c7988adfc7db4ed8bfdc73acd16e999da Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.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>
* Import QMimeType / QMimeDatabase into QtCore.David Faure2012-02-181-0/+165
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>