summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarch <ABBAPOH@nextmail.ru>2012-02-26 11:26:10 +0400
committerDavid Faure <faure@kde.org>2012-02-26 10:32:35 +0100
commit466e001efe56c9419c4e3e1fabbd96c3600fee39 (patch)
tree04bb904dda665ce400e6dc5f7b93328278241a3f
parentd71f43b6c75fe114734101b3920a8e6d972c7f71 (diff)
Code is synced with qt5 code.
Change-Id: I550b4eeb15caab9641b0de892e2d5680e8ecaa0a Reviewed-by: David Faure <faure@kde.org>
-rw-r--r--src/imports/mimetypes/qdeclarativemimedatabase.cpp8
-rw-r--r--src/imports/mimetypes/qdeclarativemimetype.cpp8
-rw-r--r--src/mimetypes/mimetypes.pro6
-rw-r--r--src/mimetypes/qmimedatabase.cpp238
-rw-r--r--src/mimetypes/qmimedatabase.h58
-rw-r--r--src/mimetypes/qmimedatabase_p.h57
-rw-r--r--src/mimetypes/qmimeglobpattern.cpp59
-rw-r--r--src/mimetypes/qmimeglobpattern_p.h77
-rw-r--r--src/mimetypes/qmimemagicrule.cpp82
-rw-r--r--src/mimetypes/qmimemagicrule_p.h53
-rw-r--r--src/mimetypes/qmimemagicrulematcher.cpp51
-rw-r--r--src/mimetypes/qmimemagicrulematcher_p.h54
-rw-r--r--src/mimetypes/qmimeprovider.cpp164
-rw-r--r--src/mimetypes/qmimeprovider_p.h60
-rw-r--r--src/mimetypes/qmimetype.cpp158
-rw-r--r--src/mimetypes/qmimetype.h65
-rw-r--r--src/mimetypes/qmimetype_p.h69
-rw-r--r--src/mimetypes/qmimetypeparser.cpp (renamed from src/mimetypes/mimetypeparser.cpp)113
-rw-r--r--src/mimetypes/qmimetypeparser_p.h (renamed from src/mimetypes/mimetypeparser_p.h)88
19 files changed, 865 insertions, 603 deletions
diff --git a/src/imports/mimetypes/qdeclarativemimedatabase.cpp b/src/imports/mimetypes/qdeclarativemimedatabase.cpp
index 18bdf48..fa05a84 100644
--- a/src/imports/mimetypes/qdeclarativemimedatabase.cpp
+++ b/src/imports/mimetypes/qdeclarativemimedatabase.cpp
@@ -47,10 +47,10 @@
// ------------------------------------------------------------------------------------------------
-extern bool isQMimeDatabaseDebuggingActivated;
+extern bool qt_isQMimeDatabaseDebuggingActivated;
#ifndef QT_NO_DEBUG_OUTPUT
-#define DBG() if (isQMimeDatabaseDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
+#define DBG() if (qt_isQMimeDatabaseDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#else
#define DBG() if (0) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#endif
@@ -206,14 +206,14 @@ QMimeDatabase &QDeclarativeMimeDatabase::mimeDatabase()
bool QDeclarativeMimeDatabase::isDebuggingActivated() const
{
- return isQMimeDatabaseDebuggingActivated;
+ return qt_isQMimeDatabaseDebuggingActivated;
}
// ------------------------------------------------------------------------------------------------
void QDeclarativeMimeDatabase::setIsDebuggingActivated(const bool newIsDebuggingActivated)
{
- isQMimeDatabaseDebuggingActivated = newIsDebuggingActivated;
+ qt_isQMimeDatabaseDebuggingActivated = newIsDebuggingActivated;
}
// ------------------------------------------------------------------------------------------------
diff --git a/src/imports/mimetypes/qdeclarativemimetype.cpp b/src/imports/mimetypes/qdeclarativemimetype.cpp
index 24dbe59..4e5504b 100644
--- a/src/imports/mimetypes/qdeclarativemimetype.cpp
+++ b/src/imports/mimetypes/qdeclarativemimetype.cpp
@@ -46,10 +46,10 @@
// ------------------------------------------------------------------------------------------------
-extern bool isQMimeTypeDebuggingActivated;
+extern bool qt_isQMimeTypeDebuggingActivated;
#ifndef QT_NO_DEBUG_OUTPUT
-#define DBG() if (isQMimeTypeDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
+#define DBG() if (qt_isQMimeTypeDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#else
#define DBG() if (0) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#endif
@@ -406,14 +406,14 @@ bool QDeclarativeMimeType::isValid() const
bool QDeclarativeMimeType::isDebuggingActivated() const
{
- return isQMimeTypeDebuggingActivated;
+ return qt_isQMimeTypeDebuggingActivated;
}
// ------------------------------------------------------------------------------------------------
void QDeclarativeMimeType::setIsDebuggingActivated(const bool newIsDebuggingActivated)
{
- isQMimeTypeDebuggingActivated = newIsDebuggingActivated;
+ qt_isQMimeTypeDebuggingActivated = newIsDebuggingActivated;
}
// ------------------------------------------------------------------------------------------------
diff --git a/src/mimetypes/mimetypes.pro b/src/mimetypes/mimetypes.pro
index aaccfb7..abe8dc1 100644
--- a/src/mimetypes/mimetypes.pro
+++ b/src/mimetypes/mimetypes.pro
@@ -13,14 +13,12 @@ CONFIG += depend_includepath
QT = core
-DEFINES += QT_NO_CAST_FROM_ASCII
-
QMAKE_CXXFLAGS += -W -Wall -Wextra -Werror -Wshadow -Wno-long-long -Wnon-virtual-dtor
SOURCES += qmimedatabase.cpp \
qmimetype.cpp \
qmimemagicrulematcher.cpp \
- mimetypeparser.cpp \
+ qmimetypeparser.cpp \
qmimemagicrule.cpp \
qmimeglobpattern.cpp \
qmimeprovider.cpp
@@ -32,7 +30,7 @@ the_includes.files += qmime_global.h \
HEADERS += $$the_includes.files \
qmimemagicrulematcher_p.h \
qmimetype_p.h \
- mimetypeparser_p.h \
+ qmimetypeparser_p.h \
qmimedatabase_p.h \
qmimemagicrule_p.h \
qmimeglobpattern_p.h \
diff --git a/src/mimetypes/qmimedatabase.cpp b/src/mimetypes/qmimedatabase.cpp
index 1139e00..a7e14ee 100644
--- a/src/mimetypes/qmimedatabase.cpp
+++ b/src/mimetypes/qmimedatabase.cpp
@@ -1,27 +1,53 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#include "qmimedatabase.h" // Basis
+#include <qplatformdefs.h> // always first
+
+#include "qmimedatabase.h"
#include "qmimedatabase_p.h"
+#include "qmimeprovider_p.h"
+#include "qmimetype_p.h"
+
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QSet>
@@ -29,79 +55,62 @@
#include <QtCore/QUrl>
#include <QtCore/QStack>
#include <QtCore/QDebug>
-#include <qplatformdefs.h>
#include <algorithm>
#include <functional>
-#include "qmimeprovider_p.h"
-#include "qmimetype_p.h"
-
QT_BEGIN_NAMESPACE
-// ------------------------------------------------------------------------------------------------
-
-bool isQMimeDatabaseDebuggingActivated (false);
+bool qt_isQMimeDatabaseDebuggingActivated (false);
#ifndef QT_NO_DEBUG_OUTPUT
-#define DBG() if (isQMimeDatabaseDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
+#define DBG() if (qt_isQMimeDatabaseDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#else
#define DBG() if (0) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#endif
-// ------------------------------------------------------------------------------------------------
-
Q_GLOBAL_STATIC(QMimeDatabasePrivate, staticQMimeDatabase)
-// ------------------------------------------------------------------------------------------------
-
QMimeDatabasePrivate *QMimeDatabasePrivate::instance()
{
return staticQMimeDatabase();
}
-// ------------------------------------------------------------------------------------------------
-
QMimeDatabasePrivate::QMimeDatabasePrivate()
: m_provider(0), m_defaultMimeType(QLatin1String("application/octet-stream"))
{
}
-// ------------------------------------------------------------------------------------------------
-
QMimeDatabasePrivate::~QMimeDatabasePrivate()
{
delete m_provider;
m_provider = 0;
}
-// ------------------------------------------------------------------------------------------------
-
QMimeProviderBase *QMimeDatabasePrivate::provider()
{
if (!m_provider) {
QMimeProviderBase *binaryProvider = new QMimeBinaryProvider(this);
- if (binaryProvider->isValid())
+ if (binaryProvider->isValid()) {
m_provider = binaryProvider;
- else {
- delete m_provider;
+ } else {
+ delete binaryProvider;
m_provider = new QMimeXMLProvider(this);
}
}
return m_provider;
}
-// ------------------------------------------------------------------------------------------------
-
void QMimeDatabasePrivate::setProvider(QMimeProviderBase *theProvider)
{
delete m_provider;
m_provider = theProvider;
}
-// ------------------------------------------------------------------------------------------------
-
-// Returns a MIME type or an invalid one if none found
+/*!
+ \internal
+ Returns a MIME type or an invalid one if none found
+ */
QMimeType QMimeDatabasePrivate::mimeTypeForName(const QString &nameOrAlias)
{
return provider()->mimeTypeForName(provider()->resolveAlias(nameOrAlias));
@@ -116,8 +125,6 @@ QStringList QMimeDatabasePrivate::mimeTypeForFileName(const QString &fileName, Q
return matchingMimeTypes;
}
-// ------------------------------------------------------------------------------------------------
-
static inline bool isTextFile(const QByteArray &data)
{
// UTF16 byte order marks
@@ -137,8 +144,6 @@ static inline bool isTextFile(const QByteArray &data)
return true;
}
-// ------------------------------------------------------------------------------------------------
-
QMimeType QMimeDatabasePrivate::findByData(const QByteArray &data, int *accuracyPtr)
{
if (data.isEmpty()) {
@@ -160,8 +165,6 @@ QMimeType QMimeDatabasePrivate::findByData(const QByteArray &data, int *accuracy
return mimeTypeForName(defaultMimeType());
}
-// ------------------------------------------------------------------------------------------------
-
QMimeType QMimeDatabasePrivate::mimeTypeForNameAndData(const QString &fileName, QIODevice *device, int *accuracyPtr)
{
// First, glob patterns are evaluated. If there is a match with max weight,
@@ -183,21 +186,21 @@ QMimeType QMimeDatabasePrivate::mimeTypeForNameAndData(const QString &fileName,
// Extension is unknown, or matches multiple mimetypes.
// Pass 2) Match on content, if we can read the data
- if (device->isOpen() || device->open(QIODevice::ReadOnly)) {
+ if (device->isOpen()) {
// Read 16K in one go (QIODEVICE_BUFFERSIZE in qiodevice_p.h).
// This is much faster than seeking back and forth into QIODevice.
- const QByteArray data = device->read(16384);
+ const QByteArray data = device->peek(16384);
int magicAccuracy = 0;
QMimeType candidateByData(findByData(data, &magicAccuracy));
- // Disambiguate conflicting extensions (if magic found something and the magicrule was < 80)
+ // Disambiguate conflicting extensions (if magic matching found something)
if (candidateByData.isValid() && magicAccuracy > 0) {
// "for glob_match in glob_matches:"
// "if glob_match is subclass or equal to sniffed_type, use glob_match"
const QString sniffedMime = candidateByData.name();
- foreach(const QString &m, candidatesByName) {
+ foreach (const QString &m, candidatesByName) {
if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match
*accuracyPtr = 100;
@@ -220,15 +223,11 @@ QMimeType QMimeDatabasePrivate::mimeTypeForNameAndData(const QString &fileName,
return mimeTypeForName(defaultMimeType());
}
-// ------------------------------------------------------------------------------------------------
-
QList<QMimeType> QMimeDatabasePrivate::allMimeTypes()
{
return provider()->allMimeTypes();
}
-// ------------------------------------------------------------------------------------------------
-
bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
{
const QString resolvedParent = provider()->resolveAlias(parent);
@@ -239,28 +238,29 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
const QString current = toCheck.pop();
if (current == resolvedParent)
return true;
- foreach(const QString &par, provider()->parents(current)) {
+ foreach (const QString &par, provider()->parents(current))
toCheck.push(par);
- }
}
return false;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\class QMimeDatabase
\brief The QMimeDatabase class maintains a database of MIME types.
+ \since 5.0
+
The MIME type database is provided by the freedesktop.org shared-mime-info
- project. If the MIME type database cannot be found on the system, Qt
- will use its own copy of it.
+ project. If the MIME type database cannot be found on the system, as is the case
+ on most Windows and Mac OS X systems, Qt will use its own copy of it.
Applications which want to define custom MIME types need to install an
XML file into the locations searched for MIME definitions.
These locations can be queried with
+ \code
QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/packages"),
- QStandardPaths::LocateDirectory);
+ QStandardPaths::LocateDirectory);
+ \endcode
On a typical Unix system, this will be /usr/share/mime/packages/, but it is also
possible to extend the list of directories by setting the environment variable
XDG_DATA_DIRS. For instance adding /opt/myapp/share to XDG_DATA_DIRS will result
@@ -287,16 +287,16 @@ bool QMimeDatabasePrivate::inherits(const QString &mime, const QString &parent)
in the above example. Make sure to run this command when installing the MIME type
definition file.
- The class is protected by a QMutex and can therefore be accessed by threads.
+ \threadsafe
+
+ \snippet doc/src/snippets/code/src_corelib_mimetype_qmimedatabase.cpp 0
\sa QMimeType
*/
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeDatabase::QMimeDatabase();
- \brief Constructs this QMimeDatabase object.
+ Constructs this QMimeDatabase object.
*/
QMimeDatabase::QMimeDatabase() :
d(staticQMimeDatabase())
@@ -304,11 +304,9 @@ QMimeDatabase::QMimeDatabase() :
DBG();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeDatabase::~QMimeDatabase();
- \brief Destroys the QMimeDatabase object, and resets the d pointer.
+ Destroys the QMimeDatabase object.
*/
QMimeDatabase::~QMimeDatabase()
{
@@ -317,23 +315,19 @@ QMimeDatabase::~QMimeDatabase()
d = 0;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
- \fn QMimeType QMimeDatabase::mimeTypeForName(const QString& nameOrAlias) const;
- \brief Returns a MIME type for \a nameOrAlias or an invalid one if none found.
+ \fn QMimeType QMimeDatabase::mimeTypeForName(const QString &nameOrAlias) const;
+ Returns a MIME type for \a nameOrAlias or an invalid one if none found.
*/
-QMimeType QMimeDatabase::mimeTypeForName(const QString& nameOrAlias) const
+QMimeType QMimeDatabase::mimeTypeForName(const QString &nameOrAlias) const
{
QMutexLocker locker(&d->mutex);
return d->mimeTypeForName(nameOrAlias);
}
-// ------------------------------------------------------------------------------------------------
-
/*!
- \brief Returns a MIME type for \a fileInfo.
+ Returns a MIME type for \a fileInfo.
A valid MIME type is always returned.
@@ -341,26 +335,26 @@ QMimeType QMimeDatabase::mimeTypeForName(const QString& nameOrAlias) const
contents, if necessary. The file extension has priority over the contents,
but the contents will be used if the file extension is unknown, or
matches multiple MIME types.
- If \a fileInfo is a unix symbolic link, the file that it refers to
+ If \a fileInfo is a Unix symbolic link, the file that it refers to
will be used instead.
If the file doesn't match any known pattern or data, the default MIME type
(application/octet-stream) is returned.
- When \a flags is set to MatchExtension, only the file name is used, not
+ When \a mode is set to MatchExtension, only the file name is used, not
the file contents. The file doesn't even have to exist. If the file name
doesn't match any known pattern, the default MIME type (application/octet-stream)
is returned.
If multiple MIME types match this file, the first one (alphabetically) is returned.
- When \a flags is set to MatchContent, and the file is readable, only the
+ When \a mode is set to MatchContent, and the file is readable, only the
file contents are used to determine the MIME type. This is equivalent to
calling mimeTypeForData with a QFile as input device.
In all cases, the \a fileName can also include an absolute or relative path.
- \sa isDefault
+ \sa isDefault, mimeTypeForData
*/
-QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchFlags flags) const
+QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode) const
{
DBG() << "fileInfo" << fileInfo.absoluteFilePath();
@@ -388,38 +382,42 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QFileInfo &fileInfo, MatchFlags f
#endif
int priority = 0;
- if (flags == MatchDefault) {
+ switch (mode) {
+ case MatchDefault:
+ file.open(QIODevice::ReadOnly); // isOpen() will be tested by method below
return d->mimeTypeForNameAndData(fileInfo.absoluteFilePath(), &file, &priority);
- } else if (flags == MatchExtension) {
+ case MatchExtension:
locker.unlock();
- return mimeTypeForFile(fileInfo.absoluteFilePath(), flags);
- } else { // MatchContent
+ return mimeTypeForFile(fileInfo.absoluteFilePath(), mode);
+ case MatchContent:
if (file.open(QIODevice::ReadOnly)) {
locker.unlock();
return mimeTypeForData(&file);
- } else
+ } else {
return d->mimeTypeForName(d->defaultMimeType());
+ }
+ default:
+ Q_ASSERT(false);
}
+ return d->mimeTypeForName(d->defaultMimeType());
}
-// ------------------------------------------------------------------------------------------------
-
/*!
- \brief Returns a MIME type for the file named \a fileName.
+ Returns a MIME type for the file named \a fileName using \a mode.
\overload
*/
-QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchFlags flags) const
+QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchMode mode) const
{
- if (flags == MatchExtension) {
+ if (mode == MatchExtension) {
QMutexLocker locker(&d->mutex);
QStringList matches = d->mimeTypeForFileName(fileName);
const int matchCount = matches.count();
- if (matchCount == 0)
+ if (matchCount == 0) {
return d->mimeTypeForName(d->defaultMimeType());
- else if (matchCount == 1)
+ } else if (matchCount == 1) {
return d->mimeTypeForName(matches.first());
- else {
+ } else {
// We have to pick one.
matches.sort(); // Make it deterministic
return d->mimeTypeForName(matches.first());
@@ -431,11 +429,9 @@ QMimeType QMimeDatabase::mimeTypeForFile(const QString &fileName, MatchFlags fla
}
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType QMimeDatabase::findMimeTypesByFileName(const QString &fileName) const;
- \brief Returns the MIME types for the file name \a fileName.
+ Returns the MIME types for the file name \a fileName.
If the file name doesn't match any known pattern, an empty list is returned.
If multiple MIME types match this file, they are all returned.
@@ -453,13 +449,10 @@ QList<QMimeType> QMimeDatabase::mimeTypesForFileName(const QString &fileName) co
QStringList matches = d->mimeTypeForFileName(fileName);
QList<QMimeType> mimes;
matches.sort(); // Make it deterministic
- foreach (const QString& mime, matches) {
+ foreach (const QString &mime, matches)
mimes.append(d->mimeTypeForName(mime));
- }
return mimes;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns the suffix for the file \a fileName, as known by the MIME database.
@@ -474,8 +467,6 @@ QString QMimeDatabase::suffixForFileName(const QString &fileName) const
return foundSuffix;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns a MIME type for \a data.
@@ -491,8 +482,6 @@ QMimeType QMimeDatabase::mimeTypeForData(const QByteArray &data) const
return d->findByData(data, &accuracy);
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns a MIME type for the data in \a device.
@@ -500,28 +489,33 @@ QMimeType QMimeDatabase::mimeTypeForData(const QByteArray &data) const
known MIME type data, the default MIME type (application/octet-stream)
is returned.
*/
-QMimeType QMimeDatabase::mimeTypeForData(QIODevice* device) const
+QMimeType QMimeDatabase::mimeTypeForData(QIODevice *device) const
{
QMutexLocker locker(&d->mutex);
int accuracy = 0;
- if (device->isOpen() || device->open(QIODevice::ReadOnly)) {
+ const bool openedByUs = !device->isOpen() && device->open(QIODevice::ReadOnly);
+ if (device->isOpen()) {
// Read 16K in one go (QIODEVICE_BUFFERSIZE in qiodevice_p.h).
// This is much faster than seeking back and forth into QIODevice.
- const QByteArray data = device->read(16384);
- return d->findByData(data, &accuracy);
+ const QByteArray data = device->peek(16384);
+ const QMimeType result = d->findByData(data, &accuracy);
+ if (openedByUs)
+ device->close();
+ return result;
}
return d->mimeTypeForName(d->defaultMimeType());
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns a MIME type for \a url.
- If the url is a local file, this calls mimeTypeForFile.
- Otherwise the matching is done based on the name only
- (except over schemes where filenames don't mean much, like HTTP)
+ If the URL is a local file, this calls mimeTypeForFile.
+
+ Otherwise the matching is done based on the file name only,
+ except for schemes where file names don't mean much, like HTTP.
+ This method always returns the default mimetype for HTTP URLs,
+ use QNetworkAccessManager to handle HTTP URLs properly.
A valid MIME type is always returned. If \a url doesn't match any
known MIME type data, the default MIME type (application/octet-stream)
@@ -529,14 +523,8 @@ QMimeType QMimeDatabase::mimeTypeForData(QIODevice* device) const
*/
QMimeType QMimeDatabase::mimeTypeForUrl(const QUrl &url) const
{
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
if (url.isLocalFile())
return mimeTypeForFile(url.toLocalFile());
-#else
- QString localFile(url.toLocalFile());
- if (!localFile.isEmpty())
- return mimeTypeForFile(localFile);
-#endif
const QString scheme = url.scheme();
if (scheme.startsWith(QLatin1String("http")))
@@ -545,8 +533,6 @@ QMimeType QMimeDatabase::mimeTypeForUrl(const QUrl &url) const
return mimeTypeForFile(url.path());
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns a MIME type for the given \a fileName and \a device data.
@@ -554,6 +540,9 @@ QMimeType QMimeDatabase::mimeTypeForUrl(const QUrl &url) const
download some of its data in a device. This allows to do full MIME type
matching for remote files as well.
+ If the device is not open, it will be opened by this function, and closed
+ after the MIME type detection is completed.
+
A valid MIME type is always returned. If \a device data doesn't match any
known MIME type data, the default MIME type (application/octet-stream)
is returned.
@@ -568,11 +557,13 @@ QMimeType QMimeDatabase::mimeTypeForNameAndData(const QString &fileName, QIODevi
DBG() << "fileName" << fileName;
int accuracy = 0;
- return d->mimeTypeForNameAndData(fileName, device, &accuracy);
+ const bool openedByUs = !device->isOpen() && device->open(QIODevice::ReadOnly);
+ const QMimeType result = d->mimeTypeForNameAndData(fileName, device, &accuracy);
+ if (openedByUs)
+ device->close();
+ return result;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns a MIME type for the given \a fileName and device \a data.
@@ -594,12 +585,11 @@ QMimeType QMimeDatabase::mimeTypeForNameAndData(const QString &fileName, const Q
DBG() << "fileName" << fileName;
QBuffer buffer(const_cast<QByteArray *>(&data));
+ buffer.open(QIODevice::ReadOnly);
int accuracy = 0;
return d->mimeTypeForNameAndData(fileName, &buffer, &accuracy);
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Returns the list of all available MIME types.
@@ -614,8 +604,6 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
return d->allMimeTypes();
}
-// ------------------------------------------------------------------------------------------------
-
#undef DBG
QT_END_NAMESPACE
diff --git a/src/mimetypes/qmimedatabase.h b/src/mimetypes/qmimedatabase.h
index 0418ea1..de9c6ca 100644
--- a/src/mimetypes/qmimedatabase.h
+++ b/src/mimetypes/qmimedatabase.h
@@ -1,33 +1,53 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#ifndef QMIMEDATABASE_H_INCLUDED
-#define QMIMEDATABASE_H_INCLUDED
+
+#ifndef QMIMEDATABASE_H
+#define QMIMEDATABASE_H
#include "qmime_global.h"
#include "qmimetype.h"
-#include <QtCore/QStringList>
-
-// ------------------------------------------------------------------------------------------------
+#include <QtCore/qstringlist.h>
QT_BEGIN_NAMESPACE
@@ -36,7 +56,7 @@ class QFileInfo;
class QIODevice;
class QUrl;
-struct QMimeDatabasePrivate;
+class QMimeDatabasePrivate;
class QMIME_EXPORT QMimeDatabase
{
Q_DISABLE_COPY(QMimeDatabase)
@@ -47,14 +67,14 @@ public:
QMimeType mimeTypeForName(const QString &nameOrAlias) const;
- enum MatchFlags {
+ enum MatchMode {
MatchDefault = 0x0,
MatchExtension = 0x1,
MatchContent = 0x2
};
- QMimeType mimeTypeForFile(const QString &fileName, MatchFlags flags = MatchDefault) const;
- QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchFlags flags = MatchDefault) const;
+ QMimeType mimeTypeForFile(const QString &fileName, MatchMode mode = MatchDefault) const;
+ QMimeType mimeTypeForFile(const QFileInfo &fileInfo, MatchMode mode = MatchDefault) const;
QList<QMimeType> mimeTypesForFileName(const QString &fileName) const;
QMimeType mimeTypeForData(const QByteArray &data) const;
@@ -74,4 +94,4 @@ private:
QT_END_NAMESPACE
-#endif // QMIMEDATABASE_H_INCLUDED
+#endif // QMIMEDATABASE_H
diff --git a/src/mimetypes/qmimedatabase_p.h b/src/mimetypes/qmimedatabase_p.h
index f2d4220..7e98548 100644
--- a/src/mimetypes/qmimedatabase_p.h
+++ b/src/mimetypes/qmimedatabase_p.h
@@ -1,42 +1,63 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#ifndef QMIMEDATABASE_P_H_INCLUDED
-#define QMIMEDATABASE_P_H_INCLUDED
-#include <QtCore/QMultiHash>
-#include <QtCore/QMutex>
+#ifndef QMIMEDATABASE_P_H
+#define QMIMEDATABASE_P_H
+
+#include <QtCore/qhash.h>
+#include <QtCore/qmutex.h>
#include "qmimetype.h"
#include "qmimetype_p.h"
#include "qmimeglobpattern_p.h"
-// ------------------------------------------------------------------------------------------------
-
QT_BEGIN_NAMESPACE
class QMimeDatabase;
class QMimeProviderBase;
-struct QMimeDatabasePrivate
+class QMimeDatabasePrivate
{
+public:
Q_DISABLE_COPY(QMimeDatabasePrivate)
QMimeDatabasePrivate();
@@ -47,7 +68,7 @@ struct QMimeDatabasePrivate
QMimeProviderBase *provider();
void setProvider(QMimeProviderBase *theProvider);
- QString defaultMimeType() const { return m_defaultMimeType; }
+ inline QString defaultMimeType() const { return m_defaultMimeType; }
bool inherits(const QString &mime, const QString &parent);
@@ -66,4 +87,4 @@ struct QMimeDatabasePrivate
QT_END_NAMESPACE
-#endif // QMIMEDATABASE_P_H_INCLUDED
+#endif // QMIMEDATABASE_P_H
diff --git a/src/mimetypes/qmimeglobpattern.cpp b/src/mimetypes/qmimeglobpattern.cpp
index 61bb02a..de26dba 100644
--- a/src/mimetypes/qmimeglobpattern.cpp
+++ b/src/mimetypes/qmimeglobpattern.cpp
@@ -1,9 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#include "qmimeglobpattern_p.h"
#include <QRegExp>
#include <QStringList>
#include <QDebug>
+QT_BEGIN_NAMESPACE
+
/*!
\internal
\class QMimeGlobMatchResult
@@ -46,12 +89,12 @@ void QMimeGlobMatchResult::addMatch(const QString &mimeType, int weight, const Q
\sa QMimeType, QMimeDatabase, QMimeMagicRuleMatcher, QMimeMagicRule
*/
-bool QMimeGlobPattern::matchFileName(const QString& _filename) const
+bool QMimeGlobPattern::matchFileName(const QString &inputFilename) const
{
// "Applications MUST match globs case-insensitively, except when the case-sensitive
// attribute is set to true."
// The constructor takes care of putting case-insensitive patterns in lowercase.
- const QString filename = m_caseSensitivity == Qt::CaseInsensitive ? _filename.toLower() : _filename;
+ const QString filename = m_caseSensitivity == Qt::CaseInsensitive ? inputFilename.toLower() : inputFilename;
const int pattern_len = m_pattern.length();
if (!pattern_len)
@@ -96,7 +139,7 @@ bool QMimeGlobPattern::matchFileName(const QString& _filename) const
return rx.exactMatch(filename);
}
-static bool isFastPattern(const QString& pattern)
+static bool isFastPattern(const QString &pattern)
{
// starts with "*.", has no other '*' and no other '.'
return pattern.lastIndexOf(QLatin1Char('*')) == 0
@@ -107,13 +150,11 @@ static bool isFastPattern(const QString& pattern)
;
}
-void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern& glob)
+void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern &glob)
{
const QString &pattern = glob.pattern();
Q_ASSERT(!pattern.isEmpty());
- //kDebug() << "pattern" << pattern << "glob.weight=" << glob.weight() << "isFast=" << isFastPattern(pattern) << glob.flags;
-
// Store each patterns into either m_fastPatternDict (*.txt, *.html etc. with default weight 50)
// or for the rest, like core.*, *.tar.bz2, *~, into highWeightPatternOffset (>50)
// or lowWeightPatternOffset (<=50)
@@ -121,7 +162,7 @@ void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern& glob)
if (glob.weight() == 50 && isFastPattern(pattern) && !glob.isCaseSensitive()) {
// The bulk of the patterns is *.foo with weight 50 --> those go into the fast patterns hash.
const QString extension = pattern.mid(2).toLower();
- QStringList& patterns = m_fastPatterns[extension]; // find or create
+ QStringList &patterns = m_fastPatterns[extension]; // find or create
// This would just slow things down: if (!patterns.contains(glob.mimeType()))
patterns.append(glob.mimeType());
} else {
@@ -135,7 +176,7 @@ void QMimeAllGlobPatterns::addGlob(const QMimeGlobPattern& glob)
}
}
-void QMimeAllGlobPatterns::removeMimeType(const QString& mimeType)
+void QMimeAllGlobPatterns::removeMimeType(const QString &mimeType)
{
QMutableHashIterator<QString, QStringList> it(m_fastPatterns);
while (it.hasNext()) {
@@ -195,3 +236,5 @@ void QMimeAllGlobPatterns::clear()
m_highWeightGlobs.clear();
m_lowWeightGlobs.clear();
}
+
+QT_END_NAMESPACE
diff --git a/src/mimetypes/qmimeglobpattern_p.h b/src/mimetypes/qmimeglobpattern_p.h
index 1bea4c9..b64a0e2 100644
--- a/src/mimetypes/qmimeglobpattern_p.h
+++ b/src/mimetypes/qmimeglobpattern_p.h
@@ -1,8 +1,51 @@
-#ifndef QMIMEGLOBPATTERN_H
-#define QMIMEGLOBPATTERN_H
-
-#include <QStringList>
-#include <QHash>
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMIMEGLOBPATTERN_P_H
+#define QMIMEGLOBPATTERN_P_H
+
+#include <QtCore/qstringlist.h>
+#include <QtCore/qhash.h>
+
+QT_BEGIN_NAMESPACE
struct QMimeGlobMatchResult
{
@@ -10,7 +53,7 @@ struct QMimeGlobMatchResult
: m_weight(0), m_matchingPatternLength(0)
{}
- void addMatch(const QString& mimeType, int weight, const QString &pattern);
+ void addMatch(const QString &mimeType, int weight, const QString &pattern);
QStringList m_matchingMimeTypes;
int m_weight;
@@ -34,16 +77,12 @@ public:
}
~QMimeGlobPattern() {}
- bool matchFileName(const QString& filename) const;
+ bool matchFileName(const QString &filename) const;
- inline const QString& pattern() const
- { return m_pattern; }
- inline unsigned weight() const
- { return m_weight; }
- inline const QString& mimeType() const
- { return m_mimeType; }
- inline bool isCaseSensitive() const
- { return m_caseSensitivity == Qt::CaseSensitive; }
+ inline const QString &pattern() const { return m_pattern; }
+ inline unsigned weight() const { return m_weight; }
+ inline const QString &mimeType() const { return m_mimeType; }
+ inline bool isCaseSensitive() const { return m_caseSensitivity == Qt::CaseSensitive; }
private:
QString m_pattern;
@@ -55,7 +94,7 @@ private:
class QMimeGlobPatternList : public QList<QMimeGlobPattern>
{
public:
- bool hasPattern(const QString& mimeType, const QString& pattern) const
+ bool hasPattern(const QString &mimeType, const QString &pattern) const
{
const_iterator it = begin();
const const_iterator myend = end();
@@ -68,7 +107,7 @@ public:
/*!
"noglobs" is very rare occurrence, so it's ok if it's slow
*/
- void removeMimeType(const QString& mimeType)
+ void removeMimeType(const QString &mimeType)
{
QMutableListIterator<QMimeGlobPattern> it(*this);
while (it.hasNext()) {
@@ -102,4 +141,6 @@ public:
QMimeGlobPatternList m_lowWeightGlobs; // <= 50, including the non-fast 50 patterns
};
-#endif // QMIMEGLOBPATTERN_H
+QT_END_NAMESPACE
+
+#endif // QMIMEGLOBPATTERN_P_H
diff --git a/src/mimetypes/qmimemagicrule.cpp b/src/mimetypes/qmimemagicrule.cpp
index b1de084..1dee62f 100644
--- a/src/mimetypes/qmimemagicrule.cpp
+++ b/src/mimetypes/qmimemagicrule.cpp
@@ -1,22 +1,46 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#define QT_NO_CAST_FROM_ASCII
#include "qmimemagicrule_p.h"
@@ -47,7 +71,7 @@ QMimeMagicRule::Type QMimeMagicRule::type(const QByteArray &theTypeName)
{
for (int i = String; i <= Byte; ++i) {
if (theTypeName == magicRuleTypes_string + magicRuleTypes_indices[i])
- return static_cast<Type>(i);
+ return Type(i);
}
return Invalid;
}
@@ -57,8 +81,9 @@ QByteArray QMimeMagicRule::typeName(QMimeMagicRule::Type theType)
return magicRuleTypes_string + magicRuleTypes_indices[theType];
}
-struct QMimeMagicRulePrivate
+class QMimeMagicRulePrivate
{
+public:
bool operator==(const QMimeMagicRulePrivate &other) const;
QMimeMagicRule::Type type;
@@ -71,7 +96,7 @@ struct QMimeMagicRulePrivate
quint32 number;
quint32 numberMask;
- typedef bool (*MatchFunction)(QMimeMagicRulePrivate *d, const QByteArray &data);
+ typedef bool (*MatchFunction)(const QMimeMagicRulePrivate *d, const QByteArray &data);
MatchFunction matchFunction;
};
@@ -89,24 +114,16 @@ bool QMimeMagicRulePrivate::operator==(const QMimeMagicRulePrivate &other) const
}
// Used by both providers
-bool QMimeMagicRule::matchSubstring(const char* dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char* valueData, const char* mask)
+bool QMimeMagicRule::matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength,
+ int valueLength, const char *valueData, const char *mask)
{
- const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart);
-
-// callgrind says QByteArray::indexOf is much slower
-// #define WITH_BYTEARRAY
-#ifdef WITH_BYTEARRAY
// Size of searched data.
// Example: value="ABC", rangeLength=3 -> we need 3+3-1=5 bytes (ABCxx,xABCx,xxABC would match)
- const QByteArray searchedData = QByteArray::fromRawData(dataPtr + rangeStart, dataNeeded);
-#endif
+ const int dataNeeded = qMin(rangeLength + valueLength - 1, dataSize - rangeStart);
if (!mask) {
-#ifdef WITH_BYTEARRAY
- const QByteArray value = QByteArray::fromRawData(valueData, valueLength);
- if (searchedData.indexOf(value) == -1)
- return false;
-#else
+ // callgrind says QByteArray::indexOf is much slower, since our strings are typically too
+ // short for be worth Boyer-Moore matching (1 to 71 bytes, 11 bytes on average).
bool found = false;
for (int i = rangeStart; i < rangeStart + rangeLength; ++i) {
if (i + valueLength > dataSize)
@@ -119,17 +136,16 @@ bool QMimeMagicRule::matchSubstring(const char* dataPtr, int dataSize, int range
}
if (!found)
return false;
-#endif
} else {
bool found = false;
- const char* readDataBase = dataPtr + rangeStart;
+ const char *readDataBase = dataPtr + rangeStart;
// Example (continued from above):
// deviceSize is 4, so dataNeeded was max'ed to 4.
// maxStartPos = 4 - 3 + 1 = 2, and indeed
// we need to check for a match a positions 0 and 1 (ABCx and xABC).
const int maxStartPos = dataNeeded - valueLength + 1;
for (int i = 0; i < maxStartPos; ++i) {
- const char* d = readDataBase + i;
+ const char *d = readDataBase + i;
bool valid = true;
for (int idx = 0; idx < valueLength; ++idx) {
if (((*d++) & mask[idx]) != (valueData[idx] & mask[idx])) {
@@ -147,14 +163,14 @@ bool QMimeMagicRule::matchSubstring(const char* dataPtr, int dataSize, int range
return true;
}
-static bool matchString(QMimeMagicRulePrivate *d, const QByteArray &data)
+static bool matchString(const QMimeMagicRulePrivate *d, const QByteArray &data)
{
const int rangeLength = d->endPos - d->startPos + 1;
return QMimeMagicRule::matchSubstring(data.constData(), data.size(), d->startPos, rangeLength, d->pattern.size(), d->pattern.constData(), d->mask.constData());
}
template <typename T>
-static bool matchNumber(QMimeMagicRulePrivate *d, const QByteArray &data)
+static bool matchNumber(const QMimeMagicRulePrivate *d, const QByteArray &data)
{
const T value(d->number);
const T mask(d->numberMask);
@@ -297,7 +313,7 @@ QMimeMagicRule::~QMimeMagicRule()
{
}
-QMimeMagicRule& QMimeMagicRule::operator=(const QMimeMagicRule &other)
+QMimeMagicRule &QMimeMagicRule::operator=(const QMimeMagicRule &other)
{
*d = *other.d;
return *this;
diff --git a/src/mimetypes/qmimemagicrule_p.h b/src/mimetypes/qmimemagicrule_p.h
index bb68243..e35c192 100644
--- a/src/mimetypes/qmimemagicrule_p.h
+++ b/src/mimetypes/qmimemagicrule_p.h
@@ -1,29 +1,51 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#ifndef QMIMEMAGICRULE_P_H
#define QMIMEMAGICRULE_P_H
-#include <QtCore/QByteArray>
-#include <QtCore/QScopedPointer>
-#include <QtCore/QList>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qscopedpointer.h>
+#include <QtCore/qlist.h>
QT_BEGIN_NAMESPACE
@@ -56,11 +78,12 @@ public:
static Type type(const QByteArray &type);
static QByteArray typeName(Type type);
- static bool matchSubstring(const char* dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char* valueData, const char* mask);
+ static bool matchSubstring(const char *dataPtr, int dataSize, int rangeStart, int rangeLength, int valueLength, const char *valueData, const char *mask);
private:
const QScopedPointer<QMimeMagicRulePrivate> d;
};
+Q_DECLARE_TYPEINFO(QMimeMagicRule, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
diff --git a/src/mimetypes/qmimemagicrulematcher.cpp b/src/mimetypes/qmimemagicrulematcher.cpp
index 2ffa926..8579d02 100644
--- a/src/mimetypes/qmimemagicrulematcher.cpp
+++ b/src/mimetypes/qmimemagicrulematcher.cpp
@@ -1,29 +1,50 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#define QT_NO_CAST_FROM_ASCII
#include "qmimemagicrulematcher_p.h"
#include "qmimetype_p.h"
-#include <QtCore/QDebug>
-
-#include <qendian.h>
QT_BEGIN_NAMESPACE
@@ -36,7 +57,7 @@ QT_BEGIN_NAMESPACE
It is used for rules parsed from XML files.
\sa QMimeType, QMimeDatabase, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
- \sa BaseMimeTypeParser, MimeTypeParser
+ \sa QMimeTypeParserBase, MimeTypeParser
*/
QMimeMagicRuleMatcher::QMimeMagicRuleMatcher(const QString &mime, unsigned thePriority) :
diff --git a/src/mimetypes/qmimemagicrulematcher_p.h b/src/mimetypes/qmimemagicrulematcher_p.h
index cdca9e7..299f447 100644
--- a/src/mimetypes/qmimemagicrulematcher_p.h
+++ b/src/mimetypes/qmimemagicrulematcher_p.h
@@ -1,33 +1,51 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#ifndef QMIMEMAGICRULEMATCHER_P_H
#define QMIMEMAGICRULEMATCHER_P_H
-#include "qmime_global.h"
-
-#include <QtCore/QByteArray>
-#include <QtCore/QHash>
-#include <QtCore/QList>
-#include <QtCore/QSharedPointer>
-#include <QtCore/QString>
+#include <QtCore/qbytearray.h>
+#include <QtCore/qlist.h>
+#include <QtCore/qstring.h>
#include "qmimemagicrule_p.h"
diff --git a/src/mimetypes/qmimeprovider.cpp b/src/mimetypes/qmimeprovider.cpp
index 140efc5..8ef0ee8 100644
--- a/src/mimetypes/qmimeprovider.cpp
+++ b/src/mimetypes/qmimeprovider.cpp
@@ -1,26 +1,47 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#include "qmimeprovider_p.h"
-#include "mimetypeparser_p.h"
+#include "qmimetypeparser_p.h"
#include <qstandardpaths.h>
#include "qmimemagicrulematcher_p.h"
@@ -30,9 +51,11 @@
#include <QByteArrayMatcher>
#include <QDebug>
#include <QDateTime>
-#include <qendian.h>
+#include <QtEndian>
+
+QT_BEGIN_NAMESPACE
-static QString fallbackParent(const QString& mimeTypeName)
+static QString fallbackParent(const QString &mimeTypeName)
{
const QString myGroup = mimeTypeName.left(mimeTypeName.indexOf(QLatin1Char('/')));
// All text/* types are subclasses of text/plain.
@@ -53,7 +76,7 @@ QMimeProviderBase::QMimeProviderBase(QMimeDatabasePrivate *db)
{
}
-QMIME_EXPORT int qmime_secondsBetweenChecks = 5; // exported for the unit test
+Q_CORE_EXPORT int qmime_secondsBetweenChecks = 5; // exported for the unit test
bool QMimeProviderBase::shouldCheck()
{
@@ -79,13 +102,16 @@ struct QMimeBinaryProvider::CacheFile
~CacheFile();
bool isValid() const { return m_valid; }
- inline quint16 getUint16(int offset) const {
+ inline quint16 getUint16(int offset) const
+ {
return qFromBigEndian(*reinterpret_cast<quint16 *>(data + offset));
}
- inline quint32 getUint32(int offset) const {
+ inline quint32 getUint32(int offset) const
+ {
return qFromBigEndian(*reinterpret_cast<quint32 *>(data + offset));
}
- inline const char* getCharStar(int offset) const {
+ inline const char *getCharStar(int offset) const
+ {
return reinterpret_cast<const char *>(data + offset);
}
bool load();
@@ -132,7 +158,7 @@ bool QMimeBinaryProvider::CacheFile::reload()
return load();
}
-QMimeBinaryProvider::CacheFile* QMimeBinaryProvider::CacheFileList::findCacheFile(const QString& fileName) const
+QMimeBinaryProvider::CacheFile *QMimeBinaryProvider::CacheFileList::findCacheFile(const QString &fileName) const
{
for (const_iterator it = begin(); it != end(); ++it) {
if ((*it)->file.fileName() == fileName)
@@ -147,23 +173,23 @@ QMimeBinaryProvider::~QMimeBinaryProvider()
}
// Position of the "list offsets" values, at the beginning of the mime.cache file
-enum { PosAliasListOffset = 4,
- PosParentListOffset = 8,
- PosLiteralListOffset = 12,
- PosReverseSuffixTreeOffset = 16,
- PosGlobListOffset = 20,
- PosMagicListOffset = 24,
- // PosNamespaceListOffset = 28,
- PosIconsListOffset = 32,
- PosGenericIconsListOffset = 36
- };
+enum {
+ PosAliasListOffset = 4,
+ PosParentListOffset = 8,
+ PosLiteralListOffset = 12,
+ PosReverseSuffixTreeOffset = 16,
+ PosGlobListOffset = 20,
+ PosMagicListOffset = 24,
+ // PosNamespaceListOffset = 28,
+ PosIconsListOffset = 32,
+ PosGenericIconsListOffset = 36
+};
bool QMimeBinaryProvider::isValid()
{
#if defined(QT_USE_MMAP)
- if (!qgetenv("QT_NO_MIME_CACHE").isEmpty()) {
+ if (!qgetenv("QT_NO_MIME_CACHE").isEmpty())
return false;
- }
Q_ASSERT(m_cacheFiles.isEmpty()); // this method is only ever called once
checkCache();
@@ -188,7 +214,7 @@ bool QMimeBinaryProvider::CacheFileList::checkCacheChanged()
bool somethingChanged = false;
QMutableListIterator<CacheFile *> it(*this);
while (it.hasNext()) {
- CacheFile* cacheFile = it.next();
+ CacheFile *cacheFile = it.next();
QFileInfo fileInfo(cacheFile->file);
if (!fileInfo.exists()) { // This can't happen by just running update-mime-database. But the user could use rm -rf :-)
delete cacheFile;
@@ -217,14 +243,13 @@ void QMimeBinaryProvider::checkCache()
// Then check if new cache files appeared
const QStringList cacheFileNames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/mime.cache"));
if (cacheFileNames != m_cacheFileNames) {
- foreach (const QString& cacheFileName, cacheFileNames) {
- CacheFile* cacheFile = m_cacheFiles.findCacheFile(cacheFileName);
+ foreach (const QString &cacheFileName, cacheFileNames) {
+ CacheFile *cacheFile = m_cacheFiles.findCacheFile(cacheFileName);
if (!cacheFile) {
//qDebug() << "new file:" << cacheFileName;
cacheFile = new CacheFile(cacheFileName);
- if (cacheFile->isValid()) { // verify version
+ if (cacheFile->isValid()) // verify version
m_cacheFiles.append(cacheFile);
- }
else
delete cacheFile;
}
@@ -276,7 +301,7 @@ QStringList QMimeBinaryProvider::findByFileName(const QString &fileName, QString
return result.m_matchingMimeTypes;
}
-void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult& result, CacheFile *cacheFile, int off, const QString &fileName)
+void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int off, const QString &fileName)
{
const int numGlobs = cacheFile->getUint32(off);
//qDebug() << "Loading" << numGlobs << "globs from" << cacheFile->file.fileName() << "at offset" << cacheFile->globListOffset;
@@ -289,7 +314,7 @@ void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult& result, CacheFile
const Qt::CaseSensitivity qtCaseSensitive = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
const QString pattern = QLatin1String(cacheFile->getCharStar(globOffset));
- const char* mimeType = cacheFile->getCharStar(mimeTypeOffset);
+ const char *mimeType = cacheFile->getCharStar(mimeTypeOffset);
//qDebug() << pattern << mimeType << weight << caseSensitive;
QMimeGlobPattern glob(pattern, QString() /*unused*/, weight, qtCaseSensitive);
@@ -299,7 +324,7 @@ void QMimeBinaryProvider::matchGlobList(QMimeGlobMatchResult& result, CacheFile
}
}
-bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult& result, QMimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck)
+bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult &result, QMimeBinaryProvider::CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck)
{
QChar fileChar = fileName[charPos];
int min = 0;
@@ -326,7 +351,7 @@ bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult& result, QMimeBin
if (mch != 0)
break;
const int mimeTypeOffset = cacheFile->getUint32(childOff + 4);
- const char* mimeType = cacheFile->getCharStar(mimeTypeOffset);
+ const char *mimeType = cacheFile->getCharStar(mimeTypeOffset);
const int flagsAndWeight = cacheFile->getUint32(childOff + 8);
const int weight = flagsAndWeight & 0xff;
const bool caseSensitive = flagsAndWeight & 0x100;
@@ -344,7 +369,7 @@ bool QMimeBinaryProvider::matchSuffixTree(QMimeGlobMatchResult& result, QMimeBin
bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data)
{
- const char* dataPtr = data.constData();
+ const char *dataPtr = data.constData();
const int dataSize = data.size();
for (int matchlet = 0; matchlet < numMatchlets; ++matchlet) {
const int off = firstOffset + matchlet * 32;
@@ -354,7 +379,7 @@ bool QMimeBinaryProvider::matchMagicRule(QMimeBinaryProvider::CacheFile *cacheFi
const int valueLength = cacheFile->getUint32(off + 12);
const int valueOffset = cacheFile->getUint32(off + 16);
const int maskOffset = cacheFile->getUint32(off + 20);
- const char* mask = maskOffset ? cacheFile->getCharStar(maskOffset) : NULL;
+ const char *mask = maskOffset ? cacheFile->getCharStar(maskOffset) : NULL;
if (!QMimeMagicRule::matchSubstring(dataPtr, dataSize, rangeStart, rangeLength, valueLength, cacheFile->getCharStar(valueOffset), mask))
continue;
@@ -385,7 +410,7 @@ QMimeType QMimeBinaryProvider::findByMagic(const QByteArray &data, int *accuracy
const int firstMatchletOffset = cacheFile->getUint32(off + 12);
if (matchMagicRule(cacheFile, numMatchlets, firstMatchletOffset, data)) {
const int mimeTypeOffset = cacheFile->getUint32(off + 4);
- const char* mimeType = cacheFile->getCharStar(mimeTypeOffset);
+ const char *mimeType = cacheFile->getCharStar(mimeTypeOffset);
*accuracyPtr = cacheFile->getUint32(off);
// Return the first match. We have no rules for conflicting magic data...
// (mime.cache itself is sorted, but what about local overrides with a lower prio?)
@@ -413,11 +438,11 @@ QStringList QMimeBinaryProvider::parents(const QString &mime)
const int mimeOffset = cacheFile->getUint32(off);
const char *aMime = cacheFile->getCharStar(mimeOffset);
const int cmp = qstrcmp(aMime, mimeStr);
- if (cmp < 0)
+ if (cmp < 0) {
begin = medium + 1;
- else if (cmp > 0)
+ } else if (cmp > 0) {
end = medium - 1;
- else {
+ } else {
const int parentsOffset = cacheFile->getUint32(off + 4);
const int numParents = cacheFile->getUint32(parentsOffset);
for (int i = 0; i < numParents; ++i) {
@@ -452,11 +477,11 @@ QString QMimeBinaryProvider::resolveAlias(const QString &name)
const int aliasOffset = cacheFile->getUint32(off);
const char *alias = cacheFile->getCharStar(aliasOffset);
const int cmp = qstrcmp(alias, input);
- if (cmp < 0)
+ if (cmp < 0) {
begin = medium + 1;
- else if (cmp > 0)
+ } else if (cmp > 0) {
end = medium - 1;
- else {
+ } else {
const int mimeOffset = cacheFile->getUint32(off + 4);
const char *mimeType = cacheFile->getCharStar(mimeOffset);
return QLatin1String(mimeType);
@@ -475,7 +500,7 @@ void QMimeBinaryProvider::loadMimeTypeList()
// Unfortunately mime.cache doesn't have a full list of all mimetypes.
// So we have to parse the plain-text files called "types".
const QStringList typesFilenames = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QLatin1String("mime/types"));
- foreach (const QString& typeFilename, typesFilenames) {
+ foreach (const QString &typeFilename, typesFilenames) {
QFile file(typeFilename);
if (file.open(QIODevice::ReadOnly)) {
while (!file.atEnd()) {
@@ -528,7 +553,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
QXmlStreamReader xml(&qfile);
if (xml.readNextStartElement()) {
- if (xml.name() != "mime-type") {
+ if (xml.name() != QLatin1String("mime-type")) {
continue;
}
const QString name = xml.attributes().value(QLatin1String("type")).toString();
@@ -540,7 +565,7 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
while (xml.readNextStartElement()) {
const QStringRef tag = xml.name();
- if (tag == "comment") {
+ if (tag == QLatin1String("comment")) {
QString lang = xml.attributes().value(QLatin1String("xml:lang")).toString();
const QString text = xml.readElementText();
if (lang.isEmpty()) {
@@ -548,11 +573,11 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
}
data.localeComments.insert(lang, text);
continue; // we called readElementText, so we're at the EndElement already.
- } else if (tag == "icon") { // as written out by shared-mime-info >= 0.40
+ } else if (tag == QLatin1String("icon")) { // as written out by shared-mime-info >= 0.40
data.iconName = xml.attributes().value(QLatin1String("name")).toString();
- } else if (tag == "glob-deleteall") { // as written out by shared-mime-info >= 0.70
+ } else if (tag == QLatin1String("glob-deleteall")) { // as written out by shared-mime-info >= 0.70
data.globPatterns.clear();
- } else if (tag == "glob") { // as written out by shared-mime-info >= 0.70
+ } else if (tag == QLatin1String("glob")) { // as written out by shared-mime-info >= 0.70
const QString pattern = xml.attributes().value(QLatin1String("pattern")).toString();
if (mainPattern.isEmpty() && pattern.startsWith(QLatin1Char('*'))) {
mainPattern = pattern;
@@ -562,11 +587,20 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
}
xml.skipCurrentElement();
}
- Q_ASSERT(xml.name() == "mime-type");
+ Q_ASSERT(xml.name() == QLatin1String("mime-type"));
}
}
- const bool globsInXml = true; // ## (KMimeType::sharedMimeInfoVersion() >= KDE_MAKE_VERSION(0, 70, 0));
+ // Let's assume that shared-mime-info is at least version 0.70
+ // Otherwise we would need 1) a version check, and 2) code for parsing patterns from the globs file.
+#if 1
+ if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) {
+ // ensure it's first in the list of patterns
+ data.globPatterns.removeAll(mainPattern);
+ data.globPatterns.prepend(mainPattern);
+ }
+#else
+ const bool globsInXml = sharedMimeInfoVersion() >= QT_VERSION_CHECK(0, 70, 0);
if (globsInXml) {
if (!mainPattern.isEmpty() && data.globPatterns.first() != mainPattern) {
// ensure it's first in the list of patterns
@@ -575,12 +609,14 @@ void QMimeBinaryProvider::loadMimeTypePrivate(QMimeTypePrivate &data)
}
} else {
// Fallback: get the patterns from the globs file
- //TODO data.globPatterns = KMimeTypeRepository::self()->patternsForMimetype(data.name);
+ // TODO: This would be the only way to support shared-mime-info < 0.70
+ // But is this really worth the effort?
}
+#endif
}
// Binary search in the icons or generic-icons list
-QString QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray& inputMime)
+QString QMimeBinaryProvider::iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime)
{
const int iconsListOffset = cacheFile->getUint32(posListOffset);
const int numIcons = cacheFile->getUint32(iconsListOffset);
@@ -697,7 +733,7 @@ void QMimeXMLProvider::ensureLoaded()
if (!fdoXmlFound) {
// We could instead install the file as part of installing Qt?
- allFiles.prepend(QLatin1String(":/qmime/freedesktop.org.xml"));
+ allFiles.prepend(QLatin1String(":/qt-project.org/qmime/freedesktop.org.xml"));
}
if (m_allFiles == allFiles)
@@ -712,7 +748,7 @@ void QMimeXMLProvider::ensureLoaded()
//qDebug() << "Loading" << m_allFiles;
- foreach (const QString& file, allFiles)
+ foreach (const QString &file, allFiles)
load(file);
}
}
@@ -738,11 +774,11 @@ bool QMimeXMLProvider::load(const QString &fileName, QString *errorMessage)
if (errorMessage)
errorMessage->clear();
- MimeTypeParser parser(*this);
+ QMimeTypeParser parser(*this);
return parser.parse(&file, fileName, errorMessage);
}
-void QMimeXMLProvider::addGlobPattern(const QMimeGlobPattern& glob)
+void QMimeXMLProvider::addGlobPattern(const QMimeGlobPattern &glob)
{
m_mimeTypeGlobs.addGlob(glob);
}
@@ -790,3 +826,5 @@ void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher)
{
m_magicMatchers.append(matcher);
}
+
+QT_END_NAMESPACE
diff --git a/src/mimetypes/qmimeprovider_p.h b/src/mimetypes/qmimeprovider_p.h
index 06a8d06..cb51ba1 100644
--- a/src/mimetypes/qmimeprovider_p.h
+++ b/src/mimetypes/qmimeprovider_p.h
@@ -1,29 +1,53 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#ifndef QMIMEPROVIDER_P_H
#define QMIMEPROVIDER_P_H
-#include <QDateTime>
+#include <QtCore/qdatetime.h>
#include "qmimedatabase_p.h"
-#include <QtCore/QSet>
+#include <QtCore/qset.h>
+
+QT_BEGIN_NAMESPACE
+
class QMimeMagicRuleMatcher;
class QMimeProviderBase
@@ -43,7 +67,7 @@ public:
virtual void loadIcon(QMimeTypePrivate &) {}
virtual void loadGenericIcon(QMimeTypePrivate &) {}
- QMimeDatabasePrivate* m_db;
+ QMimeDatabasePrivate *m_db;
protected:
bool shouldCheck();
QDateTime m_lastCheck;
@@ -75,14 +99,14 @@ private:
void matchGlobList(QMimeGlobMatchResult &result, CacheFile *cacheFile, int offset, const QString &fileName);
bool matchSuffixTree(QMimeGlobMatchResult &result, CacheFile *cacheFile, int numEntries, int firstOffset, const QString &fileName, int charPos, bool caseSensitiveCheck);
bool matchMagicRule(CacheFile *cacheFile, int numMatchlets, int firstOffset, const QByteArray &data);
- QString iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray& inputMime);
+ QString iconForMime(CacheFile *cacheFile, int posListOffset, const QByteArray &inputMime);
void loadMimeTypeList();
void checkCache();
class CacheFileList : public QList<CacheFile *>
{
public:
- CacheFile* findCacheFile(const QString& fileName) const;
+ CacheFile *findCacheFile(const QString &fileName) const;
bool checkCacheChanged();
};
CacheFileList m_cacheFiles;
@@ -111,7 +135,7 @@ public:
// Called by the mimetype xml parser
void addMimeType(const QMimeType &mt);
- void addGlobPattern(const QMimeGlobPattern& glob);
+ void addGlobPattern(const QMimeGlobPattern &glob);
void addParent(const QString &child, const QString &parent);
void addAlias(const QString &alias, const QString &name);
void addMagicMatcher(const QMimeMagicRuleMatcher &matcher);
@@ -136,4 +160,6 @@ private:
QStringList m_allFiles;
};
+QT_END_NAMESPACE
+
#endif // QMIMEPROVIDER_P_H
diff --git a/src/mimetypes/qmimetype.cpp b/src/mimetypes/qmimetype.cpp
index fb79ac7..7759288 100644
--- a/src/mimetypes/qmimetype.cpp
+++ b/src/mimetypes/qmimetype.cpp
@@ -1,24 +1,46 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#include "qmimetype.h" // Basis
+
+#include "qmimetype.h"
#include "qmimetype_p.h"
#include "qmimedatabase_p.h"
@@ -31,18 +53,14 @@
QT_BEGIN_NAMESPACE
-// ------------------------------------------------------------------------------------------------
-
-bool isQMimeTypeDebuggingActivated (false);
+bool qt_isQMimeTypeDebuggingActivated (false);
#ifndef QT_NO_DEBUG_OUTPUT
-#define DBG() if (isQMimeTypeDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
+#define DBG() if (qt_isQMimeTypeDebuggingActivated) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#else
#define DBG() if (0) qDebug() << static_cast<const void *>(this) << Q_FUNC_INFO
#endif
-// ------------------------------------------------------------------------------------------------
-
QMimeTypePrivate::QMimeTypePrivate()
: name()
//, comment()
@@ -52,8 +70,6 @@ QMimeTypePrivate::QMimeTypePrivate()
, globPatterns()
{}
-// ------------------------------------------------------------------------------------------------
-
QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other)
: name(other.d->name)
//, comment(other.d->comment)
@@ -63,8 +79,6 @@ QMimeTypePrivate::QMimeTypePrivate(const QMimeType &other)
, globPatterns(other.d->globPatterns)
{}
-// ------------------------------------------------------------------------------------------------
-
void QMimeTypePrivate::clear()
{
name.clear();
@@ -75,11 +89,9 @@ void QMimeTypePrivate::clear()
globPatterns.clear();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeTypePrivate::operator==(const QMimeTypePrivate &other) const;
- \brief Returns true if \a other equals this QMimeTypePrivate object, otherwise returns false.
+ Returns true if \a other equals this QMimeTypePrivate object, otherwise returns false.
*/
bool QMimeTypePrivate::operator==(const QMimeTypePrivate &other) const
{
@@ -102,19 +114,17 @@ bool QMimeTypePrivate::operator==(const QMimeTypePrivate &other) const
return false;
}
-// ------------------------------------------------------------------------------------------------
-
void QMimeTypePrivate::addGlobPattern(const QString &pattern)
{
globPatterns.append(pattern);
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\class QMimeType
\brief The QMimeType class describes types of file or data, represented by a MIME type string.
+ \since 5.0
+
For instance a file named "readme.txt" has the MIME type "text/plain".
The MIME type can be determined from the file name, or from the file
contents, or from both. MIME type determination can also be done on
@@ -133,11 +143,9 @@ void QMimeTypePrivate::addGlobPattern(const QString &pattern)
\sa QMimeDatabase
*/
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType::QMimeType();
- \brief Constructs this QMimeType object initialized with default property values that indicate an invalid MIME type.
+ Constructs this QMimeType object initialized with default property values that indicate an invalid MIME type.
*/
QMimeType::QMimeType() :
d(new QMimeTypePrivate())
@@ -152,11 +160,9 @@ QMimeType::QMimeType() :
DBG() << "preferredSuffix():" << preferredSuffix();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType::QMimeType(const QMimeType &other);
- \brief Constructs this QMimeType object as a copy of \a other.
+ Constructs this QMimeType object as a copy of \a other.
*/
QMimeType::QMimeType(const QMimeType &other) :
d(other.d)
@@ -171,11 +177,9 @@ QMimeType::QMimeType(const QMimeType &other) :
DBG() << "preferredSuffix():" << preferredSuffix();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType &QMimeType::operator=(const QMimeType &other);
- \brief Assigns the data of \a other to this QMimeType object, and returns a reference to this object.
+ Assigns the data of \a other to this QMimeType object, and returns a reference to this object.
*/
QMimeType &QMimeType::operator=(const QMimeType &other)
{
@@ -184,12 +188,10 @@ QMimeType &QMimeType::operator=(const QMimeType &other)
return *this;
}
-// ------------------------------------------------------------------------------------------------
-
#ifdef Q_COMPILER_RVALUE_REFS
/*!
\fn QMimeType::QMimeType(QMimeType &&other);
- \brief Constructs this QMimeType object by moving the data of the rvalue reference \a other.
+ Constructs this QMimeType object by moving the data of the rvalue reference \a other.
*/
QMimeType::QMimeType(QMimeType &&other) :
d(std::move(other.d))
@@ -205,11 +207,9 @@ QMimeType::QMimeType(QMimeType &&other) :
}
#endif
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType::QMimeType(const QMimeTypePrivate &dd);
- \brief Assigns the data of the QMimeTypePrivate \a dd to this QMimeType object, and returns a reference to this object.
+ Assigns the data of the QMimeTypePrivate \a dd to this QMimeType object, and returns a reference to this object.
*/
QMimeType::QMimeType(const QMimeTypePrivate &dd) :
d(new QMimeTypePrivate(dd))
@@ -224,11 +224,9 @@ QMimeType::QMimeType(const QMimeTypePrivate &dd) :
DBG() << "preferredSuffix():" << preferredSuffix();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn void QMimeType::swap(QMimeType &other);
- \brief Swaps QMimeType \a other with this QMimeType object.
+ Swaps QMimeType \a other with this QMimeType object.
This operation is very fast and never fails.
@@ -238,11 +236,9 @@ QMimeType::QMimeType(const QMimeTypePrivate &dd) :
{More C++ Idioms - Copy-and-swap}.
*/
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QMimeType::~QMimeType();
- \brief Destroys the QMimeType object, and releases the d pointer.
+ Destroys the QMimeType object, and releases the d pointer.
*/
QMimeType::~QMimeType()
{
@@ -256,29 +252,23 @@ QMimeType::~QMimeType()
DBG() << "preferredSuffix():" << preferredSuffix();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeType::operator==(const QMimeType &other) const;
- \brief Returns true if \a other equals this QMimeType object, otherwise returns false.
+ Returns true if \a other equals this QMimeType object, otherwise returns false.
*/
bool QMimeType::operator==(const QMimeType &other) const
{
return d == other.d || *d == *other.d;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeType::operator!=(const QMimeType &other) const;
- \brief Returns true if \a other does not equal this QMimeType object, otherwise returns false.
+ Returns true if \a other does not equal this QMimeType object, otherwise returns false.
*/
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeType::isValid() const;
- \brief Returns true if the QMimeType object contains valid data, otherwise returns false.
+ Returns true if the QMimeType object contains valid data, otherwise returns false.
A valid MIME type has a non-empty name().
The invalid MIME type is the default-constructed QMimeType.
*/
@@ -287,8 +277,6 @@ bool QMimeType::isValid() const
return !d->name.isEmpty();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeType::isDefault() const;
Returns true if this MIME type is the default MIME type which
@@ -299,21 +287,17 @@ bool QMimeType::isDefault() const
return d->name == QMimeDatabasePrivate::instance()->defaultMimeType();
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QString QMimeType::name() const;
- \brief Returns the name of the MIME type.
+ Returns the name of the MIME type.
*/
QString QMimeType::name() const
{
return d->name;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
- \brief Returns the description of the MIME type to be displayed on user interfaces.
+ Returns the description of the MIME type to be displayed on user interfaces.
The system language (QLocale::system().name()) is used to select the appropriate translation.
Another language can be specified by setting the \a localeName argument.
@@ -324,10 +308,8 @@ QString QMimeType::comment() const
QStringList languageList;
languageList << QLocale::system().name();
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
languageList << QLocale::system().uiLanguages();
-#endif
- Q_FOREACH(const QString& lang, languageList) {
+ Q_FOREACH (const QString &lang, languageList) {
const QString comm = d->localeComments.value(lang);
if (!comm.isEmpty())
return comm;
@@ -345,11 +327,9 @@ QString QMimeType::comment() const
return d->name;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QString QMimeType::genericIconName() const;
- \brief Returns the file name of a generic icon that represents the MIME type.
+ Returns the file name of a generic icon that represents the MIME type.
This should be used if the icon returned by iconName() cannot be found on
the system. It is used for categories of similar types (like spreadsheets
@@ -376,11 +356,9 @@ QString QMimeType::genericIconName() const
return d->genericIconName;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QString QMimeType::iconName() const;
- \brief Returns the file name of an icon image that represents the MIME type.
+ Returns the file name of an icon image that represents the MIME type.
The icon name can be given to QIcon::fromTheme() in order to load the icon.
*/
@@ -397,11 +375,9 @@ QString QMimeType::iconName() const
return d->iconName;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QStringList QMimeType::globPatterns() const;
- \brief Returns the list of glob matching patterns.
+ Returns the list of glob matching patterns.
*/
QStringList QMimeType::globPatterns() const
{
@@ -409,8 +385,6 @@ QStringList QMimeType::globPatterns() const
return d->globPatterns;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
A type is a subclass of another type if any instance of the first type is
also an instance of the second. For example, all image/svg+xml files are also
@@ -428,25 +402,21 @@ QStringList QMimeType::parentMimeTypes() const
return QMimeDatabasePrivate::instance()->provider()->parents(d->name);
}
-// ------------------------------------------------------------------------------------------------
-
-static void collectParentMimeTypes(const QString& mime, QStringList& allParents)
+static void collectParentMimeTypes(const QString &mime, QStringList &allParents)
{
QStringList parents = QMimeDatabasePrivate::instance()->provider()->parents(mime);
- foreach(const QString& parent, parents) {
+ foreach (const QString &parent, parents) {
// I would use QSet, but since order matters I better not
if (!allParents.contains(parent))
allParents.append(parent);
}
// We want a breadth-first search, so that the least-specific parent (octet-stream) is last
// This means iterating twice, unfortunately.
- foreach(const QString& parent, parents) {
+ foreach (const QString &parent, parents) {
collectParentMimeTypes(parent, allParents);
}
}
-// ------------------------------------------------------------------------------------------------
-
/*!
Return all the parent mimetypes of this mimetype, direct and indirect.
This includes the parent(s) of its parent(s), etc.
@@ -464,18 +434,16 @@ QStringList QMimeType::allAncestors() const
return allParents;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QStringList QMimeType::suffixes() const;
- \brief Returns the known suffixes for the MIME type.
+ Returns the known suffixes for the MIME type.
*/
QStringList QMimeType::suffixes() const
{
QMimeDatabasePrivate::instance()->provider()->loadMimeTypePrivate(*d);
QStringList result;
- foreach (const QString& pattern, d->globPatterns) {
+ foreach (const QString &pattern, d->globPatterns) {
// Not a simple suffix if if looks like: README or *. or *.* or *.JP*G or *.JP?
if (pattern.startsWith(QLatin1String("*.")) &&
pattern.length() > 2 &&
@@ -488,11 +456,9 @@ QStringList QMimeType::suffixes() const
return result;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QString QMimeType::preferredSuffix() const;
- \brief Returns the preferred suffix for the MIME type.
+ Returns the preferred suffix for the MIME type.
*/
QString QMimeType::preferredSuffix() const
{
@@ -500,8 +466,6 @@ QString QMimeType::preferredSuffix() const
return suffixList.isEmpty() ? QString() : suffixList.at(0);
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn QString QMimeType::filterString() const;
Returns a filter string usable for a file dialog.
@@ -524,8 +488,6 @@ QString QMimeType::filterString() const
return filter;
}
-// ------------------------------------------------------------------------------------------------
-
/*!
\fn bool QMimeType::inherits(const QString &mimeTypeName) const;
Returns true if this mimetype is \a mimeTypeName,
@@ -539,8 +501,6 @@ bool QMimeType::inherits(const QString &mimeTypeName) const
return QMimeDatabasePrivate::instance()->inherits(d->name, mimeTypeName);
}
-// ------------------------------------------------------------------------------------------------
-
#undef DBG
QT_END_NAMESPACE
diff --git a/src/mimetypes/qmimetype.h b/src/mimetypes/qmimetype.h
index 83d2185..98448a5 100644
--- a/src/mimetypes/qmimetype.h
+++ b/src/mimetypes/qmimetype.h
@@ -1,40 +1,59 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#ifndef QMIMETYPE_H_INCLUDED
-#define QMIMETYPE_H_INCLUDED
-
-#include "qmime_global.h"
-
-#include <QtCore/QExplicitlySharedDataPointer>
-#include <QtCore/QString>
-QT_BEGIN_NAMESPACE struct QMimeTypePrivate; QT_END_NAMESPACE
+#ifndef QMIMETYPE_H
+#define QMIMETYPE_H
-QT_BEGIN_NAMESPACE class QFileinfo; QT_END_NAMESPACE
-QT_BEGIN_NAMESPACE class QStringList; QT_END_NAMESPACE
+#include "qmime_global.h"
-// ------------------------------------------------------------------------------------------------
+#include <QtCore/qshareddata.h>
+#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
+class QMimeTypePrivate;
+class QFileinfo;
+class QStringList;
+
class QMIME_EXPORT QMimeType
{
public:
@@ -83,9 +102,9 @@ public:
QString filterString() const;
protected:
- friend class BaseMimeTypeParser;
+ friend class QMimeTypeParserBase;
friend class MimeTypeMapEntry;
- friend struct QMimeDatabasePrivate;
+ friend class QMimeDatabasePrivate;
friend class QMimeXMLProvider;
friend class QMimeBinaryProvider;
friend class QMimeTypePrivate;
@@ -95,4 +114,4 @@ protected:
QT_END_NAMESPACE
-#endif // QMIMETYPE_H_INCLUDED
+#endif // QMIMETYPE_H
diff --git a/src/mimetypes/qmimetype_p.h b/src/mimetypes/qmimetype_p.h
index e7b2cef..d8aadcc 100644
--- a/src/mimetypes/qmimetype_p.h
+++ b/src/mimetypes/qmimetype_p.h
@@ -1,37 +1,58 @@
/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
****************************************************************************/
-#ifndef QMIMETYPE_P_H_INCLUDED
-#define QMIMETYPE_P_H_INCLUDED
-#include "qmimetype.h"
+#ifndef QMIMETYPE_P_H
+#define QMIMETYPE_P_H
-#include <QtCore/QHash>
-#include <QtCore/QStringList>
+#include "qmimetype.h"
-// ------------------------------------------------------------------------------------------------
+#include <QtCore/qhash.h>
+#include <QtCore/qstringlist.h>
QT_BEGIN_NAMESPACE
-struct QMIME_EXPORT QMimeTypePrivate : public QSharedData
+class Q_AUTOTEST_EXPORT QMimeTypePrivate : public QSharedData
{
+public:
typedef QHash<QString, QString> LocaleHash;
QMimeTypePrivate();
@@ -43,11 +64,7 @@ struct QMIME_EXPORT QMimeTypePrivate : public QSharedData
void addGlobPattern(const QString &pattern);
- //unsigned matchesFileBySuffix(const QString &fileName) const;
- //unsigned matchesData(const QByteArray &data) const;
-
QString name;
- //QString comment; // mostly unused, only for tests and qml bindings
LocaleHash localeComments;
QString genericIconName;
QString iconName;
@@ -56,14 +73,10 @@ struct QMIME_EXPORT QMimeTypePrivate : public QSharedData
QT_END_NAMESPACE
-// ------------------------------------------------------------------------------------------------
-
#define QMIMETYPE_BUILDER \
QT_BEGIN_NAMESPACE \
static QMimeType buildQMimeType ( \
const QString &name, \
- /*const QStringList &aliases,*/ \
- /*const QString &comment,*/ \
const QString &genericIconName, \
const QString &iconName, \
const QStringList &globPatterns \
@@ -71,8 +84,6 @@ QT_END_NAMESPACE
{ \
QMimeTypePrivate qMimeTypeData; \
qMimeTypeData.name = name; \
- /*qMimeTypeData.aliases = aliases;*/ \
- /*qMimeTypeData.comment = comment;*/ \
qMimeTypeData.genericIconName = genericIconName; \
qMimeTypeData.iconName = iconName; \
qMimeTypeData.globPatterns = globPatterns; \
@@ -85,8 +96,6 @@ QT_END_NAMESPACE
QT_BEGIN_NAMESPACE \
static QMimeType buildQMimeType ( \
QString &&name, \
- /*QStringList &&aliases,*/ \
- /*QString &&comment,*/ \
QString &&genericIconName, \
QString &&iconName, \
QStringList &&globPatterns \
@@ -94,8 +103,6 @@ QT_END_NAMESPACE
{ \
QMimeTypePrivate qMimeTypeData; \
qMimeTypeData.name = std::move(name); \
- /*qMimeTypeData.aliases = std::move(aliases);*/ \
- /*qMimeTypeData.comment = std::move(comment);*/ \
qMimeTypeData.genericIconName = std::move(genericIconName); \
qMimeTypeData.iconName = std::move(iconName); \
qMimeTypeData.globPatterns = std::move(globPatterns); \
@@ -104,4 +111,4 @@ QT_END_NAMESPACE
QT_END_NAMESPACE
#endif
-#endif // QMIMETYPE_P_H_INCLUDED
+#endif // QMIMETYPE_P_H
diff --git a/src/mimetypes/mimetypeparser.cpp b/src/mimetypes/qmimetypeparser.cpp
index 3a5da30..4a2ec0a 100644
--- a/src/mimetypes/mimetypeparser.cpp
+++ b/src/mimetypes/qmimetypeparser.cpp
@@ -1,24 +1,48 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#define QT_NO_CAST_FROM_ASCII
-#include "mimetypeparser_p.h"
+#include "qmimetypeparser_p.h"
#include "qmimetype_p.h"
#include "qmimemagicrulematcher_p.h"
@@ -34,57 +58,58 @@
QT_BEGIN_NAMESPACE
// XML tags in MIME files
-const char *const mimeInfoTagC = "mime-info";
-const char *const mimeTypeTagC = "mime-type";
-const char *const mimeTypeAttributeC = "type";
-const char *const subClassTagC = "sub-class-of";
-const char *const commentTagC = "comment";
-const char *const genericIconTagC = "generic-icon";
-const char *const iconTagC = "icon";
-const char *const nameAttributeC = "name";
-const char *const globTagC = "glob";
-const char *const aliasTagC = "alias";
-const char *const patternAttributeC = "pattern";
-const char *const weightAttributeC = "weight";
-const char *const caseSensitiveAttributeC = "case-sensitive";
-const char *const localeAttributeC = "xml:lang";
+static const char mimeInfoTagC[] = "mime-info";
+static const char mimeTypeTagC[] = "mime-type";
+static const char mimeTypeAttributeC[] = "type";
+static const char subClassTagC[] = "sub-class-of";
+static const char commentTagC[] = "comment";
+static const char genericIconTagC[] = "generic-icon";
+static const char iconTagC[] = "icon";
+static const char nameAttributeC[] = "name";
+static const char globTagC[] = "glob";
+static const char aliasTagC[] = "alias";
+static const char patternAttributeC[] = "pattern";
+static const char weightAttributeC[] = "weight";
+static const char caseSensitiveAttributeC[] = "case-sensitive";
+static const char localeAttributeC[] = "xml:lang";
-const char *const magicTagC = "magic";
-const char *const priorityAttributeC = "priority";
+static const char magicTagC[] = "magic";
+static const char priorityAttributeC[] = "priority";
-const char *const matchTagC = "match";
-const char *const matchValueAttributeC = "value";
-const char *const matchTypeAttributeC = "type";
-const char *const matchOffsetAttributeC = "offset";
-const char *const matchMaskAttributeC = "mask";
+static const char matchTagC[] = "match";
+static const char matchValueAttributeC[] = "value";
+static const char matchTypeAttributeC[] = "type";
+static const char matchOffsetAttributeC[] = "offset";
+static const char matchMaskAttributeC[] = "mask";
/*!
- \class MimeTypeParser
- \brief The MimeTypeParser class parses MIME types, and builds a MIME database hierarchy by adding to QMimeDatabasePrivate.
+ \class QMimeTypeParser
+ \internal
+ \brief The QMimeTypeParser class parses MIME types, and builds a MIME database hierarchy by adding to QMimeDatabasePrivate.
- Populates MimeDataBase
+ Populates QMimeDataBase
\sa QMimeDatabase, QMimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
- \sa MimeTypeParser
+ \sa QMimeTypeParser
*/
/*!
- \class BaseMimeTypeParser
- \brief The BaseMimeTypeParser class parses for a sequence of <mime-type> in a generic way.
+ \class QMimeTypeParserBase
+ \brief The QMimeTypeParserBase class parses for a sequence of <mime-type> in a generic way.
Calls abstract handler function process for QMimeType it finds.
\sa QMimeDatabase, QMimeMagicRuleMatcher, MagicRule, MagicStringRule, MagicByteRule, GlobPattern
- \sa MimeTypeParser
+ \sa QMimeTypeParser
*/
/*!
- \fn virtual bool BaseMimeTypeParser::process(const QMimeType &t, QString *errorMessage) = 0;
- \brief Overwrite to process the sequence of parsed data
+ \fn virtual bool QMimeTypeParserBase::process(const QMimeType &t, QString *errorMessage) = 0;
+ Overwrite to process the sequence of parsed data
*/
-BaseMimeTypeParser::ParseState BaseMimeTypeParser::nextState(ParseState currentState, const QStringRef &startElement)
+QMimeTypeParserBase::ParseState QMimeTypeParserBase::nextState(ParseState currentState, const QStringRef &startElement)
{
switch (currentState) {
case ParseBeginning:
@@ -177,7 +202,7 @@ static bool createMagicMatchRule(const QXmlStreamAttributes &atts,
return true;
}
-bool BaseMimeTypeParser::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)
+bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString *errorMessage)
{
QMimeTypePrivate data;
int priority = 50;
diff --git a/src/mimetypes/mimetypeparser_p.h b/src/mimetypes/qmimetypeparser_p.h
index 165bb8c..af01e16 100644
--- a/src/mimetypes/mimetypeparser_p.h
+++ b/src/mimetypes/qmimetypeparser_p.h
@@ -1,22 +1,44 @@
-/**************************************************************************
+/****************************************************************************
**
-** This file is part of QMime
-**
-** Based on Qt Creator source code
-**
-** Qt Creator Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
+** This file is part of the QtCore module of the Qt Toolkit.
**
+** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
-**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this file.
-** Please review the following information to ensure the GNU Lesser General
-** Public License version 2.1 requirements will be met:
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-**************************************************************************/
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
#ifndef MIMETYPEPARSER_P_H
#define MIMETYPEPARSER_P_H
@@ -28,46 +50,22 @@ QT_BEGIN_NAMESPACE
class QIODevice;
-// XML tags in MIME files
-extern const char *const mimeInfoTagC;
-extern const char *const mimeTypeTagC;
-extern const char *const mimeTypeAttributeC;
-extern const char *const subClassTagC;
-extern const char *const commentTagC;
-extern const char *const genericIconTagC;
-extern const char *const nameAttributeC;
-extern const char *const globTagC;
-extern const char *const aliasTagC;
-extern const char *const patternAttributeC;
-extern const char *const weightAttributeC;
-extern const char *const caseSensitiveAttributeC;
-extern const char *const localeAttributeC;
-
-extern const char *const magicTagC;
-extern const char *const priorityAttributeC;
-
-extern const char *const matchTagC;
-extern const char *const matchValueAttributeC;
-extern const char *const matchTypeAttributeC;
-extern const char *const matchOffsetAttributeC;
-extern const char *const matchMaskAttributeC;
-
-class BaseMimeTypeParser
+class QMimeTypeParserBase
{
- Q_DISABLE_COPY(BaseMimeTypeParser)
+ Q_DISABLE_COPY(QMimeTypeParserBase)
public:
- BaseMimeTypeParser() {}
- virtual ~BaseMimeTypeParser() {}
+ QMimeTypeParserBase() {}
+ virtual ~QMimeTypeParserBase() {}
bool parse(QIODevice *dev, const QString &fileName, QString *errorMessage);
protected:
virtual bool process(const QMimeType &t, QString *errorMessage) = 0;
virtual bool process(const QMimeGlobPattern &t, QString *errorMessage) = 0;
- virtual void processParent(const QString& child, const QString& parent) = 0;
- virtual void processAlias(const QString& alias, const QString& name) = 0;
- virtual void processMagicMatcher(const QMimeMagicRuleMatcher& matcher) = 0;
+ virtual void processParent(const QString &child, const QString &parent) = 0;
+ virtual void processAlias(const QString &alias, const QString &name) = 0;
+ virtual void processMagicMatcher(const QMimeMagicRuleMatcher &matcher) = 0;
private:
enum ParseState {
@@ -90,10 +88,10 @@ private:
};
-class MimeTypeParser : public BaseMimeTypeParser
+class QMimeTypeParser : public QMimeTypeParserBase
{
public:
- explicit MimeTypeParser(QMimeXMLProvider &provider) : m_provider(provider) {}
+ explicit QMimeTypeParser(QMimeXMLProvider &provider) : m_provider(provider) {}
protected:
inline bool process(const QMimeType &t, QString *)
@@ -108,7 +106,7 @@ protected:
inline void processAlias(const QString &alias, const QString &name)
{ m_provider.addAlias(alias, name); }
- inline void processMagicMatcher(const QMimeMagicRuleMatcher& matcher)
+ inline void processMagicMatcher(const QMimeMagicRuleMatcher &matcher)
{ m_provider.addMagicMatcher(matcher); }
private: